Repository navigation
agentHost: bind SDK customization operations to the verified policy session - #342613
Merged
Vritant Bhardwaj (vritant24) merged 3 commits intoOct 19, 2026
Merged
Vritant Bhardwaj (vritant24) merged 3 commits into
Vritant Bhardwaj (vritant24) merged 3 commits into
Conversation
…ession While a Copilot chat was open, the customization marketplace failed to load installation receipts and the renderer logged, many times per second: Unable to load session-bound SDK installation receipts The SDK could not list installed MCP servers. (refused: policy-context-unavailable) Root cause: CopilotCustomizationInstallations preferred the visible chat's SDK session as `policySessionId` for list, recover, search, and install/uninstall planning, and 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; see mcp_installation `authority()` -> `installation_account_fingerprint()`). A credential supplied at createSession (`gitHubToken`/`gitHubTokenProvider`) is never verified. Only `session.rpc.gitHubAuth.setCredentials` verifies it. #341648 added that call to the hidden policy session, but chat sessions get it only when the token changes while they are live. Chats created after the last token change, and provider-backed chats, were never verified, so every request bound to them was refused. Fix: always use the hidden, credential-verified policy session (`getOrCreatePolicySessionId`) for catalog search, inventory, recovery, and install/uninstall planning. None of these operations needs the chat's identity: - Installation receipts are scoped by the runtime's Copilot home plus the account and host fingerprints, not by session or working directory. - The hidden session enables the same catalog-installation feature flags and managed settings as chat sessions. - The client-level `installationConfirmationHandler` matches on the `policySessionId` that planned the operation. Plan and apply now always use the same hidden session, so confirmation matching is unchanged. - Catalog cursors and selections stay keyed by `policySessionId`. They are now invalidated when the hidden session is replaced (auth change, client restart, idle disposal) rather than when switching between chats. Replacement goes through the existing re-search recovery path. The visible-session getter and the no-factory path ("Start a Copilot agent session before managing SDK installations." / `unavailable: session`) are removed. The only production construction (CopilotAgent) always provides the hidden-session factory, so that path was reachable only from tests. The factory is now required. `releasePolicySession` behavior and the 10-minute idle disposal are unchanged. Co-authored-by: Copilot <[email protected]>
…aced Install and uninstall reviews now always plan in the hidden policy session. A token change, telemetry revocation, or the 10-minute idle timeout deletes that session while the client stays the same. `apply` checked only the client, so confirming a review after one of these events sent the SDK apply call to a deleted session and surfaced a raw SDK error. Pending operations now record the policy session they were planned in, or no session for the configuration-only MCP add/remove paths, which do not use one. `apply` rejects a session-bound operation when the current hidden session differs, using the existing localized "Start the operation again." error. Configuration-only operations still apply. Co-authored-by: Copilot <[email protected]>
Contributor
|
This PR will be automatically cherry-picked to |
Contributor
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
1 open issue
What changed in this PR
Binds SDK customization marketplace/inventory/recovery/installation operations to a single hidden, credential-verified policy session to prevent policy-context-unavailable refusals while chats are open.
Changes:
- Route search/list/recover/prepare through
getOrCreatePolicySessionId(hidden policy session) instead of using a visible chat session. - Update
CopilotAgentto ignore the caller’s session for customization operations while keeping the public interface stable. - Update docs and tests to reflect the hidden-session-only policy binding and to validate verified-credential behavior.
| File | Description |
|---|---|
| src/vs/sessions/AI_CUSTOMIZATIONS.md | Documents hidden, verified policy session usage for customization operations. |
| src/vs/platform/agentHost/node/copilot/customizations/copilotCustomizationInstallations.ts | Makes policy session factory required; removes visible-session path and binds operations to hidden session. |
| src/vs/platform/agentHost/node/copilot/copilotAgent.ts | Stops passing visible chat session IDs; forwards customization calls to hidden-session-bound service. |
| src/vs/platform/agentHost/test/node/copilotCustomizationInstallations.test.ts | Updates tests for new APIs and adds coverage ensuring all operations bind to the same hidden session. |
| src/vs/platform/agentHost/test/node/copilotAgent.test.ts | Adds regression test ensuring inventory uses hidden verified policy session even with a live chat. |
Review effort: Lite
…ssions Chat sessions can receive gitHubAuth.setCredentials when a token changes while they are live, so they are not guaranteed to be unverified; they are just not guaranteed to be verified. Co-authored-by: Copilot <[email protected]>
Vritant Bhardwaj (vritant24)
enabled auto-merge
October 19, 2026 17:59
Alexandru Dima (alexdima)
approved these changes
Oct 19, 2026
Vritant Bhardwaj (vritant24)
deleted the
agents/fix-copilot-sdk-policy-session-issue
branch
October 19, 2026 18:22
Vritant Bhardwaj (vritant24)
added a commit
that referenced
this pull request
Oct 19, 2026
…ified policy session (#342629) Cherry-pick of #342613 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 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`).
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
While a Copilot chat is open, the customization marketplace can't load installation receipts. The renderer logs this many times per second:
Root cause
CopilotCustomizationInstallationsused the open chat's SDK session aspolicySessionIdforlist,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_installationauthority()→installation_account_fingerprint()). A credential passed atcreateSession(gitHubToken/gitHubTokenProvider) is never verified. Onlysession.rpc.gitHubAuth.setCredentialsverifies it. A standalone SDK repro against runtimes 1.0.92-0 through 1.0.100-1 showedrefused: policy-context-unavailablewith the createSession token, even after a chat turn, andlistedright aftersetCredentialson the same session.#341648 added
setCredentialsto 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:installationConfirmationHandlermatches on thepolicySessionIdthat planned the operation. Plan and apply now always use the same hidden session, so matching is unchanged.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.releasePolicySessionand the 10-minute idle disposal are unchanged.AI_CUSTOMIZATIONS.mdis updated.Tests
copilotCustomizationInstallations.test.ts: tests that relied on a fixed chat session ID now use aTestPolicySessionshelper 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 thatlistCustomizationInstallationsgoes to the hidden session, which receivedsetCredentials, and not to the chat's session.Validation
npm run typecheck-client: passednpm 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 isisolates peer runtimes, preserves local adoption identity and refuses revoked prepared work, which also fails on unmodifiedmain(e1a22a1ad40).