Skip to content

agentHost: harden chat moves (refusals, strict movable, session moves, Copilot storage, new sessions) - #342047

Merged
Sandeep Somavarapu (sandy081) merged 13 commits into
mainfrom
agents/block4-chat-move-hardened-tests
Oct 16, 2026
Merged

Sandeep Somavarapu (sandy081) merged 13 commits into
mainfrom
agents/block4-chat-move-hardened-tests

Conversation

@sandy081

Copy link
Copy Markdown
Member

Problem

Moving chats in the Agent Host (AHP moveChat: reorder, peer move and promotion; plus the VS Code-only vscode/moveSession) had gaps that the Block 5 drag-and-drop smoke test and a hardening pass exposed:

  • Several refusals had no test showing that a refused move changes nothing.
  • After vscode/moveSession, the moved former default chat wasn't announced as movable.
  • vscode/moveSession worked only after a restart once the setting was turned on.
  • ChatSummary.movable was true for chats whose move the host would refuse anyway.
  • With Copilot, a chat moved under another session by vscode/moveSession couldn't run its next turn.
  • Moves involving new sessions were refused as legacyCatalog, or only succeeded after a ~30 s reconciliation pass.
  • moveChat was the only AHP command no E2E test covered.

Change

Eight commits, kept separate for review:

  • T1, refusal tests. Adds one focused test per refusal that had none of its own: DifferentProvider, SessionQuarantined (source and target), ConversionInProgress, Workspaceless (session on either side, or a chat without a folder), and LegacyCatalog. Each asserts the typed reason and an unchanged footprint: both sessions' catalog revisions and chats, live chats, movable, folders, ownership and moved-chat origin. setupMove gains a per-session-database option: with the shared test database, a target's conversion attempt read the source's older-build chat list.
  • T2a, moved session's chat announced movable. Root cause: transferSession announced the former default chat in session/chatAdded with the summary it had as its old session's default chat, which had no movable. The movability tracker only corrected it a tick later, and the summary-to-state merge could skip chat/movableChanged. The move now asks AgentHostChatMovability.isMovableIn and announces it in session/chatAdded, then sends chat/movableChanged once the destination lists the chat.
  • T3, E2E coverage. Adds suites/chatMoveSuite.ts. Conformance covers the refusals; parity covers peer move and reorder, promotion, and session move for Copilot, Claude and Codex, and asserts the moved chat's next turn recalls what it was told before the move. coverage/protocol-surface.json was regenerated with npm run test-agent-host-e2e-coverage: commands are 33/33, so moveChat is now covered.
  • T4, vscode/moveSession without a restart. Root cause: the host decided whether to advertise vscode.sessionMove at initialize, before the client mirrored chatMoves.enabled into root config. It is now always offered and routed to non-relay clients. A move while the setting is off gets the existing disabled refusal. Older hosts still never advertise it, so the client still refuses those moves without sending a request.
  • T5, strict ChatSummary.movable. No protocol change. Besides structural eligibility, a chat is movable only while its own state or its session's doesn't refuse the move: archived or workspace-less session, chat without a folder, a workspace change or quarantine, a folder in a worktree the session records, Agent Merge it owns, or a parked legacy catalog. The flag is recomputed from in-memory state on existing session actions plus three new minimal events: onDidChangePending, onDidChangeLoadedState and onDidChangeParkedSessions. Destination-dependent refusals and notStarted stay request-time. A request checks only structural eligibility up front, so its refusal keeps the specific reason.
  • T6, Copilot chat metadata by recorded storage. Root cause: copilotAgent chose between session state and a chat's own database by URI shape (isAhpChatChannel). A moved session's chat stays stored at its ended source session while the destination owns it, so resuming it wrote the ended source's state ("is being deleted"). The metadata helpers now take the recorded { storage, owner } and use session state only when the storage is the owner itself. Claude and Codex already use their recorded storage. This un-gates the Copilot session-move E2E test.
  • E2E harness. Root cause: the replay proxy stored an exchange when its upstream response ended, but wrote the fixture without waiting for it. Codex stops reading at response.completed, so fixtures lost their last exchange. The proxy now waits for in-flight recordings.
  • T7, convert new sessions on demand. Root cause: 4a converts a legacy catalog only after a background re-projection. That pass waits for startup (the first listing), runs at most every 30 s, and real providers create provisional sessions without a v2 catalog. A move now stages the aggregate from the session's live state, using each peer's persisted origin, and converts it immediately; a normalized catalog still costs one read. legacyCatalog is now reported only for parked sessions, and a session that still can't be converted gets sessionNotReady with the reason. A chat may now move out of, or be promoted from, a recorded provisional session. A session that moves, or one a chat moves into, must still be durable.

Validation

All runs on macOS, at load average < 20, with COPILOT_* unset, after rebasing onto main:

  • npm run build-fast -- --client-only: passed.
  • ./scripts/test.sh --runGlob "vs/platform/agentHost/test/node/**/*.test.js" --reporter dot: 11638 passing, 0 failing (76 pending).
  • ./scripts/test.sh --run src/vs/platform/agentHost/test/electron-browser/agentHostProtocolClient.test.ts: 250 passing.
  • npm run typecheck-client: passed.
  • npm run eslint -- <changed .ts files>: passed (25 files).
  • node build/hygiene.ts <changed files>: passed (27 files).
  • E2E strict replay (./scripts/test-integration.sh --run src/vs/platform/agentHost/test/node/e2e/<entry>.integrationTest.ts --grep "keeps its provider conversation|keeps its chat's provider conversation|moveChat|moveSession|archived session"):
    • conformance/agentHostConformance: 3 passing.
    • providers/copilotAgentHostE2E: 7 passing.
    • providers/claudeAgentHostE2E: 7 passing.
    • providers/codexAgentHostE2E: 7 passing.
  • New and re-recorded fixtures were recorded with AGENT_HOST_REPLAY_RECORD=1 and scanned for usernames, absolute paths and tokens (none found).
  • npm run test-agent-host-e2e-coverage (before the rebase): passed and regenerated coverage/.
  • Mutations, each restored afterwards; every one fails a test:
    • T2a: 1.
    • T4: 1, caught by the unit test and by E2E.
    • T5: 10 (each of 6 conditions, the archive trigger, and 3 service events).
    • T6: 1, caught by the unit test, and in E2E it reproduces the original error.
    • T7: 5, caught by unit and E2E tests.
  • Cross-platform Azure validation (pipeline definition 111): queued separately.

Follow-ups

  • Client: an extra empty chat group appears in the destination's grid after vscode/moveSession in the Agents window. The host emits only session/chatAdded and session/chatsReordered on the destination, then root/sessionRemoved. Candidates are in sessionsService (_onDidMoveChat) and ChatGroupsView; owned by the Block 5 drag-and-drop work.
  • A strict session-level vscode.movable, like ChatSummary.movable.
  • notStarted as a condition of movable (it blocks promotion only).
  • Moving a chat into a provisional (not yet durable) target is still refused with sessionNotReady.

…le peer it is

`vscode/moveSession` makes a session's default chat a peer of the destination,
but `transferSession` announced it in `session/chatAdded` with the summary it had
as the source's default chat, without `movable`. The movability tracker only
corrected it a scheduler tick later with `session/chatUpdated`, and the summary
merge into the chat's materialized state meant `chat/movableChanged` could be
skipped for chat-channel subscribers.

The move now asks the movability tracker whether the chat may move once the
destination owns it, announces that in `session/chatAdded`, and then publishes
`chat/movableChanged` on the chat once the destination lists it, as a promotion
already does for its new default chat.

Co-authored-by: Copilot <[email protected]>
Adds one focused test per refusal that had none of its own: a different provider,
a quarantined session (either side), a chat changing its workspace, a
workspace-less session (either side) or chat without a folder, and a parked
legacy (authority 1) target, refused twice. Each asserts the typed reason and
that both sessions' catalogs (revisions and chats), live chats, movability,
folders, ownership and moved-chat origin are unchanged.

The legacy case gives each session its own database, as in production: with the
shared test database, the target's conversion attempt read the source's
older-build chat list.

Co-authored-by: Copilot <[email protected]>
Covers AHP `moveChat` (the only E2E-uncovered command) and `vscode/moveSession`:

- Conformance: moves are refused while disabled (and `vscode/moveSession` is not
  routed); a session's default chat and a session with other chats are refused
  with their reasons.
- Parity: a peer moved to another session and reordered there, a peer promoted
  to a new session, and a session moved under another each keep their provider
  conversation: the moved chat's next turn recalls what it was told before.

The Copilot variant of the session move is gated as a known issue: its moved
chat's next turn fails. Refreshes the coverage stats with the coverage command.

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

The host advertised `vscode.sessionMove` in its initialize result only when the
root config `chatMoves.enabled` was already on. A client mirrors that setting
after it initializes, so with the setting on a fresh connection never saw the
capability and session moves needed a restart.

Non-relay transports are now always offered and routed `vscode/moveSession`; a
move while moving chats is off is refused with `disabled`, as `moveChat` already
is. Clients keep showing the action only for sessions whose `vscode.movable`
flag is set, which follows the setting. Hosts that never advertise the
capability are still refused client-side without a request.

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

`ChatSummary.movable` only reflected structural eligibility (setting on, not a
default, tool or hidden chat), so clients offered moves the host then refused.
It is now strict: the host also reports `false` while a move would be refused
for a reason of the chat or its own session: an archived or workspace-less
session or a chat without a folder, a workspace change of the chat or a
quarantined session, a folder in a worktree its session records, Agent Merge
it runs, or a legacy catalog the reconciliation parked. Destination-dependent
refusals and NotStarted (promotion only) stay request-time.

`AgentHostChatMovability` recomputes it from in-memory state when any input
changes: session actions (archive, meta, config, folders), chat folders, and
new events of the services that hold the rest: workspace conversions
(`onDidChangePending`), loaded session state (`onDidChangeLoadedState`: recorded
worktrees, catalog authority) and catalog parking (`onDidChangeParkedSessions`).
A move request checks only structural eligibility up front and validates the
rest as before, so its refusal keeps its specific reason.

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

Copilot decided between a session's state and a chat's own database by the
shape of the resource it was given (`isAhpChatChannel`). A session moved under
another session keeps its chat stored in its former session's database while
the destination owns it, so the shape said "session" and resuming the chat
wrote to the ended source session's state: its next turn failed with "Session
state of <source> is being deleted".

The metadata helpers now take the recorded storage and owner
(`ICopilotMetadataScope`): a storage that is its owner's own is that session's
state, any other is the database at the storage. Claude and Codex already open
their recorded storage. Un-gates the Copilot session-move E2E test and records
its fixture.

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

While recording, the replay proxy stores an exchange when its upstream response
ends, but wrote the fixture as soon as the test stopped it. Codex stops reading
at `response.completed` and its turn completes before that, so the last model
exchange of a test was often missing from its fixture although the recorded run
passed (3 of 4 recordings of one test, then 4 of 4). The proxy now waits for
in-flight recordings before writing the fixture.

Co-authored-by: Copilot <[email protected]>
A move refused a new session as `legacyCatalog` until the background catalog
reconciliation had re-projected its aggregate: not before the first session
listing, and then only at its 30 s pass floor. Promoting a chat of a new
session took about 30 s of retries.

A move now converts such a session on demand: as 4a does on restore, it stages
the aggregate from the session's live state (with each peer's persisted origin,
which the conversion checks the peer's own database against) and converts it at
once. `legacyCatalog` is reported only for a session whose reconciliation is
parked (its provider can't vouch for its chats); one that still can't be
converted is `sessionNotReady`, with the reason. A normalized catalog still
costs one snapshot read. A chat may also move out of, or be promoted from, a
new session whose default chat hasn't run (recorded provisional); a session
that moves, or one a chat moves into, must still be durable. Strict `movable`
already treats only parked sessions as legacy, so a new session's chats stay
movable.

The E2E move tests no longer list sessions first, retry a first move, or run a
turn on the source session's default chat: every move succeeds at once.

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 16, 2026 11:57
@sandy081 Sandeep Somavarapu (sandy081) added this to the 1.143.0 milestone Oct 16, 2026
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: 1b3cae0f Current: 93d9d98f

Changed (1)

sessions/sessionToolbar/sessionToolbar/SubmenuOpen/Light
Before After
before after

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.

🔵 Needs a closer look

Cross-cutting persistence changes, unresolved correctness concerns, and pending cross-platform validation require maintainer review.

2 open findings
What changed in this PR

Hardens Agent Host chat and session moves, preserves provider conversations, and expands regression coverage.

Changes:

  • Tightens movability checks and enables session moves without reconnecting.
  • Corrects Copilot metadata storage and converts new-session catalogs on demand.
  • Adds refusal and cross-provider move tests, fixtures, and recording-drain handling.

Paths are relative to src/vs/platform/agentHost/.

File Description
test/​node/​protocolServerHandler.test.ts Tests session moves without reconnecting.
test/​node/​e2e/​suites/​chatMoveSuite.ts Adds refusal and conversation-continuity scenarios.
test/​node/​e2e/​suites/​agentHostE2ESuites.ts Registers move scenarios.
test/​node/​e2e/​harness/​capiReplayProxy.ts Waits for outstanding recordings.
test/​node/​e2e/​coverage/​protocol-surface.json Updates protocol coverage totals.
test/​node/​e2e/​captures/​copilotcli-a-session-moved-under-another-keeps-its-chat-s-provider-conversation-as-a-movable-peer.yaml Copilot session-move fixture.
test/​node/​e2e/​captures/​copilotcli-a-peer-chat-promoted-to-a-new-session-keeps-its-provider-conversation-as-its-default-chat.yaml Copilot promotion fixture.
test/​node/​e2e/​captures/​copilotcli-a-peer-chat-moved-to-and-reordered-in-another-session-keeps-its-provider-conversation.yaml Copilot move/reorder fixture.
test/​node/​e2e/​captures/​codex-a-session-moved-under-another-keeps-its-chat-s-provider-conversation-as-a-movable-peer.yaml Codex session-move fixture.
test/​node/​e2e/​captures/​codex-a-peer-chat-promoted-to-a-new-session-keeps-its-provider-conversation-as-its-default-chat.yaml Codex promotion fixture.
test/​node/​e2e/​captures/​codex-a-peer-chat-moved-to-and-reordered-in-another-session-keeps-its-provider-conversation.yaml Codex move/reorder fixture.
test/​node/​e2e/​captures/​claude-a-session-moved-under-another-keeps-its-chat-s-provider-conversation-as-a-movable-peer.yaml Claude session-move fixture.
test/​node/​e2e/​captures/​claude-a-peer-chat-promoted-to-a-new-session-keeps-its-provider-conversation-as-its-default-chat.yaml Claude promotion fixture.
test/​node/​e2e/​captures/​claude-a-peer-chat-moved-to-and-reordered-in-another-session-keeps-its-provider-conversation.yaml Claude move/reorder fixture.
test/​node/​copilotAgent.test.ts Tests moved-chat metadata storage.
test/​node/​chatContributions.test.ts Updates conversion-service mocks.
test/​node/​agentSideEffects.test.ts Updates conversion-service mock.
test/​node/​agentService.test.ts Covers refusals, normalization, and movability.
test/​node/​agentHostTurnTelemetry.test.ts Updates conversion-service mock.
test/​node/​agentHostTurnHangTelemetry.test.ts Updates conversion-service mock.
test/​node/​agentHostToolCallTelemetry.test.ts Updates conversion-service mock.
test/​node/​agentHostStateManager.test.ts Verifies move announcement ordering.
test/​node/​agentHostChatMovability.test.ts Tests state-dependent movability.
test/​node/​agentHostChatInputService.test.ts Updates session-transfer invocation.
node/​protocolServerHandler.ts Advertises and routes session moves independently of setting state.
node/​copilot/​copilotAgent.ts Selects metadata storage using recorded ownership.
node/​chatContributions/​sessionWorkspaceConversion/​sessionWorkspaceConversionService.ts Emits pending-conversion changes.
node/​agentService.ts Integrates movability and on-demand catalog conversion.
node/​agentHostStateManager.ts Publishes movability during session transfer.
node/​agentHostSessionStateStore.ts Emits loaded-state changes.
node/​agentHostChatMovability.ts Computes and refreshes stricter eligibility.
node/​agentHostCatalogReconciliationService.ts Exposes catalog parking state and events.
common/​agentHostSessionStateStore.ts Defines loaded-state change events.
common/​agentHostExtensionProtocol.ts Documents setting-independent capability advertisement.
common/​agentHostChatMove.ts Separates structural and state-dependent eligibility.
AGENTS.md Documents move and storage contracts.

🧠 Review effort: Balanced


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

…ording drain

- `isMovableIn(chat, owner)` for a chat that doesn't belong to `owner` yet now
  takes a chat without folders of its own as working in its current owner's
  folders, which the move pins, rather than the destination's: a session moved
  under a destination that owns a worktree is no longer announced not movable
  in its `session/chatAdded`.
- The E2E replay proxy waits for forwarded upstream requests for at most 30 s
  when a recording stops. Past that, it aborts the outstanding requests and
  reports the recording incomplete without writing a partial fixture, so a
  stalled upstream can't block teardown.

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

CI (Linux, macOS) failed the refused-move tests for a quarantined or
workspace-less session: the footprint taken before the move had the peer
movable, the one after it not. Recomputing `movable` after a session input
changed (archive, meta, config, folders, a workspace change, recorded worktrees,
catalog parking) was deferred to the movability scheduler, so for a moment the
flag was stale, and the move's own awaits decided whether it flipped before or
after the first snapshot.

Only registration and owner changes need deferring: their chat isn't in its
session's catalog yet. A change of a session input now recomputes its chats'
`movable` synchronously, as `session/ready` and `session/defaultChatChanged`
already did. The per-condition unit tests read `movable` right after each change,
and the refused-move tests fire the pending-change event their stubbed
conversion state stands for and assert the peer's strict `movable` (false only
for a refusal of its own session).

Co-authored-by: Copilot <[email protected]>
…t during a move

CI (Windows) failed the Copilot peer-move and session-move E2E tests with
"can't be prepared for moving chats yet (notReady: the session aggregate is
unverified or awaits its re-projection)". A move converts a new session's
catalog on demand by staging its aggregate from live state and then converting
it. The session's own activity after a turn (its read state, changes summary,
source control state) writes projected session state, which marks the aggregate
dirty without the catalog-sync queue the conversion holds. Landing between the
staging and the conversion, as slower post-turn work on Windows does, it makes
4a refuse the conversion.

The move now stages again from live state, which includes that write, and
converts, up to three times, and only for that reason. A unit test injects a
dirty mark right after the staging cleans the aggregate; without the retry, it
fails with the CI error.

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

Registration defers a chat's `movable` until it joins its session's catalog.
A chat its session already lists can be registered again (while it is
resolved, say), and was then also deferred, so its flag could be stale for a
moment, as in the refused-move race CI showed. Such a chat is now published at
once; a chat not yet in the catalog is still deferred.

Co-authored-by: Copilot <[email protected]>
A restored chat (registerRestoredChatSummary) joins its session's catalog
before it registers, so ba274aa publishes its `movable` synchronously.
The test registers one and changes a session input, reading `movable` with
no await after each step. Re-deferring that path (reverting ba274aa)
fails it: the restored chat reads not movable. The comment now names the
actual path instead of "registered again".

Co-authored-by: Copilot <[email protected]>
@sandy081
Sandeep Somavarapu (sandy081) merged commit 9ec0857 into main Oct 16, 2026
68 checks passed
@sandy081
Sandeep Somavarapu (sandy081) deleted the agents/block4-chat-move-hardened-tests branch October 16, 2026 14:35
Sandeep Somavarapu (sandy081) added a commit that referenced this pull request Oct 16, 2026
…ts catalog becomes readable

Reconciliation parked `sourceUnresolvable` sessions but retried
`providerUnavailable` ones on every pass. A registered provider whose
catalog is unreadable (older codex sessions in production) therefore had
each session's database opened on every 30 s pass, indefinitely: about
10 re-attempts per session per hour before Block 4a and about 80 after it.

- `providerUnavailable` now parks the session like `sourceUnresolvable`,
  both when the provider is unregistered (checked before any storage is
  claimed) and when a registered provider cannot vouch for it. Parked
  sessions remember their provider.
- When a provider's catalog becomes readable, `wakeParkedProviderSessions`
  releases only that provider's parked sessions and a pass is scheduled if
  any were released. That pass re-projects them and converts their legacy
  chat catalogs. Provider registration, session mutations and the hourly
  verification still wake parked sessions as before.
- A wake generation keeps a pass from parking a session whose source it
  resolved before a wake, matching the existing dirty-marker guard.
- Parking and every wake, including the per-provider one, are announced
  through `onDidChangeParkedSessions`, so chat movability (#342047), which
  treats a parked legacy catalog as unverifiable, stays current.
- AGENTS.md describes the two parking reasons and their wake signals.

Measured with 110 such sessions and passes every 30 s: 6,000 session
database opens in an hour before, 110 after (each session's re-projection
parks it once), then only the hourly verification's sample. End to end
with 70 sessions: 150 opens every pass before; 150 and 60 in the first two
passes after, then 0. All 70 convert once the catalog becomes readable.

Co-authored-by: Copilot <[email protected]>
Sandeep Somavarapu (sandy081) added a commit that referenced this pull request Oct 16, 2026
…ts catalog becomes readable (#342127)

* agentHost: park sessions whose provider cannot vouch for them until its catalog becomes readable

Reconciliation parked `sourceUnresolvable` sessions but retried
`providerUnavailable` ones on every pass. A registered provider whose
catalog is unreadable (older codex sessions in production) therefore had
each session's database opened on every 30 s pass, indefinitely: about
10 re-attempts per session per hour before Block 4a and about 80 after it.

- `providerUnavailable` now parks the session like `sourceUnresolvable`,
  both when the provider is unregistered (checked before any storage is
  claimed) and when a registered provider cannot vouch for it. Parked
  sessions remember their provider.
- When a provider's catalog becomes readable, `wakeParkedProviderSessions`
  releases only that provider's parked sessions and a pass is scheduled if
  any were released. That pass re-projects them and converts their legacy
  chat catalogs. Provider registration, session mutations and the hourly
  verification still wake parked sessions as before.
- A wake generation keeps a pass from parking a session whose source it
  resolved before a wake, matching the existing dirty-marker guard.
- Parking and every wake, including the per-provider one, are announced
  through `onDidChangeParkedSessions`, so chat movability (#342047), which
  treats a parked legacy catalog as unverifiable, stays current.
- AGENTS.md describes the two parking reasons and their wake signals.

Measured with 110 such sessions and passes every 30 s: 6,000 session
database opens in an hour before, 110 after (each session's re-projection
parks it once), then only the hourly verification's sample. End to end
with 70 sessions: 150 opens every pass before; 150 and 60 in the first two
passes after, then 0. All 70 convert once the catalog becomes readable.

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

* agentHost: release a parked session when it restores through its own lookup

A legacy session parked as `providerUnavailable` can restore through its
provider's per-session lookup (`activation: 'restore'`) while the
provider's whole catalog stays unreadable. Codex, for example, answers a
restore but returns nothing to passive lookups until it is activated. That
restore neither made the catalog readable nor woke the session, so the
session stayed excluded from reconciliation. `_normalizeCatalogForMove`
then refused its chats as `legacyCatalog` until another wake, possibly
the hourly verification.

A successful restore is evidence that the session's source resolves, so it
now releases that session's parking and schedules a pass. Once loaded, the
session re-projects from its live state and converts.

Addresses review feedback on #342127.

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

---------

Co-authored-by: Copilot <[email protected]>
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.

4 participants