Skip to content

Agent host: move chats between sessions and promote a chat to its own session (Move Chats, Block 4) - #341788

Merged
Sandeep Somavarapu (sandy081) merged 48 commits into
mainfrom
agents/move-chats-feature-block4-design
Oct 16, 2026
Merged

Sandeep Somavarapu (sandy081) merged 48 commits into
mainfrom
agents/move-chats-feature-block4-design

Conversation

@sandy081

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

Copy link
Copy Markdown
Member

Summary

Block 4 of Move Chats: the agent host can move chats between sessions, and promote a chat to its own session, live, while a turn is running. It builds on Block 3a (central chat catalog), Block 3b (#341714, per-chat config), Block 3c (#341734, owner-split provider seam) and Block 4a (#341904, older-build reconciliation), all merged. The UI actions come in Block 5; this PR adds the host operations and what existing clients need to follow a move.

Everything is behind the setting chat.agentHost.moveChats.enabled (mirrored into the host root config chatMoves.enabled), default off. With it off, no chat is published as movable, moveChat is refused with disabled, and vscode/moveSession is neither advertised nor handled.

What Block 4 adds

  • AHP moveChat (the stub in protocolServerHandler.ts is replaced):

    • a reorder within the session;
    • a move to another session of the same agent, with an optional after anchor;
    • promotion to a new session (newSession).

    The chat moves together with its host-managed descendants (subagents, found by their recorded parent chain). Chat URIs, ChatOrigin and the chat's own database stay unchanged; ownership is re-pointed. ChatSummary.movable is published and recomputed when it changes.

  • VS Code-internal vscode/moveSession (capability vscode.sessionMove, session _meta['vscode.movable']): moves a session whose default chat is its only chat under another session. AHP says the default chat is never movable, so this is a separate, gated session-level operation rather than a protocol change. The session's chat becomes a peer of the destination and keeps its data (the ended session's session.db becomes that chat's storage). The source session is tombstoned in the same transaction.

  • Data (3a model):

    • catalog entries and per-chat central rows are carried to the destination in one transaction, guarded by a revision check;
    • v1 sessions are normalized first;
    • checkpoints (chat-only refs) are untouched;
    • nothing is written for older builds;
    • promotion initializes the new session's central state and marks it imported.
  • Config (3b):

    • a moved chat takes its source's effective chatMutable values as its own, written before the commit;
    • a promoted session starts from the source's config with the chat's own values on top;
    • neither path goes through D1 seeding.
  • Live moves (3c late-bound owner):

    • one serialized host operation, with no running-turn event between "removed from A" and "added to B";
    • queued turns are held until the commit and then start under the destination;
    • the provider runtime relaunches at the next turn boundary;
    • after the move:
      • the PTY terminal claims move to the destination;
      • client-tool completions are routed only to the chat's own runtime;
      • content access resolves through the chat's recorded storage;
      • both sessions' summaries and customizations are republished;
      • Mission Control retires a moved default chat's stream (see the caveat below).
  • Restore follows the recorded chat order (chats_v2.chat_order), so a chat moved or reordered before the default chat stays there after a restart.

  • Clients:

    • clients without vscode.ahpChatUris see a chat only in the session it was created in;
    • the Agents window keeps a moved chat's editor and subscription as it appears in the destination (AgentHostChatMoveTracker, required ISessionsProvider.onDidMoveChat, with a polite screen-reader announcement);
    • ISessionsProvider gains canMoveSessionUnder / moveSessionUnder for Block 5.
  • Attachment migration after a move (Block 4b). After a move, a background job copies the files the moved chat's messages attached in its origin (their recorded snapshot URIs, never the whole folder) into its own storage under the same relative paths. It writes through a temporary file and skips files already copied. It records its progress in agent-host.db (metadata, no migration), so a restart resumes it once the chat's session is restored. It runs 8 files per step and yields in between. A host read of a copied file the origin no longer has, for example because an older build deleted it, reads the copy. The origin still keeps its attachments while any moved chat lives, because provider-native tools read the original paths; releasing on completion is implemented but switched off (RELEASE_COPIED_ATTACHMENT_ORIGINS).

  • Docs: src/vs/platform/agentHost/AGENTS.md §3c "Moving Chats"; a paragraph in AGENT_HOST_SESSIONS_PROVIDER.md.

Integration with Block 4a (older builds)

Every move, session move, promotion and reorder follows 4a's contract for writes that re-project normalized catalogs (agentHostChatCatalogV2.md):

  • Before validating: for every session it changes, it waits for that session's in-flight peer-store writes (whenSessionsIdle), converts a legacy catalog to normalized authority, and imports what older builds changed (reconcileOlderBuildCopy).
  • In the transaction: guardOlderBuildEdits refuses an older build's edit of any chat list the write re-projects: both sessions of a move or session move, the source of a promotion, the session of a reorder. Nothing is written; the edit is imported and the write tried once more. Each write records the projection it writes (projected_revision).
  • After commit: it schedules the older-build copy of the sessions it changed (AgentHostPeerChatStore.scheduleOlderBuildCopyPublish), so older builds see a moved chat where it is now, and its source records it as left for 4a's neutralizing import.
  • Retry: a retried write re-reads the source's chats and folders after the import, so a chat an older build added on the moving chat's folder keeps that folder's Git state. A reorder re-checks its anchor after the import.

Folders of a moving chat (#341885)

Main's #341885 reserves the folders of chats being created or moved, so archiving or deleting a chat doesn't detach them before the chat is published. Moves use it:

  • the folders a moving chat brings are reserved in the destination until the destination lists the chat; a refused move ends the reservation before it removes the folders it added;
  • the folders a move prepares in the destination are consumed once the chat lands, so they count as in use rather than reserved; archiving or deleting the moved chat there detaches them;
  • like a deleted chat, a chat that moved out (peer move or promotion) leaves its source no folder that no remaining chat uses. The folders' Git and GitHub state already went with the chat. A session move ends its source.

Refusals

A refused move changes nothing. Requests are validated, re-validated after every await and once more right before the commit. The typed reason (AgentChatMoveRefusal) is returned in the protocol error's data.reason:

Reason When
disabled the setting is off
notMovable the chat isn't movable, e.g. a default chat or a subagent
destinationNotFound a missing or invisible session, or a session moved under itself
invalidAnchor the after anchor isn't a visible chat of the destination
differentProvider the destination belongs to another agent
sessionArchived either session is archived
sessionNotReady either session isn't ready (not ready, provisional, being disposed)
sessionQuarantined either session is changing its workspace or can't run turns
conversionInProgress the chat is mid workspace conversion
worktreeFolder the chat works in one of the source's worktrees, or, for vscode/moveSession, the source records any worktree (#6 records a worktree removal only when a session is deleted)
workspaceless a scratch or managed folder, or a chat without a folder
agentMergeOwner Agent Merge owners, including a session-level Agent Merge for vscode/moveSession
destinationSingleFolder the destination is limited to a single folder
legacyCatalog a session whose chat catalog Block 4a can't convert yet (its provider can't vouch for its chats, or its conversion is parked). Every other session is converted before the move. The database also refuses a stored legacy catalog in the same transaction as the revision check, never by the address.
conflict a concurrent change
unsupported the host doesn't support the move
notSingleChat vscode/moveSession on a session with other chats
notStarted promotion of a chat that has no turn yet and none running: no agent persists a conversation before the first turn, so the new session couldn't be restored (like a brand-new session, which is durable only after its first send)

The chat's folder is added to the destination's folders when it isn't already one of them.

Behaviour notes

  • Session move. A session moved under another session ends. Its chat becomes an ordinary peer there and, like every peer, follows the destination's session-level state: customization enablement and non-chatMutable config. Only its chatMutable values carry over. Promotion differs because its destination is a new session, which starts from the source's.
  • Client-sent turns are not held. Only queued turns wait for a move to commit. A turn a client sends directly starts in the source and then moves live with the chat.
  • Telemetry of an in-flight moved tool call. The tool-call and input-request telemetry trackers record the owner at start. If the source session is removed mid-call, its clean-up drops the moved chat's in-flight entries, so their completion telemetry is lost. Accepted as LOW.
  • Attachments.
    • A chat's attachments are snapshotted under its recorded storage, so a peer's attachments move and are deleted with it.
    • Pre-move attachments are copied into the chat's own storage (Block 4b). A deleted origin keeps its attachments/ while a chat that moved out of it lives, also once the copy is complete; the reference is recorded once and survives restarts.
    • A chat moved with its session already stores in the origin and keeps counting as a reference.
    • A chat's copy record (chatAttachmentCopy:<chat>) is deleted with the chat in the same transaction, for every way a chat is deleted. A copy still running when its chat is deleted stops and records nothing, and a restart resumes no copy for a deleted chat (live finding B4-2). A chat merely unloaded mid-copy resumes once it is restored.
    • Host reads fall back to the copy. Provider-native tools still read the original path baked into the SDK history; only an older build's deletion of the origin removes it, after which a model re-read of a pre-move path fails (the contents were inlined when sent).
  • Older clients, by origin. Clients without vscode.ahpChatUris see a chat only in the session it was created in. If the moved-chat origins can't be read, the host retries once, then hides conservatively.
  • Promoted sessions on disk. A promoted session is addressed natively on disk (ahp-session:/<uuid>, no compat identity), which differs from agentHost: preserve writable session downgrade compatibility #340980's allocation rule because promotion bypasses prepareSessionStorage. The allocation is isolated in _allocatePromotedSession so switching to a compat identity is a small change; Block 4a plans it.
  • Promoted session title. A promoted session is titled by its chat, keeping the chat's title source (user, agent or auto). The title is persisted through the ordered list-visible state write: the session's own title keys and its catalog row, which older builds read. A restart, the session list and older builds then keep it rather than the agent's first-prompt summary (live finding B4-1). A rename known only in memory is recorded as a user title, and a rename of the new session in the meantime wins. 4a's older-build copy reads the same keys, so publishing and importing it changes nothing.
  • Provisional markers on promoted sessions. A sessionProvisional: marker ("no conversation at the session's own storage") is ignored for a session whose catalog records its default chat stored elsewhere, as a promoted session's is. Older builds (1.141) and the catalog reconciliation would otherwise hide it and report it as never created. Crash-orphaned drafts stay hidden (Seeing the new session in the sessions list #321269).
  • Mission Control (open item O1). Implemented per the design while confirmation from the Mission Control owner is pending:
    • a chat that moves as a single-chat session stops SDK replication, as every peer does today;
    • a promoted session starts a fresh SDK stream.

Known follow-ups

  • Startup sweep of leaked origin attachments. A crash between deleting a session and releasing its attachments leaks that directory: a leak, not data loss, and the same class as the existing cleanupOrphanedData gap.
  • Junk folders from older builds (UUID folders holding only peerChatBacking, empty sanitized-name folders).
  • Reference-aware worktree lift. Windows only - OmniSharp does not provide IntelliSense for strong named assemblies  #6's clean-up now keeps a worktree that another live session or chat uses. That could later allow moving chats that work in the source's worktree, and recording a removal when a session ends by a move instead of refusing it. This is a policy change.

How to test

  1. Enable chat.agentHost.moveChats.enabled and open the Agents window with a local agent host.
  2. Until Block 5's UI lands, drive the moves through the protocol (moveChat, vscode/moveSession) or through the unit and E2E tests below. Check that:
    • a peer moved to another session, or promoted, keeps its history, editor and running turn;
    • a queued message runs in the destination;
    • after a restart, the order and placement are restored.
  3. With the setting off, nothing is movable.

Validation

Run at load < 20 with COPILOT_* unset, on head a2ff30b8a39 (on main 38f4504f233). Locally, build-fast refuses to run because main's Copilot SDK bump (preview.1) couldn't be installed (npm registry 401), so tests ran on npm run transpile-client output.

Command Result
npm run typecheck-client passed
eslint on the 99 changed .ts files passed
npm run valid-layers-check passed
./scripts/test.sh --runGlob "vs/platform/agentHost/test/node/**/*.test.js" 11469 passing, 0 failing
./scripts/test.sh --runGlob "vs/platform/agentHost/test/{common,browser}/**/*.test.js" 1534 passing
./scripts/test.sh --runGlob "vs/platform/agentHost/test/electron-browser/**/*.test.js" 437 passing
./scripts/test.sh --runGlob "vs/sessions/**/*.test.js" 7009 passing
./scripts/test.sh --runGlob "vs/workbench/contrib/chat/test/browser/agentSessions/**/*.test.js" 2553 passing
npm run test-agent-host-e2e -- --jobs 2 (strict replay, all providers) Copilot 268, Claude 124, Codex 152, conformance 368, plus 22. Copilot managed permissions: 7 passing, 3 failing; the same 3 fail on main (38f4504f233) without this PR, so they're environmental (the uninstalled SDK bump).

Mutation checks accompany the main rules: refusals, the D1 pin, the attachments keep/release, the authority gate, restore order, worktree recording, tracker untracking, each 4a guard, import, retry and publish, and the folder reservations. Each mutation fails its test.

Later fixes (B4-1 promoted-session title, B4-2 attachment-copy record cleanup, B4-4 refusals logged at info, the perf fix, and Agent Merge's #341698 pre-warmer adaptation) each have their own tests and mutations; the full agentHost node suite on those heads: 11535 passing.

Live (Agents window, transpile-client builds, genuine commit-verified stable 1.140.0 / 1.141.2 / 1.142.0):

  • move a peer with a subagent, attachment, draft and unread; promote; reorder; move a single-chat session; folder cases (agentHost: only real chats' folders count for archive/delete detaching and Git state #341885); logs: PASS.
  • Old-build round trip: moved/promoted chats are shown and their old-build edits neutralized; nothing lost: PASS.
  • Re-check on the fix head: promoted title (agent and user renames) across a restart, a real 4b copy from the origin's attachments root (byte-identical, opens after the move and a restart, origin keeps its file), copy-record cleanup on delete, move sanity: PASS.

Perf (quiet ABBA vs 4a-on-main at 2k/10k sessions, plus a re-count on the final head vs main):

  • listing: the same agent-host.db statements as main, 0 session.db opens;
  • hot paths equal to main (peer delete equal with no moves; +2 statements only in profiles with moved chats);
  • moves are bounded (identical counts at 2k and 10k): peer move ~11–14 ms, promotion ~9–12 ms, session move ~10 ms, reorder ~3 ms;
  • the 4b copy runs after the request, 8 files per step, max 1.1 ms block.

Real user data (a copy, 24 GB): Block 4 vs main lists and opens identically with no new log errors. Real moves couldn't be exercised: the real sessions are archived, worktree-bound or live, and every attempt was refused cleanly with no data change. An old-build open plus rename round trip on the Block-4-touched copy lost nothing.

Reviews: passes 1–8 SHIP (no HIGH/MEDIUM open).

Copilot AI balanced review requested due to automatic review settings October 15, 2026 14:58
@sandy081 Sandeep Somavarapu (sandy081) added this to the 1.143.0 milestone Oct 15, 2026
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Base: 394399aa Current: 5d2c4d44

No screenshot changes.

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

One or more issues must be addressed before approval.

6 open findings
What changed in this PR

Adds gated chat relocation support across Agent Host storage, runtime services, and client views.

Changes:

  • Introduces move capabilities, eligibility checks, and persistence contracts.
  • Preserves chat-owned state and follows moved conversations in clients.
  • Adds regression tests and lifecycle documentation.
File Description
src/​vs/​workbench/​services/​agentHost/​browser/​editorRemoteAgentHostServiceClient.ts Updated as part of this pull request.
src/​vs/​workbench/​contrib/​terminal/​test/​browser/​agentHostPty.test.ts Updated as part of this pull request.
src/​vs/​workbench/​contrib/​chat/​test/​browser/​agentSessions/​agentHostChatContribution.test.ts Updated as part of this pull request.
src/​vs/​workbench/​contrib/​chat/​test/​browser/​agentSessions/​agentHost/​agentHostChatMoveTracker.test.ts Updated as part of this pull request.
src/​vs/​workbench/​contrib/​chat/​test/​browser/​agentSessions/​agentHost/​agentHostChatMoveEditors.test.ts Updated as part of this pull request.
src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentHost/​agentHostSessionListController.ts Updated as part of this pull request.
src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentHost/​agentHostSessionListContribution.ts Updated as part of this pull request.
src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentHost/​agentHostChatMoveTracker.ts Updated as part of this pull request.
src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentHost/​agentHostChatMoveEditors.ts Updated as part of this pull request.
src/​vs/​sessions/​SESSIONS.md Updated as part of this pull request.
src/​vs/​sessions/​services/​sessions/​test/​browser/​sessionsManagementService.test.ts Updated as part of this pull request.
src/​vs/​sessions/​services/​sessions/​test/​browser/​sessionNavigation.test.ts Updated as part of this pull request.
src/​vs/​sessions/​services/​sessions/​common/​sessionsProvider.ts Updated as part of this pull request.
src/​vs/​sessions/​services/​sessions/​common/​sessionsManagement.ts Updated as part of this pull request.
src/​vs/​sessions/​services/​sessions/​browser/​visibleSessions.ts Updated as part of this pull request.
src/​vs/​sessions/​services/​sessions/​browser/​sessionsService.ts Updated as part of this pull request.
src/​vs/​sessions/​services/​sessions/​browser/​sessionsManagementService.ts Updated as part of this pull request.
src/​vs/​sessions/​contrib/​providers/​copilotChatSessions/​browser/​copilotChatSessionsProvider.ts Updated as part of this pull request.
src/​vs/​sessions/​contrib/​providers/​agentHost/​test/​browser/​localAgentHostSessionsProvider.test.ts Updated as part of this pull request.
src/​vs/​sessions/​contrib/​providers/​agentHost/​browser/​baseAgentHostSessionsProvider.ts Updated as part of this pull request.
src/​vs/​sessions/​contrib/​providers/​agentHost/​AGENT_HOST_SESSIONS_PROVIDER.md Updated as part of this pull request.
src/​vs/​sessions/​contrib/​chat/​test/​browser/​sessionWorkspacePicker.test.ts Updated as part of this pull request.
src/​vs/​sessions/​common/​agentHostSessionsProvider.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​shared/​editArcReporter.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​sessionStorageIdentity.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​sessionPermissions.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​sessionDataService.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​sandboxConfigForSdk.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​missionControlSdkEventSource.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​missionControlHost.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​customizations/​claudeCommandSlashCompletion.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​copilotShellTools.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​copilotAgentSession.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​copilotAgent.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​codex/​codexCreateChat.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​claudeAgent.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​agentSideEffects.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​agentSessionRegistry.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​agentHostTerminalManager.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​agentHostSkillCompletionProvider.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​agentHostCustomizationEnablementService.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​agentHostChatMovability.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​agentHostChatInputService.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​agentHostChangesetOperationService.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​agentHostChangesetCoordinator.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​node/​agentHostCatalogReconciliationService.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​electron-browser/​agentHostProtocolClient.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​common/​sessionTestHelpers.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​test/​common/​agentHostSessionStateChatMove.test.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​shared/​worktreeIsolation.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​sessionPermissions.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​sessionDataService.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​missionControl/​missionControlSdkEventSource.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​missionControl/​missionControlHost.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​missionControl/​MISSION_CONTROL.md Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotSessionSandbox.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgentSession.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgent.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​copilot/​agentHostSandboxEngine.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​compatibleAgentHostDatabase.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​codex/​codexAgent.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​chatContributions/​workspaceContext/​workspaceContextContribution.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​chatContributions/​sessionWorkspaceConversion/​sessionWorkspaceConversionService.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​chatContributions/​queueDrain/​queueDrainContribution.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​chatContributions/​chatInput/​chatInputContribution.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​agentSideEffects.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​agentMergeController.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​agentHostTerminalManager.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​agentHostSkillCompletionProvider.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​agentHostSessionStateDatabase.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​agentHostChatRowStore.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​agentHostChatMovability.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​agentHostChatInputService.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​agentHostChangesetCoordinator.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​node/​agentConfigurationService.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​electron-browser/​localAgentHostService.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​common/​vscodeSandboxPaths.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​common/​state/​sessionState.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​common/​sessionDataService.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​common/​meta/​vscode/​agentHostSessionMoveMeta.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​common/​meta/​agentHostSessionMoveMeta.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​common/​agentService.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​common/​agentHostStarter.config.contribution.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​common/​agentHostSessionStateStore.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​common/​agentHostExtensionProtocol.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​common/​agentHostChatMove.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​browser/​nullAgentHostService.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​browser/​agentHostProtocolClient.ts Updated as part of this pull request.
src/​vs/​platform/​agentHost/​AGENTS.md Updated as part of this pull request.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@sandy081
Sandeep Somavarapu (sandy081) force-pushed the agents/move-chats-feature-block4-design branch from 6ce7ecb to c87abb3 Compare October 16, 2026 01:04
… one (Block 4)

Adds the agent-host.db primitives for moving chats:
- moveChatV2 moves a visible non-default chat with its private descendants to
  another normalized catalog in one transaction. It records the origin session
  before the first move, keeps storage, pins the chat's folders when asked,
  bumps both catalog revisions, re-projects the older-build session_chats rows
  and marks both list payloads dirty.
- reorderChatV2 places a visible chat after an anchor (or first).

Both keep every catalog's visible orders a contiguous zero-based sequence:
older builds reject a catalog with gaps and then can't open the session
(downgrade probe with Insiders and 1.142).

Co-authored-by: Copilot <[email protected]>
…ck 4)

A chat move now commits the catalog move and the chats' central state in one
agent-host.db transaction:
- every moved chat's session_chat_state row moves to the target, never as its
  default chat, with the moved chat pinned to its folders; its row mirror bases
  in the source go (a moved chat gets no older-build row copies);
- the per-folder git, GitHub and base-branch rows of the moved chat's folders
  come along: re-keyed when no chat staying in the source uses the folder,
  copied when one does. A row the target already has wins, and then the source
  keeps its own, so recorded pull requests and base branches are never dropped.

The session state store's moveChat holds both sessions (in one order, so two
moves can't deadlock), flushes their pending mirrors, commits, and refreshes
both loaded states. It writes nothing to either session's session.db.

Co-authored-by: Copilot <[email protected]>
AgentHostStateManager.transferChats moves a chat and its descendants to
another session once the move is committed: it reassigns their owners
(3c's reassignChatOwner), then dispatches session/chatRemoved on the source and
session/chatAdded plus session/chatsReordered on the target, all synchronously
so nothing runs between a chat leaving one session and joining the other. The
chats keep their state, changesets, canvases and in-progress turn; the
active-turn set and both sessions' summaries follow.

A deleted chat is unregistered before its removal is dispatched, while a moved
chat is still registered, so session/chatRemoved listeners tell the two apart
with isChatRegistered. A moved chat keeps its changesets and file monitors,
workspace-context preparation, isolation state and pending Agent Merge notices,
and its blocked-input marker moves to its new session.

Co-authored-by: Copilot <[email protected]>
Adds the experimental chat.agentHost.moveChats.enabled setting (default off),
mirrored into the host's chatMoves.enabled root config. AgentHostChatMovability
keeps ChatSummary.movable and ChatState.movable current: a chat is movable when
moves are enabled and it isn't its session's default chat, a tool-spawned chat
(it moves with its parent) or a hidden chat. It follows registration, owner
changes, default chat changes and the setting, publishing session/chatUpdated
and chat/movableChanged. Chat state and catalog summaries now carry movable.

Co-authored-by: Copilot <[email protected]>
AgentService.moveChat validates the whole move first, adds the moved chat's
folder to the target (pinning the target's inheriting chats), commits the
catalog and central state in one transaction, then transfers the chats in
memory. Refusals carry a stable reason, which the protocol handler returns
as InvalidParams data. Promotion is refused until it lands.

Co-authored-by: Copilot <[email protected]>
- A committed move always completes in memory: the store's post-commit
  reload never throws (a failed reload drops the cached model so it
  reloads on next use), and memory follows the database's moved chats in
  its order, with an anchor that disappeared falling back to first place.
- session/chatRemoved listeners ask the state manager for a typed
  ChatRemovalReason (moved or deleted) instead of inferring it.
- Tests: a reload failure after commit, moves in both directions at once
  (store and service), a moved peer's later edits writing no older-build
  copies, and the rule that a target's folder row wins while the source
  keeps its own.

Co-authored-by: Copilot <[email protected]>
- moveChat reads the catalog revisions before validating, holds the
  admission of the moved chats' queued turns and keeps both sessions
  resident, then checks the move again after adding folders and right
  before committing; a refusal or failure removes the added folders.
- A queued turn of a moved chat starts once the move is done, in the
  chat's new session (holdChatAdmission, consulted by the queue drain).
- After the commit the in-memory move never fails the request; memory
  follows the database's placement (moveChatV2 now reports the moved
  chats in placement order and the target's resulting order).
- The worktree check includes the session's resolved worktree; a session
  being disposed or deleted is refused as not ready.
- Tests: every refusal reason, the undo of an added folder, changes made
  while folders are added, placement order with two visible descendants,
  and the held queued turn.

Co-authored-by: Copilot <[email protected]>
The moved chat's effective value in its source session, for every
property a chat may set for itself in the target, becomes its own value
right after the move, so it keeps working as it did; its subagents
inherit through it. Host-owned values are left to the target.

Co-authored-by: Copilot <[email protected]>
…e (Block 4)

promoteChatV2 registers the new session in both registries, creates its
normalized catalog with the promoted chat as its default chat followed by
its visible descendants, compacts the source, records the origin session
and creates the new session's imported central state (the chat as its
default chat, pinned to its folders, its session values and the folder
state it carries), all in one transaction. The store holds both sessions
and refreshes the source.

A session whose default chat stores elsewhere has no database at its
URI: neither its session values nor its chats' rows are mirrored there.

Co-authored-by: Copilot <[email protected]>
AHP moveChat to a new session now promotes a peer chat and its
descendants: the host mints a session of the same agent, commits it with
the chat as its default chat, then creates it in memory and moves the
chats there synchronously (state manager promoteChats), announcing it to
clients. The chat keeps its runtime, which relaunches under the new
session at its next turn. The new session starts with the chat's folders
and its source's config with the chat's own values over it.

The promoted chat records its own storage, and restore passes a default
chat's recorded storage to its provider, so the new session never reads
a database at its own URI. A chat without a recorded conversation of its
own is refused. Movability is published after a chat joins its new
session's catalog.

Co-authored-by: Copilot <[email protected]>
- Both sessions' customizations are republished after a move or a
  promotion, so MCP entries a moved runtime published under its source
  and the chat's folder customizations follow it.
- Deferred work kept for a chat (Agent Merge notices, external history,
  history watches) follows its owner when it moves, so it waits on the
  new owner's activity and survives the old owner ending.
- A chat-row read or write addressed to a session the chat moved out of
  runs in its new owner, so it never writes a copy into the old
  session's database or its mirror bookkeeping.

Co-authored-by: Copilot <[email protected]>
- M1: a session's default chat is looked up in its recorded storage
  everywhere: the loaded central state, else the catalog for a session
  that is not loaded (external title, teardown, provider disposal), so a
  promoted session never looks for its default chat in a database at its
  own URI, also after a restart.
- L1: the config a moved chat takes along is written to its own database
  before the commit (and restored if the move is refused), so a crash
  after the commit keeps it.
- L2: when memory can't follow a committed move, both sessions' loaded
  state is dropped so it loads from the database on next use.
- L3: the target's catalog revision is re-read before the last checks.
- L4: a promoted session is announced with its default chat not movable.
- L5: a chat's applied sandbox state moves with it; a promoted chat's is
  its new session's.

Co-authored-by: Copilot <[email protected]>
… relaunches (Block 4)

Once a chat moved, the session-level MCP and customization state its
running provider process publishes describes a configuration its new
session does not have, so it is published to neither session until the
next turn relaunches the process with the new owner's (C6): Copilot drops
launch actions once the launch owner is not the chat's owner, and Codex
publishes no MCP state while its thread was started for another owner.
Claude publishes only plugin customizations, to the current owner.

Co-authored-by: Copilot <[email protected]>
…ddress (Block 4)

Moves, promotions and reorders change normalized catalogs only. They are
now allowed whenever every catalog they touch has normalized authority,
which the database checks in the same transaction that applies them,
whatever a session's address or compatibility identity: historical
copilotcli:, claude: and codex: sessions with normalized catalogs can
move chats. A legacy or missing catalog is refused (notReady, reported
as legacyCatalog). Registering and normalizing a catalog stay gated by
the compatibility window as before.

Co-authored-by: Copilot <[email protected]>
A promoted session is stored natively (no compatibility identity), unlike
a session created for a client. Keeping its allocation in one helper
makes giving it one a single call if that is decided.

Co-authored-by: Copilot <[email protected]>
…lock 4)

A chat's terminals belong to its runtime, not to its session. When it
moves, every live terminal (shell or output-only) whose session claim
names it is claimed by its new session (terminal/claimed), so clients
show it there, and deleting the previous session leaves it running.

Co-authored-by: Copilot <[email protected]>
…(Block 4)

Copilot routed a client tool call completion whose chat and spawning
chat have no runtime to the runtime of its owner's session-backed chat.
That runtime never made the call, and after a move it is another
session's chat. The completion is now dropped (traced) instead, as
Claude and Codex already do.

Co-authored-by: Copilot <[email protected]>
…k 4)

A session-db, git-blob or pending-edit-content URI embeds the storage of
the data it names. Access resolves that storage to its live owner: a
chat's owner, a session itself, else the owner of the registered chat
recorded as storing there. A moved single-chat session's database stores
a chat another session owns, so its content stays readable without
deriving an owner from the address.

Co-authored-by: Copilot <[email protected]>
…d in (Block 4)

A client without vscode.ahpChatUris derives a chat's session from its
URI. It now sees a chat only in the session it was created in: a moved
chat disappears from it (its removal from its first session is still
delivered) and a promoted session, whose default chat came from another
session, is hidden. The host knows where each moved chat came from: the
first move records it, and the catalog's origin sessions are loaded at
startup (before any listing), so no owner is derived from an address.

Co-authored-by: Copilot <[email protected]>
A chat's attachment snapshots are now written under its recorded storage
(the session's data dir for the default chat, unchanged; a peer's own dir),
so they move and are deleted with the chat. The directories a chat may read
snapshots from are its owner, its recorded storage and, for a moved chat,
the session it was created in (the recorded origin, never parsed from a
URI). They feed the attachment rewriter's known roots, the Copilot SDK and
host sandbox read roots and the read auto-approval / snapshot-write deny.

Co-authored-by: Copilot <[email protected]>
…out of it live

Deleting a session keeps its attachments directory while a live chat whose
recorded origin (chats_v2.origin_session_uri) is that session exists; the
moved chat still reads the attachments it took there. Deleting a moved chat
(as a peer or with its session) releases its origin's kept attachments once
the origin is deleted and no live moved chat names it, so nothing leaks.
Both checks read recorded data, so they hold across restarts.
ISessionDataService.deleteSessionDataExcept deletes all but the named
children of a data directory.

Co-authored-by: Copilot <[email protected]>
…seed (Block 4)

Pins that neither a move nor a promotion goes through 3b's D1 seeding
(createChat / seedChatConfig): a chat seeded in its source keeps its own
values in the target even when the target's default chat uses others, and
a promoted session starts from the source's config with the chat's own
values on top.

Co-authored-by: Copilot <[email protected]>
A host moves a chat by removing it from one session's catalog and adding it
to another's under the same backend chat URI. AgentHostChatMoveTracker pairs
the two, in either order, by the backend chat (never by parsing its URI);
promotion maps to the new session's main chat.

- Agents window: the Agent Host sessions provider tracks every cached
  session and reports the required ISessionsProvider.onDidMoveChat (the
  Copilot Chat provider never moves chats). The sessions service keeps
  showing a moved chat: the slot that showed it, also after it fell back
  because the removal arrived first, shows the chat's new session with the
  chat active, announced to screen readers.
- Main window: the Agent Host session list recognizes moves the same way
  and replaces each open chat editor of the moved chat in place.

Co-authored-by: Copilot <[email protected]>
A sessionProvisional marker means there is no conversation at the
session's own storage. That's no evidence for a session whose catalog
records its default chat stored elsewhere, as a promoted session's is:
1.141 marks such a session it can't resolve (probe P2-2), and so does
this build's catalog reconciliation. Once marked, the session was
hidden and reported as never created for good whenever the agent
couldn't describe it yet.

The marker is now ignored when reading for such a session, and the
reconciliation doesn't write it. A normalized draft, whose default chat
stores at the session, still stays hidden (#321269).

Co-authored-by: Copilot <[email protected]>
- Chat input: a check that completes after its chat moved settles the chat
  under its current owner, not the session it started in. A moved chat's
  input state is carried once its new owner lists it, also when its
  session ends by moving it under another session (which never removes
  the chat); writing it to an owner that doesn't list the chat yet
  dropped the chat's live state.
- Mission Control: a session that still advertises a default chat now
  owned by another session starts no new stream.
- Agents window: a session removed before its chat's move is known leaves
  its slot to the session the chat moved to; the fallback bookmark is
  forgotten once another chat becomes active.
- Chat editors: retargeting is serialized, so a chat that moves again
  finds its editors where the previous move put them.

Co-authored-by: Copilot <[email protected]>
The first session listing waited for the origins of moved chats, a scan
of chats_v2, although only clients that place a chat by its URI (no
vscode.ahpChatUris) need them. The origins now load in the background
from startup: only those clients' listings wait for them, and they stay
fail-closed while the origins are unknown. Until a chat first moved, the
load reads one metadata row (written by the move) instead of scanning
chats_v2; no schema change.

Co-authored-by: Copilot <[email protected]>
… keeps its input state

Moving a chat with its subagents (or a session with them) reassigned
every owner first and then added the chats to the target one at a time:
the first add's catalog sync invalidated the chats the target didn't
list yet, dropping their live state. Chats in transfer are now exempt.

Promotion now sets the new session's catalog before it reassigns owners,
so what reacts to the owner change sees the chats it takes: a blocked
chat's input state follows it into the new session.

Co-authored-by: Copilot <[email protected]>
After a peer move, a promotion or a session move commits, a background
job copies the files the moved chat's messages (and its subagents')
attached in its origin, i.e. their recorded snapshot URIs under the
origin's attachments directory, into the chat's own storage under the
same relative paths: through a temporary file, skipping files already
there, 8 files per step with a yield in between, recording its progress
in agent-host.db metadata (no migration). A restart resumes it once the
chat's session is restored.

A host resource read of a copied file the origin no longer has (deleted,
also by an older build) reads the copy. A chat whose copy is complete
no longer keeps its origin's attachments; one moved with its session
copies nothing and keeps counting.

Co-authored-by: Copilot <[email protected]>
…ision B)

Provider-native tools still read a moved chat's pre-move attachments at
their original paths, so the origin keeps its attachments directory
while any moved chat lives, also once the chat's copy is complete. The
copy protects the files from deletions by older builds, and host reads
fall back to it. Releasing on completion stays implemented behind
RELEASE_COPIED_ATTACHMENT_ORIGINS, switched off.

Co-authored-by: Copilot <[email protected]>
…s and reorders

Stacked on Block 4a. Each move, session move, promotion and reorder now
follows 4a's contract for writes that re-project normalized catalogs
(agentHostChatCatalogV2.md):
- before validating, it waits for the in-flight peer-store writes of
  every session it touches (whenSessionsIdle), converts a legacy
  catalog to normalized authority, and imports what older builds
  changed (reconcileOlderBuildCopy);
- in its transaction, guardOlderBuildEdits refuses an older build's
  edit of any chat list it re-projects (both sessions of a move);
  the edit is imported and the write tried once more;
- it records the projection it writes (projected_revision), and once
  committed schedules the older-build copy of the sessions it changed
  (new AgentHostPeerChatStore.scheduleOlderBuildCopyPublish), so older
  builds see a moved chat where it is now and record it as left.

4a converts every session, so the authority-1 legacyCatalog refusal now
remains only for a session 4a can't convert yet (its provider can't
vouch for it, or its conversion is parked).

Co-authored-by: Copilot <[email protected]>
…lders follow #341885

Main's #341885 reserves the folders of chats being created or moved, so
archiving or deleting a chat doesn't detach them from the session
workspace before the chat is published. Moves now use that:
- the folders a moving chat brings are reserved in the destination from
  the moment the move takes its chat's turns until the destination lists
  the chat; a refused move ends the reservation before it removes the
  folders it added;
- the folders prepared in the destination are consumed once the chat
  lands there, so they are in use rather than reserved forever, and
  archiving or deleting the moved chat there detaches them;
- like a deleted chat, a chat that moved out (peer move or promotion)
  leaves its source no folder no remaining chat uses: the folders' Git
  and GitHub state already went with it. A session move ends its source.

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

- A move retried after importing older-build edits reads the source's
  folders and remaining chats again when it commits: a chat an older
  build added in the source on the moving chat's folder keeps that
  folder's Git state (copied, not moved away).
- A reorder checks its anchor again after preparing, so an anchor an
  import removed is an invalid anchor rather than a conflict.
- A comment says why a folder the move prepares is reserved twice.
- Removes an orphaned doc comment.
- Tests: promotion and reorder each refuse an older build's edit at the
  database, and apply once it's imported; a retry keeps a sibling's
  folder state; a refused move leaves the destination's folders
  unreserved and detachable.

Co-authored-by: Copilot <[email protected]>
@sandy081
Sandeep Somavarapu (sandy081) force-pushed the agents/move-chats-feature-block4-design branch from c87abb3 to a2ff30b Compare October 16, 2026 03:09
…B4-1)

After a promotion the new session's own title keys were never written, so a
restart restored and listed it by the agent's summary (its first prompt). The
promotion now persists the chat's title and recorded title source (user, agent
or auto) as the new session's title after the commit. 4a's older-build copy
reads the same session keys, so publishing and importing it changes nothing.

Co-authored-by: Copilot <[email protected]>
The chatAttachmentCopy:<chat> record in agent-host.db outlived its chat until
the next startup pruned it. Every chats_v2 tombstone (a removed private chat,
a peer removed from its catalog with its private descendants, a deleted or
excluded session's chats) now deletes the record in the same transaction. A
copy step is recorded only while its chat is live: a copy running when its
chat is deleted stops, records nothing and reports no completion, and stops
before a step if the chat is no longer registered, so it doesn't recreate the
deleted storage. A restart resumes no copy for a deleted chat.

Co-authored-by: Copilot <[email protected]>
- Attachment copy: a chat unloaded while its copy runs resumes once it is
  restored. Recording its progress tells it from a deleted chat (only a live
  chat's is recorded), whose copy stops and is forgotten.
- Promoted session title: the source is the chat's after the commit, or 'user'
  for a rename known in memory only. The title is written through the ordered
  list-visible state write, which also updates the session's catalog row that
  older builds read, and is skipped if the new session was renamed meanwhile.

Co-authored-by: Copilot <[email protected]>
A chat or session move the host refuses (notMovable, destinationSingleFolder,
legacyCatalog, conflict, …) is an expected outcome, but ProtocolServer logged
it at [error] with a stack. Refusals now travel as a typed protocol error and
are logged at info with their reason and message; unexpected failures stay
errors. Clients see the same InvalidParams error with its reason.

Co-authored-by: Copilot <[email protected]>
Main's pre-warmer (#341698) read the default chat's storage through
_defaultChatStorageResource, which Block 4 split. Use the known recorded
storage, or the creation-time rule for a draft's default chat not recorded yet.

Co-authored-by: Copilot <[email protected]>
- The database caches whether any chat ever moved (the chatsV2Moved marker,
  read once per process; a move sets it). Without one, listing moved chats or
  attachment origins, reading attachment copy records at startup and deleting
  a chat's copy record on tombstone run no statement.
- The chat row store asks whether a chat moved out of a session only when a
  chat ever moved.
- Whether a deleted storage keeps its attachments for chats that moved out of
  it is answered from the moved chats' origins in memory when they are known;
  only an origin of a live moved chat reads the catalog.

Co-authored-by: Copilot <[email protected]>
@sandy081
Sandeep Somavarapu (sandy081) marked this pull request as ready for review October 16, 2026 05:25
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Ladislau Szomoru (@lszomoru)

Matched files:

  • src/vs/sessions/services/sessions/browser/sessionsManagementService.ts
  • src/vs/sessions/services/sessions/browser/sessionsService.ts
  • src/vs/sessions/services/sessions/browser/visibleSessions.ts
  • src/vs/sessions/services/sessions/common/sessionsManagement.ts
  • src/vs/sessions/services/sessions/common/sessionsProvider.ts
  • src/vs/sessions/services/sessions/test/browser/sessionNavigation.test.ts
  • src/vs/sessions/services/sessions/test/browser/sessionsManagementService.test.ts

Anthony Kim (@anthonykim1)

Matched files:

  • src/vs/workbench/contrib/terminal/test/browser/agentHostPty.test.ts

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