Skip to content

Copilot Agent Host sessions take ~60 seconds to appear after restart with a large ~/.copilot catalog #331155

Closed

Description

Description

After restarting VS Code Insiders (1.134.0-insider, commit fc62850), Copilot sessions in the Agents window take ~60 seconds to appear. Local harness sessions appear immediately.

Reproduction

Machine has ~1,207 SDK sessions under ~/.copilot/session-state and 1,373 Agent Host session databases.

Trace from agenthost.log

09:09:44 – Copilot provider registers, begins "Listing discoverable chats"
09:09:45 – 9 concurrent listSessions() calls arrive from restored windows
09:09:54 – Copilot SDK returns 1,207 sessions
09:10:30 – _discoverCopilotChats() classification finishes (0 external, 117 adoptable legacy, 1090 already known)
09:10:45 – first live listSessions() returns 47 sessions (~60 s after startup)

During classification ~1,957 session database opens and then ~2,296 more during the first live list.

Cause

_awaitInitialProviderMigration() in AgentService.listSessions() waits for the provider discovery promise before returning. The Copilot discovery pass introduced by #331082 enumerates the entire SDK catalog (~1,207 entries on this machine), classifying each one by opening its session database. The 9 concurrent listSessions() calls from the 8 restored windows all queue behind this discovery pass, so no Copilot sessions are shown in any window until classification completes.

The persisted localAgentHost.cachedSessions.v2 cache contains the correct set of recent sessions and is shown immediately by other providers; Copilot sessions appear to be withheld or replaced by the live result rather than rendered from cache while discovery runs.

Version

  • VS Code Insiders 1.134.0-insider (commit fc62850c)
  • macOS arm64

Activity

  1. added
    bug
    agent-host
    on Aug 17, 2026
  2. added this to the 1.135.0 milestone on Aug 18, 2026
  3. chrmarti commented on Aug 24, 2026

    @chrmarti
    CollaboratorAuthor

    It still takes very long. The recording shows the window open at 12s, local sessions only show at 32s and SDK sessions at 1:41.

    Screen.Recording.2026-08-24.at.10.31.36.AM.mov
  4. 3 remaining items

  5. sandy081 commented on Aug 27, 2026

    @sandy081
    Member

    Christof Marti (@chrmarti) The full catalog scan should be a one-time migration pass. Once the provider is marked migrated, session listing should no longer wait for migration. Could you please retry with the latest VS Code Insiders build after allowing the initial migration to complete, restart once more, and confirm whether the subsequent startup still delays local or SDK sessions? If it does, please attach the new Agent Host log covering that subsequent restart.

  6. added
    info-needed
    on Aug 27, 2026
  7. chrmarti commented on Aug 28, 2026

    @chrmarti
    CollaboratorAuthor

    Still seeing it, will send you the log.

  8. sandy081 commented on Aug 30, 2026

    @sandy081
    Member

    I analyzed the new Agent Host log from a subsequent restart. This confirms the delay is not caused by the one-time registry migration repeating.

    Timeline

    • 10:55:50.837 — external Copilot discovery starts.
    • 10:55:51.057 — first listSessions request starts.
    • 10:55:57.012 — SDK returns 1,281 sessions.
    • 10:56:18.743 — discovery classification completes:
      • 153 already known to Agent Host
      • 1 suppressed legacy extension-host session
      • 1,121 unsupported client names
      • 6 outside the import window
      • 0 external sessions discovered
    • 10:56:23.137 — first list computation completes after 32 seconds.
    • 10:56:45.482 — queued list requests return, approximately 54 seconds after the first request.
    • A subsequent listing takes another 10.7 seconds.

    All 14 listSessions requests eventually succeed. This is a latency problem rather than a failed request.

    Updated diagnosis

    PR #329633 changed steady-state enumeration from a full provider catalog scan to:

    Agent Host registry
        → resolve metadata for N registered sessions
    

    The full SDK scan is intended only for initial registry backfill.

    PR #331082 subsequently made Copilot external-session discovery start whenever Agent Service attaches its discovery listener:

    SDK listSessions() over the complete ~/.copilot catalog
        → compare with the Agent Host registry
        → classify unknown sessions
    

    The legacy migration setting is still respected when publishing or adopting legacy sessions, but it no longer prevents the SDK catalog scan.

    In this log, legacy adoption is disabled and no external sessions are discovered, but all 1,281 SDK sessions are still enumerated and classified.

    The registry-first follow-up optimizations avoid database reads for already-known sessions during discovery. However, discovery still begins with:

    client.rpc.sessions.list({})

    The external scan and normal registry hydration run concurrently during startup. Removing the external scan would eliminate that recurring catalog work, although other session hydration and restoration work may still contribute to startup latency.

    The three related features

    1. Extension-host Copilot session adoption

    Intent: Allow sessions created by the old VS Code extension-host Copilot CLI implementation to be adopted by Agent Host.

    Before #329633, normal Copilot listing already called SDK listSessions(). When legacy migration was enabled, that same result was also inspected for adoptable extension-host sessions.

    • Candidate discovery repeated during listing/restart.
    • Actual adoption happened once per session, on explicit open.
    • Once adopted, persisted Agent Host metadata prevented that session from being adopted again.

    2. Agent Host session catalog and orchestration

    Intent: Make Agent Host own session identity, lifecycle and enumeration through a durable registry in a dedicated orchestrator database.

    After the one-time backfill:

    0 full SDK listSessions() calls for normal listing
    N getChatMetadata() calls for N registered Agent Host sessions
    

    This avoids enumerating the complete shared SDK catalog just to find sessions already owned by Agent Host. Depending on the number of registered sessions and concurrent clients, the N individual resolutions may perform similarly or better than the previous bulk scan.

    3. External Copilot session discovery

    Intent: Surface sessions created outside Agent Host, such as standalone Copilot CLI or GitHub Copilot application sessions.

    Because those applications do not update the Agent Host registry, discovery compares the SDK catalog with the registry.

    PR #331082 made this discovery independent of legacy migration. Consequently, the complete SDK catalog is scanned during startup even when legacy migration is disabled.

    The external-session visibility setting controls which discovered sessions are shown, but it does not currently prevent the discovery scan itself.

    Preferred solution

    Use two-stage discovery:

    1. If neither external-session discovery nor legacy migration is needed, make no SDK session-catalog request.

    2. Otherwise, request only lightweight session identities/basic metadata, for example:

      client.rpc.sessions.list({ metadataLimit: 0 })
    3. Compare those IDs with the Agent Host registry.

    4. Remove already-registered sessions.

    5. Apply age or other filters available from the lightweight result.

    6. Fetch full metadata only for unknown candidates.

    7. Classify and register eligible external or legacy sessions.

    An ID-only API such as listNonEmptySessionIds() could also be considered, but its recent/non-empty/limited semantics must be compatible with exhaustive migration requirements.

    Tactical fix

    In Copilot Agent, skip catalog discovery when both features are disabled:

    showExternalSessions === none
    AND
    migrateLegacyCopilotCli === false
    

    Conceptually:

    if (!externalSessionsEnabled && !legacyMigrationEnabled) {
    	return;
    }
    
    await this._discoverCopilotChats();

    The setting lifecycle must also be handled:

    • Disabled → enabled: start a fresh discovery pass.
    • Enabled → disabled: do not publish results that are no longer requested.
    • A skipped pass must not be memoized as permanently completed.

    This tactical change removes the full SDK scan for users who want neither external nor legacy Copilot sessions, while the preferred solution reduces the cost when discovery is enabled.

  9. removed
    info-needed
    on Aug 30, 2026
  10. benibenj commented on Aug 31, 2026

    @benibenj
    Contributor

    Closing as many performance fixes have been made. If further performance issues exist, new logs should be captured as much has changed in the meantime

  11. locked and limited conversation to collaborators on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

agent-hostbug

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions