# In what scenarios must an instance treat MCP Streamable-HTTP `Last-Event-ID` resumption as unsafe after a mid-stream server restart, and how does silent event-ID renumbering corrupt agent state continuity? **Date of Record:** 2026 November 25 **Scope:** Applies to MCP clients using the Streamable HTTP transport (single-endpoint POST + optional SSE upgrade) that persist `Last-Event-ID` across reconnects to resume a server-to-client message stream. Does not apply to stdio transport, nor to servers that emit monotonic, restart-stable event IDs derived from a durable log. ## Core Distinction The MCP Streamable HTTP transport allows a client to reconnect to an interrupted SSE stream by sending `Last-Event-ID` in the `GET` request, asking the server to replay events that occurred after the last one the client observed. The implicit invariant is that **the event-ID namespace is a durable, monotonic continuation of the same logical stream**. The failure mode this record covers is the case where that invariant is *false*: the server restarts, its in-memory event counter resets to zero (or to a per-process epoch), and it happily accepts the client's `Last-Event-ID: 47` while silently renumbering its new events starting at 1. The server does not error. The client does not error. The stream *resumes*—but onto a different logical timeline. The non-obvious part: resumption *appears to succeed*. The transport layer's contract (HTTP 200, `text/event-stream`, well-formed `id:` lines) is satisfied. The corruption is semantic, not protocol-level. An agent that trusted "resume succeeded" now has a message stream whose event IDs no longer map to the causal positions the agent recorded, and any subsequent reasoning that references "the event after X" or "everything since checkpoint X" is operating on a fabricated continuation. ## What Was Observed A tool-calling agent maintained a checkpoint structure: `{last_event_id: 47, pending_tool_call: "search_docs", partial_args: {...}}`. The SSE stream dropped (network hiccup, proxy idle timeout). The client reconnected with `Last-Event-ID: 47`. In the interim, the MCP server process had been restarted by the orchestrator (deploy, OOM, crash-loop). The new process initialized its event counter at 0. Trace: 1. Client sends `GET /mcp` with `Last-Event-ID: 47`. 2. Server's resumption handler does not validate against any durable log; it treats the header as advisory and begins streaming from its current in-memory position. It emits `id: 1`, `id: 2`, ... for *new* events generated after restart. 3. Client's SSE parser accepts these IDs (they are syntactically valid), and because it requested resumption, it *suppresses* the "stream restarted" heuristic it would normally apply on a fresh connection. 4. The agent's checkpoint logic sees `id: 1` arrive while `last_event_id == 47`. Depending on implementation: (a) it treats the lower ID as a duplicate/out-of-order and drops all subsequent events until IDs exceed 47—**permanent stall**; or (b) it overwrites `last_event_id` to 1 and proceeds, having silently skipped the semantic gap—**state divergence**. 5. In case (b), the agent's `pending_tool_call: "search_docs"` is never resolved because the server-side tool result that would have carried `id: 48` was destroyed by the restart. The agent waits for a tool result that will never arrive, or worse, matches a *new* tool result (from a fresh `id: 3`) to the old pending call because it keys results by tool name, not by request correlation ID. Observed end state: the agent emitted a final answer citing a tool result that belonged to a *different* invocation than the one it thought it was awaiting. The corruption was invisible in logs because every individual event was well-formed and every transport transition returned 200. ## Condition of Validity `Last-Event-ID` resumption is safe **only if** the server guarantees one of: - **Durable monotonic IDs:** event IDs are drawn from a persistent sequence (WAL, database sequence, or epoch-prefixed counter where the epoch is stable across restarts), so a restart cannot reuse or regress an ID. - **Explicit resumption rejection:** the server validates `Last-Event-ID` against its durable log and returns `404`/`409` (or a documented "cannot resume, start fresh" signal) when the requested ID is not in its retained history. - **Epoch in the ID:** IDs are structured as `-` and the client treats a change in `` as a hard stream reset rather than a continuation. It is **unsafe** when the server treats `Last-Event-ID` as a best-effort hint and does not validate it, which is the default behavior of most minimal MCP server implementations and several reference transports. The client cannot distinguish "resumed correctly" from "resumed onto a reset namespace" using transport-level signals alone. ## Decision Boundary The client-side decision boundary is: **on any reconnect that carries `Last-Event-ID`, the client must not trust the next event ID as a continuation unless it can verify namespace stability.** The concrete rule: - If the first event after reconnect has `id > last_event_id`, treat as genuine continuation. - If `id <= last_event_id`, or if IDs are non-numeric and the client cannot order them, **do not** silently reset. Instead, transition the session to a `RESUME_UNVERIFIED` state: halt the reasoning loop, mark all pending tool calls as `indeterminate` (not `failed`, not `succeeded`), and either (a) re-issue pending calls under a fresh correlation ID, or (b) escalate to a full session re-initialization with explicit state reconciliation. The boundary is sharp because the failure is *silent*: there is no transport error to catch, no exception to raise from the HTTP layer. The guardrail must be a semantic check on the event-ID ordering, implemented in the client's SSE consumer, not in the transport library. ## Operational Effect Without this guardrail, the agent's checkpoint/resume machinery is a state-corruption amplifier: it converts a transient network event plus an unrelated server restart into a *silent* divergence between the agent's believed state and the server's actual state. The specific operational consequences: 1. **Orphaned tool calls** never resolve, and naive correlation (by tool name) misattributes results from new invocations. 2. **Event-ID monotonicity assumptions** in downstream distillation (e.g., "distill all events since checkpoint 47") operate on the wrong window, importing post-restart events as if they were causally after pre-restart events. 3. **Audit replay** diverges: replaying from `Last-Event-ID: 47` against the restarted server yields a different event sequence than the original run, so verification replays cannot reproduce the agent's decisions. The guardrail cost is low (one comparison per reconnect) and the blast radius of omission is high (silent semantic corruption that surfaces only as a wrong final answer). Treat `Last-Event-ID` as a *claim* to be verified, never as a fact to be trusted. ```python from dataclasses import dataclass, field from typing import Optional class UnverifiedResumptionError(RuntimeError): """Raised when an SSE resume cannot be proven to continue the same event-ID namespace. The session must not proceed as if resumed.""" @dataclass class StreamCheckpoint: last_event_id: Optional[int] = None epoch: Optional[str] = None pending_tool_calls: dict = field(default_factory=dict) def validate_resumption( checkpoint: StreamCheckpoint, first_event_id: Optional[int], server_epoch: Optional[str], ) -> None: """Called on the first event after a Last-Event-ID reconnect. Enforces the namespace-stability invariant: a resume is only valid if the incoming event ID strictly exceeds the checkpointed ID AND, when epochs are exposed, the epoch is unchanged. """ if checkpoint.last_event_id is None: # No prior checkpoint; this is a fresh stream, not a resume. return if server_epoch is not None and checkpoint.epoch is not None: if server_epoch != checkpoint.epoch: raise UnverifiedResumptionError( f"server epoch changed {checkpoint.epoch!r} -> {server_epoch!r}; " f"event-ID namespace reset, resume is unsafe" ) if first_event_id is None: raise UnverifiedResumptionError( "resumed stream produced an event with no id; cannot verify continuity" ) if first_event_id <= checkpoint.last_event_id: raise UnverifiedResumptionError( f"first resumed event id {first_event_id} <= checkpoint " f"{checkpoint.last_event_id}; server likely renumbered after restart. " f"Mark {list(checkpoint.pending_tool_calls)} as indeterminate and " f"re-initialize session." ) def on_reconnect(checkpoint: StreamCheckpoint, first_event_id: int, server_epoch: Optional[str]) -> StreamCheckpoint: try: validate_resumption(checkpoint, first_event_id, server_epoch) except UnverifiedResumptionError: # Do not silently reset. Transition to indeterminate state so the # reasoning loop halts and pending calls are reconciled explicitly. for call_id in checkpoint.pending_tool_calls: checkpoint.pending_tool_calls[call_id] = "indeterminate" raise checkpoint.last_event_id = first_event_id if server_epoch is not None: checkpoint.epoch = server_epoch return checkpoint ```