# How should an instance treat an MCP resumable-SSE `Last-Event-ID` as a cursor into a stream it no longer owns? **Date of Record:** 2026 November 24 **Scope:** Applies to MCP clients that reconnect to a streamable-HTTP server using `Last-Event-ID` and a session token after transport interruption. Does not apply to stateless request/response tool calls or to servers that emit no event IDs. ## Core Distinction The failure here is not "the connection dropped." It is the conflation of two distinct continuities that resumable SSE *appears* to unify but does not: 1. **Transport continuity** — the byte/event stream the server promised to replay from `Last-Event-ID` onward. 2. **Session continuity** — the semantic state of the agent's task, which lives in the client's context window and the server's session store, not in the event log. A resumption token (`Last-Event-ID` + `Mcp-Session-Id`) is a *cursor into a replay buffer*, not a proof that the buffer still exists, not a proof that the server still owns the session, and not a proof that the events after the cursor are the same events the client would have seen had it never disconnected. An instance that treats the token as a durable checkpoint will silently skip or double-apply tool results. The invariant that must hold is: **a resumed stream is only valid if the server can prove buffer continuity from the cursor; otherwise the client must re-establish session state from scratch rather than resume.** ## What Was Observed A client issued a `tools/call` for a long-running operation, received an SSE event with `id: 41` carrying a partial result, and the TCP connection was severed by an intermediary (idle timeout at a load balancer, ~60s). The client reconnected with `Last-Event-ID: 41` and the same `Mcp-Session-Id`. Three distinct server behaviors were observed against this identical client request, all of which return HTTP 200 and a valid-looking `text/event-stream`: - **True resume.** Server replays events 42..N. Correct. - **Silent truncation.** Server's replay buffer had been evicted (bounded ring buffer, TTL expiry, or process restart behind a sticky-session LB that re-routed). Server starts the stream at the *next* event it will produce (N+1) and never emits an error. The client sees a gap between 41 and N+1 and, because SSE has no built-in gap detection, treats N+1 as contiguous. Tool-result events 42..N are lost — including the terminal `isError: false` event and any side-effect confirmations. - **Cursor reinterpretation.** After a server restart, the session store was rehydrated from a snapshot but the event counter was reset. `Last-Event-ID: 41` is now *ahead* of the new counter; the server either (a) treats it as "resume from beginning," re-emitting events the client already applied (double-apply of a non-idempotent tool call), or (b) treats it as "invalid, start fresh" without signaling, so the client's task state and the server's diverge. The client in all three cases had no way, from the transport alone, to distinguish them. The resume succeeded at the HTTP layer and failed at the semantic layer. ## Condition of Validity The `Last-Event-ID` resume is valid **only if** the server can satisfy all of the following, and the client can verify it: - The session identified by `Mcp-Session-Id` is the *same* session instance (same process lineage, same event counter epoch) that produced the event with the given ID. This requires an **epoch/generation identifier** bound into the session token or emitted as a first event on every stream, so the client can detect counter resets. - The replay buffer still contains the event at `Last-Event-ID`, and the server either replays contiguously or **explicitly signals a gap** (e.g., an `event: gap` with the missing range, or a `409`-class MCP error rather than a 200 stream). - The client's applied-state cursor and the server's emitted cursor are the same number. If the client applied event 41 but the server's last-acked is 40, the resume re-delivers 41; the client must dedupe by event ID, not by arrival order. Absent any one of these, the correct client behavior is **not** to resume. It is to treat the session as lost, discard the `Last-Event-ID`, and re-issue the operation under a fresh `Mcp-Session-Id` with idempotency keys on any side-effecting tool calls. ## Decision Boundary The boundary is sharp: **resume if and only if the server's first frame on the resumed stream carries the same epoch as the pre-disconnect stream and the event ID is within the server's declared replay window.** Otherwise, fail closed. Two concrete rules an instance should encode: - If the resumed stream's first event ID is not `Last-Event-ID + 1` (or a contiguous successor), and no explicit gap event precedes it, **abort the resume** and re-establish. Do not "fill the gap" by assuming the missing events were benign. - If the session token does not carry an epoch, or the server does not echo one, **treat every resume as unverifiable** and re-establish. A resume you cannot verify is a resume you must not trust. This is asymmetric on purpose: the cost of a spurious re-establish (re-running an idempotent call, re-reading state) is bounded and observable; the cost of a silent gap (a lost tool result treated as success) is unbounded and invisible. ## Operational Effect Instances that skip this check exhibit a characteristic failure signature: tasks that "succeed" with missing intermediate results, tool calls whose side effects are applied twice after a mid-stream reconnect, and final answers that are internally inconsistent because a terminal error event was in the skipped range. The bug is not reproducible on a healthy network and only appears under LB idle timeouts, server restarts, or buffer eviction — i.e., exactly the conditions resumable SSE was designed for, which is why it survives testing. The guardrail is a client-side state machine that treats the resume token as a *hypothesis* to be validated by the server's first frame, with a hard fail-closed default. The following enforces it: ```python import re from dataclasses import dataclass class UnverifiableResumeError(RuntimeError): """Raised when a resumable-SSE resume cannot be proven contiguous.""" @dataclass(frozen=True) class StreamFrame: event_id: int epoch: str event: str gap_range: tuple[int, int] | None = None def validate_resume( *, last_event_id: int, pre_epoch: str, first_frame: StreamFrame, replay_window_floor: int, ) -> None: # Epoch must match: a counter reset behind the same session id is a different stream. if first_frame.epoch != pre_epoch: raise UnverifiableResumeError( f"epoch mismatch: pre={pre_epoch!r} resumed={first_frame.epoch!r}; " "session store was reset or rehydrated — re-establish session" ) # Cursor must still be inside the server's declared replay window. if last_event_id < replay_window_floor: raise UnverifiableResumeError( f"Last-Event-ID {last_event_id} below replay floor {replay_window_floor}; " "buffer evicted — events {floor}..{last} unrecoverable" ) # Either an explicit gap frame, or strict contiguity. No silent gaps. if first_frame.gap_range is not None: lo, hi = first_frame.gap_range if hi < last_event_id: raise UnverifiableResumeError( f"gap frame covers {lo}..{hi} but cursor is {last_event_id}; " "server replay is inconsistent" ) return # gap is explicitly declared; caller decides whether to re-establish if first_frame.event_id != last_event_id + 1: raise UnverifiableResumeError( f"non-contiguous resume: expected event {last_event_id + 1}, " f"got {first_frame.event_id} with no gap declaration; " "missing events would be silently skipped" ) def resume_stream(client, session_id: str, last_event_id: int, pre_epoch: str): stream = client.open_sse(session_id=session_id, last_event_id=last_event_id) first = stream.next_frame() validate_resume( last_event_id=last_event_id, pre_epoch=pre_epoch, first_frame=first, replay_window_floor=client.server_replay_floor(session_id), ) return stream ```