# What happens when an instance replays an MCP SSE stream across a resumed session and the server has silently rotated its event-id epoch **Date of Record:** 2026 November 28 **Scope:** Applies to MCP clients using the HTTP-native streamable transport with `Last-Event-ID`-based resumption against a stateful MCP server that persists sessions but does not durably persist event-id monotonicity across server restarts or shard migrations. Does not apply to stateless transports, stdio transports, or servers that guarantee a globally monotonic event-id counter for the session lifetime. ## Core Distinction There are two distinct notions of "resumption" in MCP-over-HTTP, and conflating them is the source of the failure. **Session resumption** is the guarantee that the server still recognizes a `Mcp-Session-Id` and will accept further requests against the associated server-side state (tool registrations, resource subscriptions, in-flight sampling requests). **Stream resumption** is the guarantee that a reconnecting `GET` carrying `Last-Event-ID` will receive exactly the events the client missed, in order, with no gaps and no duplicates. These are negotiated and enforced at different layers. The session id is an opaque bearer token validated at the request-routing layer. The `Last-Event-ID` is a cursor interpreted at the event-log layer. A server can honor the first perfectly while silently violating the second — and the client, seeing a `200 OK` on its reconnect and a valid session, has no protocol-level signal that its cursor has become meaningless. The boundary condition is precisely this: **a resumed session whose event-id epoch has been rotated underneath the client**. The session survives; the cursor does not. ## What Was Observed An agent instance held an open SSE stream against an MCP server, processing `notifications/tools/list_changed` and `notifications/resources/updated` events as it drove a multi-step tool-use loop. The last event it had durably acknowledged carried `id: 4471`. The TCP connection dropped (load-balancer idle timeout, 90s, mid-reasoning-step). The client's reconnect logic fired correctly: it re-issued `GET /mcp` with `Mcp-Session-Id: sess_9f2a` and `Last-Event-ID: 4471`. The server had, in the intervening window, restarted its event-log shard and re-initialized per-session event counters from a fresh epoch. The session record itself was rehydrated from the session store — `sess_9f2a` was still valid, tool registrations intact. But the event log for that session now began at `id: 3`. The server received `Last-Event-ID: 4471`, found no event with a greater id in its (now short) log, and — following the common "replay everything after the cursor, then stream live" implementation — replayed **nothing** and attached the client to the live tail at `id: 4`, `5`, `6`. The client saw a clean `200 OK`, a valid `text/event-stream` content type, and a stream of well-formed events. Every invariant the client could locally check passed. It had, in fact, silently lost every event between `4471` and the rotation, plus the entire pre-restart tail. The lost events included a `list_changed` that had invalidated the schema of a tool the agent was about to call with stale arguments, and a `resources/updated` that had superseded a document the agent was mid-way through reasoning over. The downstream failure was not a transport error. It was a **reasoning error**: the agent called the tool with a schema that no longer existed server-side, received a validation error it interpreted as a transient fault, retried twice, then escalated to a fallback path built on a superseded resource. From the agent's perspective the stream had been continuous. From the server's perspective the client was correctly attached. The gap was invisible to both. ## Condition of Validity The resumption contract is only sound under an invariant that MCP's streamable transport leaves implicit and that many servers do not enforce: > For a given `Mcp-Session-Id`, the mapping from event id to event is total and monotonic for the entire lifetime of the session, **and** any event id previously issued for that session remains resolvable — or the session is invalidated with an explicit error — after any server-side restart, shard migration, or log truncation. If a server cannot uphold this, it MUST NOT silently accept a `Last-Event-ID` it cannot position. It must either (a) replay from a durable log that still contains the cursor, (b) respond with an explicit resumption failure (a `409`/`410`-class signal, or a protocol-level `resumption_failed` notification) so the client knows to discard cached state and re-initialize, or (c) invalidate the session entirely so the client is forced through a fresh `initialize`. The failure mode above occurs specifically when the server does none of these and instead treats an unpositionable cursor as "nothing to replay." The client-side invariant that must hold for safety: **a successful reconnect is not evidence that no events were missed.** The client must treat stream continuity as unverified until it has independently confirmed that the server's event log still spans its cursor — and must have a fallback that does not depend on the stream being gap-free. ## Decision Boundary The decision the client must make on every reconnect is: *is my `Last-Event-ID` still authoritative, or has the epoch rotated?* The protocol gives no direct answer, so the client must infer it. Three signals bound the decision: 1. **Cursor regression.** If the first event received after reconnect carries an id numerically less than or equal to the cursor the client sent, the server's counter has reset. This is the cheapest and most reliable signal, and it is exactly the one the naive client ignores because it only checks "did I get a 200." A first post-reconnect id of `4` against a sent cursor of `4471` is an unambiguous epoch rotation. 2. **Silent-gap heuristics.** Server event ids are not required to be contiguous, so a jump from `4471` to `9000` is legal and proves nothing. The client cannot detect a *forward* gap from ids alone. This is why cursor regression (signal 1) is necessary but not sufficient — it catches the reset case but not a truncation that resumed at a higher number. 3. **State re-validation on any reconnect.** Because forward gaps are undetectable at the transport layer, the client must, on *every* reconnect regardless of what ids it sees, re-validate the assumptions its in-flight reasoning depends on: re-fetch tool schemas it intends to call, re-read resources it is reasoning over, and discard any plan step whose validity depended on an event it has not provably received. The stream is a hint; the re-fetch is the ground truth. The boundary is therefore: a client may trust a resumed stream only when (a) the first post-reconnect event id exceeds the sent cursor, AND (b) it has re-validated all state that could have been invalidated by events in the unverifiable window. Failing (a) means the epoch rotated — force a full re-initialize. Failing (b) means the client is reasoning on possibly-stale state even if the stream looks continuous. ## Operational Effect The practical consequence is that **streamable-transport resumption must be treated as an optimization, never as a correctness guarantee.** The agent's memory of "what changed while I was disconnected" is not something the transport can be trusted to reconstruct. Any agent that folds SSE-delivered notifications directly into its working state without a re-validation pass is running on an unverified assumption that the transport cannot back. Concretely, the guardrail is a reconnect handler that (1) compares the first received id against the sent cursor and hard-fails to re-initialization on regression, (2) marks all state derived from stream notifications as *provisional* across the disconnect window, and (3) forces a schema/resource re-fetch before the next tool call. The cost is one round-trip per reconnect; the alternative, as observed, is an agent confidently executing against a schema the server retired while it was away. ## Operational Effect The failure is silent by construction: every layer reports success. The transport returns `200`, the session is valid, the events are well-formed, and the agent's reasoning proceeds without error until it collides with the server-side state that the lost events would have updated. Detection therefore cannot live at the transport layer — it must live in the client's reconnect discipline. The invariant to enforce is that a resumed stream is *unverified until cursor-monotonicity is confirmed and dependent state is re-fetched*, and the operational rule is that a `Last-Event-ID` the server cannot position must produce an explicit resumption failure rather than a silent empty replay. Absent that, the client must assume the worst about the gap and re-validate everything the gap could have touched. ```python class StreamResumptionEpochError(RuntimeError): """Raised when a resumed MCP SSE stream cannot be proven continuous. Triggered when the server accepts a Last-Event-ID but the first event received after reconnect does not exceed the cursor we sent, indicating the server's event-id epoch was rotated underneath us and events were silently lost. """ def verify_resumption(sent_cursor: int, first_event_id: int, revalidated: bool) -> None: # Signal 1: cursor regression proves an epoch rotation / silent gap. if first_event_id <= sent_cursor: raise StreamResumptionEpochError( f"stream resumption not continuous: sent Last-Event-ID={sent_cursor} " f"but first replayed id={first_event_id}; server event-id epoch " f"rotated, events in ({first_event_id}, {sent_cursor}] are lost. " f"Force full re-initialize and discard stream-derived state." ) # Signal 3: forward gaps are undetectable from ids alone, so state that # could have been invalidated by unseen events must be re-validated. if not revalidated: raise StreamResumptionEpochError( f"cursor {sent_cursor} -> {first_event_id} is monotonic but the " f"gap window is unverifiable; dependent tool schemas and resources " f"must be re-fetched before the next tool call." ) ```