Skip to content

agentHost: make startup session discovery registry-first - #331239

Merged
Benjamin Christopher Simmonds (benibenj) merged 4 commits into
release/1.134from
perf/agent-host-startup-discovery-331155-release-1.134
Aug 17, 2026
Merged

Benjamin Christopher Simmonds (benibenj) merged 4 commits into
release/1.134from
perf/agent-host-startup-discovery-331155-release-1.134

Conversation

@benibenj

Copy link
Copy Markdown
Contributor

Backport of #331176 to release/1.134 for #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.

  • Filters SDK discovery candidates against the Agent Service registry before per-session I/O.
  • Skips project resolution for adoptable extension-host candidates while legacy migration is disabled.
  • Rejects already-registered discovery candidates before backing-session checks.
  • Coalesces concurrent listSessions() computations per external-session mode with registry-mutation invalidation.
  • Uses bulk metadata reads for remaining stored-session metadata lookups.
  • Adds call/open-count tests for the performance shape and tombstone/backing behavior.

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-client
  • Changed-file formatter verification
  • git diff --check

Full gulp hygiene could not run locally because the shared dependency checkout lacks gulp-merge-json; CI remains authoritative.

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]>

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.

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

@benibenj
Benjamin Christopher Simmonds (benibenj) merged commit fe89391 into release/1.134 Aug 17, 2026
27 checks passed
@benibenj
Benjamin Christopher Simmonds (benibenj) deleted the perf/agent-host-startup-discovery-331155-release-1.134 branch August 17, 2026 21:10
@vs-code-engineering vs-code-engineering Bot added this to the 1.134.0 milestone Aug 17, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Oct 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants