Repository navigation
Copilot CLI: Stop large session stores exhausting file handles - #345095
Merged
Merged
Conversation
Contributor
|
Base:
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The regression test checks metadata but not whether events.jsonl or workspace.yaml is opened, leaving file-handle exhaustion regressions undetected.
1 open issue
What changed in this PR
This PR reduces file-handle pressure when the Copilot CLI session store is large, addressing #344829 and reducing repeated metadata reads related to #327021.
Changes:
- Lists IDs first, filters unrelated sessions, and enriches metadata with bounded concurrency and file-change-aware caching.
- Limits session-item building to 32 concurrent operations and resolves unlisted sessions’ working directories asynchronously.
- Adds regression coverage and documents the listing contract.
| File | Description |
|---|---|
extensions/copilot/src/extension/chatSessions/vscode-node/test/folderRepositoryManager.spec.ts |
Updates the working-directory mock to return a promise. |
extensions/copilot/src/extension/chatSessions/vscode-node/test/copilotCLIChatSessions.spec.ts |
Makes the session-service mock asynchronous. |
extensions/copilot/src/extension/chatSessions/vscode-node/test/copilotCLIChatSessionParticipant.spec.ts |
Updates the participant’s working-directory mock. |
extensions/copilot/src/extension/chatSessions/vscode-node/folderRepositoryManagerImpl.ts |
Awaits fallback working-directory resolution. |
extensions/copilot/src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts |
Bounds concurrent session-item construction. |
extensions/copilot/src/extension/chatSessions/vscode-node/copilotCLIChatSessions.ts |
Bounds item construction during list refreshes. |
extensions/copilot/src/extension/chatSessions/copilotcli/vscode-node/test/copilotCLISDKUpgrade.spec.ts |
Checks lightweight listing and enrichment results against the real SDK. |
extensions/copilot/src/extension/chatSessions/copilotcli/node/test/testHelpers.ts |
Models lightweight listing, enrichment, and modification times. |
extensions/copilot/src/extension/chatSessions/copilotcli/node/test/copilotCliSessionService.spec.ts |
Tests filtering, concurrency, caching, adoption, and working-directory fallback. |
extensions/copilot/src/extension/chatSessions/copilotcli/node/copilotcliSessionService.ts |
Implements filtered, bounded metadata reads, caching, and asynchronous directory lookup. |
extensions/copilot/src/extension/chatSessions/copilotcli/AGENTS.md |
Documents listing constraints and cache behavior. |
Review effort: Balanced
The SDK guard test only checked the returned metadata, so an SDK update that went back to opening every events.jsonl (e.g. for detached detection) while still returning ids only would have passed. Observe events.jsonl and workspace.yaml access through Node's fs during the ids-only listing and assert there is none. The full listing serves as a positive control that the observer still sees the SDK's reads. Co-authored-by: Copilot <[email protected]>
Vijay Upadya (vijayupadya)
marked this pull request as ready for review
October 29, 2026 23:51
Vijay Upadya (vijayupadya)
enabled auto-merge (squash)
October 29, 2026 23:51
Benjamin Christopher Simmonds (benibenj)
approved these changes
Oct 29, 2026
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Fixes #344829. Related: #327021.
Problem
_getAllSessionscalledsessionManager.listSessions()with no options. For every directory in~/.copilot/session-state, the SDK then openedevents.jsonl(twice) andworkspace.yaml, all at the same time. Only after that did we throw away every session VS Code didn't create. With a large store (42k sessions fromcopilot -pin the report), each window's extension host held 10k–20k open files during startup. On macOS that breaks child-process spawning (spawn EBADFfor ESLint, ripgrep and git), and several windows together fill the system file table (ENFILE).Passing only
metadataLimitis not enough. While detached sessions are included (the default), the SDK still opens everyevents.jsonlat once to detect them.Solution
The listing in copilot CLI provider now fetches only session IDs, skips sessions the agent host already lists and sessions VS Code didn't create, and reads details just for the rest, at most 10 at a time and cached until their files change
Changes
copilotcliSessionService.ts)listSessions({ metadataLimit: 0, includeDetached: false }), which returns only IDs and times and opens noevents.jsonlorworkspace.yaml.agentSessionData/<id>) and sessions VS Code didn't create before any SDK read.clientName, context) withenrichSessionMetadata, 10 at a time, only for the remaining sessions. Output is identical to a full listing, including the SDK's pruning of empty sessions.clientName === vscode-agent-hostfilter now runs after the details read; agent-host ownership is re-read on every listing and checked first, so an adopted legacy session still drops out on the next refresh.modifiedTime(events.jsonl) and theworkspace.yamlmodification time are unchanged. A rename that only rewritesworkspace.yamldoesn't changemodifiedTime, so both are needed. Also cleared on delete, rename and summary updates. Repeated refreshes become nearly free (Copilot Chat re-walks the entire CLI session store on every refresh — extension host stalls for minutes with a large store #327021).getSessionWorkingDirectoryis now async. The listing only records working directories for VS Code-created sessions, so for any other session (e.g. a legacy session opened after declined adoption, or one restored at startup) it reads that one session from the SDK on demand.copilotcli/AGENTS.mddocuments the listing contract.No change to which sessions are shown, their titles, timing or order, or to legacy → agent-host migration, remote (WSL/SSH) or the Agents window. None of those paths call this listing differently.
How to test
Automated:
npx vitest run src/extension/chatSessions(inextensions/copilot): 1335 passed, 1 failed. The failure ("preserves order of edit toolCallIds and permissions…" incopilotcliSession.spec.ts) also fails onmainwithout this change.clientNameand empty sessions are filtered; the working directory resolves for a session that was never listed.copilotCLISDKUpgrade.spec.ts: 4/4 passed. A new test runs the real SDK and fails if a future SDK version changes whatmetadataLimit: 0does, or ifenrichSessionMetadatastops matching a full listing.tsc --noEmit -p tsconfig.jsonandeslint --max-warnings=0on the changed files: clean.Manual end to end (Windows, generated store of 20,000 external + 100 VS Code-created sessions):
Listed 20100 sessions: … 20000 external, 100 read … 100 shown, and the refresh shows100 cached(about 1 s). No Code OSS process went above about 1,700 handles. No EMFILE, ENFILE or EBADF in any log. The Sessions view shows only the VS Code-created sessions.To reproduce: generate many session directories under a temporary
COPILOT_HOME(script in the issue), launch Code OSS with--log GitHub.copilot-chat:trace, and check theListed … sessionsline in the Copilot Chat log.Not covered: the macOS-specific
spawn EBADFitself (only Windows was tested, though the fix removes its cause).Follow-ups, out of scope:
listSessions(SDK: unbounded concurrency in listSessions() exhausts file descriptors with a large session-state github/copilot-cli#5282).