Bound MCP tool calls with their own watchdog timeout - #528
Merged
TheGreatAxios merged 2 commits intoAug 22, 2026
Merged
Conversation
A wedged MCP server previously hung a tool call (and the stall watchdog treats an in-flight tool as activity, so the turn) forever, since the generic tool watchdog no longer arms by default. mcp__* calls now arm unconditionally through resolveToolExecutionTimeoutMs, defaulting to 5 minutes (settings.mcp.timeoutMs to override, capped by tools.maxTimeoutMs), and time out with a normal model-reactable tool error instead of hanging. Investigated the MCP client for a concurrency deadlock: our client.ts and the vendored SDK's Protocol.request() multiplex requests by JSON-RPC id with no serial queue or mutex, so parallel calls to one server should not deadlock each other. Live forensics for this issue showed multi-minute MCP calls that later completed, consistent with a slow server rather than a client-side deadlock. Fixes CL-6895 https://linear.app/abklabs/issue/CL-6895
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
mcp__*call.mcp__*calls now go through their own branch inresolveToolExecutionTimeoutMs(src/tui/tool-execution-watchdog.ts) that arms unconditionally — default 5 minutes (DEFAULT_MCP_TOOL_TIMEOUT_MS), configurable viasettings.mcp.timeoutMs, still capped bytools.maxTimeoutMswhen set.taskandrun_shellbehavior is unchanged.MCP tool <name> timed out after <n>s — the server may be wedged; retry or continue without it(formatMcpToolTimeoutMessageinsrc/plugins/tool-time-budget.ts). The turn is never aborted.Settings.mcp.timeoutMs(src/config/settings.ts), folded intotoolWatchdogFromSettings's existing return shape asmcpTimeoutMs.Concurrency investigation (CL-6895)
Read
src/mcp/client.tsand the vendored@modelcontextprotocol/sdk'sProtocol.request()(node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js). Requests are keyed by an incrementing JSON-RPC message id in aMap, with per-request abort/timeout handling — there is no serial queue or mutex around outgoing requests in either our code or the SDK, so N parallel calls to one server should not deadlock each other at the client layer.Live forensics for this issue showed the hung calls eventually completing (multi-minute, but not indefinite), which is consistent with a slow MCP server response rather than a client-side deadlock. No fix applied here beyond the timeout bound; if a real deadlock resurfaces it likely lives in the vendored SDK or the server itself, not in
src/mcp/client.ts.Per-tool elapsed-time surfacing and notice-clearing for long-running tools are tracked separately (CL-6894) and are out of scope here.
Test plan
bun test src/tui/tool-execution-watchdog.test.ts— new cases: mcp default timeout with no config,mcp.timeoutMsoverride,tools.maxTimeoutMsstill caps it, a never-resolving mock MCP tool times out with a model-reactable error while the runner keeps working, concurrent MCP calls time out independently of each other and of a fast sibling call.bun test src/settings.test.ts—toolWatchdogFromSettingsmapsmcp.timeoutMsalone and merged withtools.*.bun test src/tui/dynamic-tool-runner.test.ts src/mcp/ src/tui/tool-rows.test.ts— unaffected, all pass.bunx tsc --noEmit -p .clean.stream-event-map.ts/turns-to-blocks.ts) that a timed-out tool result (isError: true) flows through the existing error-row paint path — no separate TUI change needed.Fixes CL-6895
https://linear.app/abklabs/issue/CL-6895