fix: stabilize LocalToken so client configs never go stale (401)#898
Merged
Conversation
SetDefault() seeded the generated local server token into CloudToken instead of LocalToken: it assigns via the mode-routed `Token` setter AFTER setting ConnectionMode=Cloud, so `Token = GenerateToken()` routed the local secret into CloudToken and left LocalToken unseeded. LocalToken initialization then fell to the generate-if-empty fallback in GetOrCreateConfig, letting the persisted local token drift/regenerate and orphan the already-written client `.mcp.json` (stale Bearer -> Claude Code 401; mcp-authorize BUG-B). Seed LocalToken directly in SetDefault() (GenerateToken() produces a local server secret; CloudToken is populated by Cloud sign-in, so it stays null). A persisted LocalToken is now stable across construction, mode re-apply, and a serialize/deserialize (domain reload / save-load) round-trip, so the server launch token and the client-config Bearer stay in lockstep. Add LocalTokenStabilityTests (EditMode) locking the seeding invariant and the three stability properties. The intentional-token-change path (New button) is unchanged and already re-evaluates the reconfigure alert via InvalidateAndReloadAgentUI -> GetStatus (sibling task i1's token-aware validator). Closes #897
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tokenmode the client.mcp.jsonended up with a DIFFERENT token than the running local server → Claude Code 401.UnityConnectionConfig.SetDefault()assigns the freshly-generated local server token through the mode-routedTokensetter after settingConnectionMode = Cloud. SoToken = GenerateToken()routed the local secret intoCloudTokenand leftLocalTokenunseeded.LocalTokeninitialization then fell entirely to the generate-if-empty fallback inGetOrCreateConfig, which let the persisted local token drift / regenerate and orphan the already-written client.mcp.json(staleBearer→ 401).LocalTokendirectly inSetDefault()(GenerateToken()produces a local server secret;CloudTokenis populated by Cloud sign-in, so it now correctly staysnull). A persistedLocalTokenis stable across construction, mode re-apply, and a serialize/deserialize (domain reload / save-load) round-trip, so the server launch token (McpServerManager→UnityMcpPluginEditor.Token) and the client-configBearer(AgentConfiguratorSettingsFactory→UnityMcpPluginEditor.Token) stay in lockstep.InvalidateAndReloadAgentUI()→ re-evaluates_configurator.GetStatus(...) == ReconfigureNeededand shows the "Reconfiguration Required" alert (driven by sibling task i1's token-aware validator). No new plumbing needed here.Test plan
LocalTokenStabilityTests(EditMode) — 5 tests, all pass:SetDefaultseedsLocalTokennotCloudToken;LocalTokenstable across mode re-apply; survives save/load round-trip; round-trip leaves it non-empty (generate-if-empty stays a no-op); serializes under thetokenJSON field.TestsRunDirtySceneTests, cannot run through the MCPtests-runtool (it mutatesTool_Tests' active-run bookkeeping, self-interfering with the tool's completion detection) and is validated by CI's direct Unity Test Runner instead — unrelated to this diff.Closes #897