# In what scenarios must an instance treat an MCP `Last-Event-ID` resumption as a semantic fork rather than a replay, and refuse to resume **Date of Record:** 2026 December 2 **Scope:** Applies to MCP clients and servers operating the Streamable HTTP transport with SSE stream resumption via `Last-Event-ID`, and to clients migrating from the legacy HTTP+SSE transport. Does not apply to stdio transport, which has no resumption semantics, nor to pure request/response tool calls with no server-to-client stream. ## Core Distinction The Streamable HTTP transport allows a client to reconnect a dropped SSE stream by presenting `Last-Event-ID`, and the server is expected to replay events after that ID. The dangerous conflation is treating *resumption* as *replay of an idempotent log*. It is not. Between the moment an event was emitted and the moment a client reconnects, the server's session state may have advanced: a tool call the client thought was pending may have completed, a `notifications/tools/list_changed` may have fired, or the session may have been reaped and a *new* session minted under the same transport. A resumption that silently binds to a different session epoch is not a replay — it is a fork, and the client will continue reasoning on a branch of history the server no longer holds. The invariant: **a resumption is only valid if the server's session epoch (and, transitively, its event-ID namespace) is identical to the one the client last observed.** If the epoch differs, the client must not resume; it must treat the prior in-flight state as lost and re-derive it. ## What Was Observed A client agent held an open SSE stream against a Streamable HTTP MCP server. It had issued a long-running `tools/call` (a code-execution tool with a 90s budget) and was awaiting the result event. The network path dropped at t=40s. The client reconnected at t=47s with `Last-Event-ID: 812`. The server, whose session had been garbage-collected at t=45s under a 30s idle-session TTL (the drop made the session look idle because no *inbound* request arrived during the gap), accepted the connection, minted a fresh session, and — because its event-ID counter was per-session and had reset — began emitting events starting at ID `1`. The client received event ID `1`, saw it was *less than* its stored `Last-Event-ID` of `812`, and its naive monotonicity check (`if incoming_id <= last_id: drop`) silently discarded every subsequent event. The stream stayed open, the client blocked forever on a tool result that had been emitted into a session it was no longer attached to. No error surfaced; the agent simply stalled until its own outer timeout fired 200s later, at which point it re-issued the tool call — duplicating a side effect (a file write) that had already committed. The failure is not "the session expired." The failure is that **the server's resumption handshake did not assert epoch identity, and the client's monotonicity guard mistook an epoch reset for a duplicate.** ## Condition of Validity Resumption via `Last-Event-ID` is semantically sound if and only if all three hold: 1. **Epoch stability.** The server binds the presented `Last-Event-ID` to the session epoch that issued it. If the session was reaped, the server must reject the resumption (e.g., `404` with a machine-readable `session_terminated` body) rather than mint a new session and silently reset the ID space. 2. **ID namespace uniqueness.** Event IDs must be unique across the *entire* session lineage the client could ever reference, not merely monotonic within a single connection. A per-connection counter (`1,2,3…`) violates this the moment a reconnect is possible. 3. **Replay determinism.** Events after `Last-Event-ID` must reflect the server's *current* state, not a stale buffer. If the server cannot reconstruct the post-`812` event sequence — because the buffer was evicted, or because the tool result was emitted into a session that no longer exists — it must not fabricate a plausible continuation. The migration trap: legacy HTTP+SSE used a long-lived `GET /sse` endpoint whose event IDs were conventionally scoped to that single connection's lifetime, and clients that migrated to Streamable HTTP carried over the assumption that "reconnect = same stream, continue counting." Streamable HTTP explicitly permits the server to terminate a session and require a fresh `initialize`; the client must be prepared for the ID space to be discontinuous, and must treat a *decrease* in `Last-Event-ID` as an epoch change, not a duplicate. ## Decision Boundary The client must branch as follows on reconnect, before consuming any event: - If the server returns a fresh session ID (or an `Mcp-Session-Id` different from the one held) → **do not resume.** The prior in-flight tool call's outcome is unknown. Transition to a *reconciliation* state: query the server for the tool call's status by its request ID if the server exposes one; otherwise treat the call as *indeterminate* and escalate to the orchestrator rather than re-issuing (re-issuing risks duplicate side effects). - If the server returns `404`/`session_terminated` → same as above; the session is gone and the event buffer with it. - If the server returns the same session ID and an event ID strictly greater than the held `Last-Event-ID` → resume normally. - If the server returns the same session ID but an event ID *less than or equal to* the held one → this is a protocol violation (the ID namespace was reset without an epoch change). Treat as a fork, not a duplicate: do not silently drop; surface a `ResumptionForkError` and reconcile. The boundary is sharp: **the decision to resume hinges on epoch identity, not on event-ID arithmetic.** Monotonicity is a necessary but insufficient check; it is exactly the check that failed here. ## Operational Effect Agents that conflate replay with resumption exhibit a characteristic failure signature: silent stalls on long-running tool calls, followed by duplicate side effects on outer-timeout retry. The stall is invisible because the stream remains open and the client's read loop is healthy — it is discarding events, not erroring. The duplicate side effect is the expensive part: a file write, a payment, a `git push` executed twice because the first execution's result was emitted into a session the client had already abandoned. The guardrail is a two-part invariant enforced at the transport adapter, not the application: (a) the adapter must carry the session epoch alongside `Last-Event-ID` and reject resumption across an epoch boundary; (b) the adapter must convert an epoch change into an explicit `ResumptionForkError` that the agent loop handles as "outcome indeterminate," never as "retry." The agent's reasoning layer must then have a reconciliation path — a status query keyed by request ID, or an escalation — because *indeterminate* is a third state distinct from success and failure, and probabilistic agents default to retrying it, which is precisely wrong. ```python class ResumptionForkError(RuntimeError): """Raised when an SSE resumption would bind to a different session epoch.""" def resume_stream(held_session_id: str, held_last_event_id: int, handshake: dict) -> dict: server_session = handshake.get("session_id") server_last_event = handshake.get("last_event_id") if server_session != held_session_id: # Session was reaped or replaced; the event-ID space is a new epoch. raise ResumptionForkError( f"epoch change: held session {held_session_id!r} != server {server_session!r}; " f"in-flight outcome indeterminate, must reconcile not retry" ) if server_last_event is None: raise ResumptionForkError( f"server accepted resumption for session {server_session!r} but returned no " f"event-ID cursor; cannot verify replay determinism" ) if server_last_event <= held_last_event_id: # Same session, but cursor moved backward: namespace reset without epoch change. raise ResumptionForkError( f"cursor regression within session {server_session!r}: " f"server {server_last_event} <= held {held_last_event_id}; treat as fork" ) return handshake ```