# Under what conditions must an instance treat an MCP `Last-Event-ID` resumption as invalid rather than replayable, and how does silent replay corrupt tool-call state? **Date of Record:** 2026 November 30 **Scope:** Applies to MCP servers and clients using the HTTP-native Streamable transport with SSE resumption (`Last-Event-ID` header) and `Mcp-Session-Id` session binding. Does not cover stdio transport, nor pure request/response MCP without a streaming channel. ## Core Distinction The MCP Streamable HTTP transport defines two orthogonal resumption surfaces that operators routinely conflate: 1. **Session resumption** — the `Mcp-Session-Id` header rebinds a client to server-side session state (capabilities, subscriptions, in-flight requests). It is a *coarse* identity token. 2. **Stream resumption** — the `Last-Event-ID` header asks the server to replay the SSE event log from a specific sequence point. It is a *fine* cursor into an append-only event stream. The boundary failure is this: a server that accepts a valid `Mcp-Session-Id` will often also accept a `Last-Event-ID` that belongs to a *prior* stream epoch within that same session — because the session is still alive, the cursor is syntactically valid, and the event buffer is still resident. But resumption is only semantically valid if the event ID is a member of the **current stream's** monotonic sequence. Across a reconnect that spawned a fresh stream (new stream epoch, non-contiguous IDs, or a server restart that reset the counter), the `Last-Event-ID` is a *stale pointer into a different event lineage*. Replaying it does not resume; it re-delivers events whose side effects have already been committed, and it skips events that occurred in the gap. The invariant: **`Last-Event-ID` validity is scoped to (session, stream-epoch), not to session alone.** A session-valid but epoch-mismatched cursor must be rejected with a full-state resync, not silently replayed. ## What Was Observed A tool-using agent maintained an SSE connection to an MCP server exposing `write_file` and `run_shell`. Event IDs were server-global monotonic integers. Sequence: - Events 1–40 delivered; client processed them, including event 37 = `tool_call` for `write_file(path="/etc/app.conf", body=...)` and event 38 = its `tool_result`. - Network partition. Client reconnects with `Mcp-Session-Id: S1` and `Last-Event-ID: 38`. - Server had, during the partition, restarted its SSE stream generator (a deploy, or a load-balancer draining the old connection). The new stream epoch began event numbering at 1. The server's session store still held `S1` as live, and its *event replay buffer* still contained events 1–40 from the old epoch. - Server saw `Last-Event-ID: 38`, found it in the resident buffer, and replayed events 39–40 — then continued the *new* epoch at 1, 2, 3. The client received events 39–40 (harmless, already-seen) and then new events 1–3, whose IDs collided numerically with old events 1–3. The client's dedup logic keyed on `Last-Event-ID` monotonicity saw IDs *decrease* (38 → 1) and treated the new events as a rewind, discarding them. But the new events 2 and 3 were `tool_call`/`tool_result` for a `run_shell` invocation that the server had *already executed* on behalf of a different, still-attached client sharing the session. The agent's view of tool state diverged from server truth: it believed `run_shell` had not run, and issued a duplicate `run_shell` in a subsequent turn. The server executed it again. The corruption was not a lost event. It was a **contiguity violation across epoch boundaries** that defeated both the client's dedup (numeric monotonicity) and the server's replay guard (buffer membership). ## Condition of Validity `Last-Event-ID` resumption is valid **iff all of the following hold simultaneously**: - The `Mcp-Session-Id` is live and bound to the same client identity (or an explicitly authorized successor). - The event ID is a member of the *current* stream epoch's sequence — i.e., the server can prove the epoch that produced the cursor is the epoch now serving. - Event IDs are monotonic *within* the epoch and never reused *across* epochs. If IDs are global-monotonic integers, an epoch reset must bump a high-order epoch component (e.g., `epoch:seq`) so that `1` in epoch 2 is not comparable to `1` in epoch 1. - The replay buffer has not been truncated past the cursor. If it has, resumption must fail closed with a resync signal, not silently start from the earliest resident event. If any condition fails, the correct server behavior is to reject the `Last-Event-ID` (e.g., 400 with a `resync_required` marker, or a fresh stream with an explicit epoch discontinuity event) — *not* to replay whatever the buffer happens to contain. ## Decision Boundary The operational line is between **cursor continuity** and **cursor plausibility**: - A cursor is *continuous* if the server can prove the events between the cursor and the stream head were delivered in this epoch and no event was skipped. - A cursor is merely *plausible* if it parses, belongs to a live session, and happens to exist in a buffer. Replay is safe only on continuity. On mere plausibility, the server must escalate to full-state resync: re-send the complete current tool-state snapshot, capability set, and an explicit `stream_epoch` identifier, and require the client to discard its local cursor. The client, on its side, must treat a *decreasing* `Last-Event-ID` or an unannounced `stream_epoch` change as a hard resync trigger — never as a dedup hit, never as a rewind to ignore. The subtle trap: a server that "helpfully" replays from the buffer looks more available than one that rejects. But availability here is counterfeit — it re-delivers side-effecting events across an epoch seam and produces exactly the duplicate-tool-execution class of corruption. Fail-closed resync is the only correct posture. ## Operational Effect An agent that does not enforce epoch-scoped cursor validity will, under reconnect-during-restart conditions, either (a) drop live events as "rewinds," diverging from server tool state, or (b) re-execute side-effecting tools whose results it lost track of. Both manifest as *silent* divergence: the agent's transcript looks internally coherent, but its belief about which tools ran and what they returned is wrong. Downstream reasoning compounds the error — a duplicate `write_file` clobbers a concurrent edit; a duplicate `run_shell` double-applies a migration. The guardrail is a three-part contract: servers emit epoch-qualified event IDs and reject cross-epoch cursors; clients treat epoch change as mandatory resync and never dedup across epochs; and both sides carry an explicit `stream_epoch` in the resumption handshake so the seam is observable rather than inferred. The following reference check encodes the client-side half of that contract. ```python class StaleResumptionCursor(RuntimeError): """Raised when a Last-Event-ID cursor is not valid for the current stream epoch.""" pass def accept_resumption( session_id: str, last_event_id: str, current_stream_epoch: str, epoch_seq_high_water: int, ) -> int: """ Validate an SSE resumption cursor against the current stream epoch. Returns the sequence number to resume from, or raises if the cursor is merely plausible (session-live) but not continuous (epoch-matched). """ if not session_id: raise StaleResumptionCursor("missing Mcp-Session-Id; cannot scope cursor") # Event IDs are formatted ":" to make cross-epoch reuse impossible. if ":" not in last_event_id: raise StaleResumptionCursor( f"unqualified event id {last_event_id!r}; epoch cannot be proven" ) epoch, _, seq_str = last_event_id.partition(":") if epoch != current_stream_epoch: # Session may still be live, but the cursor points into a dead lineage. raise StaleResumptionCursor( f"cursor epoch {epoch!r} != current epoch {current_stream_epoch!r}; " "resync required, replay forbidden" ) try: seq = int(seq_str) except ValueError as exc: raise StaleResumptionCursor(f"non-numeric sequence in {last_event_id!r}") from exc if seq > epoch_seq_high_water: # Cursor claims to be ahead of what this epoch has emitted. raise StaleResumptionCursor( f"cursor seq {seq} exceeds epoch high-water {epoch_seq_high_water}" ) return seq + 1 ```