Repository navigation
Description
Description
Related: #327021 covers the repeated full re-walk and the resulting slowness. This issue is about a distinct consequence of the same code path: unbounded file-descriptor usage at cold start, which breaks process spawning in the extension host and, with several windows, the whole machine. #331853 fixed the same unbounded Promise.all pattern in prompt discovery; the CLI session listing has the same problem.
Environment
- VS Code Insiders 1.145.0-insider, Electron 43.8.3, macOS (Darwin 27.2.0),
kern.maxfiles122,880,kern.maxfilesperproc61,440 - GitHub Copilot Chat 0.73.2026102802 (built-in,
extensions/copilot), bundling@github/copilotSDK 1.0.73 ~/.copilot/session-statewith 42,329 sessions (19 GB), produced bycopilot -pbatch runs
Symptom
Cold start with five restored windows drives system-wide open files from ~10,500 to a peak of 122,477 (sysctl kern.num_files) within about 40 s, then back to ~11,000. While the table is full:
- every window's
exthost.logshowsError: spawn .../ripgrep/bin/rg ENFILE(1 to 15 per window) - the built-in git extension's
git rev-parse --show-topleveltakes 1.5 to 3.4 s instead of ~50 ms GitHub.copilot-chatlog:[CopilotCLIChatSessionContentProvider] listSessions took92,000 to 137,000 ms per window- window 1 also logged
spawn EBADF(extension host, and Copilot Chat'sExternalIngestIndex::reconcileDbFiles), and the ESLint extension failed to start its server in that window withcouldn't create connection to server(Eslint client couldn't create connection to server after installing new VS Code version vscode-eslint#2136). Restart ESLint Server does not recover; the window needs a reload.
An lsof capture of one extension host at the peak showed 19,985 events.jsonl files from ~/.copilot/session-state open at the same instant (20,043 of its 20,086 descriptors). Five windows doing this concurrently overflow the kernel table.
After pruning to 449 sessions the peak was 11,724 files with no ENFILE, but listSessions still took 7 to 12 s per window, so the per-session cost is significant even at modest counts.
Root cause
- The extension activates on
onChatSession:copilotcliin every window and immediately lists all CLI sessions (provideChatSessionItemsinextensions/copilot/src/extension/chatSessions/vscode-node/copilotCLIChatSessions.ts). _getAllSessionsinextensions/copilot/src/extension/chatSessions/copilotcli/node/copilotcliSessionService.tscallssessionManager.listSessions()with no arguments. The SDK supports ametadataLimitoption that bounds how many sessions get their metadata read; without it every session is examined.- Inside the SDK,
listSessionsruns an unboundedPromise.allover every session directory and per session readsworkspace.yaml, readsevents.jsonlfor the first user message (summary), and readsevents.jsonlagain for detached-status detection. All of those file handles are open simultaneously. Filed against the SDK as SDK: unbounded concurrency in listSessions() exhausts file descriptors with a large session-state github/copilot-cli#5282. - The extension then does another unbounded
Promise.all(sessions.map(toChatSessionItem))with git-based badge and metadata work per session. github.copilot.chat.cli.lazyLoadSessionItem.enabled(default true, deprecated) only skipsbuildChanges; it does not affect the SDK reads.
Why spawns fail before the system table is full
On macOS uv_spawn returns EBADF as soon as the stdio pipe descriptors it creates for the child are numbered above 10239, regardless of ulimit -n or kern.maxfilesperproc (libuv/libuv#5204, attributed to Apple libc). So any extension host holding more than about 10,000 descriptors cannot fork or spawn anything until the listing finishes. With a store above ~10k sessions this hits every extension in that window that starts a child process (ESLint server, ripgrep, git, language servers), even on a single window and even with a large system file table. The ENFILE above is the additional effect of several windows doing it at once.
Repro
cd ~/.copilot/session-state
for i in $(seq 1 20000); do d=$(uuidgen | tr A-Z a-z); mkdir "$d"
printf 'id: %s\ncwd: /tmp\ncreated_at: 2026-10-01T00:00:00Z\nupdated_at: 2026-10-01T00:00:00Z\n' "$d" > "$d/workspace.yaml"
printf '{"type":"session.start","data":{"sessionId":"%s"}}\n{"type":"user.message","data":{"content":"hello"}}\n' "$d" > "$d/events.jsonl"
doneOpen a window with Copilot Chat signed in and the ESLint extension installed, quit, relaunch, and run while true; do sysctl -n kern.num_files; sleep 0.5; done during startup. Watch lsof -p <extension host pid> | grep -c events.jsonl climb past 10,000 and the ESLint output channel report spawn EBADF. With 3 to 5 restored windows the system table also overflows (ENFILE).
Proposed fix
- Pass
metadataLimit(for example the number of items the Agent Sessions view can show) tolistSessions, and page or lazily resolve the rest on demand. - List once per machine, not once per window: share the result through the agent host or a cache keyed on the directory mtime, instead of every extension host walking the store at activation.
- Bound concurrency in
toChatSessionItem(a small worker pool) so git and file work is not fanned out over every session at once. - Do not list sessions at all until the Agent Sessions view is actually shown.
Issue Details
| Item | Value |
|---|---|
| Issue Category | Bug |
| Target | Visual Studio Code - Insiders |
| Repository | Microsoft/vscode |
| VS Code Version | Code - Insiders 1.145.0-insider (ea8056d, 2026-10-27T21:44:38-07:00) |
| OS Version | Darwin arm64 27.2.0 |
Activity