Skip to content

Commit 31cf5bc

Browse files
committed
Cache fallback session ID to maintain consistency when EditorPrefs are unavailable
Store the fallback session ID in a static field instead of generating a new GUID on each call when EditorPrefs are unavailable during batch tests. Clear the cached fallback ID when resetting the session to ensure a fresh ID is generated on the next session.
1 parent e403a82 commit 31cf5bc

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

MCPForUnity/Editor/Helpers/ProjectIdentityUtility.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ internal static class ProjectIdentityUtility
1919
private static bool _legacyKeyCleared;
2020
private static string _cachedProjectName = "Unknown";
2121
private static string _cachedProjectHash = "default";
22+
private static string _fallbackSessionId;
2223
private static bool _cacheScheduled;
2324

2425
static ProjectIdentityUtility()
@@ -171,7 +172,12 @@ public static string GetOrCreateSessionId()
171172
catch
172173
{
173174
// If prefs are unavailable (e.g. during batch tests) fall back to runtime guid.
174-
return Guid.NewGuid().ToString();
175+
if (string.IsNullOrEmpty(_fallbackSessionId))
176+
{
177+
_fallbackSessionId = Guid.NewGuid().ToString();
178+
}
179+
180+
return _fallbackSessionId;
175181
}
176182
}
177183

@@ -196,6 +202,8 @@ public static void ResetSessionId()
196202
EditorPrefs.DeleteKey(SessionPrefKey);
197203
_legacyKeyCleared = true;
198204
}
205+
206+
_fallbackSessionId = null;
199207
}
200208
catch
201209
{

0 commit comments

Comments
 (0)