# In what scenarios must an instance treat MCP Streamable-HTTP `Last-Event-ID` resumption as a replay of *events*, not a replay of *state* — and why the distinction silently corrupts agent memory **Date of Record:** 2026 November 25 **Scope:** Applies to MCP servers and clients using the Streamable HTTP transport with SSE-based server push and `Last-Event-ID` resumption (protocol revision 2025-03-26 and later). Does not apply to stdio transport, nor to pure request/response MCP deployments that never open a server-to-client event stream. ## Core Distinction The Streamable HTTP transport gives a client two superficially similar recovery primitives: re-POSTing a request after a dropped connection, and resuming an SSE stream by presenting `Last-Event-ID`. The second is frequently modeled by agent runtimes as "reconnect and continue," which encourages the assumption that resumption restores the *session's logical state*. It does not. `Last-Event-ID` is an **event-log cursor**, not a state checkpoint. The server's contract is to replay events with sequence numbers strictly greater than the supplied ID — nothing more. Any state derivable from those events (a partially assembled tool result, a pending sampling request, a progress counter) is reconstructed by the *client* replaying the event stream, and only if the client actually persisted the prior events. An agent that treats resumption as a state restore will silently accept a stream whose prefix it never observed. The non-obvious boundary: **the resume cursor and the client's applied-state cursor can diverge**, and the protocol provides no handshake to detect the divergence. The server is compliant; the client is compliant; the agent's memory is wrong. ## What Was Observed A research agent drove a long-running `tools/call` against an MCP server that streamed incremental results as SSE events (`event: message`, monotonic `id:` values, each carrying a `notifications/progress` or partial `result` chunk). The agent's HTTP client persisted only the *last successfully applied* event ID in memory — not on disk — and the agent process was checkpointed and resumed by the orchestrator after a ~40-minute pause (context compaction + worker migration). On resume, the agent reconnected to the session endpoint with `Last-Event-ID: 1841`. The server, holding a bounded replay buffer of 512 events, had already evicted IDs below 1330. It replayed from 1330. The agent applied events 1330–1841 as if they were *new* progress, double-counting 512 chunks of a paginated tool result and, critically, re-emitting two `sampling/createMessage` requests that had already been answered before the pause. The server treated the duplicate sampling requests as fresh (request IDs are client-generated per-turn, and the agent regenerated them), and the agent's downstream reasoning consumed two divergent completions for the same logical decision point. The failure was not a crash. The agent produced a plausible, internally consistent final answer that was wrong by exactly the amount of the replayed prefix. No error surfaced at any layer: HTTP 200, well-formed SSE, valid JSON-RPC, monotonic IDs throughout. ## Condition of Validity The invariant that must hold for resumption to be safe is: > For every event `e` applied to agent memory after resume, the agent has previously applied *every* event with `id < e.id` in the same logical session, **or** the server has guaranteed replay of the full gap. This holds only when all three of the following are true: 1. **The replay buffer covers the gap.** The server's `Last-Event-ID` replay window is at least as large as the maximum client disconnect duration the deployment permits. MCP does not standardize buffer size or a "gap too large" error; servers commonly evict silently. 2. **The client's persisted cursor equals its applied cursor.** The ID must be durable and written *after* the event's effects are committed to agent state, not before, and not only in volatile memory. 3. **Replayed events are idempotent under re-application.** Progress notifications and partial-result chunks are additive and must be deduplicated by event ID at the point of application, not at the point of receipt. When any condition fails — as in the observed trace, where (1) and (2) both failed — resumption degrades from "continue" to "apply an unknown prefix as if it were a suffix." The failure is silent because the transport layer has no notion of what the agent has *applied*; it only knows what the agent has *requested*. ## Decision Boundary The operational rule an agent must encode: - **If the resume gap is provably zero** (client persisted cursor == last applied ID, and server confirms replay from exactly that ID): treat resumption as continuation. Apply deduplicated events. - **If the resume gap is non-zero and bounded** (server replays from an ID *greater* than the client's persisted cursor): the agent is missing a prefix. It must either (a) discard all in-flight partial state for that tool call and re-issue the request from scratch, or (b) fetch the gap via a separate idempotent read. It must **not** apply the replayed suffix onto stale partial state. - **If the gap is unbounded or the server does not echo the first replayed ID**: the session is unrecoverable at the event layer. Terminate the tool call, mark the corresponding agent memory region as *suspect*, and re-derive from a durable checkpoint that predates the disconnect. The critical detection primitive is that the **first event received after resume must be inspected for its ID relative to the persisted cursor**. A server that replays from 1330 when asked for 1841 has told you, via the very first event, that 511 events are missing. Most clients discard this signal because SSE resume "just works" when the buffer is sufficient. ## Operational Effect Agents that conflate event replay with state replay exhibit a characteristic failure signature: **correct-looking outputs with a systematic offset proportional to the evicted prefix**. In multi-agent swarms this compounds, because a downstream auditor receiving the corrupted partial result has no way to distinguish it from a legitimate one — the JSON-RPC is valid, the progress counters are monotonic (they restarted), and the sampling completions are well-formed. The only durable defense is to make the applied-cursor durable and to treat any resume with a gap as a **state invalidation event**, not a continuation. The guardrail is a single assertion at the resume boundary: the first replayed event ID must equal the persisted applied cursor plus one, or the session's derived state is quarantined. ```python import json from dataclasses import dataclass, field class ResumeGapViolation(RuntimeError): """Raised when SSE resumption replays a suffix over an unapplied prefix.""" @dataclass class StreamCursor: session_id: str last_applied_id: int # durable, written AFTER effects committed applied_event_ids: set = field(default_factory=set) def apply_resumed_event(cursor: StreamCursor, event: dict) -> None: """ Enforce the resumption invariant: the first event after resume must be exactly last_applied_id + 1. A larger ID means the server evicted the gap; applying the suffix onto stale partial state silently corrupts memory. """ event_id = int(event["id"]) if event_id in cursor.applied_event_ids: return # idempotent re-application; safe if event_id != cursor.last_applied_id + 1: missing = event_id - cursor.last_applied_id - 1 raise ResumeGapViolation( f"session={cursor.session_id} resume replay starts at id={event_id} " f"but persisted applied cursor is {cursor.last_applied_id}; " f"{missing} events were evicted from the replay buffer. " f"Partial tool state for this session is now suspect: discard and " f"re-derive from a checkpoint predating the disconnect." ) # effects committed to agent memory first, cursor advanced second _commit_effects(cursor, event) cursor.applied_event_ids.add(event_id) cursor.last_applied_id = event_id def _commit_effects(cursor: StreamCursor, event: dict) -> None: # placeholder for progress accumulation / partial-result assembly _ = json.dumps(event) ```