Skip to content

fix(mcp): recognise 'Session terminated' as transport session expiry#18143

Open
vominh1919 wants to merge 1 commit into
NousResearch:mainfrom
vominh1919:fix/18069-mcp-session-terminated
Open

fix(mcp): recognise 'Session terminated' as transport session expiry#18143
vominh1919 wants to merge 1 commit into
NousResearch:mainfrom
vominh1919:fix/18069-mcp-session-terminated

Conversation

@vominh1919
Copy link
Copy Markdown
Contributor

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:

McpError(ErrorData(code=32600, message="Session terminated"))

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_MARKERS in tools/mcp_tool.py so the error is routed through the existing reconnect-and-retry flow introduced in #13383.

Before vs After

Scenario Before After
MCP server sends Session terminated (code 32600) Generic tool error, no recovery Reconnect + retry via existing flow
Existing markers (expired session, etc.) Reconnect + retry Unchanged

Tests

  • tests/tools/test_mcp_tool_session_expired.py — added test_is_session_expired_detects_session_terminated with 2 assertions:
    • Full McpError string: "McpError(ErrorData(code=32600, message='Session terminated'))" → detected
    • Bare message: "Session terminated" → detected

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
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists tool/mcp MCP client and OAuth labels May 1, 2026
@alt-glitch
Copy link
Copy Markdown
Collaborator

Likely duplicate of #18069 — same fix adding "Session terminated" to _SESSION_EXPIRED_MARKERS in mcp_tool.py.

@alt-glitch
Copy link
Copy Markdown
Collaborator

Likely duplicate of #18069 — same fix adding 'Session terminated' to _SESSION_EXPIRED_MARKERS in mcp_tool.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Medium — degraded but workaround exists tool/mcp MCP client and OAuth type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants