Skip to content

agentHost: refresh plugin state when the runtime reloads contributions - #348606

Merged
Vritant Bhardwaj (vritant24) merged 2 commits into
mainfrom
agents/refresh-plugin-state-on-skills-loaded
Nov 16, 2026
Merged

Vritant Bhardwaj (vritant24) merged 2 commits into
mainfrom
agents/refresh-plugin-state-on-skills-loaded

Conversation

@vritant24

Copy link
Copy Markdown
Member

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.

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]>
Copilot AI balanced review requested due to automatic review settings November 16, 2026 17:41
@vritant24 Vritant Bhardwaj (vritant24) added the ~release-cherry-pick Trigger: cherry-pick this PR to the latest release branch 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

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
@vs-code-engineering

Copy link
Copy Markdown
Contributor

This PR will be automatically cherry-picked to release/1.147 when merged.

@vritant24
Vritant Bhardwaj (vritant24) added this pull request to the merge queue Nov 16, 2026
Merged via the queue into main with commit a3d7ede Nov 16, 2026
37 of 38 checks passed
@vritant24
Vritant Bhardwaj (vritant24) deleted the agents/refresh-plugin-state-on-skills-loaded branch November 16, 2026 19:22
@vs-code-engineering vs-code-engineering Bot added release-cherry-pick Automated cherry-pick between release and main branches and removed ~release-cherry-pick Trigger: cherry-pick this PR to the latest release branch labels Nov 16, 2026
@vs-code-engineering vs-code-engineering Bot added this to the 1.147.0 milestone Nov 16, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-cherry-pick Automated cherry-pick between release and main branches

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants