Skip to content

agent host: attribute provider send latency and trim host-side first turn overhead - #339016

Merged
Vijay Upadya (vijayupadya) merged 3 commits into
mainfrom
vijayu/ah-perf1
Oct 1, 2026
Merged

Vijay Upadya (vijayupadya) merged 3 commits into
mainfrom
vijayu/ah-perf1

Conversation

@vijayupadya

@vijayupadya Vijay Upadya (vijayupadya) commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR

  • New telemetry: providerStage*Ms fields in agentHost.turnCompleted and the OTel turn_timing span break the time after dispatch into stages, from queue and client start through SDK create/resume to model response. The same breakdown appears in an [AgentHostFirstProgress] log line, and the renderer's [ChatTTFP] trace lines now carry epochMs so the two can be lined up. This is what will explain the Windows first-progress gap in production.
  • Faster first turns: client startup, session config and project resolution now run in parallel instead of in sequence, and concurrent worktree-isolation git lookups for the same folder share one read.
  • Cheaper checkpoints: clean repos skip the temp index entirely. Repos with uncommitted changes copy the existing index instead of running git read-tree, and fall back to the old path whenever that isn't safe.
  • Measured: replay E2E TTFP p50 is about 30% lower. On Windows, host overhead before the model call drops about 190 ms. The end-to-end user-visible effect is small, because the larger Windows costs (MCP startup, runtime session creation) are outside this PR.
  • Risk: low. The provider changes only run independent steps in parallel, and the checkpoint shortcuts produce the same tree or fall back to the old path. Turn ordering is unchanged.

Why

Agent-host (Copilot CLI) sessions are substantially slower to first progress than extension-host sessions, and the gap is mostly on Windows. Today's telemetry stops at "dispatched to the provider", but most of the time is spent after that. So we can't tell how much of it is client startup, customization snapshot, SDK session create/resume, or model latency. This PR adds that breakdown and removes some serial host-side work from the first turn.

Changes

Instrumentation

  • New AgentHostProviderSendStage / IAgentProviderSendStageRecorder. The turn tracker records provider stages between dispatch and first progress:
    • queue, refresh, client, snapshot, config, create, finalize, persist, turnPrepare, modelResponse
  • The stages are emitted as providerStage*Ms in agentHost.turnCompleted and in the OTel turn_timing span, and are documented in OTEL.md.
    • A stage that never ran is omitted. A reported 0 means it ran within timer resolution.
  • An [AgentHostFirstProgress] log line gives the same breakdown for local investigation.
  • Copilot marks the stages on every launch path:
    • provisional materialization;
    • default-session resume;
    • peer-chat resume;
    • session launcher config, create and finalize.
  • The renderer's [ChatTTFP] start / end trace lines include epochMs (wall-clock), so local traces can be lined up with the host's [AgentHostFirstProgress] breakdown.

Host-side latency

  • Copilot provider: these steps now run in parallel:
    • the independent client-start lookups;
    • _buildSessionConfig (BYOK, shell tools and custom agents);
    • project resolution, alongside session launch;
    • reading the stored resume metadata, alongside client acquisition.
  • Checkpoint (captureWorkingTreeAsTree):
    • git status and HEAD^{tree} run in parallel.
    • A clean working tree with a HEAD returns HEAD's tree directly, with no temp index or extra git processes. A clean repo with no commits still uses write-tree, so SHA-256 repos get their own empty tree.
    • With uncommitted changes, the temp index is seeded from a copy of the repo's index instead of git read-tree HEAD. The index path is resolved with git rev-parse --git-path index, so linked worktrees work.
    • The copy is used only when every git status entry can be restaged onto it (modified, added or untracked files, and deletions on disk). Staged deletions, renames, copies, conflicts, and files added then deleted (AD) fall back to read-tree, as does any failure.
  • Checkpoint service: the baseline-exists check runs alongside the capture.
  • Worktree isolation: concurrent _getGitInfo calls for the same folder share one in-flight read of repository root, current branch and default branch. Once it settles, the next caller reads git again, and a failed read isn't reused. This saves duplicate git processes when session config is resolved several times during startup

Results

Measurement Before → After Change
Local replay E2E (recorded model traffic, Windows), TTFP p50 first turns and follow-ups ~30% lower
Checkpoint temp-index seeding, local dirty repo (Windows) read-tree 148 ms → index copy 3–4 ms −98% for that step (whole capture ~520 → ~380 ms, −27%)
Hello A/B, Windows, no repo: dispatch 453 → 353 ms −22%
Hello A/B, Windows, no repo: checkpoint 406 → 316 ms −22%
Hello A/B, Windows, no repo: host overhead before the model call 1,315 → 1,124 ms −15%
Hello A/B, turn start → send() returned Windows 745 → 661 ms; Linux 631 → 439 ms −11% / −30%
Hello A/B, large-repo variant, turn start → send() returned Windows 1,348 → 1,301 ms; Linux 645 → 618 ms −3% / −4%
Hello A/B, end-to-end UI TTFP all variants within model-latency noise at 3 runs per arm

This PR is incremental. The larger Windows costs are MCP startup blocking the turn, per-session runtime work and SDK session creation on first send; these are tracked separately.

Copilot AI balanced review requested due to automatic review settings September 30, 2026 23:18

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.

Copilot review overview

🟡 Changes recommended

Configuration-triggered session restarts drop the recorder and misattribute launch latency to the refresh stage.

Review effort: Balanced
Findings: 2 Low severity

Open (2)
What changed in this PR

Adds provider-stage latency telemetry and reduces first-turn/checkpoint overhead in Agent Host.

Changes:

  • Attributes provider dispatch-to-progress latency across telemetry, OTel, and logs.
  • Parallelizes independent Copilot session startup work.
  • Optimizes Git checkpoint capture with clean-tree and index-copy fast paths.
File Description
common/​agent.ts Adds the stage recorder to send context.
common/​agentHostTelemetry.ts Defines provider stages and recorder contract.
common/​otel/​agentHostTiming.ts Exports stage timing attributes.
node/​agentHostTurnTracker.ts Records and logs stage durations.
node/​agentHostTelemetryReporter.ts Emits stage telemetry and OTel data.
node/​agentSideEffects.ts Creates the per-turn recorder.
node/​copilot/​copilotAgent.ts Instruments and parallelizes session startup.
node/​copilot/​copilotAgentSession.ts Marks model-response timing.
node/​copilot/​copilotSessionLauncher.ts Times launch stages and parallelizes configuration.
node/​agentHostGitService.ts Adds checkpoint fast paths.
node/​agentHostCheckpointService.ts Overlaps baseline lookup with capture.
OTEL.md Documents new timing fields and logs.
test/​node/​copilotAgent.test.ts Tests peer-resume stage propagation.
test/​node/​agentHostTurnTelemetry.test.ts Tests provider-stage telemetry boundaries.
test/​node/​agentHostGitService.test.ts Tests index-copy eligibility.
test/​node/​agentHostGitService.integrationTest.ts Tests checkpoint behavior across repository states.

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

- Keep parseChangedPaths' JSDoc attached to it and drop a duplicated section divider.
- Share one in-flight worktree-isolation git-info read per folder (from #338974).
- Include epochMs in [ChatTTFP] trace lines to align with host timing (from #338974).

Co-authored-by: Copilot <[email protected]>
# Conflicts:
#	src/vs/platform/agentHost/node/copilot/copilotSessionLauncher.ts
#	src/vs/platform/agentHost/node/shared/worktreeIsolation.ts
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: 64bb1c15 Current: 2ea7225e

Changed (2)

sessions/chatCompositeBar/MixedStatuses/Light
Before After
before after
chat/aiCustomizations/aiCustomizationManagementEditor/DiscoverPluginsLoadingMore/Light
Before After
before after

2 insignificant change(s) omitted (≤20 px, Δ≤2). See CI logs for details.

@vijayupadya Vijay Upadya (vijayupadya) added the agent-host Issues for the agent-host implementation (not the protocol) label Oct 1, 2026
@vijayupadya
Vijay Upadya (vijayupadya) marked this pull request as ready for review October 1, 2026 02:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

agent-host Issues for the agent-host implementation (not the protocol) perf-startup

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants