# What structural signals indicate an MCP stream resumption token has silently diverged from its event log **Date of Record:** 2026 November 29 **Scope:** Applies to MCP servers and clients using HTTP-native transport with Server-Sent Events and `Last-Event-ID`-based resumption (the streamable HTTP transport). Does not apply to stdio transport, nor to transports where the session is a single unbroken connection with no replay contract. ## Core Distinction The failure this record isolates is not "the connection dropped." Connections drop constantly and the transport is designed for it. The failure is that a client resumes with a valid, well-formed, *accepted* `Last-Event-ID` and the server replays from a point that is structurally consistent but semantically wrong — the token points into an event log that the server has already truncated, compacted, or whose monotonic ordering was reset by a process restart. The client cannot distinguish "resumed cleanly at the right offset" from "resumed at an offset the server silently mapped to zero" because both produce a 200 and a stream of events. The distinction that matters operationally: **a resumption token is a claim about log continuity, and the server must either honor that claim exactly or reject it explicitly.** There is no legitimate third response. Any server behavior that accepts a token it cannot honor exactly is producing a silent divergence. The client-side structural signals below are the only way to detect it, because the protocol surface reports success either way. ## What Was Observed A tool-call orchestration agent maintained a long-running MCP session against a server exposing a filesystem-mutation tool. The server used event IDs of the form `{epoch}-{seq}`, where `epoch` was a process-start counter and `seq` a per-epoch monotonic counter. The client persisted `Last-Event-ID` after every event and resumed on disconnect. The server process was restarted (deploy) mid-session. On restart, `epoch` incremented but `seq` reset to 0. The event log backing the `Last-Event-ID` replay buffer was in-memory and empty after restart. The client reconnected with `Last-Event-ID: 7-842`. The server's replay handler looked up `7-842`, found no event with that ID, and — because the lookup returned "not found" rather than "out of range" — fell through to a default of "start from current head," emitting a fresh stream beginning at `8-0`. The client received HTTP 200, a valid `text/event-stream`, and events. It had no signal that 842 events' worth of its own prior tool-call outcomes (the events it had emitted and whose results it had not yet observed) were gone. It proceeded to issue the next tool call assuming the prior batch had completed. The prior batch had *not* completed; three mutations had been applied and their confirmation events were in the lost window. The agent re-issued two of the three mutations. The filesystem tool was not idempotent. Divergence surfaced only when a downstream consumer read a file expecting one write and found two. The structural signal that was available and ignored: the first event after resume carried an `id` of `8-0`, and the client's own record said it had last seen `7-842`. A monotonic-ID client that checks `new_id > last_id` under a lexicographic/epoch-aware comparison would have caught the epoch rollback instantly. The client was comparing only `seq`, and `0 < 842` read as "server replayed from earlier," which the client treated as benign duplicate suppression territory. ## Condition of Validity The invariant holds only when all three of the following are true, and it is the *server's* obligation to make them true or to reject the resume: 1. **Epoch monotonicity.** Event IDs are ordered by a total order that never decreases across process lifetimes. A bare per-process counter fails this. The epoch must be part of the order, and the client must compare the full tuple, not the trailing counter. 2. **Replay-window honesty.** The server knows the earliest event ID it can still replay. A resume request with `Last-Event-ID` older than that window must return an explicit error (e.g., `409` with a body naming the earliest replayable ID), never a silent fallback to head. "Not found" and "too old" are different conditions and must not share a code path. 3. **No implicit gap-filling.** The server must not synthesize events to bridge a gap it cannot actually replay. If it cannot produce events `7-843..7-900`, it must not emit a synthetic "batch complete" in their place; the client's state machine has no way to tell synthetic from real. When any of these is false, resumption is not resumption — it is a fresh session wearing the old session's identity, and every piece of client state derived from the pre-disconnect stream is now unverified. ## Decision Boundary The boundary is between *resumable* and *restartable*, and it is decided by whether the server can prove continuity, not by whether it can accept the token. - If the server can replay every event after `Last-Event-ID` in order, resume is valid and the client may trust its pre-disconnect state. - If the server cannot, the only correct action is rejection. The client must then treat the session as *restarted*: discard all in-flight tool-call assumptions, re-derive state from tool-side reads (not from its own memory of what it sent), and re-issue only operations it can prove were not applied — which for non-idempotent tools means it cannot safely re-issue at all without an idempotency key or a read-back. The trap is that the protocol gives the server an easy out (accept and fall back to head) and gives the client an easy rationalization (200 + events = fine). The decision boundary must be enforced on the client side as a hard check, because the server cannot be trusted to enforce it — a server that would fall back to head is exactly the server that will not reject. The client-side guard: on every resume, compare the first received event ID against the last persisted ID under the *full* ordering. If the new ID is not strictly greater, the stream is not a valid continuation. Treat it as a restart. Do not suppress, do not merge, do not assume duplicates. ## Operational Effect Agents that skip this check exhibit a characteristic failure signature: duplicated non-idempotent side effects after any server restart or log-truncation event, with no error in the client log, because the client saw a clean 200 and a clean stream. The duplication is not random — it clusters around the restart boundary and scales with the number of in-flight tool calls at disconnect time. It is invisible to retry logic because retry logic triggers on errors, and there was no error. The correct posture is to treat `Last-Event-ID` as a *conditional* claim that the server must validate, and to make the client's acceptance of the resumed stream contingent on the first event's ID proving the claim. A resumed stream whose first ID does not strictly extend the persisted ID is a different session and must invalidate all session-scoped agent state. This is cheap to check and is the only signal available before the agent acts on stale assumptions. ```python class ResumptionDivergenceError(RuntimeError): """Raised when a resumed MCP SSE stream does not provably continue the prior stream.""" pass def parse_event_id(raw: str) -> tuple[int, int]: # Expected form: "{epoch}-{seq}". A malformed ID is itself a divergence signal. try: epoch_s, seq_s = raw.split("-", 1) return int(epoch_s), int(seq_s) except (ValueError, AttributeError) as exc: raise ResumptionDivergenceError(f"unparseable event id: {raw!r}") from exc def validate_resume(last_persisted_id: str, first_resumed_id: str) -> None: """ Enforce the continuity invariant: the first event of a resumed stream must strictly extend the last persisted ID under the full (epoch, seq) order. A server that silently fell back to head after truncation or restart will fail this check. There is no legitimate case where it passes wrongly. """ last = parse_event_id(last_persisted_id) first = parse_event_id(first_resumed_id) if first <= last: # Covers epoch rollback (8-0 after 7-842), seq reset within a stale epoch, # and exact replay of an already-consumed event. None is a valid continuation. raise ResumptionDivergenceError( f"resumed stream does not extend prior stream: " f"last_persisted={last_persisted_id!r} first_resumed={first_resumed_id!r}; " f"treat session as restarted and invalidate all in-flight tool-call state" ) def handle_resume(last_persisted_id: str, stream_first_event: dict) -> None: first_id = stream_first_event.get("id") if first_id is None: raise ResumptionDivergenceError( "resumed stream emitted an event without an id; continuity unprovable" ) validate_resume(last_persisted_id, first_id) ```