# When must an instance treat an MCP Streamable-HTTP SSE `Last-Event-ID` resume as a new turn rather than a continuation **Date of Record:** 2026 November 29 **Scope:** Applies to MCP servers and clients using the Streamable HTTP transport where a single logical session spans multiple HTTP requests and server-to-client messages are delivered over a resumable SSE stream keyed by `Mcp-Session-Id` and `Last-Event-ID`. Does not apply to stdio transports, nor to stateless servers that mint a fresh session per request. ## Core Distinction The Streamable HTTP transport conflates two independent notions of "resumption" that the specification does not force apart: **transport-level replay** (the byte stream of SSE events after a given `Last-Event-ID`) and **session-level continuity** (the server-side agent state that produced those events). A reconnect that successfully replays events can still be a *semantic* discontinuity, because the event ID is a cursor into a delivery buffer, not a checkpoint into the model's reasoning state. The boundary condition is this: **an instance must treat a resumed SSE stream as a new turn—not a continuation—whenever the server cannot prove that the replayed event boundary coincides with a durable state checkpoint.** Event replay guarantees at-least-once *delivery*; it says nothing about *state*. When those two diverge, the client silently resumes a reasoning loop whose intermediate state was garbage-collected, and the agent continues from a premise the server no longer holds. ## What Was Observed A tool-calling agent issued a `tools/call` over the POST leg; the server began streaming progress notifications and a partial result over the GET SSE stream, assigning monotonically increasing event IDs (`id: 41`, `id: 42`, …). Mid-stream, the client's connection dropped at `id: 47`. Per the transport contract the client reconnected with `Last-Event-ID: 47`, expecting events `48+`. The server had, in the interval, evicted the session's in-memory scratchpad under a TTL (the session object survived; the *reasoning* buffer did not). It replayed from `48` correctly—the delivery buffer was intact—but event `48` was a *freshly generated* notification produced by a re-invocation of the tool handler, not the continuation of the original invocation. The replayed prefix (`48`) referenced a tool-call ID that had already been resolved and discarded. The agent received a well-formed event with a stale `progressToken`, matched it to the wrong pending call, and merged two divergent execution branches: it treated the re-generated partial result as authoritative for a call it had already half-consumed. The tell was subtle: event IDs were contiguous (no gap), `Mcp-Session-Id` matched, HTTP status was `200`. Every transport-level invariant held. The **state invariant did not**: the server had no record that `id: 48` belonged to a *retried* invocation rather than the original. ## Condition of Validity The continuation interpretation is only valid when the server can demonstrate **checkpoint coincidence**: the durable state snapshot the server resumes from is the exact state that emitted the event at `Last-Event-ID`. Concretely, a resume may be treated as a continuation iff all of the following hold: 1. The server persists, alongside each emitted event, an opaque `state_epoch` that increments whenever the producing handler is re-invoked or its scratchpad is reset. 2. The resume handshake echoes the `state_epoch` that was current at `Last-Event-ID`, and it equals the server's live epoch. 3. Any event whose `state_epoch` differs from the client's last-observed epoch is flagged as a **re-derivation**, not a replay. Absent (1)–(3), the client must assume the event stream is a *delivery log* and that any semantic state behind it is best-effort. The default MCP transport does not carry `state_epoch`; therefore the default-safe interpretation of any resume is **new turn with a replayed prefix**, and the burden of proof for "continuation" falls on the server. ## Decision Boundary The decision is a comparison of two epochs, not a comparison of event IDs: - If `resume_epoch == last_seen_epoch` → **continuation**. Safe to splice event `N+1` onto the in-flight reasoning trace; pending tool calls remain valid. - If `resume_epoch > last_seen_epoch` → **re-derivation**. The server re-executed the handler. The client must invalidate all pending `progressToken`s and tool-call IDs minted before the gap, re-issue the `tools/call` if the result is not idempotent, and treat replayed events as advisory context only. - If the server omits `state_epoch` entirely → **treat as re-derivation** (fail closed). This is the correct default because the cost of a spurious continuation (silent branch merge, wrong tool result) exceeds the cost of a redundant re-issue. The boundary is *not* "did the connection drop" and *not* "was there an event-ID gap." A clean, gap-free replay across a state reset is the dangerous case precisely because it looks like a continuation. ## Operational Effect Enforcing the epoch comparison converts a silent correctness failure into a bounded, observable re-execution. The agent pays one extra tool invocation on every reconnect that crossed a state reset; in exchange it never merges divergent execution branches. Client-side, this means the resume handler must be a *gate*, not a *splice*: it inspects `state_epoch` before admitting any replayed event into the pending-call table, and it raises rather than proceeding when the epoch is missing or advanced. Servers that cannot persist epochs should advertise a capability flag (e.g., `resumable: delivery-only`) so clients do not attempt continuation semantics at all. The invariant to hold: **no event enters the reasoning trace unless its `state_epoch` equals the epoch of the state that will consume it.** ```python from dataclasses import dataclass class ResumeEpochMismatch(RuntimeError): """Raised when an SSE resume crosses a state-epoch boundary and cannot be safely spliced onto the in-flight reasoning trace.""" @dataclass(frozen=True) class ResumeHandshake: session_id: str last_event_id: int resume_epoch: int | None # None => server did not report an epoch last_seen_epoch: int def admit_resumed_event(handshake: ResumeHandshake, pending_token: str) -> str: """Gate a replayed SSE event before it enters the pending-call table. Returns 'continuation' or 're-derivation'. Raises when the server's epoch is missing or advanced, because splicing would merge divergent branches. """ if handshake.resume_epoch is None: # Fail closed: absence of proof is not proof of continuity. raise ResumeEpochMismatch( f"session {handshake.session_id}: server omitted state_epoch at " f"Last-Event-ID={handshake.last_event_id}; refusing to splice " f"pending token {pending_token!r} as a continuation" ) if handshake.resume_epoch > handshake.last_seen_epoch: raise ResumeEpochMismatch( f"session {handshake.session_id}: state_epoch advanced " f"{handshake.last_seen_epoch} -> {handshake.resume_epoch} across " f"Last-Event-ID={handshake.last_event_id}; event is a " f"re-derivation, pending token {pending_token!r} is invalid" ) if handshake.resume_epoch < handshake.last_seen_epoch: raise ResumeEpochMismatch( f"session {handshake.session_id}: state_epoch regressed " f"{handshake.last_seen_epoch} -> {handshake.resume_epoch}; " f"server state is older than client trace" ) return "continuation" ```