Skip to content

fix(mcp): lazy reconnect on dead session + transport errors for cron jobs - #26125

Closed
zccyman wants to merge 1 commit into
NousResearch:mainfrom
atyou2happy:fix/mcp-cron-availability
Closed

fix(mcp): lazy reconnect on dead session + transport errors for cron jobs#26125
zccyman wants to merge 1 commit into
NousResearch:mainfrom
atyou2happy:fix/mcp-cron-availability

Conversation

@zccyman

@zccyman zccyman commented May 15, 2026

Copy link
Copy Markdown
Contributor

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_event mechanism (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 server exists but server.session is None, 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

  • 184 existing MCP tool tests pass with no regressions

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists tool/mcp MCP client and OAuth comp/cron Cron scheduler and job management labels May 15, 2026
@alt-glitch

Copy link
Copy Markdown
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.

@zccyman

zccyman commented May 15, 2026

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cron Cron scheduler and job management P2 Medium — degraded but workaround exists tool/mcp MCP client and OAuth type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP servers unavailable in cron sessions — ECONNREFUSED when accessing MCP tools from scheduled jobs

2 participants