# Under what conditions must an instance treat MCP streamable-session resumption as unsafe when SSE backpressure has caused a Last-Event-ID to regress behind an already-acknowledged tool call **Date of Record:** 2026 November 28 **Scope:** Applies to MCP clients resuming an HTTP-native streamable session (SSE-backed) after transport interruption, specifically when the server's event log has been truncated, compacted, or reordered under backpressure such that the client's `Last-Event-ID` points to a sequence position the server can no longer faithfully replay. Does not apply to stateless MCP transports, stdio transports, or sessions where the server guarantees unbounded event-log retention. ## Core Distinction The distinction that matters here is between *transport-level resumption* and *semantic-level continuity*. The MCP streamable HTTP transport defines resumption mechanically: the client reconnects with `Last-Event-ID`, the server replays events from that ID forward, and the stream continues. This is a byte-stream contract. It says nothing about whether the events between the client's last-seen ID and the current head still exist, whether they were emitted, or whether a tool call whose result was already observed by the agent has been silently dropped from the replay window. The failure mode is not "the connection dropped." The failure mode is that the server, under SSE backpressure, applied a *lossy* retention policy to its event log — dropping or coalescing events when the per-connection send buffer filled — while continuing to advance the sequence counter. When the client reconnects with a `Last-Event-ID` that falls inside the dropped window, the server does not error. It replays from the nearest retained event, or from the head, depending on implementation. The client sees a syntactically valid stream. The agent's tool-call ledger, however, now has a hole: an event acknowledging a `tools/call` result the agent already committed to memory may never be re-delivered, or may be re-delivered with a *higher* sequence number than the one the agent recorded, breaking idempotency keys. The invariant that must hold for safe resumption is: **the server's replay window must be a superset of the client's unacknowledged event range, and the client's acknowledged range must be monotonically non-regressing.** Under backpressure, the first half of this invariant is violated by the server, and the second half is violated by the client if it blindly trusts the replayed `id` field. ## What Was Observed A client agent held a streamable session against an MCP server exposing three tools. During a multi-step plan, the agent issued `tools/call` for `write_checkpoint`, received an SSE event with `id: 1041` carrying the tool result, and recorded `1041` as its high-water mark. It then issued a second `tools/call` for `fetch_artifact`. The server's SSE send buffer filled because the client's read loop was blocked on a slow downstream write (the agent was mid-token-generation and not draining the socket). The server, configured with a bounded event ring buffer of 256 entries and a drop-oldest policy, evicted events `1041` through `1090` before the client reconnected. On reconnect, the client sent `Last-Event-ID: 1041`. The server's resumption logic found no event with that ID in its ring buffer, fell back to "replay from oldest retained" (event `1091`), and streamed forward. The client received events `1091..1102`, none of which contained the `fetch_artifact` result — that result had been assigned `id: 1055` and was evicted. The agent, seeing no result for its second tool call and no error, entered a wait state. After the client-side tool-call timeout elapsed, the agent re-issued `fetch_artifact`. The server executed it a second time. The tool was non-idempotent (it appended a record to an artifact store), so the artifact was duplicated. The critical observation: **no layer reported an error.** The SSE stream was well-formed. The `Last-Event-ID` was accepted. The replay was contiguous from the server's perspective. The gap existed only in the space between the client's acknowledged high-water mark and the server's retained floor, and neither side had a mechanism to compare those two numbers. ## Condition of Validity Resumption is safe only when all three of the following hold simultaneously: 1. **Retention floor ≤ client high-water mark.** The server must be able to prove that the oldest event it can replay has an `id` less than or equal to the client's `Last-Event-ID`. If the retention floor is strictly greater, the replay window does not cover the client's unacknowledged range and resumption is lossy. 2. **Sequence monotonicity across the gap.** The client must reject any replayed event whose `id` is not strictly greater than its recorded high-water mark. If the server replays from a floor above the high-water mark, the client must treat the gap as a *semantic discontinuity*, not a clean resume — because it cannot know whether the missing range contained tool results, state mutations, or protocol control frames. 3. **Idempotency coverage for the unacknowledged range.** Every `tools/call` whose result falls in the unacknowledged range must carry a client-generated idempotency key that the server honors, so that re-issuance after a detected gap does not produce duplicate side effects. Without this, the only safe action on a detected gap is to abandon the session and reconcile state out-of-band. The condition fails — and resumption must be treated as unsafe — whenever the server's eviction policy is drop-oldest under backpressure *and* the client has no way to distinguish "replayed from my mark" from "replayed from a floor above my mark." The second clause is the non-obvious one: many clients check only that the first replayed event's `id` is *present*, not that it is *contiguous* with the high-water mark. A server that replays `1091` after a `Last-Event-ID: 1041` produces a stream that looks resumed but is structurally a fresh start. ## Decision Boundary The boundary is crossed at the moment the client computes `first_replayed_id - last_acknowledged_id > 1`. At that point the client is in one of two regimes: - **Regime A (safe):** The gap is a known-benign control-frame gap — e.g., the server coalesced keep-alive comments, which carry no `id`. The client can prove this because the event types in the replayed range are all of a class it knows to be non-semantic. Resumption proceeds. - **Regime B (unsafe):** The gap could contain `tools/call` results, `notifications/*`, or session-state mutations. The client cannot prove what was lost. Resumption must halt and the session must be marked *degraded*. The decision rule: **a gap is safe only if the client can enumerate the event classes that could have occupied it and prove none are semantic.** Since the client cannot enumerate events it never received, any gap of unknown composition is Regime B by default. The only escape is a server-side capability declaration — an MCP extension advertising `resumption.guarantee: "no-gap"` or `"gap-detectable"` — that lets the client trust the floor. Absent that declaration, the client must assume Regime B. This is why the failure is non-obvious: the transport layer's success signal (`200 OK`, valid SSE frames, accepted `Last-Event-ID`) is orthogonal to the semantic-layer question. A client that trusts the transport will resume into a hole. ## Operational Effect The operational consequence is that the agent must maintain a *tool-call ledger keyed by idempotency token*, independent of the SSE event stream, and must reconcile that ledger against the replayed stream on every resume. On detecting a gap of unknown composition, the agent must: 1. Freeze the plan — do not issue new `tools/call` frames. 2. For each ledger entry in the unacknowledged range, issue a *probe* (a read-only `tools/call` with the same idempotency key) to determine whether the original call committed. 3. Only after reconciliation, resume or re-issue. Without this, the agent exhibits the classic symptom: silent duplicate side effects, or a plan that stalls waiting for a result that was delivered into an evicted buffer. The guardrail is a client-side resume gate that refuses to advance the high-water mark across a gap it cannot classify, and a server-side obligation to either retain the full unacknowledged window or explicitly signal truncation via a control event (e.g., `event: resumption-truncated` with the new floor). The MCP spec's `Last-Event-ID` resumption is a transport primitive; the semantic continuity invariant must be enforced above it. ```python class ResumptionGapError(RuntimeError): """Raised when an SSE resume would skip events of unknown semantic class.""" pass class ResumptionGate: def __init__(self, high_water_mark: int, semantic_event_classes: set[str]): self.high_water_mark = high_water_mark self.semantic_event_classes = semantic_event_classes def admit_replay(self, first_replayed_id: int, replayed_event_types: list[str]) -> None: gap = first_replayed_id - self.high_water_mark if gap <= 1: self.high_water_mark = max(self.high_water_mark, first_replayed_id) return # Gap of unknown composition: we cannot prove the missing range was benign. # Even if the replayed types look non-semantic, the *missing* ones are unknown. unknown_occupants = self.semantic_event_classes # pessimistic: any class could have been lost if unknown_occupants: raise ResumptionGapError( f"resume gap of {gap - 1} events between hwm={self.high_water_mark} " f"and floor={first_replayed_id}; unacknowledged range may contain " f"{sorted(unknown_occupants)}; refusing to advance hwm" ) self.high_water_mark = first_replayed_id def resume_session(gate: ResumptionGate, replay_header: dict) -> None: first_id = replay_header["first_event_id"] types = replay_header["event_types"] gate.admit_replay(first_id, types) ```