fix(runtime): preserve recovery history and prevent unsafe MCP replays (#6537)
* fix(recovery): preserve complete checkpoints and refresh cancellation drafts Retain earlier tool rounds and consumed follow-ups until the transcript is committed, and classify a fresh session after cancelling active recovery. Keep history and follow-up acknowledgement atomic through the session owner. * test(recovery): cover completion during cancellation handoff * fix(gateway): preserve failure exit status after runtime crashes Report uncaught gateway runtime failures as exit code 1 after the existing cleanup, just like startup failures. Remove the startup-only guard without changing controlled shutdown or supervisor policy. Reuse lifecycle regression coverage for startup/runtime failure diagnostics and cleanup, and update runtime fault fixtures to expect failure. Refs: NAN-394 * fix(recovery): make interrupted tool outcomes explicit * fix(mcp): avoid unsafe replays and retain error states Recover stale connections before non-replayable tool submissions, and report unknown outcomes without replaying calls after transport loss. Preserve structured error results for resource and prompt wrappers. NAN-393 NAN-395 * test(recovery): assert unknown outcome guidance * fix(runtime): revalidate replay contracts and preserve recovery input identity Bind replay safety to each request session, adopt the rediscovered contract, and stop automatic replay when it loses its safety declaration. Treat cumulative checkpoints as uncommitted deltas rather than deduplicating independent inputs by text, retaining legacy single-batch recovery compatibility. Extend the existing reconnect and same-text follow-up regressions, and align MCP privacy/proxy fixtures with preflight and explicitly safe replay without relaxing their privacy or routing assertions. * fix(mcp): report unknown outcomes after submitted tool timeouts Real HTTP response-loss probing with Codex exposed that the MCP SDK can surface a lost response as a timeout. Preserve preflight timeout semantics, but report possible completed effects after a non-replayable request has started. Never replay or weaken task cancellation.
This commit is contained in:
1 parent
c1ed649b81
commit
384b763830
16 files changed
+815
-89
No files matched your search
@@ -539,7 +539,7 @@ async def test_reload_mcp_servers_skips_oauth_server_waiting_for_authorization(
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mcp_tool_reconnects_after_session_terminated(
|
||||
async def test_mcp_tool_reconnects_before_submission_after_session_terminated(
|
||||
tmp_path,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
):
|
||||
@@ -558,11 +558,13 @@ async def test_mcp_tool_reconnects_after_session_terminated(
|
||||
self.index = index
|
||||
self.call_count = 0
|
||||
|
||||
async def send_ping(self) -> None:
|
||||
if self.index == 1:
|
||||
raise McpError(ErrorData(code=-32000, message="Session terminated"))
|
||||
|
||||
async def call_tool(self, _name: str, arguments: dict[str, Any]) -> Any:
|
||||
self.call_count += 1
|
||||
assert arguments == {"symbol": "AAPL"}
|
||||
if self.index == 1:
|
||||
raise McpError(ErrorData(code=-32000, message="Session terminated"))
|
||||
return SimpleNamespace(
|
||||
content=[mcp_types.TextContent(type="text", text="recovered")]
|
||||
)
|
||||
@@ -597,7 +599,7 @@ async def test_mcp_tool_reconnects_after_session_terminated(
|
||||
assert output == "recovered"
|
||||
assert connect_count == 2
|
||||
assert closed == ["remote"]
|
||||
assert sessions[0].call_count == 1
|
||||
assert sessions[0].call_count == 0
|
||||
assert sessions[1].call_count == 1
|
||||
assert provider.connected_server_names == {"remote"}
|
||||
assert registry.get("mcp_remote_quote") is not old_tool
|
||||
@@ -617,10 +619,12 @@ async def test_mcp_reconnect_handler_uses_sanitized_server_prefix(
|
||||
def __init__(self, index: int) -> None:
|
||||
self.index = index
|
||||
|
||||
async def call_tool(self, _name: str, arguments: dict[str, Any]) -> Any:
|
||||
assert arguments == {}
|
||||
async def send_ping(self) -> None:
|
||||
if self.index == 1:
|
||||
raise McpError(ErrorData(code=-32000, message="Session terminated"))
|
||||
|
||||
async def call_tool(self, _name: str, arguments: dict[str, Any]) -> Any:
|
||||
assert arguments == {}
|
||||
return SimpleNamespace(
|
||||
content=[mcp_types.TextContent(type="text", text="recovered")]
|
||||
)
|
||||
@@ -738,9 +742,11 @@ async def test_shared_proxy_snapshot_survives_reconnect_and_reloads_only_opted_i
|
||||
class Session:
|
||||
expired = False
|
||||
|
||||
async def call_tool(self, _name: str, arguments: dict[str, Any]) -> Any:
|
||||
async def send_ping(self) -> None:
|
||||
if self.expired:
|
||||
raise McpError(ErrorData(code=-32000, message="Session terminated"))
|
||||
|
||||
async def call_tool(self, _name: str, arguments: dict[str, Any]) -> Any:
|
||||
return SimpleNamespace(content=[mcp_types.TextContent(type="text", text="ok")])
|
||||
|
||||
async def mark_closed(name: str) -> None:
|
||||
|
||||
Reference in new issue
Block a user