Skip to content

Copilot CLI session listing at startup exhausts the system file table (ENFILE) with a large ~/.copilot/session-state #344829

Closed

Description

@egamma

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.maxfiles 122,880, kern.maxfilesperproc 61,440
  • GitHub Copilot Chat 0.73.2026102802 (built-in, extensions/copilot), bundling @github/copilot SDK 1.0.73
  • ~/.copilot/session-state with 42,329 sessions (19 GB), produced by copilot -p batch 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.log shows Error: spawn .../ripgrep/bin/rg ENFILE (1 to 15 per window)
  • the built-in git extension's git rev-parse --show-toplevel takes 1.5 to 3.4 s instead of ~50 ms
  • GitHub.copilot-chat log: [CopilotCLIChatSessionContentProvider] listSessions took 92,000 to 137,000 ms per window
  • window 1 also logged spawn EBADF (extension host, and Copilot Chat's ExternalIngestIndex::reconcileDbFiles), and the ESLint extension failed to start its server in that window with couldn'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

  1. The extension activates on onChatSession:copilotcli in every window and immediately lists all CLI sessions (provideChatSessionItems in extensions/copilot/src/extension/chatSessions/vscode-node/copilotCLIChatSessions.ts).
  2. _getAllSessions in extensions/copilot/src/extension/chatSessions/copilotcli/node/copilotcliSessionService.ts calls sessionManager.listSessions() with no arguments. The SDK supports a metadataLimit option that bounds how many sessions get their metadata read; without it every session is examined.
  3. Inside the SDK, listSessions runs an unbounded Promise.all over every session directory and per session reads workspace.yaml, reads events.jsonl for the first user message (summary), and reads events.jsonl again 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.
  4. The extension then does another unbounded Promise.all(sessions.map(toChatSessionItem)) with git-based badge and metadata work per session.
  5. github.copilot.chat.cli.lazyLoadSessionItem.enabled (default true, deprecated) only skips buildChanges; 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"
done

Open 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) to listSessions, 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

Additional Issue Data

issue-data.md

Activity

  1. added
    unreleased
    on Oct 29, 2026
  2. added this to the 1.145.0 milestone on Oct 29, 2026
  3. added
    insiders-released
    and removed
    unreleased
    on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

insiders-released

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions