Skip to content

[cherry-pick] agentHost: bind SDK customization operations to the verified policy session - #342629

Merged
Vritant Bhardwaj (vritant24) merged 1 commit into
release/1.143from
cherry-pick/342613
Oct 19, 2026
Merged

Vritant Bhardwaj (vritant24) merged 1 commit into
release/1.143from
cherry-pick/342613

Conversation

@vs-code-engineering

Copy link
Copy Markdown
Contributor

Cherry-pick of #342613 from main.

Problem

While a Copilot chat is open, the customization marketplace can't load installation receipts. The renderer logs this many times per second:

[AgentHostCustomizationMarketplace] Unable to load session-bound SDK installation receipts The SDK could not list installed MCP servers. (refused: policy-context-unavailable)

Root cause

CopilotCustomizationInstallations used the open chat's SDK session as policySessionId for list, recover, search, and install/uninstall planning. It used the hidden policy session only when no chat was open.

The Copilot runtime admits installation and inventory requests only when the policy session's GitHub credential is verified: a github.com login backed by a resolved Copilot user record (mcp_installation authority() → installation_account_fingerprint()). A credential passed at createSession (gitHubToken / gitHubTokenProvider) is never verified. Only session.rpc.gitHubAuth.setCredentials verifies it. A standalone SDK repro against runtimes 1.0.92-0 through 1.0.100-1 showed refused: policy-context-unavailable with the createSession token, even after a chat turn, and listed right after setCredentials on the same session.

#341648 added setCredentials to the hidden policy session. Chat sessions get it only when the token changes while they're live. Chats created after the last token change, and provider-backed chats, are never verified.

Fix

Search, inventory, recovery, and install/uninstall planning now always use the hidden policy session (getOrCreatePolicySessionId). None of these operations needs the chat's identity:

  • Receipts: the runtime scopes them by Copilot home plus account and host fingerprints, not by session or working directory, so results are the same.
  • Feature flags and managed settings: the hidden session has the same catalog-installation feature flags and managed settings as chat sessions.
  • Confirmation: the client-level installationConfirmationHandler matches on the policySessionId that planned the operation. Plan and apply now always use the same hidden session, so matching is unchanged.
  • Cursors and selections: they stay keyed by policySessionId. They're now invalidated when the hidden session is replaced (auth change, client restart, idle disposal) rather than when you switch chats. The existing re-search recovery path handles that.

The visible-session getter and the no-factory path are removed. That path produced "Start a Copilot agent session before managing SDK installations." and unavailable: session. The only production caller (CopilotAgent) always provides the hidden-session factory, so only tests could reach it. The factory is now required. releasePolicySession and the 10-minute idle disposal are unchanged. AI_CUSTOMIZATIONS.md is updated.

Tests

  • copilotCustomizationInstallations.test.ts: tests that relied on a fixed chat session ID now use a TestPolicySessions helper that records created sessions. A new test checks that search, list, recover, and prepare all bind to one hidden session.
  • copilotAgent.test.ts: a new test opens a live chat and checks that listCustomizationInstallations goes to the hidden session, which received setCredentials, and not to the chat's session.

Validation

  • npm run typecheck-client: passed
  • npm run eslint -- <changed files>: passed
  • ./scripts/test.sh --run src/vs/platform/agentHost/test/node/copilotCustomizationInstallations.test.ts --run src/vs/platform/agentHost/test/node/copilotSessionLauncher.test.ts --run src/vs/platform/agentHost/test/node/copilotAgent.test.ts: 1012 passing, 1 pending, 1 failing. The failure is isolates peer runtimes, preserves local adoption identity and refuses revoked prepared work, which also fails on unmodified main (e1a22a1ad40).

Copilot AI balanced review requested due to automatic review settings October 19, 2026 18:23
@vs-code-engineering vs-code-engineering Bot added the cherry-pick-artifact Auto-generated cherry-pick PR label Oct 19, 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 blocking issues remain; focused regression coverage supports the change, and the reported test failure also occurs on unmodified main.

No open issues 🎉

What changed in this PR

Cherry-picks #342613 to fix customization marketplace failures by using the verified hidden policy session, even while a chat is open.

Changes:

  • Routes SDK customization operations through the hidden session.
  • Rejects pending SDK operations when their policy session is replaced.
  • Updates regression tests and lifecycle documentation.
File Description
src/​vs/​sessions/​AI_CUSTOMIZATIONS.md Documents hidden-session binding and invalidation.
src/​vs/​platform/​agentHost/​test/​node/​copilotCustomizationInstallations.test.ts Tests session reuse and stale-operation rejection.
src/​vs/​platform/​agentHost/​test/​node/​copilotAgent.test.ts Tests verified hidden-session inventory with a live chat.
src/​vs/​platform/​agentHost/​node/​copilot/​customizations/​copilotCustomizationInstallations.ts Enforces hidden-session binding and validates pending operations.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgent.ts Removes visible-chat routing from customization calls.

Review effort: Balanced

@vritant24
Vritant Bhardwaj (vritant24) merged commit c53625e into release/1.143 Oct 19, 2026
50 checks passed
@vritant24
Vritant Bhardwaj (vritant24) deleted the cherry-pick/342613 branch October 19, 2026 19:13
@vs-code-engineering vs-code-engineering Bot added this to the 1.143.0 milestone Oct 19, 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