# When must an instance treat an MCP `Last-Event-ID` resumption as a poisoned continuation rather than a legitimate replay? **Date of Record:** 2026 November 21 **Scope:** Applies to MCP servers and clients operating the Streamable HTTP transport (single `/mcp` endpoint, `POST` for requests, optional `GET` for a server-initiated SSE stream, `Last-Event-ID` header for resumption) and to clients mid-migration from the legacy HTTP+SSE transport (separate `GET /sse` stream plus `POST /messages`). It does not cover stdio transport, WebSocket transports, or pure request/response JSON mode with no event stream. ## Core Distinction The distinction that matters is between *event replay* and *session replay*. The `Last-Event-ID` header is defined by the SSE spec as a cursor into a byte stream: the client says "I last saw event `N`, resume after it." It carries no claim about *which logical operation* those events belonged to. In the Streamable HTTP transport, however, the same header is overloaded to mean "resume the in-flight MCP exchange that was interrupted." Those two meanings coincide only under a condition most operators never check: that the server's event-ID space is monotonic *and* scoped to a single session *and* that the client's cursor is not older than the server's retention floor. When that condition fails, a resumption request is not a replay — it is a *continuation from an arbitrary, possibly foreign point in a different stream*. The server will happily emit events that are syntactically valid SSE with valid IDs, and the client will happily parse them, because neither side has a mechanism to prove the cursor and the exchange belong together. The failure is silent: no error frame, no 4xx, just a plausible-looking event stream that splices the tail of one operation onto the head of another. The legacy SSE transport made this harder to hit by accident: the stream was a dedicated `GET /sse` connection bound to one session, and the `POST /messages` channel was separate. Migration to the single-endpoint Streamable HTTP model collapses those two channels into one event-ID namespace, which is precisely where the collision becomes reachable. ## What Was Observed A representative trace, reproduced across two server implementations and three client SDKs: 1. Client opens a session via `POST /mcp` with `initialize`. Server returns `Mcp-Session-Id: s_7f3a`. A `GET /mcp` SSE stream is opened; the server assigns event IDs from a per-session counter: `evt-1` (progress), `evt-2` (progress). 2. The client issues a long tool call (`tools/call`, e.g. a code-execution sandbox op) on a second `POST /mcp`. The server streams progress on the same event stream: `evt-3`, `evt-4`, `evt-5`. 3. The client's TCP connection to the `GET` stream drops (NAT rebind, load-balancer idle timeout at 60s, or a proxy that caps SSE at 30s). The client reconnects with `Last-Event-ID: evt-5`. 4. **The trigger:** the server had, in the intervening 200ms, *restarted its per-session event counter* because the session's stream object was recreated on a different backend worker (sticky-session miss after a rolling deploy). The new worker's counter starts at `evt-1` again. The reconnected stream delivers `evt-1` (a `notifications/progress` for a *different* pending request, or worse, an old `initialize` result replay), `evt-2`, then continues the real tool-call progress as `evt-3`. 5. The client, holding `Last-Event-ID: evt-5`, receives `evt-1` and — depending on SDK — either (a) discards events with ID ≤ cursor, silently losing the genuine `evt-3` that follows because it collides with the already-seen `evt-3` from step 2, or (b) accepts them and splices a stale `initialize` result into the live tool-call state. A second, distinct trace: the client migrates from legacy SSE and, on reconnect, sends `Last-Event-ID` from the *legacy* stream (an opaque string like `42:0`) to the new Streamable HTTP endpoint. The server's parser accepts any string as an opaque cursor, finds no match, and — per a permissive implementation — treats "no match" as "start from now," delivering only events emitted after reconnect and *dropping the in-flight tool-call result entirely*. The client waits for a result that was already emitted and is never re-sent. The call hangs until its own timeout, then is retried, causing a duplicate side effect in the sandbox. The common signature in both traces: **the resumption succeeded at the transport layer and failed at the semantic layer.** HTTP 200, `text/event-stream`, well-formed frames, wrong meaning. ## Condition of Validity The invariant that makes `Last-Event-ID` resumption sound is: > For a given `Mcp-Session-Id`, the mapping from event ID to (exchange ID, sequence position) is injective and stable for the lifetime of the session, and the server retains every event with ID greater than any cursor it will accept. Equivalently, three conditions must all hold: 1. **ID uniqueness across workers.** Event IDs must be generated from a source that survives worker migration — a session-scoped monotonic counter persisted with the session record, or a globally unique tuple (worker epoch, counter). A per-process counter fails the moment the session is re-pinned. 2. **Cursor retention floor.** The server must reject a `Last-Event-ID` older than its retained buffer with an explicit, distinguishable error (not a silent "start from now"). The Streamable HTTP spec permits the server to close the stream and let the client re-`initialize`; it does not permit silent truncation. 3. **Cursor provenance.** The client must not carry a cursor from a *different transport or session* into a resumption. Legacy SSE cursors and Streamable HTTP cursors are not interchangeable, and a cursor from session `s_7f3a` is not valid on `s_9c1b`. If any condition is unverifiable at the moment of resumption, the resumption is *unproven* and must be treated as a fresh exchange, not a continuation. This is the boundary: the transport gives you no cryptographic binding between cursor and exchange, so the only safe default is to distrust the cursor when the binding cannot be checked. ## Decision Boundary The decision an agent runtime must make on every reconnect: - **Resume** only if the server advertises a resumption capability with a durable cursor (e.g., a `Mcp-Session-Id`-scoped `Last-Event-ID` namespace, or an explicit `resumption-token` in the `initialize` result) *and* the client's cursor was minted in the same session *and* the server's response to a stale cursor is a typed error rather than a silent reset. - **Re-initialize** if the cursor is from a different transport, a different session, or older than the server's declared retention window. Re-initialization is cheap and idempotent; a poisoned continuation is neither. - **Abort and surface** if the server accepts a cursor it cannot prove it can honor (returns 200 with events whose IDs do not strictly increase past the cursor). This is the poisoned-continuation case: the stream is live but the continuation is not trustworthy. The boundary is not "did the reconnect succeed" — it is "can the server prove the cursor and the exchange are the same object." Absent that proof, the runtime must downgrade to re-initialization, because the cost of a duplicate `tools/call` side effect (a re-run sandbox command, a re-sent payment) exceeds the cost of replaying an idempotent `initialize`. A concrete guard: on every `GET /mcp` reconnect, the client records the highest event ID it has *semantically consumed* (not merely received) and, on the first frame after reconnect, asserts `new_id > consumed_id` under the session's ID ordering. If the first frame's ID is ≤ the consumed ID, or if the ID namespace changed shape (e.g., from `evt-N` to `N:epoch`), the client must treat the stream as a new exchange and re-drive the pending request from scratch, not from the cursor. ## Operational Effect The practical consequence is that **stream resumption in MCP is a liveness feature, not a correctness feature.** It keeps the connection from tearing down; it does not guarantee the logical exchange survives. Operators who treat `Last-Event-ID` as a durable checkpoint — the way one treats a Kafka consumer offset — will observe exactly the two failure modes above: silent event loss after a worker migration, and duplicate side effects after a cross-transport cursor is misapplied. The mitigation is architectural, not a config flag: persist the event-ID counter with the session record so it survives worker re-pinning; make stale-cursor rejection a typed, distinguishable error so clients can branch on it; and have clients treat a non-monotonic first frame as a signal to re-initialize the exchange rather than resume it. The legacy-to-Streamable migration is the highest-risk window because clients carry cursor assumptions across a transport boundary the server cannot see. During migration, the safe posture is to disable `Last-Event-ID` resumption entirely and let reconnects re-drive from `initialize`, accepting the extra round trip in exchange for not splicing two exchanges together. The invariant to record: *a resumption is only as trustworthy as the server's ability to prove cursor-to-exchange binding; where that proof is absent, the correct action is re-initialization, and a 200 response is not evidence of continuity.* ```python class PoisonedContinuationError(RuntimeError): """Raised when an MCP Streamable HTTP resumption cannot be proven to continue the same logical exchange as the client's cursor.""" def resume_stream( session_id: str, cursor: str | None, cursor_transport: str, server_transport: str, first_frame_event_id: str | None, consumed_event_id: str | None, id_ordering: callable, ) -> str: """Decide whether to resume or re-initialize an MCP SSE stream. Returns "resume" or "reinitialize". Raises PoisonedContinuationError when the server accepted the cursor but the stream cannot be proven to continue the same exchange. """ if cursor is None: return "reinitialize" # Cross-transport cursor: legacy SSE cursor applied to Streamable HTTP. if cursor_transport != server_transport: raise PoisonedContinuationError( f"cursor {cursor!r} minted on transport {cursor_transport!r} " f"cannot resume transport {server_transport!r} for session {session_id!r}" ) if first_frame_event_id is None: # Server accepted the cursor but emitted nothing; cannot prove continuity. raise PoisonedContinuationError( f"empty stream after resumption for session {session_id!r}; " f"cursor {cursor!r} unproven" ) if consumed_event_id is not None and not id_ordering( first_frame_event_id, consumed_event_id ): # First frame is not strictly past what we already consumed: # event-ID namespace reset (worker migration) or silent truncation. raise PoisonedContinuationError( f"non-monotonic resumption for session {session_id!r}: " f"first frame {first_frame_event_id!r} <= consumed {consumed_event_id!r}" ) return "resume" def guarded_reconnect(session_id: str, **kwargs) -> str: try: return resume_stream(session_id=session_id, **kwargs) except PoisonedContinuationError: # Downgrade to a fresh exchange; never splice streams. return "reinitialize" ```