Skip to content

fix: convert sync I/O to async in session discovery to prevent VS Code UI freeze#527

Merged
rajbos merged 2 commits intomainfrom
fix-sync-io-blocking-startup
Mar 30, 2026
Merged

fix: convert sync I/O to async in session discovery to prevent VS Code UI freeze#527
rajbos merged 2 commits intomainfrom
fix-sync-io-blocking-startup

Conversation

@rajbos
Copy link
Copy Markdown
Owner

@rajbos rajbos commented Mar 30, 2026

Problem

Two user reports of VS Code becoming completely unresponsive after installing the extension:

  • "It just makes VS Code unstable, Git would not start"
  • "It's not starting properly and seems to be blocking other extensions as well. It's stuck at loading the token tracker stage."

From the attached screenshot, the extension activates quickly but the status bar is permanently stuck at "AI Fluency: Loading..." while VS Code's UI is frozen (blank splash screen, no editor loaded).

Root Cause

getCopilotSessionFiles() in sessionDiscovery.ts is declared async but performed all filesystem I/O synchronously using fs.existsSync, fs.readdirSync, and fs.statSync. Since JavaScript is single-threaded, synchronous I/O blocks Node.js's entire event loop — including VS Code's UI rendering and all other extension activity.

The scan touches:

  • All workspaceStorage/<hash>/chatSessions/ directories (one per workspace — can be 500+)
  • globalStorage/github.copilot-chat/ (recursive scan)
  • Copilot CLI ~/.copilot/session-state/ subdirectories (one statSync per session)
  • OpenCode storage directory (recursive scan)
  • Crush and Continue data directories

With 300+ sessions across many workspaces, this froze VS Code for long enough to break Git and other extensions.

Fix

Converted all filesystem operations in getCopilotSessionFiles() and scanDirectoryForSessionFiles() to async equivalents:

  • Added private async pathExists(p) helper using fs.promises.access() to replace fs.existsSync()
  • fs.readdirSync()await fs.promises.readdir()
  • fs.statSync()await fs.promises.stat()
  • Made scanDirectoryForSessionFiles() async throughout
  • Converted the inline OpenCode recursive scan to an async function
  • Simplified the Copilot CLI loop: combined existsSync + statSync into a single await fs.promises.stat() call (catches ENOENT instead)

Async I/O yields the event loop between operations, allowing VS Code's UI and other extensions to remain responsive during the filesystem scan.

Closes #493

…S Code UI freeze

All filesystem operations in getCopilotSessionFiles() and
scanDirectoryForSessionFiles() were synchronous (fs.existsSync,
fs.readdirSync, fs.statSync), blocking Node.js's event loop during
startup. With many workspaces/sessions (300+ is common), this caused VS
Code to become completely unresponsive — extensions could not load, git
would not start, and the status bar was permanently stuck on 'Loading...'.

Changes:
- Add private pathExists() async helper using fs.promises.access()
- Convert getCopilotSessionFiles() to use fs.promises.readdir/stat/access
  throughout (workspaceStorage, globalStorage, Copilot CLI, OpenCode,
  Crush scan loops)
- Make scanDirectoryForSessionFiles() async (fs.promises.readdir/stat)
- Replace inline fs.existsSync in log messages with deferred path checks
- Copilot CLI subdirectory loop now uses fs.promises.stat directly
  (combining the existsSync + statSync into a single async stat call)

These async I/O calls yield the event loop between operations, allowing
VS Code's UI and other extensions to run during the filesystem scan.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rajbos rajbos merged commit 0721125 into main Mar 30, 2026
18 checks passed
@rajbos rajbos deleted the fix-sync-io-blocking-startup branch March 30, 2026 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Causing VS Code to hang in latest update 113.

1 participant