Skip to content

fix(cli,vscode): invalidate caches on config update and sync marketplace/settings state - #7235

Closed
markijbema wants to merge 3 commits into
mainfrom
mark/fix-stale-config-after-global-update-pr7179
Closed

fix(cli,vscode): invalidate caches on config update and sync marketplace/settings state#7235
markijbema wants to merge 3 commits into
mainfrom
mark/fix-stale-config-after-global-update-pr7179

Conversation

@markijbema

@markijbema markijbema commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixes stale per-instance config after Config.updateGlobal() — active instances now pick up global config changes (modes, providers, models, etc.) without requiring a server restart
  • Adds State.resetCaches() which clears all cache-only Instance.state entries across all instances without tearing down side-effectful resources
  • Fixes marketplace installed state not updating when removing a mode from the settings panel
  • Fixes newly installed marketplace modes not appearing in Agent Behaviour settings

Problem

PR #7172 correctly removed Instance.disposeAll() from Config.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-instance Config.state (or downstream caches like Agent.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 the global.disposed SSE event, but get back the old values.

Additionally, marketplace install/remove operations only refreshed the agents list but not the config context or marketplace metadata, causing:

  • Settings panel showing stale agent data after marketplace changes
  • Marketplace showing modes as still installed after removal from settings

As noted by the review bot on #7172: comment

Fix

CLI (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:

updateGlobal() writes config to disk
  → global.reset()           // clear global config lazy cache
  → State.resetCaches()      // clear all per-instance derived caches
  → emit "global.disposed"   // SSE to extension
  → extension re-fetches     // HTTP requests hit server
  → Config.state() re-inits  // fresh merge with updated global config
  → Agent.state() re-inits   // fresh agent list
  → UI updates correctly

Extension (refreshAfterMarketplaceChange): After every marketplace install or remove, pushes fresh agents, config, and marketplace metadata to the webview in parallel. Previously only agentsLoaded was sent, leaving the config context stale — so config().agent in the settings view wouldn't reflect the change until the fire-and-forget SSE reloadAfterAuthChange happened to complete.

Extension (handleRemoveMode): Calls refreshAfterMarketplaceChange after removing a mode from the settings panel, so the marketplace view immediately reflects the removal.

@markijbema
markijbema force-pushed the mark/fix-stale-config-after-global-update-pr7179 branch from be77738 to e6e06cb Compare March 18, 2026 11:32
@markijbema markijbema changed the title fix(cli): invalidate per-instance config caches on global config update fix(cli,vscode): invalidate caches on config update and sync marketplace/settings state Mar 18, 2026
kilo-code-bot Bot and others added 3 commits March 18, 2026 16:56
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.
After a marketplace install or remove, only agentsLoaded was pushed to
the webview — the config context stayed stale. If the user then opened
Agent Behaviour settings, config().agent would be missing the new mode.

Introduce refreshAfterMarketplaceChange() that pushes agents, config,
and marketplace metadata in parallel after every install/remove.
@markijbema
markijbema force-pushed the mark/fix-stale-config-after-global-update-pr7179 branch from b6c4ca4 to b68567d Compare March 18, 2026 15:57
* etc. without tearing down side-effectful resources (MCP connections,
* sessions, file watchers, etc.).
*/
export function resetCaches() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks dangerous

@markijbema markijbema closed this Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants