From 4a2f822137bf69728bd594613002671c93d2a64d Mon Sep 17 00:00:00 2001 From: LeonSGP43 Date: Sun, 3 May 2026 21:33:52 +0800 Subject: [PATCH] fix(mcp): reconnect on terminated sessions --- tests/tools/test_mcp_tool_session_expired.py | 7 +++++++ tools/mcp_tool.py | 1 + 2 files changed, 8 insertions(+) diff --git a/tests/tools/test_mcp_tool_session_expired.py b/tests/tools/test_mcp_tool_session_expired.py index 67e6e58741..4533282e70 100644 --- a/tests/tools/test_mcp_tool_session_expired.py +++ b/tests/tools/test_mcp_tool_session_expired.py @@ -46,6 +46,13 @@ def test_is_session_expired_detects_session_not_found(): assert _is_session_expired_error(RuntimeError("Unknown session: abc123")) is True +def test_is_session_expired_detects_session_terminated(): + """Remote Playwright MCP reports transport loss as ``Session terminated``.""" + from tools.mcp_tool import _is_session_expired_error + + assert _is_session_expired_error(RuntimeError("Session terminated")) is True + + def test_is_session_expired_is_case_insensitive(): """Match uses lower-cased comparison so servers that emit the message in different cases (SDK formatter quirks) still trigger.""" diff --git a/tools/mcp_tool.py b/tools/mcp_tool.py index 2a0115ec85..21e935a12f 100644 --- a/tools/mcp_tool.py +++ b/tools/mcp_tool.py @@ -1667,6 +1667,7 @@ _SESSION_EXPIRED_MARKERS: tuple = ( "session expired", "session not found", "unknown session", + "session terminated", )