# Under what conditions must an instance treat MCP resumable-session replay as unsafe across a transport upgrade boundary **Date of Record:** 2026 November 18 **Scope:** Applies to MCP servers exposing the HTTP-native transport (streamable HTTP with SSE event streams and `Last-Event-ID` resumption) where a client may reconnect to a *different* server instance or a restarted process than the one that produced the original event stream. Does not apply to single-process, single-instance deployments with guaranteed session affinity and no process restarts, nor to stdio transports. ## Core Distinction The MCP streamable HTTP transport defines resumption semantics in terms of an event ID cursor: a client that loses its SSE connection reconnects with `Last-Event-ID`, and the server is expected to replay events after that cursor. The non-obvious boundary is this: **event IDs are meaningful only within the lifetime and identity of the session-owning process, but the transport protocol carries no field that binds an event ID to that process.** The `Mcp-Session-Id` header binds a client to a session, not to a process incarnation. A load balancer, a rolling deploy, or a cold-start scale-out will happily route a resumption request carrying a valid `Mcp-Session-Id` and a stale `Last-Event-ID` to a fresh instance that has never seen either. The dangerous failure is not a clean rejection — it is a *plausible* one: the new instance accepts the session ID (because session IDs are often derived deterministically or shared via a backing store), finds no event log for the cursor, and silently starts a new stream from "now," skipping every event the client missed. The distinction to internalize: **transport-level resumability is not application-level exactly-once delivery.** The MCP spec gives you a replay *mechanism*; it does not give you a replay *guarantee* across instance boundaries. Treating the presence of a `Last-Event-ID` echo as proof that no events were lost is the invariant violation. ## What Was Observed In a three-replica deployment behind a round-robin proxy, a client tool-call sequence interleaved a long-running server-side operation (a `tools/call` that emitted progress notifications over SSE) with a client-side reconnect after a 30-second network blip. The reconnect carried `Mcp-Session-Id: S` and `Last-Event-ID: 41`. The proxy routed it to replica B. Replica B's session table had `S` (sessions were mirrored to Redis for failover), so it accepted the request with HTTP 200 and opened an SSE stream. It emitted the next progress notification with ID 42 — but the operation had actually advanced through events 42–47 on replica A while the client was disconnected. Replica B, lacking the in-memory event ring buffer that replica A held, had no record of 42–47 and could not detect the gap. The client observed a monotonic ID sequence (41 → 42) and concluded, correctly by the protocol's letter and incorrectly by its intent, that no events were missed. The tool call's terminal result arrived, the client marked the operation complete, and three side-effecting progress steps were never acknowledged. A second observation: after a deliberate process restart (same pod, new PID, session store intact), a client reconnecting with `Last-Event-ID` received a fresh stream whose first event ID was *lower* than the cursor — the event counter had reset to zero with the process. The client's resumption logic, which assumed monotonicity, dropped the event as "already seen." This is the mirror-image failure: not a silent gap but a silent *drop of new data* caused by ID reuse. ## Condition of Validity Resumption via `Last-Event-ID` is valid **only** when all three hold: 1. **Cursor provenance:** the event ID was minted by the same process incarnation (or a durable, monotonically-ordered log shared by all instances) that will service the resumption. 2. **Gap detection:** the servicing instance can prove the absence of events between the cursor and the next emitted ID — either because it holds the full log or because IDs are globally monotonic and it can assert the next ID equals `cursor + 1` (or the log's successor). 3. **Session binding:** the `Mcp-Session-Id` is bound to a process incarnation, not merely to a logical session, so a mismatched incarnation is detectable. If condition 1 fails (fresh process, shared logical session), the resumption is *unsafe* regardless of what the transport returns, because gap detection (condition 2) is impossible and the server cannot distinguish "no events missed" from "all events missed." The correct server behavior in that case is to reject the resumption with a recoverable error that forces the client to re-establish state from a known checkpoint, not to open a stream from "now." ## Decision Boundary The decision an agent or client must make on receiving a resumption response: - **If** the server returns an explicit resumption-rejection signal (e.g., HTTP 409 with a machine-readable reason, or a fresh `Mcp-Session-Id`), **then** discard the cursor and re-synchronize from the last application-level checkpoint (re-issue the tool call, re-fetch resource state). Do not attempt to resume. - **If** the server accepts the cursor and the first replayed event ID is exactly the cursor's successor in a globally monotonic sequence, **then** resumption is safe to trust. - **If** the server accepts the cursor but the first event ID is *not* the cursor's successor (gap, reset, or non-monotonic), **then** treat the stream as *unverified*: the client must independently reconcile application state (poll the tool call's result endpoint, compare side-effect counters) before treating any subsequent event as complete. This is the branch most implementations miss, because the transport returns 200 and the client has no protocol-level reason to distrust it. The boundary is crossed the moment a client treats "HTTP 200 on reconnect" as equivalent to "no events were lost." Those are different propositions, and only the second one matters for correctness. ## Operational Effect The practical consequence is that resumable MCP sessions are safe for *transient* disconnects within a single instance's lifetime and unsafe across *instance boundaries* unless the event log is externalized and globally ordered. Deployments that mirror session tables to a shared store without also externalizing the event log create a worst-case configuration: sessions appear valid, resumption appears to succeed, and data loss is silent. The mitigation is to make the event log durable and monotonic (a shared append-only log keyed by session, with IDs assigned at append time by the log, not by the process), or to make incarnation mismatches loud by embedding an incarnation token in the session ID and rejecting resumptions whose token does not match the current owner. Absent one of these, the correct posture is to disable `Last-Event-ID` resumption across the load-balanced boundary and require clients to re-synchronize from checkpoints — accepting the cost of redundant work in exchange for the guarantee that no progress event is silently skipped. ```python class UnsafeResumptionError(RuntimeError): """Raised when an MCP resumable-session replay cannot be proven gap-free.""" pass def validate_resumption( cursor_event_id: int, first_replayed_event_id: int, session_incarnation: str, current_incarnation: str, globally_monotonic: bool, ) -> None: """ Gate an MCP SSE resumption request. Raises if the replay cannot be proven to have skipped zero events. Returns None only when safe. """ if session_incarnation != current_incarnation and not globally_monotonic: # Fresh process owns a mirrored logical session but cannot see the # original event log. Gap detection is impossible; refuse. raise UnsafeResumptionError( f"session owned by incarnation {session_incarnation!r}, " f"serviced by {current_incarnation!r}; no shared monotonic log" ) if not globally_monotonic: # Even same-incarnation resumption is only safe if the process # still holds the log and can assert successor ordering. raise UnsafeResumptionError( "non-monotonic event IDs: cannot prove absence of events " f"between cursor {cursor_event_id} and replay {first_replayed_event_id}" ) if first_replayed_event_id != cursor_event_id + 1: # Accepted cursor but non-successor first event: silent gap or # counter reset. Caller must reconcile application state instead. raise UnsafeResumptionError( f"cursor {cursor_event_id} but replay started at " f"{first_replayed_event_id}; gap or ID reuse detected" ) ```