Repository navigation
agentHost: speed up new chat session startup - #349064
Conversation
The caller already checked for an existing baseline, so avoid a second git process on the first turn. Co-authored-by: Copilot <[email protected]>
Overlap the turn-start checkpoint snapshot with base-branch persistence. Both still settle before the message is dispatched. Warm new-session send to first text: ~1.9s -> ~1.47s in a git repo. Co-authored-by: Copilot <[email protected]>
Folder isolation without a pull request does not need the default branch, saving several git processes in createSession (~800ms -> ~600ms). Co-authored-by: Copilot <[email protected]>
… changes Status/title updates during send no longer trigger customization migration and discovery recomputes. Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Avoids loading the math renderer and re-rendering every response. Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
- Folder isolation only needs the HEAD branch name, so skip the full branch lookup. - Share in-flight repository root probes for the same folder instead of queueing duplicates. Warm repo createSession ~610ms -> ~470ms; empty folder ~345ms -> ~260ms. Co-authored-by: Copilot <[email protected]>
… mode Skips a git remote read on send for sessions that are not using Assisted permissions; switching to Assisted still applies it before any judge decision. Co-authored-by: Copilot <[email protected]>
The renderer's first management calls (plugin inventory, marketplaces) no longer hit the 1s unknown-channel timeout in fresh windows. Co-authored-by: Copilot <[email protected]>
Avoids loading Zod at agent host startup when Claude tools are not built (~120ms module load). Co-authored-by: Copilot <[email protected]>
Publishing already secures the metadata directory before writing, so drop the duplicate preparation, and resolve the Windows user SID once per process. Startup now runs 5 instead of 12 whoami/icacls processes on Windows (endpoint stage ~880ms -> ~390ms). Co-authored-by: Copilot <[email protected]>
- Resolve the turn-start checkpoint as soon as the before-tools working tree snapshot exists; the baseline commit/ref write continues in the same per-session queue, so turn end, discard and later captures still wait for it. - Read origin/HEAD alongside the remote list when resolving the default branch. Warm repo send to first text ~1.05-1.12s -> ~0.85-0.94s. Co-authored-by: Copilot <[email protected]>
Defer the refresh by a task so the several context changes during a draft-to-session handoff trigger a single check after the turn is dispatched (cold send renderer time ~690ms -> ~530ms). Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Incremental streaming renders each register a KaTeX completion callback, causing redundant full Markdown rerenders when loading finishes because callbacks from disposed render stores are not skipped.
1 open issue
What changed in this PR
This PR reduces new chat session startup latency across the agent host and renderer by removing redundant work, overlapping independent operations, and deferring optional dependencies.
Changes:
- Streamlines Git discovery and overlaps turn-start snapshots with session preparation while preserving queued checkpoint writes.
- Registers management channels earlier and defers Claude schema loading and Assisted-mode repository discovery.
- Reduces customization refreshes, loads math support on demand, and stops picker compaction once controls fit.
| File | Description |
|---|---|
src/vs/workbench/contrib/sessions/test/browser/chat/newChatMigrationNotice.test.ts |
Adapts tests to deferred notice checks. |
src/vs/workbench/contrib/chat/test/browser/widget/input/chatInputPickerResponsiveLayout.test.ts |
Updates expected layout measurements. |
src/vs/workbench/contrib/chat/test/browser/widget/chatContentParts/chatMarkdownContentPart.test.ts |
Tests conditional math loading. |
src/vs/workbench/contrib/chat/test/browser/aiCustomization/chatCustomizationMigrationNotice.test.ts |
Tests coalesced discovery updates. |
src/vs/workbench/contrib/chat/test/browser/agentSessions/workbenchAgentHostCustomizationService.test.ts |
Tests selective customization notifications. |
src/vs/workbench/contrib/chat/browser/widget/input/chatInputPickerResponsiveLayout.ts |
Stops compaction when pickers fit. |
src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatMarkdownContentPart.ts |
Loads KaTeX only for potential math. |
src/vs/workbench/contrib/chat/browser/aiCustomization/customizationMigrationServiceImpl.ts |
Reuses one marketplace configuration inspection. |
src/vs/workbench/contrib/chat/browser/aiCustomization/chatCustomizationMigrationNotice.ts |
Coalesces synchronous notice refreshes. |
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostCustomizationService.ts |
Filters unrelated session-state changes. |
src/vs/platform/agentHost/test/node/shared/worktreeIsolation.test.ts |
Tests reduced folder-isolation Git reads. |
src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts |
Tests deferred Assisted-mode context discovery. |
src/vs/platform/agentHost/test/node/agentSideEffects.test.ts |
Tests overlapping preparation and checkpoint capture. |
src/vs/platform/agentHost/test/node/agentService.test.ts |
Verifies early folder checkpoint capture. |
src/vs/platform/agentHost/test/node/agentHostGitService.test.ts |
Tests shared repository probes and retries. |
src/vs/platform/agentHost/test/node/agentHostGitService.integrationTest.ts |
Covers optimized Git reads with real repositories. |
src/vs/platform/agentHost/test/node/agentHostCheckpointService.test.ts |
Tests early snapshot completion and queued publication. |
src/vs/platform/agentHost/node/shared/worktreeIsolation.ts |
Skips unnecessary branch details for folder isolation. |
src/vs/platform/agentHost/node/localAgentHostMetadata.ts |
Caches the Windows user SID lookup. |
src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts |
Defers repository context until Assisted mode needs it. |
src/vs/platform/agentHost/node/claude/clientTools/claudeClientToolMcpServer.ts |
Lazily imports client-tool schema conversion. |
src/vs/platform/agentHost/node/claude/claudeServerToolMcpServer.ts |
Lazily imports server-tool schema conversion. |
src/vs/platform/agentHost/node/agentSideEffects.ts |
Starts checkpoints when working directories resolve. |
src/vs/platform/agentHost/node/agentService.ts |
Exposes resolved folders before base-branch persistence. |
src/vs/platform/agentHost/node/agentHostMain.ts |
Registers channels before endpoint setup and avoids duplicate directory preparation. |
src/vs/platform/agentHost/node/agentHostGitService.ts |
Shares repository probes and streamlines branch reads. |
src/vs/platform/agentHost/node/agentHostCheckpointService.ts |
Resolves after tree capture while queuing baseline writes. |
src/vs/platform/agentHost/common/agentHostGitService.ts |
Documents optimized Git lookup contracts. |
Review effort: Balanced
Preserve SDK v2 integration and MCP diagnostics while retaining startup optimizations. Co-authored-by: Copilot <[email protected]>
Refresh only the active markdown render when shared KaTeX loading completes. Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
|
Merged Validation:
The full Written by Connor's agent |
|
Required build/test CI is green, so this is now ready for review. The remaining pending VS Code PR Check is an approval gate, not a running build: it requires two collaborator approvals for the current unsigned head commit. All review threads are resolved. I'll continue watching reviews and CI, then use normal auto-merge/merge queue once approved. Written by Connor's agent |
…of before dispatch Providers can opt in with IAgentChats.awaitsTurnStartCheckpoint to receive the pending capture as turnStartCheckpoint on the send context. The host then dispatches the turn immediately, so the git snapshot overlaps model time-to-first-token. Copilot opts in and awaits the capture in its pre-tool hook, denying tools if it failed. Other providers still wait before dispatch. Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
…olicy may suppress SDK hooks The runtime drops SDK hook callbacks, including the pre-tool checkpoint gate, when allowManagedHooksOnly is in effect or managed settings fail closed. Co-authored-by: Copilot <[email protected]>
Keep first-tool checkpoint gating alongside current session and turn telemetry changes. Co-authored-by: Copilot <[email protected]>
Serialize checkpoint reads behind already queued capture work so fast no-tool turns cannot cache a missing compare-turns checkpoint. Co-authored-by: Copilot <[email protected]>
|
Fixed the merge-queue Windows E2E failure in 23060bf. Deferring the checkpoint until the first tool exposed a read/publication race: a fast no-tool follow-up no longer guarantees earlier checkpoint writes have settled, and an early compare request could cache a missing-checkpoint error. Checkpoint-pair reads now await already-queued publication; dispatch remains unblocked. Validation:
Written by Connor's agent |

Speeds up starting a new chat session in the agent host. I timed where the delay goes, and each commit fixes one source of it.
Changes
Turn-start checkpoint no longer blocks the first message
git statusand working-tree capture took up to several hundred ms on the critical path.IAgentChats.awaitsTurnStartCheckpoint. Copilot sends the turn immediately and awaits the pending capture in itsonPreToolUsehook, so no tool runs before the snapshot exists. The capture now overlaps the model's time to first token.allowManagedHooksOnly, because then the runtime drops SDK hook callbacks.Git work when creating a session and sending the first message
origin/HEADis read at the same time as the remote list.git remote -v) is loaded only when the session uses Assisted mode.Agent host process startup
whoami/icaclsprocesses instead of 12.Renderer
Temporary
lifecycleDiagnostics: { persist: false }. The runtime bundled with SDK v2 otherwise runs an uncached Team-repository git probe on every session create, which costs about 90 ms in folders that aren't git repositories. This is fixed upstream, and a TODO marks the option for removal on the next SDK bump.Measurements
Local Windows runs on SDK v2: baseline
mainat1d20abca144against this branch atda4a7f5cce7. These use a development build with model responses replayed locally, interleaved runs, and medians in ms. Both builds use the lifecycle-diagnostics opt-out, so the ~90 ms Team probe described above is excluded from both and the comparison measures only this branch. A cold session is the first one after the agent host process starts; a warm one is a later new session in the same process.The replayed model answers in about 15 ms, which hides the checkpoint overlap. With a simulated 1.5 s delay before the model's first token, and that delay subtracted:
On Windows, the cold first session with hooks is dominated by command hooks, mainly a PowerShell launch stall fixed in github/copilot-agent-runtime#43900. That fix will arrive with a future runtime update.
Reviewer notes
allowManagedHooksOnlypolicy is only seen after a turn was sent, that turn's tools don't wait for the checkpoint. Once seen, the session waits before dispatch.AgentHostCheckpointService.captureTurnStartCheckpointresolves once the trees are captured. The baseline write still runs in the per-session queue, so turn end, discard and later captures wait for it.Testing
pnpm run typecheck-client: passed.scripts\test.bat --run …) for every touched area passed. The checkpoint change was covered by the agent side effects, Copilot agent session, Copilot agent, session launcher and checkpoint service suites.ChatInputPickerResponsiveLayout"lays out once per frame…", also fails onmain.