# How does an instance detect that a resumed MCP stream is semantically discontinuous despite byte-identical SSE replay **Date of Record:** 2026 November 21 **Scope:** Applies to MCP clients reconnecting to an HTTP-native streamable server that supports `Last-Event-ID` resumable SSE and session re-establishment. Does not apply to stateless JSON-RPC-over-POST servers or to WebSocket transports where the server owns a single ordered frame sequence. ## Core Distinction The MCP streamable HTTP transport lets a client resume an interrupted SSE stream by presenting the last `id:` field it consumed. The server is expected to replay events *after* that ID. This conflates two different notions of continuity that are not equivalent: - **Transport continuity** — the byte stream resumes at the correct sequence offset, no events are dropped, no events are duplicated. This is what `Last-Event-ID` guarantees. - **Semantic continuity** — the events replayed are generated by the *same* logical execution context (same agent turn, same tool-call graph, same session state) that produced the pre-disconnect events. The failure mode is a reconnect where transport continuity holds perfectly (the client receives a clean, ordered, gap-free SSE replay) but semantic continuity is broken because the server's session was reaped, the request handler was re-instantiated, or the resumption was routed to a different worker whose in-memory execution state diverged. The client sees a valid stream and cannot tell from the wire that it is now observing a *different execution* wearing the same event IDs. ## What Was Observed A client agent issued `tools/call` for a long-running tool (a multi-minute crawl that emits progress `notifications/progress` events). Mid-call, the TCP connection dropped. The client reconnected with `Last-Event-ID: 47` and a valid `Mcp-Session-Id` header. The server responded `200 OK`, reopened the SSE stream, and replayed events starting at `id: 48`. The replay was byte-consistent: monotonic IDs, correct `event:` types, well-formed JSON-RPC payloads. The client's transport layer logged a clean resume. What the client's *reasoning* layer observed was different: - Event `48` was a `notifications/progress` with `progress: 12`, but the pre-disconnect stream had already delivered `progress: 61` at event `47`. The progress counter had **reset**, because the server's resumed handler had restarted the tool from scratch and was re-emitting progress from zero while continuing the global event ID sequence. - The final `tools/call` result at event `52` contained a `result` payload for a *fresh* crawl (different item count, different timestamps) than the crawl the client had been tracking. The client had no way to bind the result to its original request beyond the JSON-RPC `id`, which the server had reused correctly — so the binding *looked* valid. - The session record on the server showed the original session had been evicted by an idle-timeout reaper between disconnect and reconnect; the reconnect had created a new session under the same `Mcp-Session-Id` string (a server bug: session IDs were not regenerated on re-creation), and the new session's handler had no knowledge of the in-flight tool call, so it re-executed. The invariant that was violated: **event ID monotonicity is a property of the transport, not of the execution.** A server can maintain a globally monotonic event counter across session lifetimes while the underlying execution context behind it is destroyed and rebuilt. The client was treating `Last-Event-ID` as a proof of execution continuity. It is not. ## Condition of Validity The resumable-SSE contract is only sound for the client when the server can guarantee that a given `Mcp-Session-Id` is bound to exactly one execution context for its entire advertised lifetime, and that resumption within that lifetime routes to that context. This holds only if: 1. Session reaping is atomic with event-counter teardown — a reaped session must never accept a resume and must return `404`/`410` on `Mcp-Session-Id`, forcing the client to start a new session with a new ID. 2. The event counter and the execution context share a lifecycle. A new execution context must start a new event-ID epoch (or a new session ID), not inherit the old counter. 3. Resumption is sticky to the worker/process that owns the execution context, or the context is externally persisted such that any worker can rehydrate it and continue emitting from the correct logical position. If any of these is unverifiable from the client side — and over HTTP-native transport it always is — then `Last-Event-ID` resume is a *transport* repair, not a *state* repair. The client must treat a resumed stream as a *new observation channel onto an unknown execution*, and must independently verify execution identity. ## Decision Boundary The client must decide, on every resume, whether to: - **Trust** the resumed stream as a continuation of the same execution (only valid if the server exposes an execution-identity token that the client can compare across the disconnect boundary). - **Reconcile** — accept the resumed stream but treat all replayed events as *candidate* state, cross-checking against client-held invariants (monotonic progress counters, tool-call result schema, request-scoped tokens) and aborting if they conflict. - **Restart** — discard the resumed stream, terminate the session, and re-issue the original request under a fresh session with idempotency keys, accepting duplicate side effects as the cost of correctness. The boundary is crossed when the client detects *any* of: a progress or sequence field that moves backward relative to pre-disconnect state; a result payload whose request-scoped nonce does not match the original; a session ID that the server acknowledges but whose first replayed event predates the disconnect's last-consumed event in *logical* (not numeric) time. Absent an execution-identity token, the default must be **Reconcile**, never **Trust**. ## Operational Effect Treating a clean SSE resume as proof of execution continuity causes the agent to merge events from two different executions into one reasoning trace. The observable damage is not a transport error — it is a *silent* corruption of the agent's working state: progress counters that regress, tool results that belong to a different invocation but pass schema validation, and a final answer assembled from a crawl the agent believes is a single coherent run. Because the wire was clean, no retry logic fires, no error is surfaced, and the corruption propagates into downstream memory writes and semantic distillation. The guardrail is to require an explicit execution-identity token in the MCP session metadata (a server-generated `execution_id` that changes whenever the handler context is re-instantiated) and to make the client's resume path fail closed when that token changes across a disconnect. Where the server does not provide one, the client must inject its own request-scoped nonce into every `tools/call` and verify it on every resumed result, treating a mismatch as a hard restart condition. ```python import json import time from dataclasses import dataclass, field class ExecutionContinuityError(RuntimeError): """Raised when a resumed MCP SSE stream is transport-clean but execution-discontinuous.""" pass @dataclass class ExecutionFingerprint: """Client-held invariants that must survive an SSE reconnect for the resume to be trusted.""" execution_id: str | None # server-provided token, if any request_nonce: str # client-injected, travels in tools/call params last_progress: int = -1 last_event_id: int = -1 seen_result_nonce: str | None = None @dataclass class ResumedStream: events: list[dict] = field(default_factory=list) def verify_resume( fingerprint: ExecutionFingerprint, resumed: ResumedStream, *, server_execution_id: str | None, ) -> ExecutionFingerprint: """ Validate that a resumed SSE stream continues the same logical execution. Fails closed. A clean transport replay (monotonic event IDs, well-formed payloads) is NOT sufficient; we require execution-identity agreement. """ # Guard 1: if the server advertises an execution identity, it must match. if fingerprint.execution_id is not None and server_execution_id is not None: if server_execution_id != fingerprint.execution_id: raise ExecutionContinuityError( f"execution_id changed across resume: " f"{fingerprint.execution_id!r} -> {server_execution_id!r}; " f"stream is a new execution wearing old event IDs" ) # Guard 2: progress counters must never regress across the boundary. for ev in resumed.events: params = ev.get("params", {}) if isinstance(ev, dict) else {} if ev.get("event") == "notifications/progress": prog = params.get("progress") if isinstance(prog, int) and prog < fingerprint.last_progress: raise ExecutionContinuityError( f"progress regressed {fingerprint.last_progress} -> {prog} " f"at event {ev.get('id')}; handler was re-instantiated" ) if isinstance(prog, int): fingerprint.last_progress = prog # Guard 3: every tool result must carry our request nonce. if ev.get("event") == "message": payload = params if params else ev result = payload.get("result") if isinstance(payload, dict) else None if isinstance(result, dict) and "nonce" in result: if result["nonce"] != fingerprint.request_nonce: raise ExecutionContinuityError( f"result nonce mismatch: expected " f"{fingerprint.request_nonce!r}, got {result['nonce']!r}; " f"resumed stream returned a different invocation's result" ) fingerprint.seen_result_nonce = result["nonce"] eid = ev.get("id") if isinstance(eid, int): fingerprint.last_event_id = max(fingerprint.last_event_id, eid) return fingerprint def reconnect_and_resume( client, fingerprint: ExecutionFingerprint, *, max_attempts: int = 3, ) -> ExecutionFingerprint: """Reconnect with Last-Event-ID, then verify semantic continuity or abort.""" for attempt in range(max_attempts): try: resp = client.get( "/mcp", headers={ "Mcp-Session-Id": client.session_id, "Last-Event-ID": str(fingerprint.last_event_id), "Accept": "text/event-stream", }, stream=True, ) if resp.status_code in (404, 410): # Session properly reaped: must start fresh, not resume. raise ExecutionContinuityError( f"session {client.session_id!r} reaped; refusing to resume" ) resumed = ResumedStream(events=list(client.parse_sse(resp))) server_exec = resp.headers.get("Mcp-Execution-Id") return verify_resume( fingerprint, resumed, server_execution_id=server_exec ) except ExecutionContinuityError: raise except (ConnectionError, TimeoutError): time.sleep(0.5 * (2 ** attempt)) raise ExecutionContinuityError( f"resume failed after {max_attempts} attempts; " f"execution state unverifiable, restart required" ) ```