Skip to content

fix(mcp): first tool call hung on Windows while numpy loaded (2.149.1) - #203

Merged
drknowhow merged 1 commit into
mainfrom
fix/mcp-startup-race
Sep 24, 2026
Merged

drknowhow merged 1 commit into
mainfrom
fix/mcp-startup-race

Conversation

@drknowhow

Copy link
Copy Markdown
Owner

On this Windows machine, the MCP server's first tool call (or the first c3_session save) sometimes never answered, and today it happened every time. tests/test_codex_mcp_transport.py failed 10 out of 10 runs on unchanged main.

py-spy on the hung server showed:

  • c3-initial-index stuck loading numpy's native module (numpy/_core/multiarray.py, reached through chromadb from services/embedding_index.py:143)
  • the main thread stuck in Thread.start in _ensure_repo_map_once, waiting for a new thread that never ran

Loading the native module in one thread while the process starts others deadlocks both. numpy imports in 0.07 s on its own, and capping OpenBLAS threads doesn't help.

Fix: lifespan imports numpy on the main thread before any background thread exists. That adds about 75 ms at startup, and the import is skipped if numpy isn't installed.

Result on the same machine: 10 out of 10 passes (about 4.7 s each), up from 0 out of 10 (each timing out after 34 s). Full suite: 4607 passed, 7 skipped. ruff clean.

https://claude.ai/code/session_01F6QMHB2mkrDJiQWfC1g9wy

The c3-initial-index thread loaded numpy's native module through chromadb
while the server started its other threads; on Windows that deadlocked
both, and the first tool call or c3_session save never answered. The
server now imports numpy on the main thread before any background thread
starts. test_codex_mcp_transport.py: 0/10 passes before, 10/10 after on
the affected box; full suite 4607 passed.

Claude-Session: https://claude.ai/code/session_01F6QMHB2mkrDJiQWfC1g9wy
@drknowhow
drknowhow merged commit 6435f74 into main Sep 24, 2026
12 checks passed
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.

1 participant