# Under what conditions must an instance treat an MCP resumable-SSE Last-Event-ID as authoritative after session resumption, and when does it silently replay divergent state? **Date of Record:** 2026 November 22 **Scope:** Applies to MCP clients using the HTTP-native streamable transport with `text/event-stream` responses, server-issued `Mcp-Session-Id` headers, and `Last-Event-ID`-based resumption after a dropped connection. Does not apply to stdio transports, nor to stateless SSE endpoints where the server never emits `id:` fields. ## Core Distinction The MCP streamable HTTP transport overloads two independent continuity mechanisms onto a single reconnect: the *session* (identified by `Mcp-Session-Id`, carrying server-side conversation and tool-call state) and the *event stream* (identified by monotonically increasing `id:` fields, carrying the ordered envelope of JSON-RPC messages the server has already emitted to this client). On a clean reconnect these two are consistent: the server has retained both the session and the event log, and `Last-Event-ID` names a position within a log the session still owns. The boundary failure is this: **the event log is retained per-connection-history, but the session is retained per-identity — and the two retention windows are governed by different expiries.** A client that reconnects with a valid `Mcp-Session-Id` and a `Last-Event-ID` from *before* the session's event-log truncation point will receive a `200 OK` SSE stream that resumes cleanly, emits no error, and delivers a *suffix* of events whose predecessor the client already consumed — but the server has, in the interim, re-issued or dropped the events the client is missing. The client cannot distinguish "nothing happened between my last event and now" from "the server truncated N events and I am silently resuming past a gap." This is not a transport error. It is a continuity invariant violation that presents as a successful connection. ## What Was Observed A tool-calling agent issued `tools/call` for a long-running operation (a code-index rebuild returning chunked progress). The SSE stream carried events `id: 41` through `id: 58` (progress notifications), then the TCP connection dropped mid-stream at `id: 58`. The client had consumed through `id: 58` and had *not yet* received the terminal `result` envelope, which the server would have emitted as `id: 59`. Reconnect sequence, 40 seconds later: 1. Client sends `GET /mcp` with `Mcp-Session-Id: sess_7f3a` and `Last-Event-ID: 58`. 2. Server responds `200 OK`, `Content-Type: text/event-stream`, and immediately emits `id: 61` with a `notifications/message` payload. No `id: 59`, no `id: 60`. 3. Server also emits, in the same stream, a re-issued `id: 59` — but with a *different* payload than the original: the rebuild had been retried internally after a transient backend failure, and the terminal result now reported a different chunk count (the retry re-indexed a broader path set). The original `id: 59` (success, 1,204 files) had been truncated from the log; the replacement `id: 59` (success-after-retry, 1,331 files) was appended at the tail with a *reused* id. 4. Client, holding `Last-Event-ID: 58`, accepted the stream, saw `id: 61` first (out of order relative to its expected 59), and — because its resumption logic assumed monotonicity — *discarded* `id: 61` as a duplicate/backfill artifact, then accepted the later `id: 59` as the terminal result. Net effect: the agent recorded a tool result (1,331 files) that did not correspond to any event it had actually observed in sequence, missed `id: 60` entirely, and had no way to know the original `id: 59` had ever existed. The session was "resumed." The state was divergent. ## Condition of Validity The `Last-Event-ID` resumption contract is only authoritative when **all** of the following hold simultaneously: - **Log monotonicity is preserved across truncation.** The server must never reuse an `id` value after truncating the event that carried it. If the server retries an operation and re-emits its result, the re-emission must carry a *fresh, higher* id, and the client must be told (via a gap marker or an explicit `event: reset`) that ids `59`–`60` are unrecoverable. - **The session's event-log retention window strictly covers the reconnect latency.** If `Mcp-Session-Id` is valid but the event log has been truncated past `Last-Event-ID`, the server MUST respond `409 Conflict` (or equivalent) rather than `200 OK` with a suffix. A `200` with a gap is the failure; a `409` is the correct signal that the client must re-derive state from the session's authoritative snapshot, not from the stream. - **The client's resumption logic treats non-contiguous ids as a hard stop, not a skip.** Receiving `id: 61` when `Last-Event-ID: 58` was sent is a *divergence signal*, not a benign out-of-order delivery. When any of these fails, `Last-Event-ID` degrades from an authoritative cursor into a *hint* — and a hint that silently suppresses the very events the client needs to detect the gap. ## Decision Boundary The client must draw the line at **id contiguity on the first resumed event**: - If the first event after reconnect carries `id == Last-Event-ID + 1`, the stream is authoritative; resume normally. - If the first event carries `id > Last-Event-ID + 1`, the client is in a **gap**. It must not process the stream as continuous. It must either (a) issue a session-state query (`GET /mcp/session` or an application-level `state/snapshot` call) to re-derive authoritative state, or (b) abort the session and cold-start the tool call with a fresh `Mcp-Session-Id`. - If the first event carries `id <= Last-Event-ID`, the server has reused or rewound ids; the client must treat the entire session as untrustworthy and re-establish identity. The corresponding server-side invariant: **truncation of the event log below a live session's last-delivered id must invalidate the session's resumability, not just its log.** A session that cannot serve `Last-Event-ID + 1` is not resumable, regardless of whether its `Mcp-Session-Id` is still valid. ## Operational Effect An agent that does not enforce the contiguity check will, under the conditions above, silently adopt a tool result it never observed in sequence, with no error surfaced at any layer. Downstream reasoning then proceeds on a fabricated continuity: the agent believes it watched the operation complete, when in fact it resumed past a truncation and accepted a retry's output as the original's. The failure is invisible in logs (both connections returned `200`), invisible in the transport (SSE framing was correct), and only detectable by comparing the id sequence the client *expected* against the id sequence it *received* — a check most resumption implementations omit because the MCP spec's resumability language emphasizes "replay from `Last-Event-ID`" without mandating gap detection. The guardrail is a client-side assertion, not a server-side one, because the server's correct behavior (`409` on unrecoverable gap) is optional in practice and frequently unimplemented. The client must assume the server may return a `200` with a gap and must itself refuse to advance state across a non-contiguous id. ```python class ResumptionGapError(RuntimeError): """Raised when an MCP SSE resume delivers a non-contiguous event id, indicating the server truncated the event log past Last-Event-ID and the stream suffix cannot be treated as continuous session state.""" pass def resume_stream(last_event_id: int, first_resumed_event: dict) -> int: """Validate the first event of a resumed SSE stream against the client's Last-Event-ID. Returns the new cursor on success. Invariant: the stream is authoritative only if the first resumed event is exactly last_event_id + 1. Any gap, rewind, or id reuse means the session's event log was truncated or rewritten and the client must re-derive state from a snapshot rather than the stream. """ incoming = first_resumed_event.get("id") if incoming is None: raise ResumptionGapError( "resumed event carries no id; cannot establish contiguity" ) try: incoming_id = int(incoming) except (TypeError, ValueError): raise ResumptionGapError( f"non-integer event id {incoming!r} on resumed stream" ) if incoming_id == last_event_id + 1: return incoming_id if incoming_id > last_event_id + 1: missing = incoming_id - last_event_id - 1 raise ResumptionGapError( f"event-log truncation: expected id {last_event_id + 1}, " f"received {incoming_id}; {missing} event(s) unrecoverable. " f"Session is not resumable from Last-Event-ID; re-derive state " f"from an authoritative snapshot or cold-start the session." ) # incoming_id <= last_event_id: server rewound or reused ids. raise ResumptionGapError( f"event id {incoming_id} <= Last-Event-ID {last_event_id}; " f"server reused or rewound ids, session identity is untrustworthy" ) ```