Repository navigation
Agent Host: pre-warm Copilot sessions before the first send (experimental) - #341698
Merged
Vritant Bhardwaj (vritant24) merged 7 commits intoOct 16, 2026
Merged
Vritant Bhardwaj (vritant24) merged 7 commits into
Vritant Bhardwaj (vritant24) merged 7 commits into
Conversation
…ntal) Behind the new experiment-controlled setting chat.agentHost.experimental.prewarmSessions (default off), a new Copilot draft starts its SDK session and MCP servers before the first message: - CopilotAgent splits _materializeProvisional into a launch half and a persist/announce half. warmChat launches through the per-chat queue and starts MCP with rpc.mcp.list(); the first send claims the warm session, or discards it and materializes normally when something fixed at launch changed (working directory, client tools, plugins, MCP definitions). An unclaimed warm session is never resumed; disposal, a 5 minute time limit and debounced revalidation discard it. - AgentHostSessionPrewarmer gates warming in AgentService (active client arrived, enablement resolved, folder trusted), logs the experiment trigger before reading the setting (pending until the assignment context arrives), and warms worktree drafts through a throwaway folder draft. - Turn telemetry reports usedPrewarmedSession when a turn claimed a warm session. - The pending experiment-trigger logic moves out of AgentSideEffects into AgentHostSettingExperimentTrigger so both features share it. Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Trust validation and warm-session lifecycle, retry, and model-configuration handling need correction before approval.
4 open findings
What changed in this PR
Adds experimental, default-off prewarming for Copilot Agent Host drafts to start runtimes and MCP servers while users compose.
Changes:
- Adds configuration, eligibility gates, and shared experiment-trigger handling.
- Implements warm-session launch, claim, replacement, expiry, and cleanup.
- Adds usage telemetry and focused regression tests.
| File | Description |
|---|---|
src/vs/platform/agentHost/test/node/copilotAgent.test.ts |
Tests warm-session lifecycle and reuse. |
src/vs/platform/agentHost/test/node/agentSideEffects.test.ts |
Tests claimed-session telemetry. |
src/vs/platform/agentHost/test/node/agentService.test.ts |
Tests gates and throwaway worktree drafts. |
src/vs/platform/agentHost/test/node/agentHostTelemetryReporter.test.ts |
Tests telemetry field emission. |
src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts |
Starts MCP servers and defers error telemetry. |
src/vs/platform/agentHost/node/copilot/copilotAgent.ts |
Implements warm-session lifecycle. |
src/vs/platform/agentHost/node/agentSideEffects.ts |
Connects experiment and turn reporting. |
src/vs/platform/agentHost/node/agentService.ts |
Integrates prewarming with draft lifecycle. |
src/vs/platform/agentHost/node/agentHostTurnTracker.ts |
Records warm-session claims. |
src/vs/platform/agentHost/node/agentHostTelemetryReporter.ts |
Emits prewarming usage telemetry. |
src/vs/platform/agentHost/node/agentHostSettingExperimentTrigger.ts |
Shares deferred experiment-trigger logic. |
src/vs/platform/agentHost/node/agentHostSessionPrewarmer.ts |
Gates warming and manages throwaway drafts. |
src/vs/platform/agentHost/common/agentService.ts |
Defines the setting identifier. |
src/vs/platform/agentHost/common/agentHostTelemetry.ts |
Extends provider telemetry context. |
src/vs/platform/agentHost/common/agentHostStarter.config.contribution.ts |
Registers the experimental setting. |
src/vs/platform/agentHost/common/agentHostSchema.ts |
Defines host configuration. |
src/vs/platform/agentHost/common/agent.ts |
Adds warming and claim-reporting contracts. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Workspace-less ("Quick Chat") drafts run in a provider-owned scratch folder
and their customization enablement resolves, so they can warm like folder
drafts. The trust gate now applies only to a picked folder, since the scratch
folder holds no workspace content for it to protect. Ephemeral drafts stay
excluded because they launch with MCP disabled.
Co-authored-by: Copilot <[email protected]>
Records in the prewarmer and the Copilot claim path that a worktree chat's own session always starts at the first send, that the throwaway folder draft's live MCP status is not mirrored onto the worktree draft, and that clients which choose isolation at Send warm a folder session that the send discards. Co-authored-by: Copilot <[email protected]>
Address review feedback on Copilot session pre-warming: - Require every launch folder, including additional multi-root folders, to be trusted before warming. - Keep a create retry for a warm draft provisional, so it is not announced as materialized. - Forget warm sessions whose runtime is torn down by a client restart, closed-connection recovery or release, keeping the draft's reservation so the next send launches a fresh runtime. - Replace a warm session when the selected model id changes, because model-specific launch configuration is fixed at launch. - Drop 'local' from the setting description: the setting is mirrored to every Agent Host connection. - Document session pre-warming in the Agent Host AGENTS.md. Co-authored-by: Copilot <[email protected]>
…tion Port session pre-warming to main's chat-owner context: warm sessions are keyed by the provisional reservation key, queue on the chat's lifetime, take the active client from the owner session, and the launch records the chat's storage and owner. The refresh-reason check now holds the chat's customization anchor and includes the ownerChanged reason. The prewarmer asks the host for the default chat's operation context. Co-authored-by: Copilot <[email protected]>
Vritant Bhardwaj (vritant24)
marked this pull request as ready for review
October 15, 2026 21:12
roblourens
previously approved these changes
Oct 15, 2026
Restructure Copilot session pre-warming per review: the early launch is now the launch the first send would run, started early and kept on the provisional reservation instead of in a separate warm-session lifecycle. - The first send completes the early launch, or discards it and launches cold when anything fixed at launch changed (working directory, model or agent selection, client tools, plugin or MCP definitions, owner). Nothing is applied to it live; the debounced revalidation and re-warm on model change are gone. - A runtime torn down underneath an early launch is detected lazily and its leftover SDK state deleted before the id is launched again. - Drop the worktree throwaway folder draft: worktree drafts never warm. - Turn telemetry reports why a send discarded a pre-warmed session (prewarmedSessionDiscardReason) alongside usedPrewarmedSession. - Starting an MCP server on a warm draft now reaches its early launch instead of failing. Co-authored-by: Copilot <[email protected]>
Contributor
|
Base:
|
Vritant Bhardwaj (vritant24)
enabled auto-merge
October 15, 2026 22:27
roblourens
previously approved these changes
Oct 15, 2026
…tion Co-authored-by: Copilot <[email protected]>
roblourens
approved these changes
Oct 16, 2026
Vritant Bhardwaj (vritant24)
deleted the
agents/prewarm-copilot-sessions-pr1-implementation
branch
October 16, 2026 03:22
Sandeep Somavarapu (sandy081)
added a commit
that referenced
this pull request
Oct 16, 2026
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]>
Sandeep Somavarapu (sandy081)
added a commit
that referenced
this pull request
Oct 16, 2026
… session (Move Chats, Block 4) (#341788) * agentHost: move a chat between normalized catalogs and reorder within 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]> * agentHost: carry a moved chat's central state to its new session (Block 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]> * agentHost: move registered chats between sessions in memory (Block 4) 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]> * agentHost: publish which chats can be moved, behind a setting (Block 4) 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]> * agentHost: implement moveChat for peers and in-session reorder (Block 4) 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]> * agentHost: harden chat moves after review (Block 4) - 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]> * agentHost: Block 4 review pass-2 fixes - 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]> * agentHost: a moved chat keeps its source's config (Block 4) 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]> * agentHost: promote a chat into a new session in the database and store (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]> * agentHost: promote a chat into a new session (Block 4) 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]> * agentHost: a moved chat's live state follows it (Block 4) - 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]> * agentHost: Block 4 review pass-3 fixes - 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]> * agentHost: a moved chat's runtime publishes no session state until it 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]> * agentHost: gate chat moves on the stored catalog authority, not the address (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]> * agentHost: allocate a promoted session's address in one place (Block 4) 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]> * agentHost: a moved chat's terminals are claimed by its new session (Block 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]> * agentHost: complete client tool calls on the chat's own runtime only (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]> * agentHost: resolve content access through the chat stored there (Block 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]> * agentHost: older clients see a chat only in the session it was created 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]> * Block 4: snapshot a chat's attachments in its recorded storage 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]> * Block 4: keep a deleted session's attachments while chats that moved 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]> * agentHost: a moved or promoted chat keeps its own config, never D1's 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]> * Block 4: keep showing a chat that moved to another session 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]> * Block 4 review pass-4 fixes - L2: deleting a session's data except its attachments treats what a concurrent full delete removed first as deleted. - L3: a chat is no longer a moved chat once it moves back to its origin or is deleted. Reading the origins of moved chats is retried once; while it fails, older clients see no chat that may have moved and the next session listing reads them again. - L4: the owner of a recorded storage is found through an index kept with the chat registry. - L5: the reload after a failed in-memory move is awaited and its failures are logged. - L6: no synchronous lookup of a default chat's storage falls back to the creation-time rule: creation uses it explicitly, everything else uses the recorded storage (skill completion now resolves it asynchronously). - 4b-L1: a row access of a chat deleted between finding it moved and finding its new owner is dropped and logged instead of throwing. - 4b-L2: work deferred until a chat's turn ends (Agent Merge notices, external histories) reads the chat's owner when it is delivered. - 4b-L3: the D1 pin also covers a property the moved chat never set while the target's default chat sets it. - 4b-L4: attachment tests for a chat moved on again and for deleting a session together with its last moved chat. Co-authored-by: Copilot <[email protected]> * Block 4: Mission Control follows chat moves Mirror streams are per session and already follow a chat's owner at emit time. The SDK namespace replicates only a session's default chat: - a chat promoted to a new session's default chat starts that session's SDK stream at promotion, from the start of its journal; - a default chat that moves under another session (where it is a peer) is replicated no more: its old stream is retired, without replaying its history. Both rules await the Mission Control owner's confirmation and are documented as such. Read-only content access also reaches the data of a session's loaded chats and of the session a moved chat came from. promoteChats records the new session's default chat before the owner change is reported, so listeners see the session complete. Co-authored-by: Copilot <[email protected]> * Block 4: move a single-chat session under another session (VS Code-internal) A session whose default chat is its only chat (with that chat's subagents) can move under another session of the same agent: its chat becomes a peer of the destination, keeping the session's database as its storage, and the session ends (its registration, catalog and central state are tombstoned in the same transaction; its data stays). It runs on the shared chat-move path, so the same validation, folder additions, config carry-over, admission hold and live-turn handling apply. Behind the chat-moves setting (default off). - Protocol: VS Code extension `vscode/moveSession` (every parameter required, `after` may be null), capability `vscode.sessionMove` (never on relay transports) and session `_meta['vscode.movable']`; other hosts never see it. - Required `IAgentService.moveSession` and `IAgentConnection.moveSession` (rejects with AgentHostSessionMoveUnsupportedError without a request when the host lacks the capability) in every implementation, and `canMoveSessionUnder` / `moveSessionUnder` on the Agent Host sessions provider. - Deleting a chat's storage keeps the attachments that chats moved out of that session still read. Co-authored-by: Copilot <[email protected]> * Block 4: restore the chat order a move or a reorder recorded A session's restore listed its default chat first and then persisted that order, so a chat a move or a reorder placed before the default chat lost its place at the first restart. Restoring a normalized catalog now orders the visible chats by their recorded order before the listing is persisted; chats the order doesn't list keep their places. Co-authored-by: Copilot <[email protected]> * Block 4: document moving chats in the agent host spec Adds AGENTS.md section 3c: what moves with a chat, how refusals and live moves behave, config and data rules, and what clients and Mission Control see. Co-authored-by: Copilot <[email protected]> * Block 4: a session that owns a worktree does not move under another session A session that ends by a move records no pending worktree removal (#6 records one only when a session is deleted), so a detached worktree the moved chat doesn't work in would stay claimed by the ended session. Refuse such a move with worktreeFolder; nothing changes. Co-authored-by: Copilot <[email protected]> * Block 4 review pass-5 fixes - L1: document that a session moved under another session ends and its chat follows the destination's session-level state like every peer; only its chatMutable values carry (AGENTS.md section 3c). - L2: comment the backend-only pairing of the chat move tracker. - L3: untracking a session drops its catalog even when it was reported only through update, and nothing is scheduled once the tracker is disposed; a provider test pins that a session the provider drops is untracked, so a session that ends by a move reports its chat moved. Co-authored-by: Copilot <[email protected]> * Block 4: promote a chat only once its first turn started No agent persists a chat's conversation before its first turn starts (Copilot defers the SDK session, Claude writes its transcript and Codex its rollout when the turn begins). A session whose default chat has none can't be restored: after a restart it stayed listed but never opened (probe P2-1). Like a brand-new session, which is durable only after its first send, a chat now becomes its own session only when its resolved history has a turn or one is running; otherwise the promotion is refused with notStarted and nothing changes. Co-authored-by: Copilot <[email protected]> * Block 4: don't take a promoted session for a never-created draft 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]> * Block 4: address review feedback on moving chats live - 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]> * Block 4: note that a moved chat's attachment keep-reference is interim Co-authored-by: Copilot <[email protected]> * Block 4: take the moved-chat origins off the session listing's path 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]> * Block 4: a moved chat's descendants keep their state; a promoted chat 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]> * Block 4b: copy a moved chat's pre-move attachments into its own storage 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]> * Block 4b: keep the origin's attachments while a moved chat lives (decision 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]> * Block 4: integrate Block 4a's older-build guard into moves, promotions 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]> * Block 4: a chat's folders in transit stay attached; a moved chat's folders 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]> * Block 4: review pass-6 fixes for the 4a integration and the folder reservation - 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]> * Block 4: a promoted session keeps its chat's title across a restart (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]> * Block 4b: a deleted chat's attachment copy record goes with it (B4-2) 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]> * Block 4: pass-7 review fixes for promoted titles and attachment copies - 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]> * Block 4: log expected move refusals at info, not as errors (B4-4) 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]> * Block 4: give the session pre-warmer the recorded default chat storage 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]> * Block 4: no moved-chat statements where no chat moved (perf) - 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]> --------- Co-authored-by: Copilot <[email protected]>
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


First PR of the "pre-warmed Copilot sessions" plan: the Agent Host starts a new Copilot draft's SDK session and MCP servers before the first message, so connectors and plugins come up while the user is still composing. Copilot harness only; Claude and Codex are unchanged.
Everything is behind the new experiment-controlled setting
chat.agentHost.experimental.prewarmSessions(boolean, off by default,experiment: { mode: 'auto' }, mirrored to the host as root configprewarmSessions). With it off, drafts behave as today: their launch starts on the first send. Client-side sign-in before Send (plan §7.4) is a follow-up PR. In this PR, a connector that needs sign-in shows as "auth required" but VS Code still only prompts during the first turn, as it does today.What changed
AgentHostPrewarmSessionsSettingId/AgentHostPrewarmSessionsConfigKey, registered likechat.agentHost.experimental.overlapProviderPreparation. The trigger (logSettingExperimentTrigger) fires once every other gate has passed and before the setting is read, so both arms report the same moment. It stays pending until the workbench forwards the assignment context. The pending logic moved out ofAgentSideEffectsinto the sharedAgentHostSettingExperimentTrigger, which both features now use.CopilotAgent: start the draft's launch early, complete it on send._materializeProvisionalis split into_launchProvisional(create + register the SDK session, nothing persisted) and_completeProvisionalMaterialization(metadata, execution marker, agent metadata, baseline checkpoint,onDidMaterializeChat).IAgentChats.warmChatstarts the same launch early and keeps it onIProvisionalSession.earlyLaunch, rather than in a separate warm-session map. It runs through the per-chat queue, like_prepareTurn, so a Send arriving mid-launch waits for and reuses it, and disposal cannot interleave with registration.rpc.mcp.list()outside the chat queue, because creating a session alone doesn't start MCP servers and a Send must not wait behind slow MCP startup._sessionRefreshReasonfor client tools, plugins, root MCP definitions, additional roots, disabled servers, runtime refresh requirements and chat ownership._resumeSession'd. Discard destroys it and deletes its SDK state.isDisposed; the draft keeps its reservation, and leftover SDK state is deleted before the next launch or on disposal.startMcpServercan address an early launch without materializing the draft. The regression where it rejected every provisional chat is fixed and covered by a test.localModelProvider.onAutoSessionStarted()andagentHost.copilotSdkSessionErrorare deferred to claim (held errors are dropped on discard).[warm]info lines log start, claim and discard, including discard reasons and session IDs.AgentServicegating (AgentHostSessionPrewarmer). Idle, non-ephemeral, non-imported drafts, including workspace-less ("Quick Chat") ones, warm only once an active client has arrived, customization enablement has resolved, and every launch folder, including additional multi-root folders, is trusted. A missing trust configuration fails closed for folder drafts. Workspace-less drafts run in a scratch folder with no workspace content, so they skip the trust check. Copilot never needs a cold SDK download.usedPrewarmedSessionremains onagentHost.turnCompleted/agentHost.turnFailed(boolean,isMeasurement: true) when the turn uses an early launch. If the send instead discards one and starts cold,prewarmedSessionDiscardReasonrecords the code-defined reason, such asmodelChanged,agentChanged,clientToolsChangedorworkingDirectoryChanged. Both fields are absent when no early launch is found. Discards outside the send path, such as expiry or closing a draft, are logged rather than emitted as turn discard reasons.Key decisions (from the implementation edge-case log)
IAgentChatContext.reportPrewarmedSession(discardReason?)reports that dispatch fact back to the turn tracker: no reason means the launch was used; a reason means it was discarded. The tracker merges it into the provider context, following the existingreportCodexModelProviderpattern.startMcpServeron a warm draft doesn't claim it. Claiming would persist and announce an unsent draft.mcp.list()runs outside the chat queue so a Send never waits on slow MCP startup.Validation
npm run typecheck-client: passed for the refactor and MCP-start fix.npm run build-fast -- --client-only: passed, producing fresh client output.Changed-TypeScript ESLint: passed, no warnings. Executed before committing with:
npm run eslint -- $(git diff --name-only -- '*.ts')Pre-commit hygiene: passed, 12 files checked for the refactor commit.
Focused tests: 33 passing, re-run on the final commit with:
./scripts/test.sh --reporter dot \ --run src/vs/platform/agentHost/test/node/copilotAgent.test.ts \ --run src/vs/platform/agentHost/test/node/agentService.test.ts \ --run src/vs/platform/agentHost/test/node/agentSideEffects.test.ts \ --run src/vs/platform/agentHost/test/node/agentHostTelemetryReporter.test.ts \ --grep "pre-warmed sessions|session prewarming|pre-warmed session|overlap"Coverage includes setting off/on and trigger timing in both arms; active-client arrival and draft disposal while waiting; untrusted and partially trusted multi-root folders; workspace-less and ephemeral drafts; skipping pending-worktree drafts; claim, immediate Send, disposal and stale-tool replacement; cold replacement after model-option/model-id changes; repeated create; client restart, closed-connection recovery and release; worktree send; starting an MCP server without claiming the draft; and used/discarded/absent telemetry through the reporter and
AgentSideEffects. The MCP-start regression test was also verified to fail without its production fix.Full affected suites: 3,364 passing, 14 failing on the final refactor code, with:
The same 14
CopilotAgentfailures were reproduced without the PR's review fixes earlier in this branch: external chat discovery, state/plan-file resolution and persisted debug-log collection. They remain local environment-dependent failures; the full run is not claimed as green.Earlier manual validation, before this refactor (Code OSS Agents window,
--log trace, test folder with a stdioeverythingMCP server and asessionStarthook):[warm]lines and no MCP process.[warm] Started, andserver-everythingran before Send while the hook had not run.[warm] Claimedwith no second SDK create, the hook ran exactly once, andagentHost.turnCompletedhadusedPrewarmedSession.[warm] Discarded ... reason=chatDisposedand its MCP process exited.[warm] Discarded ... reason=workingDirectoryChanged, then materialized normally in the worktree.