fix(mcp): retry stale pipe transport failures as session-expired#21289
Merged
Conversation
Treat closed-resource, closed-transport, broken-pipe, and EOF MCP failures as stale session equivalents so the existing reconnect/retry-once path can recover. Add regression coverage for the stale-pipe marker variants.\n\nChecks:\n- python -m py_compile tools/mcp_tool.py tests/tools/test_mcp_tool_session_expired.py\n- python -m pytest tests/tools/test_mcp_tool_session_expired.py -q -o addopts=\n- selected secret scan over touched files
Contributor
🔎 Lint report:
|
1 task
5 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.
Salvage of #19935 by @subtract0 onto current main. Resolved a tiny rebase conflict against the recent
"session terminated"marker addition (kept both).Summary
Extends
_SESSION_EXPIRED_MARKERSwith six stdio/anyio stale-pipe variants so they trigger the existing reconnect-and-retry-once path rather than bubbling up as a one-shot failure. CoversClosedResourceError,closed resource,transport is closed,connection closed,broken pipe, andend of file. Pairs directly with the stale-session recovery infrastructure from #13383.Changes
tools/mcp_tool.py: +6 markers to_SESSION_EXPIRED_MARKERStests/tools/test_mcp_tool_session_expired.py: +11 lines of regression coveragescripts/release.py: AUTHOR_MAP entry for @subtract0Partial fix for #19417
This covers the stale-pipe retry gap for callers that format exceptions with a message (
str(exc)contains the type name or a description). It does NOT fully close #19417 because_is_session_expired_errorreturns False for empty-string exception messages, and bare anyioClosedResourceError()instances havestr(exc) == ''. That's a separate fix (match ontype(exc).__name__too) and deserves its own PR. Leaving #19417 open.Validation
scripts/run_tests.sh tests/tools/test_mcp_tool*.pyCLOSEDRESOURCEERRORvariantsCloses #19935. @subtract0's authorship preserved via rebase-merge.