Repository navigation
agentHost: make startup session discovery registry-first - #331176
Merged
Benjamin Christopher Simmonds (benibenj) merged 3 commits intoAug 17, 2026
Merged
Benjamin Christopher Simmonds (benibenj) merged 3 commits into
Benjamin Christopher Simmonds (benibenj) merged 3 commits into
Conversation
Benjamin Christopher Simmonds (benibenj)
enabled auto-merge (squash)
August 17, 2026 11:21
Copilot started reviewing on behalf of
Benjamin Christopher Simmonds (benibenj)
August 17, 2026 11:25
Contributor
There was a problem hiding this comment.
Pull request overview
Optimizes Agent Host startup discovery and session listing for large Copilot catalogs.
Changes:
- Filters registry-known sessions before per-session database access.
- Coalesces concurrent session-list computations with mutation-aware invalidation.
- Bulk-reads metadata and adds performance-focused coverage.
Show a summary per file
| File | Description |
|---|---|
AGENTS.md |
Documents registry-first discovery and list coalescing. |
common/agent.ts |
Adds the known-session filter provider seam. |
node/agentService.ts |
Implements filtering, early rejection, and list coalescing. |
node/copilot/copilotAgent.ts |
Avoids unnecessary database and Git work. |
test/node/agentService.test.ts |
Tests registration and list coalescing behavior. |
test/node/copilotAgent.test.ts |
Tests discovery and bulk metadata optimizations. |
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
Sandeep Somavarapu (sandy081)
previously approved these changes
Aug 17, 2026
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]>
Benjamin Christopher Simmonds (benibenj)
force-pushed
the
perf/agent-host-startup-discovery-331155
branch
from
August 17, 2026 13:40
5f9d4e3 to
a4d576e
Compare
Dirk Bäumer (dbaeumer)
previously approved these changes
Aug 17, 2026
Co-authored-by: Copilot <[email protected]>
Osvaldo Ortega (osortega)
approved these changes
Aug 17, 2026
Benjamin Christopher Simmonds (benibenj)
merged commit Aug 17, 2026
be2aecc
into
main
27 checks passed
Benjamin Christopher Simmonds (benibenj)
deleted the
perf/agent-host-startup-discovery-331155
branch
August 17, 2026 20:26
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.
agentHost: make startup session discovery registry-first (#331155)
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:copilotcliwas already true and migration wasskipped. 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
listSessionscalls109.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.
IAgentgainsan optional
setKnownSessionsFilterseam thatAgentServiceinstallsat provider registration; it answers, in one registry query for the
whole candidate set, which sessions the host already owns.
CopilotAgentdrops those candidates instead of opening a sessiondatabase 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 aregistered 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.
_emitCopilotChatskeeps itsfilter as a re-check, since the setting can flip mid-pass.
Registration (21.9s):
_registerDiscoveredChatsrejects analready-registered candidate with unchanged provenance before
_isChatBacking()or any other per-session I/O.Listing (109.8s / 91.0s / 73.2s):
listSessions()coalesces concurrentcomputations 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/_readSessionMetadatanow issue onebulk
getMetadataObject()query instead of nine and six single-keyreads, 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
IsReadwhenthe 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: thereproduction 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]