Repository navigation
fix(mcp): deterministic request timeout test; keep handshake timeout as the failure cause - #74
Merged
Merged
Conversation
ifielker
approved these changes
Nov 10, 2026
…dshake timeout as the failure cause - The stall test's request timeout also bounded initialize, which races fake server startup. The stalled call now carries its own SDK timeout. - A late initialize reply broke the SDK's closed read stream and replaced the 408 with BrokenResourceError as the connection's cause. Record the handshake McpError and report it. - Fake server marker files are written atomically, so a poller never reads an empty file. - Fake server skips importing rfc3987_syntax, a Lark grammar compiled at import that dominated its startup.
huangjeff5
force-pushed
the
fix/mcp-timeout-test-flake
branch
from
November 10, 2026 20:37
b892605 to
d7ef376
Compare
huangjeff5
enabled auto-merge (squash)
November 10, 2026 20:38
This was referenced Nov 15, 2026
Merged
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.
test_a_request_timeout_fails_that_call_alonefailed whenever the fake server took longer than 8s to start, because the request timeout also boundsinitialize. Under 10 parallel runs on main it failed 20/20. It now passes 20/20 under the same load. Two other things fall out of the same investigation: a handshake timeout was sometimes reported with the wrong cause, and the fake server's marker files could be read while still empty (the'' == 'wait'CI flake intest_close_interrupts_an_in_flight_call).Main Changes
initializereply arrived after the timeout, the SDK's stdout reader tried to hand it to the read streamClientSessionhad already closed. That raisedBrokenResourceError, which cancelled the stdio shutdown that was still carrying the 408. The connection failed with the right status but the wrong cause, both in the log and in__cause__._runnow records theMcpErrorfrominitializeand reports it ahead of whatever the SDK's task groups surface.late_handshake_server.pyreproduces this every time: it holds the reply until stdin closes. The new test fails on main.request_timeout_millis=8000, which bounded the stall and also the handshake. The handshake's length depends on machine load, so the test was a race. The stall now goes throughconnection._requestwith the SDK's per-callread_timeout_seconds=100ms. The SDK enforces that with the samefail_afterand raises the same 408, so_executeand_answered_errortake the same path as before.test_a_handshake_which_never_answers_gives_upstill covers wiring the session-wide timeout intoClientSession. The follow-up call is nowawait_stall, which only answers once the timed-out stall is actually in flight on the server.write_text, which creates the file, truncates it, then writes. A poller could see the file exist and read''. Markers are now written to a.partialfile and thenos.replaced into place.rfc3987_syntax:mcp.serverimportsjsonschema, which loadsrfc3987_syntaxwhen it's installed (dotpromptzpulls it in viajsonschema[format-nongpl]). That module compiles a Lark grammar at import time: 4.5s of self time in-X importtime. At load average ~70, importingmcp.servertook 11-21s with it and 4-5s without. Every MCP test spawns this server, so this shortens every handshake in the suite. The server never runs IRI format checks.Verification
-k test_a_request_timeout_fails_that_call_aloneon main: 0/20.test_close_interrupts_an_in_flight_calland the new handshake test: 20/20 (load average 51 → 139 during the run).packages/genkit-mcp/tests: 247 passed.This also applies on top of #72. The only conflict is in the stall test, where #72 adds the
nameargument toMcpConnection('fake', ...).