{{ message }}
Repository navigation
Commit c53625e
authored
[cherry-pick] agentHost: bind SDK customization operations to the verified 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`).5 files changed
Lines changed: 353 additions & 98 deletions
File tree
- src/vs
- platform/agentHost
- node/copilot
- customizations
- test/node
- sessions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
158 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
159 | 164 | | |
160 | 165 | | |
161 | 166 | | |
| |||
186 | 191 | | |
187 | 192 | | |
188 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
189 | 203 | | |
190 | 204 | | |
191 | | - | |
192 | | - | |
| 205 | + | |
193 | 206 | | |
194 | 207 | | |
195 | 208 | | |
196 | 209 | | |
197 | | - | |
| 210 | + | |
198 | 211 | | |
199 | 212 | | |
200 | 213 | | |
201 | 214 | | |
202 | 215 | | |
203 | 216 | | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | 217 | | |
209 | | - | |
| 218 | + | |
210 | 219 | | |
211 | 220 | | |
212 | 221 | | |
| |||
291 | 300 | | |
292 | 301 | | |
293 | 302 | | |
294 | | - | |
295 | | - | |
| 303 | + | |
296 | 304 | | |
297 | | - | |
| 305 | + | |
298 | 306 | | |
299 | 307 | | |
300 | 308 | | |
| |||
314 | 322 | | |
315 | 323 | | |
316 | 324 | | |
317 | | - | |
318 | | - | |
| 325 | + | |
319 | 326 | | |
320 | | - | |
| 327 | + | |
321 | 328 | | |
322 | 329 | | |
323 | 330 | | |
| |||
336 | 343 | | |
337 | 344 | | |
338 | 345 | | |
339 | | - | |
340 | | - | |
| 346 | + | |
341 | 347 | | |
342 | | - | |
| 348 | + | |
343 | 349 | | |
344 | 350 | | |
345 | 351 | | |
| |||
350 | 356 | | |
351 | 357 | | |
352 | 358 | | |
353 | | - | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
354 | 363 | | |
355 | 364 | | |
356 | 365 | | |
| |||
513 | 522 | | |
514 | 523 | | |
515 | 524 | | |
516 | | - | |
| 525 | + | |
517 | 526 | | |
518 | 527 | | |
519 | 528 | | |
| |||
573 | 582 | | |
574 | 583 | | |
575 | 584 | | |
576 | | - | |
577 | 585 | | |
578 | 586 | | |
579 | 587 | | |
| |||
607 | 615 | | |
608 | 616 | | |
609 | 617 | | |
610 | | - | |
| 618 | + | |
611 | 619 | | |
612 | 620 | | |
613 | 621 | | |
| |||
634 | 642 | | |
635 | 643 | | |
636 | 644 | | |
637 | | - | |
| 645 | + | |
638 | 646 | | |
639 | 647 | | |
640 | 648 | | |
| |||
712 | 720 | | |
713 | 721 | | |
714 | 722 | | |
715 | | - | |
| 723 | + | |
716 | 724 | | |
717 | 725 | | |
718 | 726 | | |
| |||
730 | 738 | | |
731 | 739 | | |
732 | 740 | | |
733 | | - | |
| 741 | + | |
734 | 742 | | |
735 | 743 | | |
736 | 744 | | |
| |||
909 | 917 | | |
910 | 918 | | |
911 | 919 | | |
912 | | - | |
913 | | - | |
914 | | - | |
915 | | - | |
916 | | - | |
917 | | - | |
918 | | - | |
919 | | - | |
920 | | - | |
921 | | - | |
922 | | - | |
923 | 920 | | |
924 | 921 | | |
925 | 922 | | |
| |||
934 | 931 | | |
935 | 932 | | |
936 | 933 | | |
937 | | - | |
| 934 | + | |
938 | 935 | | |
939 | 936 | | |
940 | 937 | | |
| |||

0 commit comments