Repository navigation
agentHost: refresh plugin state when the runtime reloads contributions - #348606
Merged
Vritant Bhardwaj (vritant24) merged 2 commits intoNov 16, 2026
Merged
Vritant Bhardwaj (vritant24) merged 2 commits into
Vritant Bhardwaj (vritant24) merged 2 commits into
Conversation
Organization and team plugins finish preparing in the background after a session starts. The plugin list was only re-read on managed_plugins_complete, which the runtime does not send after a partial failure or best-effort preparation, so an enabled plugin stayed stale until the chat was reopened. Top-level skills_loaded, mcp_servers_loaded and custom_agents_updated events, which end every runtime plugin reload, now trigger a throttled check that reads plugins.list once and republishes customizations only when the inventory changed. Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The review identifies no active issues with the runtime reload and plugin-state synchronization changes.
No open issues 🎉
What changed in this PR
This PR keeps Agent Host plugin state current when the Copilot runtime reloads contributions, including after partial plugin preparation failures and best-effort team plugin installation.
Changes:
- Forward top-level skill, custom-agent, and MCP-server reload events without treating subagent events as plugin changes.
- Coalesce plugin-state checks, publish only when the inventory changes, and handle reloads received before peer-chat registration.
- Add tests for event filtering, changed and unchanged inventories, burst throttling, and registration timing.
| File | Description |
|---|---|
src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts |
Tests top-level reload signals with MCP skills disabled and excludes subagent events. |
src/vs/platform/agentHost/test/node/copilotAgent.test.ts |
Tests inventory publication, throttling, and peer-chat registration timing; updates session stubs. |
src/vs/platform/agentHost/node/copilot/copilotSessionWrapper.ts |
Exposes the runtime custom-agent update event. |
src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts |
Emits a shared signal for top-level runtime contribution reloads. |
src/vs/platform/agentHost/node/copilot/copilotAgent.ts |
Routes reload signals to throttled plugin checks and preserves signals during registration. |
Review effort: Balanced
…-state-on-skills-loaded # Conflicts: # src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts
Vritant Bhardwaj (vritant24)
enabled auto-merge
November 16, 2026 17:57
Contributor
|
This PR will be automatically cherry-picked to |
roblourens
approved these changes
Nov 16, 2026
Vritant Bhardwaj (vritant24)
deleted the
agents/refresh-plugin-state-on-skills-loaded
branch
November 16, 2026 19:22
Vritant Bhardwaj (vritant24)
added a commit
that referenced
this pull request
Nov 16, 2026
…s contributions (#348660) Cherry-pick of #348606 from `main`. <!-- Thank you for submitting a Pull Request. Please: * Read our Pull Request guidelines: https://github.com/microsoft/vscode/wiki/How-to-Contribute#pull-requests * Associate an issue with the Pull Request. * Ensure that the code is up-to-date with the `main` branch. * Include a description of the proposed changes and how to test them. --> ## Problem The Copilot runtime installs organization-required and team plugins in the background after a session starts. The Agent Host only re-read plugin state on `session.info` `managed_plugins_complete`, which the runtime sends **only when every required plugin succeeds**. After a partial failure (for example, an org policy that requires a plugin that doesn't exist), or on the runtime's best-effort team-default path, nothing tells the UI to refresh. A plugin the runtime enabled then appears out of date until the user switches chats and back. Plugin preparation can finish after the first turn ends, so checking at the end of a turn is too early. ## Change Every runtime plugin reload ends by reloading skills, agents and MCP servers. The top-level `session.skills_loaded`, `session.mcp_servers_loaded` and `session.custom_agents_updated` events are now used as a cue to re-check plugin state: - `CopilotAgentSession` fires a new `onDidReloadRuntimeContributions` event for these top-level events. Subagent events are ignored. It fires whether or not MCP skills are enabled. The existing MCP skills and MCP server inventory handlers are unchanged. - `CopilotSessionWrapper` exposes `onCustomAgentsUpdated`. - `CopilotChatEntry` routes the new event to `SessionPluginController.publishIfRuntimePluginsChanged()`. This is a `Throttler` around the existing `publishWhenSettled(true)`: it reads `plugins.list` once, compares the result with the previous read, and publishes only if something changed. A reload fires several events at once, so they are combined into at most one check running and one waiting. - This is separate from `onDidChangeRuntimePlugins`, which still does the full rediscovery for `managed_plugins_complete`. - If a reload event arrives while a peer chat is still registering, the check runs once registration finishes. The default chat was already covered by the existing check after registration. ## Notes for reviewers - A successful check doesn't log anything. If `plugins.list` keeps failing, the existing warning repeats about once per reload burst. - `mcp_servers_loaded` is re-sent on later turns, so this adds one `plugins.list` call per chat per turn when nothing changed. Nothing is published in that case. - Known gaps: - No SDK event reports hook reloads, so plugins that only add hooks rely on the reload still emitting `skills_loaded`. - The runtime's internal `PluginCachesInvalidated` event would be the ideal signal, but the SDK doesn't expose it. - The change check compares with the last *read* of the plugin list, not the last *publish*. This was already true for existing `publishWhenSettled(true)` callers. ## Testing - `./scripts/test.sh --reporter dot --run src/vs/platform/agentHost/test/node/copilotAgent.test.ts --run src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts`: passed (2838 passing, 1 pending) - New tests check that: - The events trigger only for the main session (not subagents) and with the MCP skills flag off. - A changed enablement republishes. - An unchanged inventory doesn't publish. - A burst of events makes at most 2 `plugins.list` calls. - The check runs before and after a peer chat registers. - The burst test fails when the throttle is removed. - `pnpm run typecheck-client`: passed - `pnpm run oxlint <changed files>`: passed **Manual test:** 1. Use an org policy with a failing required plugin. 2. Open a new chat and send "hi". 3. Expected: after the "could not be prepared" warning, the team plugin shows as enabled without switching chats.
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.
Problem
The Copilot runtime installs organization-required and team plugins in the background after a session starts. The Agent Host only re-read plugin state on
session.infomanaged_plugins_complete, which the runtime sends only when every required plugin succeeds. After a partial failure (for example, an org policy that requires a plugin that doesn't exist), or on the runtime's best-effort team-default path, nothing tells the UI to refresh. A plugin the runtime enabled then appears out of date until the user switches chats and back. Plugin preparation can finish after the first turn ends, so checking at the end of a turn is too early.Change
Every runtime plugin reload ends by reloading skills, agents and MCP servers. The top-level
session.skills_loaded,session.mcp_servers_loadedandsession.custom_agents_updatedevents are now used as a cue to re-check plugin state:CopilotAgentSessionfires a newonDidReloadRuntimeContributionsevent for these top-level events. Subagent events are ignored. It fires whether or not MCP skills are enabled. The existing MCP skills and MCP server inventory handlers are unchanged.CopilotSessionWrapperexposesonCustomAgentsUpdated.CopilotChatEntryroutes the new event toSessionPluginController.publishIfRuntimePluginsChanged(). This is aThrottleraround the existingpublishWhenSettled(true): it readsplugins.listonce, compares the result with the previous read, and publishes only if something changed. A reload fires several events at once, so they are combined into at most one check running and one waiting.onDidChangeRuntimePlugins, which still does the full rediscovery formanaged_plugins_complete.Notes for reviewers
plugins.listkeeps failing, the existing warning repeats about once per reload burst.mcp_servers_loadedis re-sent on later turns, so this adds oneplugins.listcall per chat per turn when nothing changed. Nothing is published in that case.skills_loaded.PluginCachesInvalidatedevent would be the ideal signal, but the SDK doesn't expose it.publishWhenSettled(true)callers.Testing
./scripts/test.sh --reporter dot --run src/vs/platform/agentHost/test/node/copilotAgent.test.ts --run src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts: passed (2838 passing, 1 pending)plugins.listcalls.pnpm run typecheck-client: passedpnpm run oxlint <changed files>: passedManual test: