fix(mcp): don't block initialize handshake on heavy init (#172) (#177)

The MCP `initialize` handler was awaiting `tryInitializeDefault` —
which opens the SQLite DB and runs `await initGrammars()` (tree-sitter
WASM bootstrap) — before sending the JSON-RPC response. On slow
filesystems (Docker Desktop VirtioFS on macOS, WSL2) this could exceed
Claude Code's ~30s handshake timeout, leaving the codegraph child
process alive and unresponsive with no tools visible in the client.

Send the response first; defer the open to a tracked background
promise. The lazy retry path used by `tools/list` and `tools/call`
now awaits that promise instead of racing it with `openSync`, so we
never double-open the SQLite file.

Adds a subprocess-based regression test that asserts the JSON-RPC
response arrives on stdout before `startWatching()` logs to stderr.
This ordering check catches the regression on any filesystem, not
just slow ones where the timing matters in practice.

Reported by @sashanclrp; isolated by @sgrimm's wire capture.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Colby Mchenry
2026-05-19 10:20:02 -05:00
committed by GitHub
co-authored by Claude Opus 4.7
parent 9b6a917d32
commit 36c8dbc404
3 changed files with 200 additions and 10 deletions
+18
View File
@@ -7,6 +7,24 @@ a [GitHub Release](https://github.com/colbymchenry/codegraph/releases) tagged
This project follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.7.10] - 2026-05-19
### Fixed
- **MCP**: tools no longer silently fail to appear in clients on slow
filesystems (Docker Desktop VirtioFS on macOS, WSL2). The `initialize`
handshake was blocking on opening the SQLite database and bootstrapping
the tree-sitter WASM runtime, which on slow I/O could exceed Claude
Code's ~30s handshake timeout — leaving the codegraph process alive but
unresponsive and no tools visible. The handshake now returns immediately
and defers project open to the background; tool calls wait on the
in-flight init rather than racing it with a second open. Closes
[#172](https://github.com/colbymchenry/codegraph/issues/172). Thanks to
[@sashanclrp](https://github.com/sashanclrp) for the original report and
detailed reproduction, and [@sgrimm](https://github.com/sgrimm) for the
decisive wire capture that isolated the actual root cause.
[0.7.10]: https://github.com/colbymchenry/codegraph/releases/tag/v0.7.10
## [0.7.8] - 2026-05-17
### Fixed