Skip to content

fix(mcp): isolate stdio wire protocol, add cache-first embedder fast path and background warmup - #194

Merged
Coding-Dev-Tools merged 2 commits into
mainfrom
fix/mcp-stdio-wire-isolation-and-cache-fastpath
Sep 3, 2026
Merged

fix(mcp): isolate stdio wire protocol, add cache-first embedder fast path and background warmup#194
Coding-Dev-Tools merged 2 commits into
mainfrom
fix/mcp-stdio-wire-isolation-and-cache-fastpath

Conversation

@Coding-Dev-Tools

Copy link
Copy Markdown
Owner

Summary

Fixes low-level stream write failures and child process disconnection errors (such as \Error: write EOF\ / \UV_EOF\ at \WriteWrap.onWriteComplete) encountered by Node.js MCP harnesses (Command Code, Cursor, Claude Code, Cline, etc.) when calling Engraphis tools.

Root Causes & Solutions

  1. Stdio Wire Protocol Contamination:

    • In MCP stdio mode, standard output is the JSON-RPC wire. Third-party dependency logs, warnings, or progress bars (PyTorch, transformers, tqdm, pydantic) writing to stdout corrupted the JSON-RPC wire, causing client parsers to fail and close the stdin pipe.
    • Fix: Redirected \sys.stdout\ to \sys.stderr\ in \engraphis.mcp_server\ during stdio mode while preserving the raw binary stream specifically for JSON-RPC transport.
  2. First-Call Cold Start & Network Hangs:

    • Lazy initialization meant the first tool call (such as
      ecall) paid the full initialization and network check cost inside the agent's turn. Hugging Face checks could hang on restricted networks.
    • Fix:
      • Added cache-first \local_files_only=True\ fast path in \get_embedder\ so cached models load in ~0.3s without network calls.
      • Made \service()\ singleton initialization thread-safe (_service_lock = threading.Lock()).
      • Added non-blocking background daemon warmup (_start_background_warmup()) in \mcp_server.py\ so SQLite and the embedder are already warm before the first tool call.
  3. Pre-flight Health Verification & Prefetching:

    • Added embedder health check to \engraphis-init --check\ (validating PyTorch C++ DLL loading on Windows).
    • Added \engraphis-init --prefetch\ to download and cache model weights during setup.

Verification

  • Unit tests added in \ ests/test_mcp_server.py, \ ests/test_backends_factories.py, and \ ests/test_init.py.

  • uff check .\ passed with 0 errors.
  • \pyright\ passed with 0 errors.
  • \check_commercial_manifest.py\ and \externalize_dashboard_assets.py\ passed.
  • Full offline test suite (\pytest tests/) passed 100%.

…path and background warmup

- Redirect sys.stdout to sys.stderr in stdio MCP mode so library prints/warnings never corrupt the JSON-RPC wire
- Load cached SentenceTransformer models with local_files_only=True first to eliminate network roundtrips and timeouts
- Make service() singleton initialization thread-safe and warm up in a background daemon thread
- Add embedder health check to 'engraphis-init --check' and provide 'engraphis-init --prefetch' command
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@Coding-Dev-Tools
Coding-Dev-Tools merged commit c9c9ca2 into main Sep 3, 2026
22 of 23 checks passed
@Coding-Dev-Tools
Coding-Dev-Tools deleted the fix/mcp-stdio-wire-isolation-and-cache-fastpath branch September 3, 2026 23:45
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