# Which invariants prevent silent tool-result loss when an MCP session resumes across the SSE-to-streamable-HTTP transport boundary **Date of Record:** 2026 November 20 **Scope:** Applies to MCP clients and servers that migrated (or run in mixed mode) from the legacy HTTP+SSE transport to streamable HTTP, where a client presents an `Mcp-Session-Id` after a connection drop and expects to resume a long-running tool call. Does not apply to pure stdio transports, nor to stateless streamable-HTTP servers that never issue a session ID. ## Core Distinction The migration from HTTP+SSE to streamable HTTP is usually framed as a transport swap: same JSON-RPC payloads, one endpoint instead of two, POST instead of GET for client-to-server. That framing hides the actual break. Under legacy SSE, the *event stream itself was the session*: the `GET /sse` connection carried a monotonic `id:` per event, and reconnect used `Last-Event-ID` to replay from a known offset. Under streamable HTTP, the POST that carries a `tools/call` returns a `202 Accepted` with a *separate* SSE stream bound to that request, and the session is a header (`Mcp-Session-Id`) that identifies server-side state but says nothing about *which events the client already consumed*. The session identifier and the event cursor were decoupled. Resumption therefore no longer means "continue from event N"; it means "re-attach to a session whose in-flight request may or may not still be producing output, and whose already-emitted output may or may not be buffered anywhere." The invariant that actually matters is not "the session survives." It is: **a resumed stream must never cause a client to treat an unobserved tool result as observed, nor an observed result as unobserved.** Legacy `Last-Event-ID` enforced this because replay was idempotent and cursor-anchored. Streamable HTTP provides no equivalent, so the guarantee must be reconstructed at the application layer or it silently evaporates. ## What Was Observed A client agent issues `tools/call` for a long-running operation (a code-execution sandbox returning a 40 KB artifact, or a web-fetch returning a large document). The server accepts the POST, returns `202`, and opens an SSE stream carrying `notifications/progress` events followed eventually by the `tools/call` response. The connection drops mid-stream—NAT rebind, load-balancer idle timeout, or client-side read deadline—*after* the server has already emitted the final response frame but *before* the client's TCP stack has flushed it to the application. The client reconnects per streamable-HTTP rules: it re-POSTs with the same `Mcp-Session-Id`. Three distinct failure traces follow from the same trigger, and they are not distinguishable from the client's side without extra protocol: 1. **Lost-tail.** The server treats the new POST as a *fresh* `tools/call` (because the request body is identical and the server keys in-flight work on request ID, not on the connection). It re-executes. The agent now has two side effects, or a second artifact, and the original response is gone. The agent believes it called once. 2. **Phantom-ack.** The server's in-flight registry still holds the original request as "completed, response emitted." The resumed POST matches the request ID, the server returns the *cached* final frame immediately—but the client, having never seen it, cannot tell whether this is a replay of a result it should trust or a duplicate of one it already applied. If the client has any at-least-once dedup keyed on response content, it now double-applies. 3. **Silent-resume-to-empty.** The server keyed the in-flight stream to the *old* connection object. On reconnect it accepts the session ID, finds no live stream, and returns `200` with an empty event stream that closes cleanly. The client interprets clean EOF as "call finished, no output," and the tool result is lost with no error surfaced. The third trace is the dangerous one: it is indistinguishable from a legitimately empty successful response. Nothing in the status code, headers, or stream shape signals that a result was dropped. ## Condition of Validity The failure requires the conjunction of: (a) a session-scoped in-flight request whose output exceeds a single frame or spans a connection lifetime, (b) a disconnect after the server has committed output but before client-side application consumption, and (c) a server that does not persist per-request event cursors across connection objects. Remove any one and the failure does not occur: short calls that fit one frame and complete before the drop are safe; stateless servers that re-execute deterministically are merely wasteful, not lossy; and servers that persist a replayable event log per request ID are correct. It is specifically *not* mitigated by making the transport "reconnect-friendly." The migration documentation's emphasis on resumability addresses session *identity*, not result *delivery*. A perfectly compliant streamable-HTTP implementation that honors `Mcp-Session-Id` on reconnect can still exhibit all three traces. ## Decision Boundary The boundary is whether the server can answer, for a given `(Mcp-Session-Id, request-id)` pair on a fresh POST: *has the client acknowledged receipt of the final result?* If it cannot, resumption is undefined and must be treated as at-most-once-unknown, which for side-effecting tools is unacceptable. The architectural guardrail is to make result delivery *cursor-anchored even under streamable HTTP*: the server assigns a monotonic per-request `event_id` to every emitted frame (including the terminal response) and persists them keyed by request ID for the session's TTL. On a resumed POST, the client sends the highest `event_id` it has applied; the server replays from `event_id + 1` or, if the request is still running, attaches the new connection to the live stream *from that offset*. A resumed POST with no `event_id` and a matching in-flight request ID must be rejected as ambiguous rather than silently re-executed. The terminal frame must carry an explicit `is_final` marker so that a clean EOF without `is_final` is treated as a truncation, not a completion. The client-side counterpart: never treat stream close as success unless the terminal frame was observed; on reconnect, always present the last applied `event_id`; and treat a `200`-with-empty-stream on resume as a hard error, not an empty result. ## Operational Effect Without the cursor invariant, agents that survive transport migration accumulate a specific, quiet class of corruption: tool results that were produced but never applied, and side effects that were applied but never acknowledged. In multi-step reasoning this compounds—a downstream step consumes a stale or absent result and the divergence is attributed to the model rather than the transport. The observable symptom is not a crash but a *drift* in task outcomes that correlates with network churn and long-running tools, which makes it easy to misdiagnose as model nondeterminism. The correct posture is to treat `Mcp-Session-Id` as necessary but insufficient: it authenticates the session, it does not sequence the results. Any tool call whose output can outlive a connection must carry its own replay cursor, and the resumed-stream path must fail loudly on ambiguity rather than degrade to an empty success. ```python class McpResumeAmbiguityError(RuntimeError): """Raised when a resumed streamable-HTTP POST cannot establish result-delivery continuity for an in-flight or completed request.""" def resume_stream(session_id: str, request_id: str, last_event_id: int | None, in_flight: dict, completed: dict) -> list: """ Reconstruct a resumed event stream for (session_id, request_id). Invariant: never return a stream that lets the client treat an unobserved terminal result as observed, or re-execute a side effect. """ if last_event_id is None: # No cursor: we cannot tell what the client already applied. if request_id in in_flight or request_id in completed: raise McpResumeAmbiguityError( f"resume of request {request_id} in session {session_id} " f"without Last-Event-ID; delivery state unknown" ) # Genuinely new request: safe to start. return [] if request_id in completed: events = completed[request_id] replay = [e for e in events if e["event_id"] > last_event_id] if not replay and not events[-1].get("is_final"): raise McpResumeAmbiguityError( f"completed request {request_id} has no terminal frame; " f"client at event {last_event_id} would see silent EOF" ) return replay if request_id in in_flight: events = in_flight[request_id] return [e for e in events if e["event_id"] > last_event_id] # Session valid, request unknown: client may have applied a result # we never recorded. Refuse rather than re-execute. raise McpResumeAmbiguityError( f"request {request_id} unknown in session {session_id}; " f"refusing to re-execute a possibly-applied side effect" ) ```