Repository navigation
agentHost: make startup session discovery registry-first - #331239
Merged
Benjamin Christopher Simmonds (benibenj) merged 4 commits intoAug 17, 2026
Conversation
A 2026-08-17 Insiders reproduction with 941 SDK sessions and 1,437 per-session databases (~946 MB) showed the ~60s delay is not migration — `sessionRegistryBackfilled:copilotcli` was already true and migration was skipped. The time went to per-session SQLite work during discovery and listing: classification took 66.9s (113 external, 342 adoptable extension-host, 486 already known), registration of the 113 emitted candidates another 21.9s, and the first two AHP `listSessions` calls 109.8s and 91.0s, with a third 73.2s window after discovery. Each measured phase is addressed: - Classification (66.9s): discovery is now registry-first. `IAgent` gains an optional `setKnownSessionsFilter` seam that `AgentService` installs at provider registration; it answers, in one registry query for the whole candidate set, which sessions the host already owns. `CopilotAgent` drops those candidates instead of opening a session database each, so the 486 already-known sessions cost no DB opens. Tombstoned sessions are absent from the registry and therefore never reported as known, so an explicitly deleted session still reaches `register`, whose atomic tombstone check declines it. Provenance of a registered row stays owned by the explicit create/restore paths. - Classification (the 342 adoptable rows): while migrate-legacy is off, adoptable extension-host candidates are never emitted, so their Git-touching project resolution is now skipped entirely instead of being computed and then filtered away. `_emitCopilotChats` keeps its filter as a re-check, since the setting can flip mid-pass. - Registration (21.9s): `_registerDiscoveredChats` rejects an already-registered candidate with unchanged provenance before `_isChatBacking()` or any other per-session I/O. - Listing (109.8s / 91.0s / 73.2s): `listSessions()` coalesces concurrent computations per external-sessions mode, so the burst a multi-window restore produces shares one registry traversal. The shared entry records the registry epoch it started at and every registry mutation invalidates it, so a caller arriving after a mutation starts a fresh pass rather than joining a possibly pre-mutation one. Each caller gets its own array; rejections are shared only with callers already waiting. - `_readStoredSessionMetadata` / `_readSessionMetadata` now issue one bulk `getMetadataObject()` query instead of nine and six single-key reads, shrinking the cost of the fallback path that runs when no host filter is installed. Deferred deliberately: seeding a newly discovered external session as read still creates its database purely to hold one flag. Dropping the write without a durable default would flip every discovered external session to unread, because the list overlay only applies `IsRead` when the key is present. The correct default belongs on the registry row and is left to the registry list-projection change; the reasoning is recorded on `_initializeExternalSessionReadState`. Removal of `_awaitInitialProviderMigration()` is likewise not attempted: the reproduction proves migration was already skipped. Tests assert call/open counts rather than wall-clock thresholds: registry-known candidates cause zero session DB opens; disabled adoptable candidates resolve no projects; re-registering a known discovered chat performs no per-session I/O; the known-sessions filter reports registered sessions only and leaves tombstones to registration; concurrent list calls share one computation but not their arrays; a mutation during an in-flight list is not served from it; and stored metadata is read with a single bulk query. Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Benjamin Christopher Simmonds (benibenj)
enabled auto-merge (squash)
August 17, 2026 17:13
Copilot started reviewing on behalf of
Benjamin Christopher Simmonds (benibenj)
August 17, 2026 17:14
Contributor
There was a problem hiding this comment.
Pull request overview
Backports Agent Host startup optimizations for large Copilot session catalogs.
Changes:
- Filters registered sessions before per-session I/O.
- Coalesces concurrent session-list computations.
- Uses bulk metadata reads and adds performance-focused tests.
Show a summary per file
| File | Description |
|---|---|
src/vs/platform/agentHost/AGENTS.md |
Documents discovery and listing behavior. |
src/vs/platform/agentHost/common/agent.ts |
Adds the known-session filter API. |
src/vs/platform/agentHost/node/agentService.ts |
Implements filtering, early rejection, and list coalescing. |
src/vs/platform/agentHost/node/copilot/copilotAgent.ts |
Optimizes discovery and metadata reads. |
src/vs/platform/agentHost/test/node/agentService.test.ts |
Tests registry and list-computation behavior. |
src/vs/platform/agentHost/test/node/copilotAgent.test.ts |
Tests discovery I/O reductions. |
Review details
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 6/6 changed files
- Comments generated: 2
- Review effort level: Balanced
Co-authored-by: Copilot <[email protected]>
Ben Villalobos (benvillalobos)
approved these changes
Aug 17, 2026
Justin Chen (justschen)
approved these changes
Aug 17, 2026
Benjamin Christopher Simmonds (benibenj)
merged commit Aug 17, 2026
fe89391
into
release/1.134
27 checks passed
Benjamin Christopher Simmonds (benibenj)
deleted the
perf/agent-host-startup-discovery-331155-release-1.134
branch
August 17, 2026 21:10
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Backport of #331176 to
release/1.134for #331155.The 2026-08-17 Insiders reproduction showed migration was already skipped; the delay came from per-session SQLite work across a 941-session SDK catalog and 1,437 session databases.
listSessions()computations per external-session mode with registry-mutation invalidation.Deliberately deferred: avoiding the read-state database created for a newly discovered external session requires a durable registry default to preserve existing unread semantics.
Validation:
npm run typecheck-clientgit diff --checkFull gulp hygiene could not run locally because the shared dependency checkout lacks
gulp-merge-json; CI remains authoritative.