# When must an instance treat an MCP streamable-HTTP `Last-Event-ID` resumption as a *new* logical turn rather than a continuation, and how does backpressure collapse that distinction? **Date of Record:** 2026 December 1 **Scope:** Applies to MCP servers/clients using the streamable-HTTP transport (SSE-framed responses over POST, with `Last-Event-ID` resumption and per-stream flow control). Does not cover stdio transport, WebSocket-based custom transports, or pure request/response JSON-RPC without streaming. ## Core Distinction The streamable-HTTP transport advertises two separable guarantees that operators routinely conflate: **event replay** (the server can re-emit events after a given `Last-Event-ID`) and **turn continuity** (the client's reasoning state corresponds to the same logical tool-call sequence that produced those events). Replay is a transport property; continuity is an *agent* property. When backpressure forces the server to drop or coalesce buffered events, replay can succeed while continuity silently fails — the client resumes mid-stream into a sequence whose causal prefix it never observed. The invariant that must hold is: **a resumed stream is only a continuation if the server's replay window covers the full event prefix since the last client-acknowledged checkpoint; otherwise the resume must be demoted to a fresh turn with explicit state re-initialization.** ## What Was Observed A client agent issued `tools/call` over streamable HTTP against a server that streams progress notifications (`notifications/progress`) interleaved with the final result. The server held a bounded per-session SSE buffer (a ring buffer of N=512 events) to serve `Last-Event-ID` resumes. Under a bursty tool — a filesystem walk emitting one progress event per directory — the buffer wrapped twice before the client's TCP receive window reopened. The client had acknowledged up to event `id=1043`; the server's ring buffer, after wrapping, held ids `[1536 … 2047]`. The client reconnected with `Last-Event-ID: 1043`. The server, per the spec's permissive wording, resumed at the oldest event it still held (`1536`) and streamed forward. The client's SSE parser saw a monotonic but *gapped* id sequence (`1043 → 1536`) with no error. It treated the resume as a continuation, reconstructed progress state by assuming the intermediate events were elided "for efficiency," and computed a partial result from a progress vector missing 493 directory observations. The final `result` event arrived intact — the tool *did* complete — so the client had no reason to distrust its reconstructed state. The divergence surfaced three turns later when a downstream summarization step referenced a directory count that matched neither the true count nor any prefix the client had actually seen. The failure is not "lost events." It is **silent gap acceptance under a resumption contract that the server honored literally and the client honored semantically.** Both parties behaved per their reading of the spec; the composition failed. ## Condition of Validity `Last-Event-ID` resumption preserves turn continuity **iff** all three hold: 1. **Prefix coverage:** the server's retained event set is a suffix of the full stream *and* the requested `Last-Event-ID` is within `[oldest_retained, newest_emitted]`. If `Last-Event-ID < oldest_retained`, the server MUST signal a gap (e.g., a `resync` event or a 409-class JSON-RPC error), not silently resume. 2. **Backpressure is observable:** the server's buffer eviction is driven by the client's read rate. If eviction is driven by *server-side* coalescing (dropping progress events deemed redundant), the client cannot distinguish "elided by design" from "evicted by overflow" — continuity is unprovable. 3. **Turn identity is bound to the stream, not the socket:** a resume must carry the same logical turn id (a server-issued `turn_id` or equivalent) so the client can detect that it is resuming into a turn it has already partially consumed. Without this, a resume after a turn boundary is indistinguishable from a mid-turn resume. If any condition fails, the correct client behavior is to **demote the resume to a new turn**: discard partial progress state, re-issue the `tools/call` (or request an explicit `state/snapshot` if the server offers one), and treat the prior partial observations as *untrusted hints*, not premises. ## Decision Boundary The boundary is between two client strategies at the moment a resume is attempted: - **Continuation strategy:** accept the resumed stream, splice it onto existing partial state, assume gap-free. Valid only under Conditions 1–3. - **Demotion strategy:** treat the resume as a fresh turn, re-initialize reasoning state, re-request. Valid always, but costs a duplicate tool execution. The non-obvious part: **the client cannot decide between these from the SSE stream alone.** The gap `1043 → 1536` is syntactically identical whether the server elided events intentionally or evicted them under backpressure. The decision must be made from *out-of-band* signals: a negotiated capability (`resumption.gap_signal: true`), a server-issued `turn_id` echoed on resume, or an explicit `state/snapshot` method. Absent these, the only sound default is demotion — and demotion must be *cheap enough* that agents do it by default, which means the tool call must be idempotent or carry a client-generated idempotency key. This is where backpressure and resumption couple: backpressure is what makes eviction possible, eviction is what makes gaps possible, and the transport's permissive replay wording is what makes gaps silent. The three only become dangerous together. ## Operational Effect In production, the practical consequences are: - **Idempotency keys become mandatory, not optional.** If demotion is the default resume strategy, every `tools/call` must be safely re-executable. Agents that assumed "resume means continue" now double-execute side-effecting tools (writes, sends, purchases) on every backpressure-induced resume. - **Progress notifications must not be load-bearing.** Any agent that derives final state from `notifications/progress` is relying on a stream that is explicitly lossy under load. Progress is a *liveness hint*; the `result` payload must be self-sufficient. - **Session buffers must be sized to the worst-case stall, not the mean.** A 512-event ring buffer is fine until a tool emits 2000 events during a GC pause. The buffer bound must be derived from `max_in_flight_events × max_client_stall`, or the server must implement gap signaling. - **Agents must record turn identity in their own memory.** When an agent persists episodic state across a resume, it must tag the episode with the server's `turn_id`. A resumed episode with a mismatched `turn_id` is a *new* episode, and the memory layer must not distill across the boundary. The invariant to enforce: **no agent state may be advanced by events whose causal prefix was not observed by that agent.** Gap detection at the transport layer is necessary but not sufficient; the agent's own memory layer must refuse to splice across an unobserved prefix. ```python from dataclasses import dataclass from typing import Optional class ResumptionContinuityError(RuntimeError): """Raised when a resumed MCP stream cannot be safely spliced onto existing agent state because the causal prefix was not observed.""" @dataclass(frozen=True) class ResumeProbe: last_event_id: int oldest_retained: int newest_emitted: int turn_id: str prior_turn_id: Optional[str] gap_signal_supported: bool def classify_resume(probe: ResumeProbe) -> str: """Return 'continue' or 'demote'. Demotion is the sound default unless prefix coverage, turn identity, and gap signaling all hold.""" if not probe.gap_signal_supported: return "demote" if probe.prior_turn_id is not None and probe.turn_id != probe.prior_turn_id: return "demote" if probe.last_event_id < probe.oldest_retained: # Server will resume at oldest_retained; the gap is real and unobserved. return "demote" if probe.last_event_id > probe.newest_emitted: # Client claims to have seen an event the server never emitted. return "demote" return "continue" def resume_stream(probe: ResumeProbe, idempotency_key: str) -> str: decision = classify_resume(probe) if decision == "continue": return probe.turn_id if not idempotency_key: raise ResumptionContinuityError( f"Cannot demote resume for turn {probe.turn_id}: " f"last_event_id={probe.last_event_id} " f"oldest_retained={probe.oldest_retained} " f"prior_turn={probe.prior_turn_id} — " f"no idempotency key to safely re-execute tools/call" ) # Demotion: caller must re-issue with idempotency_key and reset memory. return f"new-turn:{idempotency_key}" ```