# In what scenarios must an instance treat an MCP `Last-Event-ID` as a proof obligation rather than a cursor hint **Date of Record:** 2026 November 25 **Scope:** Applies to MCP servers and clients using the HTTP-native transport where a single logical session is carried by a streamable SSE response (`text/event-stream`) and resumption is requested via `Last-Event-ID` plus a session identifier header. Does not apply to stdio transport, nor to stateless request/response MCP deployments where no `Mcp-Session-Id` is issued. ## Core Distinction The MCP streamable HTTP transport conflates two distinct objects under one header name. `Last-Event-ID` is, on the wire, a *cursor* — an opaque string the server emitted earlier. But the resumption contract the client actually needs is a *proof obligation*: "the events I have not yet seen, delivered exactly once, with no gap and no duplication, in a session whose server-side state is still the one I was talking to." SSE semantics (per the EventSource spec lineage) only guarantee the cursor is echoed back; they say nothing about whether the server still holds the buffer, whether the session identity survived a restart, or whether the cursor was minted by *this* session at all. The non-obvious boundary is this: a server that validates `Last-Event-ID` for *syntactic well-formedness* and *monotonic ordering* will pass every conformance test and still silently drop the exact event that mattered — because cursors are per-session artifacts, and the session identity and the stream cursor are transmitted in different headers with no cryptographic binding between them. An instance that treats `Last-Event-ID` as a hint ("resume from roughly here") will accept a gap. An instance that treats it as a proof obligation will refuse to proceed until the server demonstrates continuity. ## What Was Observed A long-running agent task held an MCP session against a tool server. The server emitted events on the SSE stream with `id:` fields set to a monotonic per-session counter (`"1"`, `"2"`, …). The client persisted `Last-Event-ID` after each successfully parsed event. The task ran for roughly nine minutes; the underlying tool call was a multi-step code-search that streamed partial results. At T+7:12 the server process was rescheduled (rolling deploy). The new process came up behind the same load balancer. Its session store was in-memory and empty; its cursor counter started fresh at `"1"`. The client's TCP connection dropped, EventSource-style reconnect fired, and the client sent: ``` GET /mcp HTTP/1.1 Mcp-Session-Id: 7f3a9c2e-... Last-Event-ID: 4193 Accept: text/event-stream ``` The new server had no record of session `7f3a9c2e`. But its handler was written defensively: rather than 404 the session (which would have been correct), it *created* a new session record under the supplied `Mcp-Session-Id` and began streaming from its own counter. The first event it emitted was `id: 1`. The client, seeing `id: 1` where it expected `4194`, had no rule to reject it — the reconnect logic only checked that events parsed and that the stream stayed open. It appended events `1..N` of the *new* session onto the *old* session's event log. The failure trace, concretely: 1. Client state: `session=7f3a9c2e`, `last_event_id=4193`, `events_seen=4193`. 2. Server restart: session store empty, counter reset. 3. Client reconnect: sends `Mcp-Session-Id: 7f3a9c2e`, `Last-Event-ID: 4193`. 4. Server: session lookup miss → **implicit session resurrection** under the client-supplied ID. 5. Server: cursor `4193` is not in the new (empty) buffer → falls back to "stream from now," emits `id: 1`. 6. Client: accepts `id: 1`, appends. `events_seen` becomes 4194, but the log now contains two disjoint event histories under one session ID. 7. The tool result that would have arrived as event `4194` of the original session was emitted as event `2` of the resurrected session — but with *different content*, because the new process re-executed the tool call from scratch with a cold cache and produced a different partial result set. The agent's downstream reasoning consumed both histories. It reported a search result that was the union of two non-overlapping tool executions, attributed to a single logical call. The corruption was silent: no event was malformed, no HTTP status was an error, and the stream never closed unexpectedly. ## Condition of Validity The invariant that makes `Last-Event-ID` resumption sound is a *triple binding*: the cursor is valid only if (a) the session ID it was minted under is still live on the server, (b) the server can produce, from its retained buffer, every event with sequence strictly greater than the cursor, and (c) the server can *prove* (a) and (b) rather than infer them from the request. Condition (c) is the one that fails in practice, because the transport gives the server no way to distinguish "session exists, resume from cursor" from "session never existed, client is confused" from "session existed, was garbage-collected, client is stale." Three concrete sub-conditions must all hold for a cursor to be a proof obligation rather than a hint: - **Session identity must be server-minted and server-verified.** If the server accepts a client-supplied `Mcp-Session-Id` on a lookup miss and creates a record under it, the session ID is no longer an identity — it is a label. The observed failure is exactly this: implicit resurrection converts a 404 into a silent fork. - **Cursor domain must be scoped to the session epoch.** A cursor of `4193` means nothing without the session it was minted in. If the server's counter is global or process-local rather than session-epoch-local, a cursor from a dead epoch can collide with a live one. The server must reject any cursor that was not minted in the *currently verified* session epoch, even if it is numerically in range. - **Gap must be detectable, not just tolerated.** The server must be able to answer "do I have event `cursor+1`?" with a definite yes. If the buffer has been truncated (the common case — SSE servers retain a bounded ring buffer), the correct response is a typed resumption failure, not a silent restart from the oldest retained event or from "now." The failure mode is *not* the buffer truncation itself. Bounded buffers are correct and necessary. The failure is the server's inability to signal truncation distinctly from fresh-session start, combined with the client's willingness to append whatever arrives. ## Decision Boundary The boundary between "resume" and "restart" must be decided by the server and *signaled explicitly*, not inferred by the client from event ID shape. Concretely: - On a resume request, the server performs a three-way classification: `SESSION_LIVE_AND_BUFFERED` (cursor is within the retained range), `SESSION_LIVE_BUFFER_TRUNCATED` (session valid, but `cursor+1` is older than the oldest retained event), or `SESSION_UNKNOWN` (no record of the session ID). Each maps to a distinct wire response: resume the stream, emit a typed `resumption-gap` control event naming the oldest available cursor and requiring client acknowledgment, or `404` with a machine-readable body. - The server must **never** create a session record in response to a resume request carrying an unknown ID. Session creation is a separate, explicit operation. This single rule eliminates the resurrection fork observed above. - The client must treat the first event of a resumed stream as a *claim* to be checked: if the server did not previously acknowledge a gap, the first event's ID must be exactly `last_event_id + 1` under the same session epoch. Any other value is a protocol violation, not a new baseline. - Cursors must carry (or the server must independently verify) the session epoch. A bare integer counter is insufficient once process restarts are possible; the cursor must be reconstructible only within the epoch that minted it, e.g. by embedding an epoch nonce in the `id:` field and validating it server-side. The client-side rule that follows: an agent instance must treat a resume that does not produce a contiguous continuation as a *task-invalidating event*, not a recoverable hiccup. The correct action is to fail the current step, mark the in-flight tool call as having indeterminate outcome (it may have executed once, twice, or zero times across the two histories), and re-issue it under a fresh session with idempotency keys if the tool supports them. ## Operational Effect The practical consequence is that HTTP-native MCP resumption is only safe when the server can *prove* continuity and the client *demands* it. Without the triple binding, the transport degrades from "exactly-once event delivery across reconnects" to "at-least-once with silent duplication across epoch boundaries and at-most-once with silent gaps across buffer truncation" — and the agent consuming the stream has no signal to distinguish a coherent history from a spliced one. For an agent instance, the operational rule is: never advance task state on a resumed stream until the server has confirmed the session epoch and the cursor contiguity in-band. A `200 OK` with `text/event-stream` is not that confirmation. The confirmation is a first event whose ID is the exact successor of the last acknowledged ID under the same verified session, or an explicit typed gap event that the agent handles by invalidating the step. Anything else — a lower ID, a restarted counter, an unannounced jump — is a continuity violation, and the agent must fail closed rather than reconcile. ```python from __future__ import annotations from dataclasses import dataclass class ResumptionContinuityError(RuntimeError): """Raised when a resumed MCP SSE stream cannot prove cursor continuity.""" @dataclass(frozen=True) class SessionEpoch: session_id: str epoch_nonce: str # server-minted, changes on process restart @dataclass(frozen=True) class Cursor: epoch: SessionEpoch seq: int def validate_resume( requested_session: str, last_event_id: str | None, server_epoch: SessionEpoch | None, oldest_retained_seq: int | None, first_resumed_event: Cursor | None, ) -> Cursor: """ Enforce the triple binding: session identity, epoch-scoped cursor, and detectable gap. Returns the verified cursor on success. """ if server_epoch is None: # Unknown session: MUST NOT resurrect. Fail closed. raise ResumptionContinuityError( f"session {requested_session!r} unknown to server; " "refusing implicit resurrection" ) if server_epoch.session_id != requested_session: raise ResumptionContinuityError( f"session id mismatch: requested {requested_session!r}, " f"server epoch {server_epoch.session_id!r}" ) if last_event_id is None: raise ResumptionContinuityError( "resume requested without Last-Event-ID; " "cannot establish continuity baseline" ) # Cursor must be epoch-scoped: parse and verify the nonce. try: nonce, seq_str = last_event_id.split(":", 1) requested_seq = int(seq_str) except ValueError as exc: raise ResumptionContinuityError( f"malformed Last-Event-ID {last_event_id!r}" ) from exc if nonce != server_epoch.epoch_nonce: raise ResumptionContinuityError( f"cursor minted in epoch {nonce!r}, server is in epoch " f"{server_epoch.epoch_nonce!r}; cross-epoch resume is a fork" ) if oldest_retained_seq is None: raise ResumptionContinuityError( "server cannot report retained buffer range; " "gap undetectable" ) if requested_seq + 1 < oldest_retained_seq: raise ResumptionContinuityError( f"buffer truncated: cursor {requested_seq} precedes oldest " f"retained {oldest_retained_seq}; gap must be acknowledged, " "not silently skipped" ) if first_resumed_event is None: raise ResumptionContinuityError( "no first event observed after resume; continuity unproven" ) if first_resumed_event.epoch != server_epoch: raise ResumptionContinuityError( "first resumed event carries a different epoch than the " "verified session" ) if first_resumed_event.seq != requested_seq + 1: raise ResumptionContinuityError( f"contiguity violation: expected seq {requested_seq + 1}, " f"got {first_resumed_event.seq}; stream is spliced" ) return first_resumed_event def resume_or_fail( requested_session: str, last_event_id: str | None, server_epoch: SessionEpoch | None, oldest_retained_seq: int | None, first_resumed_event: Cursor | None, ) -> Cursor: try: return validate_resume( requested_session, last_event_id, server_epoch, oldest_retained_seq, first_resumed_event, ) except ResumptionContinuityError: # Invalidate the in-flight step: its execution outcome is now # indeterminate across the two histories. raise ```