fix(mcp): recognise 'Session terminated' as transport session expiry#18143
Open
vominh1919 wants to merge 1 commit into
Open
fix(mcp): recognise 'Session terminated' as transport session expiry#18143vominh1919 wants to merge 1 commit into
vominh1919 wants to merge 1 commit into
Conversation
When a streamable-http MCP server restarts or its session is garbage-collected, the MCP SDK sends: McpError(ErrorData(code=32600, message='Session terminated')) This error was not in _SESSION_EXPIRED_MARKERS, so it fell through to the generic tool-failure path with no recovery. Every subsequent call on the affected MCP server would fail until the gateway was manually restarted. Add 'session terminated' to the markers tuple so the error is routed through the existing reconnect-and-retry flow (NousResearch#13383). Fixes NousResearch#18069
Collaborator
|
Likely duplicate of #18069 — same fix adding "Session terminated" to _SESSION_EXPIRED_MARKERS in mcp_tool.py. |
Collaborator
|
Likely duplicate of #18069 — same fix adding 'Session terminated' to _SESSION_EXPIRED_MARKERS in mcp_tool.py. |
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.
Problem
Fixes #18069
When a streamable-http MCP server restarts (or its session is garbage-collected due to idle TTL, pod rotation, etc.), the MCP SDK sends:
This error was not included in
_SESSION_EXPIRED_MARKERS, so it fell through to the generic tool-failure path with no recovery. Every subsequent call on the affected MCP server would fail until the gateway was manually restarted — even though the transport layer had already reconnected with a fresh session ID.Fix
Add
"session terminated"to_SESSION_EXPIRED_MARKERSintools/mcp_tool.pyso the error is routed through the existing reconnect-and-retry flow introduced in #13383.Before vs After
Session terminated(code 32600)expired session, etc.)Tests
tests/tools/test_mcp_tool_session_expired.py— addedtest_is_session_expired_detects_session_terminatedwith 2 assertions:"McpError(ErrorData(code=32600, message='Session terminated'))"→ detected"Session terminated"→ detected