Bug
MCP server exits with code=0 shortly after startup or after first tool call, causing MCP error -32000: Connection closed on every subsequent call.
Root cause
The fix from #236 (commit bfbf654) — which removed process.stdin.on("end", ...) from the lifecycle guard — was reverted in commit 2e44cf6. The revert brought the stdin listener back.
PR #311 (v1.0.111) added grandparent ppid detection but explicitly noted "stdin intentionally not touched." However, server.bundle.mjs in v1.0.111 still contains the reverted stdin listener:
process.stdin.isTTY||process.stdin.on("end",a)
This means the original #236 bug is back: transient stdin pipe events trigger gracefulShutdown() → process.exit(0), and the MCP client logs -32000: Connection closed.
Evidence from spy log
=== START PID=306114 ===
initialize → OK response
notifications/initialized → received
EXIT code=0 ← 120ms after init, before tools/list even arrives
=== START PID=306161 (after /mcp reconnect) ===
initialize → OK
tools/list → OK
ctx_stats call → response sent
EXIT code=0 ← ~10s after last response
Pattern: server starts, processes 0-1 requests, then exits cleanly. Every /mcp reconnect starts a new process that dies the same way.
Timeline
| Version |
Commit |
What happened |
| ~1.0.103 |
939c5ca |
#103 added lifecycle guard with stdin listeners |
| ~1.0.110 |
bfbf654 |
#236 removed stdin listeners (fix) |
| ~1.0.110 |
2e44cf6 |
Reverted the fix ← regression introduced here |
| 1.0.111 |
1c66d5c |
#311 added grandparent check, stdin "not touched" |
Fix
Remove the stdin end listener from the lifecycle guard, exactly as #236 originally did. ppid polling (30s) + SIGTERM/SIGINT/SIGHUP signals are sufficient for orphan detection.
In src/lifecycle.ts, remove:
process.stdin.isTTY || process.stdin.on("end", a)
And rebuild server.bundle.mjs.
Workaround
Patch server.bundle.mjs directly:
- process.stdin.isTTY||process.stdin.on("end",a)
+ /* PATCHED */ void 0
Environment
- context-mode v1.0.111
- Claude Code v2.1.92
- Linux 6.8.0-110-generic
- Node v22.x
Bug
MCP server exits with code=0 shortly after startup or after first tool call, causing
MCP error -32000: Connection closedon every subsequent call.Root cause
The fix from #236 (commit
bfbf654) — which removedprocess.stdin.on("end", ...)from the lifecycle guard — was reverted in commit2e44cf6. The revert brought the stdin listener back.PR #311 (v1.0.111) added grandparent ppid detection but explicitly noted "stdin intentionally not touched." However,
server.bundle.mjsin v1.0.111 still contains the reverted stdin listener:This means the original #236 bug is back: transient stdin pipe events trigger
gracefulShutdown() → process.exit(0), and the MCP client logs-32000: Connection closed.Evidence from spy log
Pattern: server starts, processes 0-1 requests, then exits cleanly. Every
/mcpreconnect starts a new process that dies the same way.Timeline
939c5cabfbf6542e44cf61c66d5cFix
Remove the stdin end listener from the lifecycle guard, exactly as #236 originally did. ppid polling (30s) + SIGTERM/SIGINT/SIGHUP signals are sufficient for orphan detection.
In
src/lifecycle.ts, remove:And rebuild
server.bundle.mjs.Workaround
Patch
server.bundle.mjsdirectly:Environment