fix(mcp): lazy reconnect on dead session + transport errors for cron jobs - #26125
Closed
zccyman wants to merge 1 commit into
Closed
fix(mcp): lazy reconnect on dead session + transport errors for cron jobs#26125zccyman wants to merge 1 commit into
zccyman wants to merge 1 commit into
Conversation
Collaborator
|
Related: #23540 (lazy reconnect MCP tools on call), #19208 (stale session retry), #21006 (reconnect dead stdio before breaker probe). Umbrella issue: #18165 (unify MCP HTTP recovery). The cron-specific angle (dead session between ticks) may be novel, but the reconnect mechanism overlaps significantly with existing PRs. |
Contributor
Author
|
Thanks @alt-glitch. Closing in favor of #23540 — that lazy reconnect approach is more comprehensive. The cron-specific angle can be addressed as a follow-up on #23540 if needed. |
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.
Summary
Fixes #26042
When cron jobs call MCP tools, the connection may have gone stale since the MCP servers were initialized by the gateway process at startup. The tool handler returned
"MCP server X is not connected"without any recovery attempt.Changes
1.
_reconnect_server_sync()(new helper)Reuses the existing
_reconnect_eventmechanism (same as auth-recovery and session-expiry paths) to trigger a transport reconnect and wait for readiness. Thread-safe — sets the event on the MCP loop.2. Lazy reconnect in
_make_tool_handler(line ~2204)When
serverexists butserver.sessionisNone, attempts one_reconnect_server_sync()before returning the "not connected" error. This handles the case where the MCP child process crashed between cron ticks.3. Transport-level error retry (line ~2342)
After auth-recovery and session-expiry paths, detects transport errors (
ECONNREFUSED,ECONNRESET,Connection refused,Connection reset,EPIPE) in the exception message. Triggers a reconnect + single retry before surfacing the error.Testing