Skip to content

[cherry-pick] agentHost: refresh plugin state when the runtime reloads contributions - #348660

Merged
Vritant Bhardwaj (vritant24) merged 1 commit into
release/1.147from
cherry-pick/348606
Nov 16, 2026
Merged

Vritant Bhardwaj (vritant24) merged 1 commit into
release/1.147from
cherry-pick/348606

Conversation

@vs-code-engineering

Copy link
Copy Markdown
Contributor

Cherry-pick of #348606 from main.

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.

Copilot AI balanced review requested due to automatic review settings November 16, 2026 19:24
@vs-code-engineering vs-code-engineering Bot added the cherry-pick-artifact Auto-generated cherry-pick PR label Nov 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were reported for the changes that refresh plugin state after runtime contribution reloads.

No open issues 🎉

What changed in this PR

Cherry-picks #348606 to keep Agent Host plugin state current when the Copilot runtime reloads contributions, reducing stale plugin enablement in the UI.

Changes:

  • Uses top-level skill, custom-agent, and MCP-server reload events to trigger plugin-state checks.
  • Coalesces overlapping checks and republishes only when inventory changes, including reloads received before peer-chat registration.
  • Adds tests for event filtering, change detection, burst handling, and registration timing.
File Description
src/​vs/​platform/​agentHost/​test/​node/​copilotAgentSession.test.ts Tests top-level reload signals with MCP skills disabled and subagent events ignored.
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’s custom-agent update event.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgentSession.ts Emits contribution-reload notifications for top-level runtime events.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgent.ts Routes reload notifications to throttled plugin checks and handles pre-registration events.

Review effort: Balanced

@vritant24
Vritant Bhardwaj (vritant24) merged commit d4344e3 into release/1.147 Nov 16, 2026
53 of 54 checks passed
@vritant24
Vritant Bhardwaj (vritant24) deleted the cherry-pick/348606 branch November 16, 2026 20:25
@vs-code-engineering vs-code-engineering Bot added this to the 1.147.0 milestone Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick-artifact Auto-generated cherry-pick PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants