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
@@ -46,7 +46,10 @@ async def test_mcp_reconnect_failure_obeys_private_log_policy(
|
||||
yield # pragma: no cover
|
||||
|
||||
monkeypatch.setattr("mcp.client.stdio.stdio_client", broken_stdio)
|
||||
session = SimpleNamespace(call_tool=AsyncMock(side_effect=RuntimeError("session terminated")))
|
||||
session = SimpleNamespace(
|
||||
send_ping=AsyncMock(side_effect=RuntimeError("session terminated")),
|
||||
call_tool=AsyncMock(),
|
||||
)
|
||||
wrapper = MCPToolWrapper(session, "sample", SimpleNamespace(
|
||||
name="search", description="synthetic", inputSchema={},
|
||||
))
|
||||
@@ -61,6 +64,8 @@ async def test_mcp_reconnect_failure_obeys_private_log_policy(
|
||||
await provider.aclose()
|
||||
|
||||
assert "failed" in result
|
||||
session.send_ping.assert_awaited_once()
|
||||
session.call_tool.assert_not_awaited()
|
||||
failures = [
|
||||
r for r in diagnostic_records
|
||||
if "connection failure" in r["message"] or "failed to connect" in r["message"]
|
||||
@@ -122,7 +127,10 @@ async def test_mcp_private_errors_exclude_exception_payloads(
|
||||
log_content, kind, monkeypatch, diagnostic_records,
|
||||
):
|
||||
session = MagicMock()
|
||||
definition = SimpleNamespace(name="sample", description="sample", inputSchema={})
|
||||
definition = SimpleNamespace(
|
||||
name="sample", description="sample", inputSchema={},
|
||||
annotations=types.ToolAnnotations(readOnlyHint=True) if kind == "retry" else None,
|
||||
)
|
||||
error = ValueError(_SECRET)
|
||||
if kind in {"tool", "render", "retry"}:
|
||||
tool = MCPToolWrapper(session, "test", definition)
|
||||
@@ -148,6 +156,8 @@ async def test_mcp_private_errors_exclude_exception_payloads(
|
||||
with request_context(RequestContext(channel="websocket", chat_id="test", log_content=log_content)):
|
||||
result = await tool.execute()
|
||||
assert "failed" in result or "malformed" in result
|
||||
if kind == "retry":
|
||||
assert session.call_tool.await_count == 2
|
||||
errors = [r for r in diagnostic_records if r["level"].name == "ERROR"]
|
||||
assert errors
|
||||
if log_content:
|
||||
|
||||
Reference in new issue
Block a user