fix(mcp): fail RPCs when transport sessions restart - #82071
Closed
embwl0x wants to merge 1 commit into
Closed
Conversation
Collaborator
Contributor
Author
|
Closing as a duplicate of #48069 after collaborator triage. That earlier PR owns the in-flight MCP request cancellation/reconnect repair. Our current-main implementation and broader resource, prompt, and tool-list regression coverage remain available in commit 684ebb6 if maintainers want to salvage any of those tests. Thanks for catching the overlap. |
7 tasks
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
ClientSessiongeneration that started itRoot cause
A keepalive or lifecycle signal could rebuild an MCP transport while
session.call_tool()was still awaiting the old SDK session. The server'ssessionreference changed, but the in-flight coroutine had no ownership signal, so it remained attached to the old transport until the configured tool timeout (300 seconds by default).The lifecycle now owns a per-session invalidation event. RPCs race their SDK operation against that event, cancel the stale operation when the transport is invalidated, and return a retryable error. The session reference remains available until the transport context exits, but its set invalidation event prevents new work from entering the stale generation.
Fixes #81995
Coverage
The sibling-path audit covers:
tools/callresources/listandresources/readprompts/listandprompts/gettools/listrefreshValidation
scripts/run_tests.sh tests/tools/test_mcp_session_invalidation.py— 8 passedscripts/run_tests.sh tests/tools/test_mcp_*.py— 459 passed across 51 filestests/— 240 passed across 24 files (with the lockfile-pinnedacpextra for ACP suites)uv run ruff check .— passedpython scripts/check-windows-footguns.py --all— passed, 939 files scannedpython -m compileall -q tools/mcp_tool.py tests/tools/test_mcp_session_invalidation.py— passedtydiagnostics improved from 10 on exact base to 4 on this branch; no new diagnosticsNo live MCP server, credentials, or user Hermes state was used; all lifecycle behavior is exercised with isolated fake transports.