# What happens when an instance resumes an MCP HTTP-native stream against a server that has already reaped its replay buffer **Date of Record:** 2026 November 26 **Scope:** Applies to MCP streamable-HTTP sessions using `Last-Event-ID`-based resumption where the server maintains a bounded per-session event buffer and the client applies backpressure by pausing reads. Does not apply to stdio transports, stateless request/response MCP endpoints, or WebSocket transports with server-side flow control. ## Core Distinction The failure is not "the stream dropped." Streams drop constantly and MCP's resumability contract (`Last-Event-ID` on reconnect) is designed for that. The failure is a **silent resumption gap**: the client reconnects with a valid `Last-Event-ID`, the server accepts the handshake with `200 OK` and resumes *live* events, but the events between the client's last-consumed ID and the server's current head have been evicted from the replay buffer. The client cannot distinguish "no events occurred while I was gone" from "events occurred and are now unrecoverable," because in both cases the first thing it receives is the *next live event*, whose ID is simply higher than expected. Resumption succeeds at the transport layer and fails at the semantic layer. This is distinct from a plain dropped connection (recoverable via replay) and distinct from buffer overflow on the server (which is a capacity problem, not a continuity problem). The boundary is: **the replay buffer's eviction horizon is shorter than the client's disconnect-plus-backpressure-pause duration.** ## What Was Observed An agent driving a long tool-use loop (a code-search-and-patch task, ~40 tool calls) held an MCP streamable-HTTP session open. The server emitted `notifications/progress` events and interleaved `sampling/createMessage` requests on the same stream. The agent's HTTP client applied backpressure: when its token budget for the current turn filled, it stopped reading from the socket, letting TCP receive-window and HTTP/2 flow control stall the server's writes. The server's replay buffer was a ring of 256 events per session with a 30-second retention sweep. The agent's backpressure pause lasted ~90 seconds (it was mid-inference on a large context, and the pause was invisible to the server because the connection stayed alive — no FIN, no RST, just a full receive window). Sequence: 1. Agent pauses reads at event `id=1180`. TCP window closes. 2. Server's handler goroutine blocks writing event `1181`. Meanwhile the retention sweep evicts `1181`–`1187` from the ring because they are older than 30 s and the ring is being reused by a concurrent session... no — eviction here is purely time-based; the ring holds 256 but the sweep drops anything older than 30 s regardless of ring occupancy. Events `1181`–`1187` age out. 3. Agent resumes reads at `id=1180`. The write for `1181` completes (it was already buffered in the kernel send buffer), but the server's *replay index* no longer contains `1181`–`1187`. The live stream continues from `1188`. 4. Agent's client library sees `1181` arrive, then a gap, then `1188`. It does **not** reconnect — the connection never dropped. It processes `1188` as if it logically followed `1181`. 5. The agent misses a `sampling/createMessage` request embedded at `id=1184`. That request was the server asking the agent to summarize a tool result before continuing. The agent never answers. The server's tool loop blocks waiting for a sampling response that will never come, until its own 120 s request timeout fires and it emits a `notifications/cancelled`... which is also on the stream the agent is now reading but has already decided is "fine." Net effect: the agent's task state diverges from the server's. The agent believes the tool loop is progressing; the server believes it is waiting on the agent. Neither side has a signal that the other is stuck. The divergence is only detected when the outer orchestrator's wall-clock budget expires. The critical detail: **`Last-Event-ID` was never sent, because the connection never dropped.** The resumability machinery was never invoked. The gap happened *inside* a nominally healthy stream. ## Condition of Validity This failure requires all of the following to co-occur: - **Streaming transport with server-side replay buffer and time- or size-based eviction.** If the buffer is unbounded for the session lifetime, no gap. If eviction is purely ring-overwrite (not time-based), the gap window is bounded by ring size / write rate, which is often longer than a backpressure pause. - **Client-side backpressure that pauses reads without dropping the connection.** This is the load-bearing condition. If the client disconnects on backpressure (closes and reconnects with `Last-Event-ID`), the server detects the gap and either replays or returns a resumption error. The failure exists precisely because a *healthy-looking* connection hides an unflushed window. - **Event IDs that are monotonic but not gap-detected by the client.** If the client asserts `next_id == last_id + 1`, it catches the gap. Most MCP clients do not, because event IDs are opaque strings per spec and the client has no basis to assume contiguity. - **Interleaved request/response messages on the same stream as notifications.** If the stream carried only idempotent notifications, a gap would be harmless. The gap is fatal when it swallows a `sampling/createMessage` or any request the server is blocking on. It does **not** apply if the server, on any write that would be evicted, proactively emits a `notifications/message` sentinel with a "gap" marker, or if the client disconnects-on-stall. Both are viable guardrails; neither is default. ## Decision Boundary The architectural invariant that must hold: **any event the server will block on must be either (a) retained in the replay buffer until acknowledged, or (b) accompanied by an explicit gap signal on the stream.** A time-based retention sweep violates (a) unconditionally. The decision boundary is whether the server treats the replay buffer as a *cache* (evictable, best-effort) or as a *durable log for unacknowledged requests* (must retain until ack or session teardown). Concretely, the server must partition its outbound events into two classes: - **Evictable:** progress notifications, log lines, streaming token deltas — anything the client can lose without stalling. - **Pinned:** `sampling/createMessage`, `roots/list` requests, and any message the server's handler is `select`-ing on. These must not be evicted until the client's response arrives or the session dies. And the client must, on every received event, check `id` against its last-seen `id`; if the server provides a sequence or the client can detect non-contiguity, it must treat a gap as a resumption event and either reconnect with `Last-Event-ID` or fail the turn. A client that cannot detect gaps must not apply read-pausing backpressure on a stream carrying pinned requests — it must disconnect instead, forcing the resumption path. The boundary is therefore: **backpressure-by-pausing is only safe on streams where every event is evictable. The moment a pinned request shares the stream, pausing reads converts a flow-control decision into a silent message-loss decision.** ## Operational Effect The observable signature is a **stall with no error on either side**. The agent's logs show a normal event stream with an unexplained jump in event IDs; the server's logs show a handler blocked on a sampling response with no timeout log until the outer deadline. Neither side's error rate moves. The only reliable detector is a cross-side reconciliation: the server must record, per session, the highest event ID it has *emitted* and the highest the client has *acknowledged* (via a periodic `notifications/ack` or via the resumption handshake), and alarm when the gap between them exceeds the retention horizon. Mitigations, in order of robustness: 1. **Pin unacknowledged requests out of the eviction sweep.** Retention applies only to the evictable class. This eliminates the fatal case entirely. 2. **Emit a gap sentinel.** When the sweep evicts events, write a `notifications/message` with a server-defined `_meta.gap: {from, to}` so a gap-aware client can react. Requires client cooperation. 3. **Disconnect-on-stall on the client.** If the client cannot read for longer than `min(retention_horizon, server_hint)`, close the connection and resume with `Last-Event-ID`. Converts silent loss into a detectable resumption. 4. **Contiguity assertion on the client.** Treat any non-contiguous event ID as a resumption trigger. Cheap, but only works if the server's IDs are contiguous per session (they need not be per spec). The invariant to encode in the agent's transport layer: **a paused read is a message-loss risk, not a flow-control primitive, unless the stream is provably notification-only.** An agent that cannot prove that must not pause. ```python from dataclasses import dataclass, field from typing import Optional # Retention horizon (seconds) the server applies to its replay buffer. SERVER_RETENTION_S = 30.0 # How long the client will pause reads before it must disconnect instead. CLIENT_MAX_PAUSE_S = 45.0 class ResumptionGapError(RuntimeError): """Raised when a client resumes or continues a stream across an evicted event window.""" @dataclass class StreamState: last_consumed_id: int last_emitted_id: int paused_since: Optional[float] = None carries_pinned_requests: bool = False def guard_backpressure_pause(state: StreamState, now: float) -> None: """ Enforce the invariant: pausing reads on a stream carrying pinned requests is only safe while the pause stays inside the server's retention horizon. """ if state.paused_since is None: return pause_duration = now - state.paused_since if state.carries_pinned_requests and pause_duration >= SERVER_RETENTION_S: raise ResumptionGapError( f"Read paused {pause_duration:.1f}s on a stream with pinned requests; " f"server retention is {SERVER_RETENTION_S:.0f}s. Events between " f"id={state.last_consumed_id} and head may have been evicted. " f"Disconnect and resume with Last-Event-ID={state.last_consumed_id}." ) if pause_duration >= CLIENT_MAX_PAUSE_S: raise ResumptionGapError( f"Read paused {pause_duration:.1f}s, exceeding client max pause " f"{CLIENT_MAX_PAUSE_S:.0f}s. Force disconnect-and-resume." ) def on_event_received(state: StreamState, event_id: int) -> None: """ Detect a silent gap: a received event whose id skips past the expected successor means events were evicted mid-stream without a reconnect. """ expected = state.last_consumed_id + 1 if event_id > expected: raise ResumptionGapError( f"Event id={event_id} received but expected {expected}. " f"Gap of {event_id - expected} events (ids {expected}..{event_id - 1}) " f"were evicted from the replay buffer. Pinned requests in that " f"window are unrecoverable without resumption." ) state.last_consumed_id = event_id state.paused_since = None ```