Skip to content

agentHost: keep credentials and isolation with a moved session's chat; refuse moves across credential owners - #342548

Merged
Sandeep Somavarapu (sandy081) merged 7 commits into
mainfrom
agents/fix-vscode-move-session-bugs
Oct 19, 2026
Merged

Sandeep Somavarapu (sandy081) merged 7 commits into
mainfrom
agents/fix-vscode-move-session-bugs

Conversation

@sandy081

@sandy081 Sandeep Somavarapu (sandy081) commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Fixes two bugs in agent host session moves (moveChat / moveSession), found while reviewing the "Move Chats" feature.

  • F1, credentials: a moved main chat's sponsored credential binding was released with the source session, so a server tool could fail with AuthRequired. The binding now follows the chat on a recorded owner change (onDidChangeChatOwner).
  • F2, isolation: SessionWorkspaceConversionService cleared the isolation markers of a moved main chat when the source ended. Removal now skips a chat that moved away.
  • Fail closed across credential owners: moves between different credential owners (including sponsored ↔ unsponsored, both directions) are refused with the new AgentChatMoveRefusal.DifferentCredentialOwner (differentCredentialOwner) in the shared validation, before anything changes. A promoted session inherits the chat's principal, written to the new session's session.db before the promote commit (a failed write refuses the promote with nothing changed; a failed commit leaves a harmless orphan session.db). Unsponsored sessions can't gain a principal while a move into/out of them is committing. A mismatch that gets through anyway drops the chat's sponsored bindings and never falls back to the ambient token. An agentMerge-only binding counts as sponsored.

Client mapping (not on main yet; branches adding refusal maps must map differentCredentialOwner):

  • UI: "This chat uses a different account's credentials than the destination session."
  • Model: "Sessions with different credential owners can't be combined; pick a destination that uses the same account, or move it to its own session."

How to test (all passed):

  • ./scripts/test.sh --run src/vs/platform/agentHost/test/node/agentService.test.ts — 1185 passing, 16 pending
  • ./scripts/test.sh --run src/vs/platform/agentHost/test/node/sessionWorkspaceConversion.test.ts — 120 passing, 1 pending
  • ./scripts/test.sh --run src/vs/platform/agentHost/test/node/agentHostAuthenticationScope.test.ts — 22 passing
  • ./scripts/test.sh --run src/vs/platform/agentHost/test/node/agentHostSessionStateStore.test.ts — 80 passing
  • npm run typecheck-client — passed
  • npm run eslint -- <changed files> and the commit hygiene hook — passed

Fail-first (each test run with its fix reverted, then restored):

  • AgentHostAuthenticationService … a chat without a recorded credential owner follows its session when it moves, and keeps the principal after the source is released — failed: AssertionError: Expected values to be strictly deep-equal: + principal: undefined, + target: undefined - principal: { apiOrigin: 'https://api.github.com', userId: '1' }
  • credential owners … a persisted principal is restored for a session a move holds, while binding a new one is refused — failed: + restored: 'undefined' - restored: 'allowed' (new restorePersistedCredentialPrincipal)
  • Earlier rounds: the credential-owner refusal, same-owner move, promote restart/downgrade, persist-failure and upgrade tests each failed on their assertions without their fix (e.g. upgrade (a): resolved ambient).

…s chat

Moving a session under another one ends the source. Its credential binding
(_credentialOwners) and the workspace-conversion isolation markers were still
keyed to the source, so removing it dropped them for the moved chat. Both now
follow onDidChangeChatOwner.

Co-authored-by: Copilot <[email protected]>
Moving a chat or session between sessions whose credential principals differ
(including sponsored and unsponsored) is refused with differentCredentialOwner
before anything changes. Same-principal moves re-key the chat's credential
binding to its new owner; a promoted chat's new session inherits its principal.

Co-authored-by: Copilot <[email protected]>
A promoted session persists its inherited credential principal, so a restart
never falls back to the ambient token. Sessions of a move or promotion are
held so an unsponsored one can't gain a principal while the move commits.
A chat that changes owner across different credential owners anyway loses its
sponsored bindings and resolves under its new owner instead of throwing.

Co-authored-by: Copilot <[email protected]>
… the promotion

The new session's principal is part of the promote commit's values (a central session value restored through the state store), so a restart never falls back to the ambient token. The target is held during promotion, and a failed in-memory step moves the chat's credentials fail-closed.

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 19, 2026 13:50
@sandy081 Sandeep Somavarapu (sandy081) added this to the 1.144.0 milestone Oct 19, 2026
@sandy081
Sandeep Somavarapu (sandy081) marked this pull request as draft October 19, 2026 13:53
auto-merge was automatically disabled October 19, 2026 13:53

Pull request was converted to draft

…owngrade

Restoring the principal now falls back to session.db when central state lacks it (sessions imported before the key was registered), and a promoted session's principal is also written to its session.db for older builds.

Co-authored-by: Copilot <[email protected]>
@sandy081
Sandeep Somavarapu (sandy081) marked this pull request as ready for review October 19, 2026 13:55

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.

🟡 Changes recommended

Upgrade restoration and promotion of unmapped peers can lose credential-owner enforcement and allow ambient credential fallback.

1 open issue
What changed in this PR

Preserves chat credentials and isolation during Agent Host moves, and rejects moves between different credential owners.

Changes:

  • Transfers credential and isolation ownership with moved chats.
  • Adds credential-owner validation and atomic principal persistence for promotions.
  • Adds regression tests and documents move guarantees.
File Description
src/​vs/​platform/​agentHost/​test/​node/​sessionWorkspaceConversion.test.ts Tests isolation retention after moves.
src/​vs/​platform/​agentHost/​test/​node/​agentService.test.ts Tests credential transfer, refusals, promotion, and restart behavior.
src/​vs/​platform/​agentHost/​node/​chatContributions/​sessionWorkspaceConversion/​sessionWorkspaceConversionService.ts Preserves moved chats’ isolation state.
src/​vs/​platform/​agentHost/​node/​agentService.ts Integrates credential validation, transfer, and persistence.
src/​vs/​platform/​agentHost/​node/​agentHostSessionStateMirror.ts Registers the credential principal as central state.
src/​vs/​platform/​agentHost/​node/​agentHostAuthenticationService.ts Adds credential-owner comparison, holds, and transfer.
src/​vs/​platform/​agentHost/​common/​agentHostChatMove.ts Adds the credential-owner mismatch refusal.
src/​vs/​platform/​agentHost/​AGENTS.md Documents credential guarantees for moves.

Review effort: Balanced

@sandy081
Sandeep Somavarapu (sandy081) marked this pull request as draft October 19, 2026 14:17
…sion.db before the promotion commits

The principal stays in session.db only, as older builds read it, instead of being a central session value. A promotion writes it to the new session's database before the commit, so a committed promotion always has it on disk and a failed write refuses the promotion with nothing changed.

Co-authored-by: Copilot <[email protected]>
…owner

Read the promoted principal from the source session and seed an unmapped chat's credential owner from the previous owner, so a restored sponsored session never falls back to the ambient token. Restoring an already persisted principal is no longer blocked by a move hold; only binding a new one is.

Co-authored-by: Copilot <[email protected]>
@sandy081
Sandeep Somavarapu (sandy081) marked this pull request as ready for review October 19, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants