Repository navigation
Conversation
Mode-aware tools were called directly, ignoring the step timeout, and sync tools blocked the event loop. Run them under asyncio.wait_for (sync ones via asyncio.to_thread) and return the same TIMEOUT error as the FastMCP path.
Merged
2 tasks done
…and event-loop tests Co-authored-by: burtenshaw <burtenshaw@users.noreply.github.com>
Contributor
|
The docs for this pull request built successfully. A maintainer can publish a preview of this commit by adding the |
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f616949. Configure here.
The timeout handler for @self.tool() tools also caught TimeoutError raised inside the tool (socket, urllib, aiohttp). On Python 3.11+ asyncio.TimeoutError is the builtin TimeoutError, so those were reported as ToolErrorType.TIMEOUT with a message naming timeout_s. Wrap the tool's own timeout before it reaches wait_for, so only timeout_s expiring maps to TIMEOUT. The tool's error is returned as EXECUTION_ERROR with its own message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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
In
_async_handle_call_tool, tools registered with@self.tool()(the mode-aware branch) were called directly. Only the FastMCP path usedasyncio.wait_for, sotimeout_swas ignored: a tool sleeping 3 s undertimeout_s=0.5returned after 3.1 s with no error. Sync tools also blocked the event loop.The branch now awaits the call under
asyncio.wait_for, running sync functions throughasyncio.to_thread. On expiry it returns the sameToolErrorType.TIMEOUTerror and message as the FastMCP path.Type of Change
Alignment Checklist
Before submitting, verify:
.claude/docs/PRINCIPLES.mdand this PR aligns with our principles.claude/docs/INVARIANTS.mdand no invariants are violated/pre-submit-pr(orbash .claude/hooks/lint.shand tests) and addressed all issuesRFC Status
Test Plan
TestModeToolTimeout::test_slow_mode_tool_times_out[sync|async]intests/core/test_mcp/test_mode_aware_tools.py. Onmain: 2 failed, 19 passed. With the fix: 21 passed, andtests/core/test_mcpplustest_mode_selection.pygive 166 passed (WSL, Python 3.12).bash .claude/hooks/lint.shpasses.Claude Code Review
Alignment review by Opus 5.5, in the format of
.claude/skills/alignment-review/SKILL.md.Automated Checks
bash .claude/hooks/lint.shTier 1: Fixes Required
None.
Tier 2: Alignment Discussion
A sync tool that times out keeps running in its worker thread until it returns, because Python can't cancel a thread. The step returns the TIMEOUT error, but
step()called throughasyncio.runstill waits for that thread at shutdown. The FastMCP path has the same limitation for tools run in threads.Note
Medium Risk
Changes core MCP tool execution (timeouts, threading, error classification) for all
@self.tool()calls; behavior is more correct but sync tools now run off the event loop with documented caveats.Overview
Fixes a bug where
timeout_swas ignored for tools registered via@self.tool()(the mode-aware branch in_async_handle_call_tool). Those calls ran inline withoutasyncio.wait_for, while FastMCP-registered tools already honored the timeout.Mode-aware invocations are now wrapped in
asyncio.wait_forwith the same default andToolErrorType.TIMEOUTresponse as the FastMCP path. Sync tools run throughasyncio.to_threadso they no longer block the event loop.TimeoutErrorraised inside a tool (e.g. upstream HTTP) is distinguished from MCP deadline expiry via_ToolRaisedTimeoutand surfaced asEXECUTION_ERROR, not timeout.The
@self.tool()docstring documents thread-affine state and that timed-out sync work may keep running until the thread finishes.TestModeToolTimeoutadds coverage for slow sync/async tools, in-tool timeouts, fast return on expiry, and non-blocking sync execution.Reviewed by Cursor Bugbot for commit 7c31dcd. Bugbot is set up for automated code reviews on this repo. Configure here.