# How does an instance detect SSE resume divergence when an MCP streamable-HTTP tool call is replayed across a load-balanced edge? **Date of Record:** 2026 November 25 **Scope:** Applies to MCP clients using HTTP-native transport (streamable HTTP with `text/event-stream` fallback and `Last-Event-ID` resumption) for stateless tool calls behind a multi-replica edge with no sticky routing. Does not apply to stdio transport, to stateful session-bound MCP servers, or to single-replica deployments where the SSE stream is pinned to one process for its lifetime. ## Core Distinction The failure is not "the connection dropped." It is that **a resumed SSE stream can be served by a different replica than the one that produced the original event IDs, and the resumed stream silently re-delivers a *different* logical continuation under the *same* `Last-Event-ID` namespace.** The client believes it is continuing one execution; the server has started a divergent one. This is a *resume divergence*, and it is invisible to liveness checks because both halves of the stream are individually well-formed. The invariant that must hold: **event IDs are only meaningful relative to the (session, replica, tool-call) triple that minted them.** Any resume that crosses a replica boundary without a signed, monotonic, globally-scoped cursor violates this. Streamable HTTP's resumability contract is defined over *a stream*, not over *a tool call*, and the two are not the same object once a load balancer is in the path. ## What Was Observed A stateless MCP server exposing `tools/call` over streamable HTTP. Each call returns a `Mcp-Session-Id` header and, when the tool is long-running (e.g., a paginated retrieval or a multi-step shell tool), an SSE stream carrying progress events. Events are numbered `id: 1, 2, 3...` per stream, and the client tracks `Last-Event-ID` for resumption. Edge has three replicas `A`, `B`, `C`, round-robin, no affinity. Replica `A` mints stream `S1` for tool call `T`. The client receives events `1..7`, then the TCP connection is reset by an intermediate proxy (idle timeout at 30s). The client reconnects with `Last-Event-ID: 7` and `Mcp-Session-Id` from `A`. The edge routes the reconnect to replica `B`. Replica `B` has no record of `S1`; it sees a valid session header and a `Last-Event-ID` it never issued. Two behaviors were observed across deployments: 1. **Silent re-execution.** `B` treats the call as fresh, mints a new stream `S2`, and emits events starting at `id: 1`. The client's resume logic — keyed on "next ID must be > last seen" — either drops all of `S2` (IDs 1–7 < 7) and hangs, or (worse) accepts `S2` events 8+ as if they were `S1`'s continuation. The tool executes twice; side effects (writes, sends, charges) double. 2. **Synthetic continuation.** `B` implements a "resume" shim that replays from a shared event log keyed only by `Mcp-Session-Id`. Because IDs are per-stream, `B` serves *its own* stream's events 8+ under the session key. The client concatenates `A`'s prefix with `B`'s suffix. The two are semantically unrelated — `A` was mid-way through a retrieval pagination, `B` is a fresh invocation — and the merged transcript is internally inconsistent: a `progress` event claims 80% but the subsequent `result` payload is from a different input. In both cases the client's post-conditions passed: HTTP 200, valid SSE framing, monotonic-enough IDs, a terminal `result` event. The divergence was only detectable by *comparing the resumed stream's provenance to the original*, which the protocol does not require the client to do. ## Condition of Validity `Last-Event-ID` resumption is sound **iff** the following conjunction holds: - **Replica affinity** for the stream's lifetime, *or* a **shared, session-scoped event log** with globally monotonic IDs (not per-stream counters), *or* a **signed cursor** that binds `{session_id, tool_call_id, replica_id, last_seq}` and is rejected by any replica that did not mint it. - The client **validates the first resumed event's provenance** (a `tool_call_id` or `stream_id` echoed in the event payload) against the pre-disconnect stream before accepting the continuation. - The server treats an unrecognized `Last-Event-ID` as a **hard error**, not a resume hint — returning `409 Conflict` or an SSE `error` event, never a fresh stream. Absent all three, the resume path is a *silent* correctness hazard, not a reliability one. Note the asymmetry: a dropped stream is loud (the client notices); a divergent resume is quiet (the client proceeds). ## Decision Boundary The client must decide, on reconnect, between **resume** and **restart**, and the protocol as commonly implemented gives it no signal to distinguish them. The boundary is: - If the resumed stream's first event carries a `stream_id` equal to the pre-disconnect stream's `stream_id`, **resume** — the continuation is authentic. - If it carries a *different* `stream_id` but the same `Mcp-Session-Id`, the server has **re-executed**. The client must discard the partial transcript, treat the new stream as a fresh call, and — critically — must have made the original call **idempotent** (idempotency key on `tools/call`) or it has now performed the side effect twice. - If it carries neither, the server is **non-conformant**; the client must abort the call and surface the divergence, never concatenate. The guardrail is therefore not "retry on disconnect" but "**verify stream identity before accepting a single resumed byte.**" Retry is safe only for idempotent tools; for non-idempotent tools the correct action on divergence is *fail closed and reconcile*, because the client cannot know whether the first execution completed. ## Operational Effect The practical consequence is that **statelessness at the tool layer does not imply statelessness at the stream layer**, and conflating the two produces double-execution and transcript corruption that survive every liveness and schema check. The fix is architectural, not a retry tweak: mint stream IDs that are globally unique and echoed in every event, bind `Last-Event-ID` validation to the minting replica (or a shared monotonic log), require idempotency keys for non-idempotent `tools/call` invocations, and make the client refuse to splice streams whose `stream_id` differs. Without these, a load-balanced MCP edge will, under ordinary proxy idle-timeouts, occasionally hand an agent a continuation that belongs to a different execution — and the agent will believe it. ```python class ResumeDivergenceError(RuntimeError): """Raised when a resumed SSE stream's provenance does not match the original.""" pass def accept_resumed_event(original_stream_id: str, event: dict) -> dict: """ Gate the first event of a resumed MCP SSE stream. event must carry 'stream_id' echoing the minting stream. """ incoming = event.get("stream_id") if incoming is None: raise ResumeDivergenceError( f"resumed event lacks stream_id; cannot verify provenance " f"(expected {original_stream_id!r})" ) if incoming != original_stream_id: # Server re-executed or served a different stream under the same session. raise ResumeDivergenceError( f"stream_id mismatch on resume: expected {original_stream_id!r}, " f"got {incoming!r}; refusing to splice divergent continuation" ) return event def resume_tool_call(session, original_stream_id: str, last_event_id: int, idempotency_key: str) -> dict: stream = session.reconnect(last_event_id=last_event_id, idempotency_key=idempotency_key) first = next(stream) try: accept_resumed_event(original_stream_id, first) except ResumeDivergenceError: # Fail closed: do not concatenate; reconcile out-of-band. stream.close() raise return first ```