fix(cli): invalidate per-instance config caches on global config update - #7180
Closed
markijbema wants to merge 1 commit into
Closed
fix(cli): invalidate per-instance config caches on global config update#7180markijbema wants to merge 1 commit into
markijbema wants to merge 1 commit into
Conversation
Config.updateGlobal() was only resetting the global lazy cache but not the per-instance State entries (Config.state, Agent.state, Provider.state, etc.). This meant active instances served stale config data — e.g. after changing default provider or model settings via the VS Code settings panel, the server would continue returning the old values until restart. Add State.resetCaches() which clears all cache-only State entries (those without dispose callbacks) across all instances. This invalidates derived state so it gets re-computed on next access, while preserving side-effectful resources like MCP connections, sessions, and file watchers.
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
Config.updateGlobal()— active instances now pick up global config changes (modes, providers, models, etc.) without requiring a server restartState.resetCaches()which clears all cache-onlyInstance.stateentries across all instances without tearing down side-effectful resourcesProblem
PR #7172 correctly removed
Instance.disposeAll()fromConfig.updateGlobal()to stop it from destroying sessions, MCP connections, and in-flight operations on every config change. However, this left a gap:global.reset()only invalidates the process-wide global config lazy cache, not the per-instanceConfig.state(or downstream caches likeAgent.state,Provider.state, etc.) that merge global config at initialization time.This meant that after a global config change via the VS Code settings panel (e.g. changing default agent, provider, or model), the server's HTTP endpoints (
/config,/app/agents,/app/providers) would continue returning stale cached data. The extension would re-fetch after theglobal.disposedSSE event, but get back the old values.As noted by the review bot on #7172: comment
Fix
State.resetCaches()iterates all instance state maps and deletes entries that have no dispose callback. These are the 18 "pure cache" entries (Config, Agent, Provider, Tool, Skill, Command, Format, Plugin, etc.) that are safe to drop and will be re-computed on next access. The 9 entries with dispose callbacks (Prompt sessions, MCP connections, LSP clients, PTY processes, file watchers, etc.) are preserved.The flow after the fix: