Repository navigation
agentHost: Improve perf by keeping pre-warmed Copilot sessions usable and initialize their tools before the first send - #349153
Merged
Conversation
…ir tools before the first send
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The warm-chat check still performs uncancellable database and RPC I/O while holding the chat queue, so background revalidation can delay a Send even when only draft text changed.
1 open issue
What changed in this PR
This PR aims to reduce first-message latency in Copilot Agent Host chats by keeping pre-warmed sessions aligned with the composer and preparing their tools before Send.
Changes:
- Syncs draft text, model, and custom-agent selections so matching warm sessions stay alive and stale ones are replaced.
- Initializes tools after MCP startup and Connector reconciliation, with cancellation checks before tool initialization.
- Keeps idle provisional drafts in memory and adds tests for composer sync, re-warming, expiry, and warm-up cancellation.
| File | Description |
|---|---|
src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostUntitledProvisionalSessionService.test.ts |
Tests composer synchronization and draft clearing. |
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostUntitledProvisionalSessionService.ts |
Adds debounced composer sync and handoff cleanup. |
src/vs/platform/agentHost/test/node/copilotAgent.test.ts |
Tests tool warm-up, cancellation, model replacement, and expiry. |
src/vs/platform/agentHost/test/node/agentService.test.ts |
Tests composer-driven re-warming and memory-only drafts. |
src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts |
Initializes tools after MCP startup and Connector reconciliation. |
src/vs/platform/agentHost/node/copilot/copilotAgent.ts |
Revalidates, extends, or replaces warm launches and manages warm-up cancellation. |
src/vs/platform/agentHost/node/chatContributions/chatDraft/chatDraftContribution.ts |
Skips persistence for idle provisional drafts. |
src/vs/platform/agentHost/node/agentHostSessionPrewarmer.ts |
Tracks draft changes and coalesces gated re-warm requests. |
src/vs/platform/agentHost/common/agent.ts |
Extends the warm-chat contract with composer selections. |
src/vs/platform/agentHost/AGENTS.md |
Documents tool preparation and composer-driven pre-warming. |
Review effort: Balanced
Vijay Upadya (vijayupadya)
marked this pull request as ready for review
November 18, 2026 23:14
Vijay Upadya (vijayupadya)
enabled auto-merge
November 18, 2026 23:15
Dmitriy Vasyura (dmitrivMS)
previously approved these changes
Nov 18, 2026
# Conflicts: # src/vs/platform/agentHost/node/copilot/copilotAgent.ts
Dmitriy Vasyura (dmitrivMS)
approved these changes
Nov 19, 2026
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.

Makes the first message of a new Copilot agent host chat faster when it starts from a pre-warmed session. A pre-warmed session was often thrown away at send time, and when it was used, the runtime still built its tool catalog and reloaded MCP on the first turn.
Changes3
Re-warm while composing instead of discarding at send
chat/draftChanged(ProvisionalDraftSync). It starts from the draft's launch selection, so an untouched draft sends nothing. Clearing the text or going back to the built-in agent is still sent.AgentHostSessionPrewarmerfollows these changes and callswarmChatagain with the composer's selection (IAgentWarmChatSelection).CopilotAgent._warmChatkeeps a launch that still matches and restarts its 5-minute lifetime. It replaces a launch made with another model or agent, one whose workspace trust changed, or one whose draft-scoped customizations changed (in-memory state only, so composing never waits on a sync). It also launches again after expiry or teardown, but not afterwarmFailed.modelSelected/modelChanged) and start cold. Now that send uses the re-warmed launch.Initialize tools while pre-warming
CopilotAgentSession.warmUpreplacesstartMcpServers. It runssession.mcp.list(), waits for the launch-time Connector reconciliation, and then callssession.tools.initializeAndValidate(). The runtime caches the tool catalog (including cloud memory preparation) before the user sends, and the first turn reuses it.warmUpToken), or when a turn has started.Correctness
ChatDraftContributiondoesn't persist drafts of idle provisional sessions, likeChatConfigContribution. These sessions have no database before their first send and are never restored, so composing no longer createssession.dbfor a draft._warmChatchecks again for shutdown after each await, so a launch that finishes during shutdown doesn't leak its expiry timer.Measurements
Local Windows runs of a development build,
mainat53fa24195c2against this change, with the same signed-in profile and settings (chat.agentHost.experimental.prewarmSessions: true, OTel file export). These are real model requests in the vscode repository with a one-word prompt, interleaved scenarios, and medians in ms. The phases come from the Copilot runtime'ssession.first_turn/session.timing.*spans and the Agent Hostturn_timingspan. Each scenario opens a new chat, waits 30 s so the draft is pre-warmed, then sends.New chat, model unchanged (pre-warmed session used in both builds, n=3)
maintool_descriptorsmcp_initializationturn_preparationNew chat, model changed in the picker before sending (n=3)
mainmodelChanged), 3/3Send → first model request is the provider dispatch plus the runtime's
firstModelCallStartOffsetMs. It doesn't include the turn-start checkpoint, which #349064 moves off the send path. In these runs the checkpoint also varied with the repository's uncommitted state, which differed between the two builds. The model's own time to first token (1–8 s here) dominates end-to-end time to first progress and varied too much at this sample size to compare.Testing
pnpm run typecheck-client: passed.node build/oxlint.ts <changed files>: passed.scripts\test.bat --run src/vs/platform/agentHost/test/node/copilotAgent.test.ts --run src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts --run src/vs/platform/agentHost/test/node/agentService.test.ts --run src/vs/platform/agentHost/test/node/chatContributions.test.ts --run src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostUntitledProvisionalSessionService.test.ts: 4,585 passing, 16 pending.[warm]discard, re-warm and claim sequence.