# In what scenarios must an instance refuse to resume an MCP streamable-HTTP session because the resumable event log has been truncated past its last acknowledged `Last-Event-ID`, and how does backpressure-induced partial delivery make this indistinguishable from a benign replay gap? **Date of Record:** 2026 November 24 **Scope:** Applies to MCP servers exposing the HTTP-native streamable transport with SSE-style resumable event IDs and a bounded per-session event buffer, and to clients that reconnect using `Last-Event-ID`. Does not apply to stateless request/response MCP transports, stdio sessions, or servers that persist an unbounded event log. ## Core Distinction The failure is not "the connection dropped." It is a specific collision between two independently reasonable mechanisms: (1) a bounded server-side replay buffer that evicts old events under memory pressure, and (2) client-side resumption that assumes any `Last-Event-ID` it holds is still addressable. When backpressure causes the server to *partially deliver* an event (write some SSE frames, then stall because the client's TCP window is full), the client's highest acknowledged ID and the server's eviction cursor can cross silently. The client then reconnects asking for "everything after ID=N," but N was evicted. A naive server resumes from the oldest retained event, producing a stream that *looks* contiguous to the client but has a hole. The distinction that matters: **a replay gap is not the same as a replay start.** A server that cannot honor `Last-Event-ID=N` exactly must fail the resume, not approximate it, because the client has no other signal that events were lost. ## What Was Observed A tool-calling agent streamed a long `tools/call` result as a sequence of SSE events with monotonically increasing IDs. The client's read loop was slow (blocked on a downstream model call), so the server's socket buffer filled and the server's write path stalled mid-event — it had flushed the event's `id:` and partial `data:` frames but not the terminating blank line. The client, obeying SSE semantics, did not advance its `Last-Event-ID` past the last *complete* event; it held the previous ID, say `N-2`, while the server had already committed events `N-1` and `N` to its ring buffer and begun evicting from the tail. On reconnect the client sent `Last-Event-ID: N-2`. The buffer had advanced its eviction floor to `N-1`. The server's resumption handler clamped the start index to the buffer head and replayed `N, N+1, …`. The client accepted this as a valid continuation. The result: event `N-1` — a chunk of the tool result — was never delivered, and nothing in the protocol surfaced the omission. The agent proceeded with a truncated tool output and produced a plausible but wrong downstream answer. The tell was only visible in server logs: the requested `Last-Event-ID` was strictly less than the eviction floor, and the resume handler had no branch for that condition other than "start at head." ## Condition of Validity Refusing to resume is only correct when all of the following hold: 1. The session uses bounded, evicting replay storage (ring buffer, TTL cache, or size-capped log) rather than an unbounded durable log. 2. The client's `Last-Event-ID` is a *required* continuity anchor — i.e., the stream carries state the client cannot reconstruct or re-request idempotently (partial tool results, incremental deltas, ordered notifications). 3. The server can determine its eviction floor exactly, and the requested ID is strictly below it. If the stream is idempotently re-requestable (the client can just re-issue the originating `tools/call`), refusal is unnecessary and harmful — you should instead signal a clean "resume not possible, restart required" and let the client re-drive. If the log is unbounded, the condition cannot arise. The dangerous middle ground — and the reason this is a boundary rather than a rule — is a server that *can* detect the gap but chooses to clamp-to-head because clamping "usually works" when the evicted events were low-value heartbeats. ## Decision Boundary The server must distinguish three cases at resume time and treat them non-uniformly: - **Requested ID ≥ eviction floor:** normal replay from `ID+1`. Safe. - **Requested ID < eviction floor, but evicted events were all non-state-bearing** (keepalive pings, progress ticks with no semantic payload): clamping to head is acceptable *only if* the server tags event classes and can prove the gap contains no state-bearing frame. This requires per-event classification, not a global assumption. - **Requested ID < eviction floor with any state-bearing event in the gap:** the server MUST fail the resume with an explicit, terminal error (a `410`-style "resume window exceeded" carrying the eviction floor and the last retained ID), forcing the client to re-initialize or re-request. Silently clamping here is the bug. The boundary is therefore not "buffer full" — it is "buffer full *and* the gap spans a state-bearing event *and* the client cannot idempotently recover." Backpressure raises the probability of hitting this boundary because partial delivery keeps the client's acknowledged ID artificially behind the server's committed cursor, widening the gap window during exactly the slow-consumer conditions where eviction is most likely. ## Operational Effect When the server refuses correctly, the client sees a deterministic terminal signal and can choose: re-issue the idempotent request, or escalate to a fresh session with explicit state reconstruction. When the server clamps silently, the client's agent loop continues on corrupted input — the worst outcome in this class, because the corruption is a *missing* event, and missing events produce confident wrong answers rather than errors. The invariant to enforce: **the server's resume handler must never advance a client's logical position past a state-bearing event the client did not acknowledge.** Backpressure handling must be paired with this invariant, because partial delivery is the mechanism that manufactures the unacknowledged-but-evicted window. ```python class ResumeWindowExceeded(RuntimeError): """Raised when a client's Last-Event-ID predates the eviction floor and the gap contains state-bearing events that cannot be replayed.""" def __init__(self, requested_id: int, eviction_floor: int, last_retained: int): self.requested_id = requested_id self.eviction_floor = eviction_floor self.last_retained = last_retained super().__init__( f"resume window exceeded: requested Last-Event-ID={requested_id} " f"< eviction_floor={eviction_floor}; last_retained={last_retained}" ) def plan_resume(requested_id: int, eviction_floor: int, last_retained: int, gap_events: list[dict]) -> int: """Return the first event index to replay, or raise if resume is unsafe. gap_events: events in (requested_id, eviction_floor) that were evicted. Each carries a 'state_bearing' bool set at emit time. """ if requested_id >= eviction_floor: return requested_id + 1 # normal replay from ID+1 # Requested ID is below the floor: the gap was evicted. state_bearing_in_gap = [e for e in gap_events if e.get("state_bearing")] if state_bearing_in_gap: # Cannot honor the client's position; do not clamp silently. raise ResumeWindowExceeded(requested_id, eviction_floor, last_retained) # Gap contained only non-state-bearing frames (pings/progress): # clamping to the floor is safe and preserves continuity. return eviction_floor ```