fix: check transport liveness before idle-timeout shutdown#21
Merged
ForLoopCodes merged 1 commit intoForLoopCodes:mainfrom Mar 28, 2026
Merged
Conversation
The idle monitor fires after 15 minutes of no tool calls and triggers process.exit(). This kills the MCP server even when the agent connection (stdio transport) is still alive - the agent may just be idle (thinking, waiting for user input, etc). The abrupt exit breaks the SSE stream for the calling agent. The fix adds an optional isTransportAlive callback to createIdleMonitor. When the idle timer fires, it checks whether the transport (stdin) is still readable. If so, the timer reschedules instead of shutting down. When the transport is actually dead, shutdown proceeds normally. In index.ts, the callback checks process.stdin.readable && !destroyed. Backward compatible: when isTransportAlive is not provided, the original behavior (unconditional shutdown) is preserved. Includes 7 new tests: - 5 unit tests for createIdleMonitor with isTransportAlive - 2 spawn-level integration tests proving the bug (without fix) and the fix (with isTransportAlive) at the process level
|
@overtimepog is attempting to deploy a commit to the ForLoopCodes' projects Team on Vercel. A member of the Team first needs to authorize it. |
Owner
|
lgtm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The idle monitor in
process-lifecycle.tsfires after 15 minutes (default) of no tool calls and unconditionally triggersprocess.exit(). This kills the MCP server even when the agent connection (stdio transport) is still alive — the agent may simply be idle (thinking, waiting for user input, reading a long response, etc).The abrupt exit breaks the stdio pipe, which manifests as an SSE stream break to the calling agent, crashing the agent session.
Root Cause
createIdleMonitorhas no awareness of whether the transport is still connected. It treats "no tool calls for N minutes" as "nobody is using me" — but that's wrong when the agent is just idle between requests.The existing shutdown guards (parent-exit monitor, stdin-end, stdin-close, SIGINT/SIGTERM/SIGHUP, broken-pipe detection) already cover all legitimate shutdown scenarios. The idle timeout is a false positive that kills healthy connections.
Fix
Added an optional
isTransportAlivecallback toIdleMonitorOptions:When the idle timer fires:
isTransportAliveis provided and returnstrue→ reschedule the timer (don't shutdown)isTransportAlivereturnsfalse→ proceed with shutdown (transport is dead)isTransportAliveis not provided → original behavior (unconditional shutdown, backward compat)In
index.ts, the callback checksprocess.stdin.readable && !process.stdin.destroyed.Changes
src/core/process-lifecycle.ts: AddedisTransportAlive?toIdleMonitorOptions, check it before firingonIdlesrc/index.ts: PassisTransportAlivethat checks stdin livenesstest/main/idle-timeout-spawn.test.mjs: 7 new tests (5 unit + 2 spawn-level integration)Test Results
All 15 tests pass (8 original + 7 new):
The spawn-level tests prove the bug at the process level: a child process with
stdin: 'pipe'(open, readable) gets killed by idle-timeout without the fix, and survives with it.