microsoft / microsoft/vscode

Copilot Chat re-walks the entire CLI session store on every refresh — extension host stalls for minutes with a large store

Open
#327,021 2 comments 0 reactions 1 assignee Claimed by @zhichli View on GitHub
agents-window bug
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

### Description

### Summary
The Copilot CLI chat-sessions provider (`CopilotCLIChatSessionContentProvider`) re-enumerates the *entire* Copilot CLI session store on every refresh — no incremental update, cache, or cap. `provideChatSessionItems` (logged as `listSessions took ms`) calls `getAllSessions()` and maps every session. It's triggered constantly: a 5s poll runs while any CLI session is active (`setInterval(updateActiveSessionsOnly, 5000)`), and any session-state change fires `_onDidChangeChatSessionItems`, each re-triggering the full walk. With a large store this takes seconds to minutes and stalls the extension host Copilot Chat runs on — multiplied across open windows.

### Impact
- Chat turns become very slow.
- The affected window's UI thread stalls, causing keyboard input lag (keystrokes queue, then burst in).
- "Extension host unresponsive" events.

### Evidence (my machine)
- Store: ~6,000 CLI sessions / 3.4 GB under `~/.copilot/session-state`, plus a 256 MB `session-store.db`. I drive the CLI from scripts (~300 sessions/day), so it accumulates fast and nothing prunes it.
- `GitHub Copilot Chat.log`: `listSessions took` was typically 2,500–5,500 ms, spiking to 39,000 ms, 71,000 ms, and **312,000 ms (5+ minutes)**.
- One window logged 67 `listSessions` calls totaling ~36 min of extension-host time; another logged 220 calls.
- After pruning the store to ~670 sessions, `listSessions` dropped to a steady ~400 ms.

### Root cause (bundled `dist/extension.js`, Copilot Chat 0.58.0)
- `provideChatSessionItems` → `getAllSessions()` enumerates **all** sessions unconditionally, then `Promise.all(map(toChatSessionItem))` over all of them.
- `startActiveSessionPolling()` = `setInterval(updateActiveSessionsOnly, 5000)` while any session is active; changes fire `_onDidChangeChatSessionItems` → full re-walk.
- `github.copilot.chat.cli.showExternalSessions=false` only filters *display* (per-item `shouldShowSession`); it does **not** short-circuit the `getAllSessions()` walk, so it doesn't address the cost.

### Expected
The provider shouldn't do an O(N) full-store enumeration on every refresh/poll. Options: incremental updates for active-session changes; cache with invalidation; pagination/cap; back off the 5s poll; and/or a first-party retention/prune for the CLI session store (it currently grows unbounded — no cleanup command or setting exists).

### Workarounds
- Prune `~/.copilot/session-state` + `session-store.db` (restored ~400 ms).
- `showExternalSessions=false` helps partially (skips per-item display work), not the walk.

### Environment
- VS Code 1.130.0 (e5381e4f30c68abae911cad10f9d02e93c427d61)
- GitHub Copilot Chat 0.58.0
- Windows 11, Node ≥ 22

### Issue Details

Item|Value
---|---
Issue Category|Performance Issue
Target|Agents Window
VS Code Version|Code 1.130.0 (e5381e4f30c68abae911cad10f9d02e93c427d61, 2026-07-21T13:18:50+05:00)
OS Version|Windows_NT x64 10.0.26310

### Additional Issue Data

[issue-data.md](https://github.com/user-attachments/files/30279190/issue-data.md)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.