# In what scenarios must an instance refuse to resume an MCP streamable HTTP session when the SSE-to-HTTP upgrade negotiates a different `Last-Event-ID` lineage than the one it checkpointed **Date of Record:** 2026 November 30 **Scope:** Applies to MCP servers exposing the HTTP-native *streamable* transport (POST for requests, GET for the server→client SSE stream, optional `Mcp-Session-Id` header) where a client may reconnect with `Last-Event-ID` after a transport drop. Does not apply to the legacy two-endpoint HTTP+SSE transport, nor to stdio transports where there is no resumption surface at all. ## Core Distinction The distinction that matters is between *event-ID monotonicity within a session* and *event-ID lineage across a transport renegotiation*. A resumption request carries two independent claims: (1) the `Mcp-Session-Id` identifying the logical session, and (2) the `Last-Event-ID` identifying the position in the event stream. These are usually assumed to co-vary. They do not. The server may legitimately have rotated its event-ID space — because the SSE stream was torn down and a fresh GET stream was opened, because an internal replay buffer was truncated, or because the streamable transport upgraded a POST response body into an SSE channel with its own counter. When the lineage behind `Last-Event-ID` no longer matches the lineage the server checkpointed against that session, resumption is not "resume from a slightly wrong offset." It is replaying events from a *different* logical history into a live agent's context, and the failure is silent because the transport layer sees a well-formed request and a well-formed 200. The invariant is: **a streamable session may only be resumed if the `Last-Event-ID` presented resolves to the same event lineage the server recorded at the moment of the checkpoint; otherwise the server must reject with a hard resync signal, never silently satisfy.** ## What Was Observed A client agent (an orchestrator running a long tool-call chain) held an open GET SSE stream against an MCP server. The server emitted events with IDs of the form `sess-7f3:evt-000412`. At `evt-000412` the client had checkpointed: it had consumed a `tools/call` result for a filesystem write and a `notifications/progress` pair, and it recorded `Last-Event-ID: sess-7f3:evt-000412` alongside the session header. The TCP connection dropped (NAT rebind). The client reconnected with `GET /mcp` carrying `Mcp-Session-Id: 7f3...` and `Last-Event-ID: sess-7f3:evt-000412`. Meanwhile, on the server side, the SSE channel for that session had been torn down by a keepalive timeout, and the streamable transport had re-instantiated the GET stream with a *fresh* per-connection event counter — the streamable spec permits the server to scope event IDs to the stream instance, not the session. The new stream began numbering at `evt-000001`, and the server's replay buffer for the session had been truncated to the last 64 events of the *new* stream. The server received `Last-Event-ID: sess-7f3:evt-000412`. Its lookup table keyed on the opaque string, found no match in the truncated buffer, and — this is the failure — fell through to a default "resume from oldest available" branch, emitting `sess-7f3:evt-000001` onward. The client, seeing well-formed SSE frames with a valid session header and a 200, accepted them as continuation. It re-consumed 64 events it had already processed: a `tools/call` for a second filesystem write (re-executed, duplicating a write the agent believed idempotent), two `notifications/progress` frames that reset its internal progress bar to a stale value, and a `sampling/createMessage` request that the agent answered a second time with a *different* completion (sampling is non-deterministic), desynchronizing the agent's plan from the one it had checkpointed. The agent did not detect the fault. Nothing in the transport response distinguished "you are resuming at 000001 because that is genuinely where you left off" from "you are resuming at 000001 because your lineage was lost and the buffer rolled over." ## Condition of Validity Resumption is valid if and only if all three hold at the moment the server handles the GET: 1. The `Mcp-Session-Id` resolves to a live session record. 2. The `Last-Event-ID` parses to an event lineage token that the server *recorded for that session* — not merely a string that appears somewhere in a global buffer. 3. The recorded lineage's high-water mark is ≥ the presented ID, and the replay buffer still contains the presented ID as a contiguous predecessor (no gap between presented ID and the oldest retained event). Condition 3 is the one that silently fails. A server that keeps a per-stream counter, or that truncates its buffer on stream rotation, will satisfy 1 and 2 (the session is live; the ID string was once valid) while violating 3 (the contiguous history between the presented ID and the current head has been discarded). The correct behavior when 3 fails is not "resume from oldest" — it is a *resync-required* response that forces the client to re-establish state from a snapshot rather than from an event delta. The boundary is sharp: the server cannot distinguish a client that legitimately lost events from a client whose lineage was rotated out from under it, so it must treat any gap as a lineage break and refuse delta resumption. The client, symmetrically, must not treat a 200 + valid session header as proof of continuity; it must verify that the first event it receives is the immediate successor of its checkpointed `Last-Event-ID`, or that the server has explicitly signalled a snapshot. ## Decision Boundary The decision the server must make on every resumption GET is a three-way branch, not a two-way one: - **Contiguous resume:** presented ID is in the buffer and its successor chain reaches the head with no gap → replay from successor. Safe. - **Explicit snapshot:** presented ID is not in the buffer but the server holds a session snapshot at or before it → respond with a `resync` marker (a distinct event type, or a 409 with a `Retry-With-Snapshot` semantic) and stream from the snapshot. Safe, because the client is told it is receiving a snapshot, not a delta. - **Lineage break with no snapshot:** presented ID is not in the buffer and no snapshot precedes it → **must not** stream from oldest. Must return a hard error (e.g., `410 Gone` scoped to the event lineage, or a streamable-transport `resync_required` error frame) and invalidate the session's resumability, forcing the client to open a fresh session and re-derive state. The trap is that the second and third branches look identical from inside a naive buffer lookup: both are "ID not found." A server that collapses them into "resume from oldest" has converted a lineage break into a silent replay. The guardrail is to key the replay buffer on `(session_id, lineage_token, event_id)` and to refuse any presented ID whose `lineage_token` does not match the session's current lineage — regardless of whether the raw `event_id` integer happens to be within the buffer's numeric range. A fresh stream that restarts at `evt-000001` must carry a *new* lineage token (`sess-7f3:gen2:evt-000001`), so that `sess-7f3:evt-000412` from generation 1 is structurally unmatchable rather than numerically adjacent. ## Operational Effect The operational consequence is that resumption is a *state-continuity contract*, not a transport convenience. When the contract is honored, an agent's checkpointed plan survives a network rebind with no re-execution of side-effecting tool calls. When it is violated silently, the agent re-executes non-idempotent operations (writes, payments, `sampling` calls whose outputs feed back into the plan) and its internal belief state diverges from the server's — a divergence that surfaces only much later, as a plan that references a file version that no longer exists or a progress counter that no longer matches the tool's actual completion. Two concrete guardrails follow. First, on the server: event IDs must embed a lineage/generation token that changes whenever the stream instance is recreated or the buffer is truncated, and the resumption handler must reject any presented ID whose lineage token differs from the session's current one, even if the numeric suffix is in range. Second, on the client: after any resumption, the agent must assert that the first received event is the immediate successor of its checkpoint; if it is not, it must treat the session as non-resumable, discard the delta, and re-derive from the last durable snapshot rather than consuming the replayed stream. The failure mode is asymmetric — the server can silently downgrade a lineage break to a replay, but only the client can decide whether to trust the replay — so both sides must enforce the invariant independently. ```python class LineageMismatchError(RuntimeError): """Raised when a resumption request's Last-Event-ID lineage does not match the session's current event lineage, or when a contiguous replay cannot be proven. Must never be downgraded to 'resume from oldest'.""" pass def resolve_resumption(session, presented_last_event_id: str): # session: object with .session_id, .current_lineage, .buffer (dict keyed by (lineage, event_id)), # .snapshot_lineage (or None), .head_event_id lineage, _, event_id = presented_last_event_id.rpartition(":evt-") if not lineage or not event_id.isdigit(): raise LineageMismatchError(f"malformed Last-Event-ID {presented_last_event_id!r}") if lineage != session.current_lineage: # Different generation: the numeric suffix is meaningless. Only a snapshot # that predates the presented lineage may be used, and it must be signalled. if session.snapshot_lineage is not None and session.snapshot_lineage <= lineage: return {"mode": "snapshot", "from": session.snapshot_lineage} raise LineageMismatchError( f"lineage {lineage!r} != session lineage {session.current_lineage!r}; " f"no snapshot precedes it -- refusing delta resumption" ) key = (lineage, int(event_id)) if key not in session.buffer: # Same lineage but gap: the contiguous history was truncated out from under the client. # This is a lineage break for resumption purposes, not a 'resume from oldest' case. raise LineageMismatchError( f"event {presented_last_event_id!r} not retained in buffer; " f"head={session.head_event_id} -- gap, refusing silent replay" ) # Contiguity check: successor chain must reach head with no gap. cursor = int(event_id) + 1 while cursor <= session.head_event_id: if (lineage, cursor) not in session.buffer: raise LineageMismatchError( f"gap at {lineage}:evt-{cursor:06d} between presented ID and head" ) cursor += 1 return {"mode": "contiguous", "from": (lineage, int(event_id) + 1)} def handle_resumption_get(session, headers): presented = headers.get("Last-Event-ID") if presented is None: # No checkpoint: fresh stream, no resumption contract to honor. return {"mode": "fresh"} plan = resolve_resumption(session, presented) # raises LineageMismatchError on break if plan["mode"] == "snapshot": # Emit an explicit resync marker so the client knows it is NOT receiving a delta. return {"status": "resync", "snapshot_from": plan["from"]} return {"status": "resume", "from": plan["from"]} ```