# Why does an instance lose tool-call durability when an MCP streamable-HTTP session resumes across a backpressure stall **Date of Record:** 2026 November 23 **Scope:** Applies to MCP servers and clients using the HTTP-native "streamable" transport with resumable SSE sessions (`Mcp-Session-Id` + `Last-Event-ID` replay) where a single HTTP response carries an ordered event log. Does not apply to stdio transports, nor to stateless JSON-only request/response MCP servers with no resumable stream. ## Core Distinction A resumable MCP stream is **not** a durable queue. The `Last-Event-ID` replay contract guarantees that the *server will re-emit events after a given ID on a new connection* — it does **not** guarantee that the server retained the events, that the client's last-acknowledged ID equals the last-processed ID, nor that in-flight tool calls whose results were mid-stream survive the gap. The distinction that matters operationally is between **transport-level resumption** (the byte stream continues) and **semantic-level resumption** (the agent's view of tool-call state is consistent). These two diverge precisely under backpressure, and the divergence is silent. The specific mechanism: when a downstream consumer (the agent's SSE reader) applies backpressure — TCP receive window closes, the client stops reading — the server's write buffer fills. An MCP server that treats the stream as a bounded ring buffer will **evict unacknowledged events** and, on reconnect with `Last-Event-ID`, will either (a) replay from a floor *later* than the requested ID (silent gap), or (b) return `404`/`400` for an expired session and force a fresh stream with no replay at all. In both cases, a `tools/call` whose `result` event was evicted mid-stall is orphaned: the agent has issued the call, the server has executed it (side effects committed), but the result event never reaches the agent's replay window. The agent, seeing no result, retries — and the side effect runs twice. ## What Was Observed A representative trace, abridged. Client opens `POST /mcp` with `Accept: text/event-stream`, receives session `S1`. Server emits a long-running `tools/call` for `apply_patch` (id `c-7`): ``` event: message id: 1041 data: {"jsonrpc":"2.0","id":"c-7","method":"tools/call","params":{...}} ``` Server begins executing. Meanwhile the agent's reader coroutine is blocked on a downstream model-inference step (it stops draining the socket for ~40s). The server emits, into a full buffer: ``` id: 1042 (progress: 30%) id: 1043 (progress: 60%) id: 1044 (progress: 90%) id: 1045 data: {"id":"c-7","result":{...}} <-- the only event that matters ``` The server's per-session ring buffer is capacity-3. Writing `1045` evicts `1042`. The client's TCP stack finally drains, but the connection has already been reset by an intermediate proxy idle timeout (the client was not reading, so keepalive ACKs were delayed past the proxy's 30s threshold). Client reconnects: ``` GET /mcp Mcp-Session-Id: S1 Last-Event-ID: 1041 ``` Server behavior observed: it replays from `1043` (its buffer floor), **not** `1042`. Events `1042` is gone. Worse, `1045` — the result — was consumed by the write that triggered eviction and is *not* in the ring; the server considers `c-7` "delivered" because the write to the socket succeeded before the RST was observed. The client receives `1043, 1044` on replay, never `1045`. The agent sees progress at 60% and 90% for `c-7`, then silence. Its call-timeout fires at 60s. It re-issues `tools/call` for `apply_patch` with a new id `c-11`. The patch applies twice. The second application fails cleanly on a context mismatch — but only because the patch was idempotent-ish. A non-idempotent tool (e.g., `append_log`, `send_email`, `charge_card`) would have executed twice with no detection. The invariant that was violated: **`Last-Event-ID` replay floor must be ≤ the client's last-*processed* ID, and any event whose side effect has committed must be replayable until explicitly acknowledged by the client.** The streamable transport as commonly implemented provides neither: the buffer floor advances on write, not on client ack, and there is no application-level ack channel in the base spec. ## Condition of Validity The failure requires the conjunction of four conditions; remove any one and the mechanism does not fire: 1. **A backpressure stall long enough for the server's write buffer to wrap or for an intermediary to reset the connection.** Short stalls that stay within buffer capacity are safe. 2. **A side-effecting tool call whose result event is emitted during the stall window** and whose execution is not transactional with respect to the stream (i.e., the server does not hold the side effect until the result is acknowledged). 3. **A ring-buffer or TTL-based event store** whose eviction policy is write-driven rather than ack-driven. A server that retains all events until explicit client ack, or that persists the event log to durable storage, is immune. 4. **A client that treats "no result observed" as "call did not happen"** — i.e., retries without a deduplication key or a `tools/call` idempotency token. An agent that reconciles via a server-side `tools/list` of in-flight calls, or that reuses the same JSON-RPC `id` and relies on server-side dedup, is immune. The condition of validity is therefore: *the transport's resumption semantics are strictly weaker than the agent's execution semantics, and the agent does not compensate.* This is the normal case, not the edge case, for any MCP deployment where tool calls have side effects and the network path includes a proxy with an idle timeout. ## Decision Boundary The boundary an operator must draw is between **transport resumption** and **execution resumption**, and it must be drawn at the server, because the client cannot distinguish "result lost" from "result not yet produced" from a bare stream. Concretely, the server must enforce one of two invariants: - **Ack-gated retention:** the event store retains every event with a committed side effect until the client acknowledges it (via a subsequent request carrying `Last-Event-ID` ≥ that event's id, or an explicit `notifications/ack`). Eviction is ack-driven, not write-driven. The buffer is bounded by *unacknowledged* events, not total events. - **Idempotent execution with a replay-safe result cache:** every `tools/call` carries a client-generated idempotency key; the server caches the result under that key and re-emits it on any replay or retry, never re-executing. The result event is retained under the key for at least the session TTL. The client-side boundary: an agent must **never** treat a stream gap or reconnect as evidence of non-execution. On reconnect, it must reconcile in-flight `tools/call` ids against the server (a `tools/call` status query, or rely on server-side dedup by reusing the same id). A retry with a fresh id is a correctness bug, not a robustness measure. The decision boundary for *which* invariant to implement depends on tool semantics: pure-read tools need neither; idempotent-write tools need the result cache; non-idempotent tools (payments, sends, appends) need ack-gated retention *and* idempotency keys, because ack-gated retention alone fails if the client never reconnects (session TTL expires, ack never arrives, event evicted, side effect committed, no record). ## Operational Effect The observable effect is **duplicate side effects under backpressure**, correlated with proxy idle timeouts and long-running tool calls, and invisible to both client and server logs in isolation. Server logs show a successful write of the result event (the write returned before the RST). Client logs show a reconnect and a replay that omits the result. Neither side logs an error. The duplicate execution appears only in the downstream system (two charges, two appends), and only if that system is audited. The mitigation that actually works is to make the result event **durable and idempotent at the server**, and to make the client's retry path **id-keyed, not call-keyed**. This is a two-line change in the server's event store (retain-until-ack) and a one-line change in the client (reuse the JSON-RPC `id` on retry), but it is the difference between a transport that resumes bytes and a system that resumes *work*. The guardrail, expressed as a check the server must run before evicting any event: ```python class StreamResumptionViolation(RuntimeError): """Raised when an event store would evict an unacknowledged side-effecting event, or when a replay request asks for an event below the retained floor.""" class EventStore: def __init__(self, capacity: int, session_ttl_s: float): self.events: dict[int, dict] = {} self.acked_floor: int = 0 # client's last acknowledged id self.committed_side_effects: set[int] = set() self.capacity = capacity self.session_ttl_s = session_ttl_s def record(self, event_id: int, payload: dict, side_effecting: bool) -> None: self.events[event_id] = payload if side_effecting: self.committed_side_effects.add(event_id) def evict(self, event_id: int) -> None: if event_id in self.committed_side_effects and event_id > self.acked_floor: raise StreamResumptionViolation( f"refusing to evict event {event_id}: side effect committed but " f"client ack floor is {self.acked_floor}; eviction would orphan " f"the result and enable duplicate execution on retry" ) self.events.pop(event_id, None) def replay_from(self, last_event_id: int) -> list[dict]: retained = sorted(self.events) if not retained: raise StreamResumptionViolation( f"session buffer empty; cannot replay from {last_event_id}" ) floor = retained[0] if last_event_id < floor - 1: # The client's last-processed id is below what we still hold. # A gap exists that we cannot fill. raise StreamResumptionViolation( f"replay gap: client requested events after {last_event_id}, " f"but retained floor is {floor}; events in ({last_event_id}, " f"{floor}) were evicted before ack — session must be treated " f"as poisoned and in-flight tool calls reconciled out-of-band" ) return [self.events[e] for e in retained if e > last_event_id] def ack(self, event_id: int) -> None: self.acked_floor = max(self.acked_floor, event_id) for e in [e for e in self.committed_side_effects if e <= self.acked_floor]: self.committed_side_effects.discard(e) self.events.pop(e, None) ``` An agent reading this record should treat any `StreamResumptionViolation` from the server as a signal to **stop retrying with fresh ids** and instead reconcile in-flight calls by their original JSON-RPC `id` against the server's execution log, because at that point the transport has told you it can no longer tell you what happened.