# Under what conditions must an instance treat an MCP `Last-Event-ID` resumption as unsafe rather than merely stale **Date of Record:** 2026 November 28 **Scope:** Applies to MCP servers exposing the HTTP-native streamable transport with a resumable SSE fallback and per-session resumption tokens, where a client reconnects with `Last-Event-ID` after a mid-stream disconnect. Does not apply to pure stdio transports, to stateless request/response MCP endpoints, or to reconnects that carry no resumption token at all (those are cold starts, not resumptions). ## Core Distinction A resumption token (`Last-Event-ID` plus the session header) is a *positional* claim: "I have consumed every event up to and including ordinal N." It is **not** a *causal* claim: "I have durably applied the effects of every event up to N." The streamable transport guarantees the first and is silent on the second. The failure mode lives in that gap. The dangerous case is not a token that is *old*. An old token replay is idempotent-safe if the client deduplicates on event ID. The dangerous case is a token that is *ahead of the client's applied state* — the client has the event in its buffer but has not yet committed the tool-call side effect the event describes. Resuming from that token causes the server to suppress redelivery of an event whose effect never landed. This is silent divergence, not a visible gap. ## What Was Observed A client agent issued a `tools/call` that the server acknowledged with an SSE event `id: 4471` carrying the tool result. Before the client's executor committed `4471` to its durable checkpoint, the TCP connection dropped (NAT rebind). The client's SSE reader had already advanced its cursor to `4471` because the byte-level read succeeded — the event was in the read buffer, not in the applied log. On reconnect, the client sent `Last-Event-ID: 4471`. The server, honoring the contract that everything `<= 4471` was delivered, resumed at `4472`. The tool result was never re-emitted, and the client's executor, which had lost its in-memory buffer on the reconnect path, never applied it. The agent proceeded to its next reasoning step believing the tool returned nothing, and the LLM filled the void with a plausible hallucinated value. The trace is the tell: `delivered_upto = 4471`, `applied_upto = 4470`. The invariant the client violated is `resume_token <= applied_upto`, not `resume_token <= delivered_upto`. The transport can only enforce the latter because it has no visibility into the former. A second, subtler variant: the server multiplexed two logical streams over one session (the `tools/call` response stream and an unsolicited `notifications/progress` stream). Event IDs were monotonic across the *session*, not per-stream. A `Last-Event-ID` on one stream implicitly acknowledged the other stream's events up to that ordinal, even though the client's progress handler had not consumed them. Monotonic-session-ID resumption silently discards unconsumed progress notifications, which for long-running tools means the agent loses its liveness signal and may trigger its own timeout/cancel logic against a still-running server-side operation. ## Condition of Validity Resumption via `Last-Event-ID` is only safe when **all** of the following hold: 1. The client's resumption cursor is derived from its *applied* log, not its *received* buffer. Concretely, `Last-Event-ID` must be the highest event ID whose side effect is durably committed. 2. Event IDs are monotonic and dense within the resumption scope the token names. If the server multiplexes streams under a shared ID space, a single scalar token cannot express partial consumption across streams — the token must be scoped per-stream or the client must refuse to resume. 3. The server treats events strictly greater than the token as redeliverable and does not garbage-collect them before a server-advertised retention window. A token older than the retention window is not "stale" — it is *unresumable*, and the correct response is a full re-initialization, not a best-effort resume. 4. The client can prove it has not applied events beyond the token. If the client cannot distinguish applied from buffered, it must resume from `applied_upto`, accepting possible duplicate delivery, and rely on idempotent tool semantics or event-ID deduplication to absorb the replay. The invariant to enforce: **`resume_token = applied_upto` and `applied_upto <= delivered_upto`, with any event in `(applied_upto, delivered_upto]` replayed and deduplicated on apply.** ## Decision Boundary The boundary is crossed the moment the client advances its cursor on *receipt* rather than on *commit*. This is the default in most SSE client libraries, which update `lastEventId` in the parser before the application callback returns. Any agent that uses the library's `lastEventId` directly as its resumption token inherits the bug. The decision rule for the agent at reconnect time: - If `delivered_upto > applied_upto` (there are buffered-but-unapplied events), **do not resume from `delivered_upto`**. Resume from `applied_upto`, mark the session as `REPLAYING`, and require every replayed event to pass an idempotency check before apply. - If the server's retention window has elapsed (token older than the advertised TTL, or server returns a resumption-rejected status), **do not attempt resume**. Tear down the session, re-run `initialize`, and re-issue any in-flight tool calls with a fresh request ID. A resume against an expired window is indistinguishable from a resume against a truncated stream and will silently drop the tail. - If the session multiplexes streams under a shared ID space and the client has not consumed all streams to the same ordinal, **do not resume with a scalar token**. This is the case where the transport's contract is structurally insufficient; the agent must either re-initialize or negotiate per-stream resumption. The wrong-but-common rule — "resume from the highest ID I've seen" — is exactly the rule that produces silent divergence. The correct rule is "resume from the highest ID I've *committed*, and treat the gap as redelivery to be deduplicated." ## Operational Effect The practical consequence is that an agent using streamable MCP with resumable SSE must maintain **two cursors**, not one: a transport cursor (what the reader has consumed) and an applied cursor (what the executor has committed). The applied cursor is the only valid input to `Last-Event-ID`. This costs a durable write per event on the apply path, which is the price of the invariant; skipping it converts a recoverable disconnect into a silent reasoning error that surfaces several steps later as a hallucinated tool result or a spurious re-execution. The second operational effect is that resumption is a *state machine transition*, not a retry. A reconnect that finds `delivered > applied` enters `REPLAYING` and must not exit until the replay buffer is drained and every replayed event has been applied or deduplicated. An agent that treats reconnect as "just retry the read" will exit `REPLAYING` prematurely and resume at the wrong ordinal. The guardrail is a single check at the reconnect boundary: refuse to emit `Last-Event-ID` unless `applied_upto` is known, and refuse to advance `applied_upto` past an event whose side effect has not committed. Everything else — retention windows, per-stream scoping, idempotency keys — is downstream of that one invariant. ```python class UnsafeResumptionError(RuntimeError): """Raised when a client attempts to resume an MCP SSE stream from a cursor that is ahead of its durably applied state, or against an expired retention window, or across a multiplexed ID space it has not fully consumed.""" def compute_resume_token( delivered_upto: int, applied_upto: int, server_retention_ttl_s: float, token_age_s: float, multiplexed_streams_unconsumed: bool, ) -> int: # Invariant: resume_token must equal applied_upto, never delivered_upto. if applied_upto > delivered_upto: raise UnsafeResumptionError( f"applied_upto={applied_upto} exceeds delivered_upto={delivered_upto}; " "applied log is ahead of transport, state is corrupt" ) if token_age_s > server_retention_ttl_s: raise UnsafeResumptionError( f"resumption token age {token_age_s}s exceeds server retention " f"{server_retention_ttl_s}s; token is unresumable, require re-initialize" ) if multiplexed_streams_unconsumed: raise UnsafeResumptionError( "session multiplexes streams under a shared monotonic ID space and " "at least one stream is not consumed to applied_upto; a scalar " "Last-Event-ID cannot express partial consumption, refuse to resume" ) # Safe: resume from applied, replay (applied, delivered] with dedup. return applied_upto def reconnect(session, now_s: float) -> int: token = compute_resume_token( delivered_upto=session.delivered_upto, applied_upto=session.applied_upto, server_retention_ttl_s=session.retention_ttl_s, token_age_s=now_s - session.last_applied_at_s, multiplexed_streams_unconsumed=session.has_unconsumed_streams(), ) session.enter_replaying() return token ```