Skip to content

agentHost: bind SDK customization operations to the verified policy session - #342613

Merged
Vritant Bhardwaj (vritant24) merged 3 commits into
mainfrom
agents/fix-copilot-sdk-policy-session-issue
Oct 19, 2026
Merged

Vritant Bhardwaj (vritant24) merged 3 commits into
mainfrom
agents/fix-copilot-sdk-policy-session-issue

Conversation

@vritant24

Copy link
Copy Markdown
Member

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).

…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]>
Copilot AI balanced review requested due to automatic review settings October 19, 2026 17:29
…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]>
@vritant24 Vritant Bhardwaj (vritant24) added the ~release-cherry-pick Trigger: cherry-pick this PR to the latest release branch label Oct 19, 2026
@vs-code-engineering

Copy link
Copy Markdown
Contributor

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

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.

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 CopilotAgent to 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]>
@vritant24
Vritant Bhardwaj (vritant24) merged commit 4d22f4f into main Oct 19, 2026
49 checks passed
@vritant24
Vritant Bhardwaj (vritant24) deleted the agents/fix-copilot-sdk-policy-session-issue branch October 19, 2026 18:22
@vs-code-engineering vs-code-engineering Bot added this to the 1.143.0 milestone Oct 19, 2026
@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 Oct 19, 2026
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`).
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