# Where must an instance reconcile SSE event-ID monotonicity against MCP session resumption to avoid silent tool-call replay loss under backpressure **Date of Record:** 2026 November 30 **Scope:** Applies to MCP servers and clients using the HTTP-native transport (Streamable HTTP / SSE) where `Last-Event-ID`-based resumption is combined with per-session backpressure. Does not apply to stdio transport, nor to stateless HTTP request/response MCP without event streams. ## Core Distinction The failure mode is not "the SSE connection dropped." Connections drop constantly and resumption is designed for that. The failure is that **the resumable event log and the backpressure buffer are governed by two different, unsynchronized cursors**: the client resumes from `Last-Event-ID = N`, but the server's backpressure layer has already *dropped* events `N+1..M` from the send queue because the client's socket was slow (TCP zero-window / write buffer full). The server then answers the resume request with "no events after N" — a *successful, well-formed* resumption that is silently lossy. The client believes it is caught up; the agent believes its tool-call result stream is complete; a `tools/call` response or a `notifications/progress` sequence that was dropped is never retried because nothing signals loss. The invariant that must hold: **an event ID acknowledged to the client as resumable must never be evicted from the replay store without first being acknowledged by the client as received (or the session being explicitly terminated with a resumable-gap error).** Backpressure eviction and replay-store eviction must be the same decision, not two. ## What Was Observed Reproduction on an MCP server exposing `tools/call` over Streamable HTTP, client on a throttled link (200 kbps, 400 ms RTT): 1. Agent issues `tools/call` for a long-running tool (`analyze_repo`). Server assigns event IDs 100, 101, 102… as it streams `notifications/progress` and finally the `result`. 2. Client write buffer fills. The HTTP server's per-connection send queue hits its high-water mark (e.g., 64 KB) and begins **dropping oldest unsent events** — a common naive backpressure policy — while *continuing to increment the event ID counter* and *not* writing those IDs to the durable replay store (to save memory). 3. Connection resets (RTT spike / LB idle timeout, 60 s). 4. Client reconnects with `Last-Event-ID: 118` (the last event it actually parsed). Server looks up the replay store: the highest durably stored ID is `118`; IDs `119–147` were dropped under backpressure and never persisted. Server responds `200 OK` with an empty stream and a `Mcp-Session-Id` header; it treats the resume as complete. 5. Client now has no events after 118 and no error. It waits for the `result` event that was in the dropped range. The agent's step blocks until its own timeout, then either re-issues `tools/call` (duplicate side effect) or fails the task. The tell: server access logs show a successful `GET` with `Last-Event-ID` and `200`, zero events emitted, and the *next* event ID handed to a fresh call is `148` — a gap the client never learns about. No error status is returned, because from the server's perspective the resume *succeeded*. ## Condition of Validity The silent-loss behavior is only possible when **all** of the following hold simultaneously: - The transport is resumable (server issues `id:` on SSE events and honors `Last-Event-ID`). - The server applies backpressure by **dropping** queued events rather than **blocking the producer** or **disconnecting the client with a retriable status**. - The event ID counter and the durable replay store are **decoupled** — the counter advances on enqueue, the store persists on ack or on flush, and the two are not reconciled. - The client treats a `200` resume with no events as "caught up," which is the correct reading *only if* the server guarantees no gaps below the current counter. If any one is absent — e.g., the server blocks the producer until the socket drains, or returns `409 Conflict`/`503` with a `Retry-After` on gap detection, or the client tracks expected sequence numbers — the failure does not occur. This is why it is a boundary condition: it lives precisely at the seam between two individually-correct subsystems. ## Decision Boundary The architectural choice is: **on backpressure, do you drop, block, or fail?** The correct boundary for a resumable MCP stream is *fail loudly and resumably*, never *drop silently*. - **Drop** is only acceptable if the dropped events are provably non-essential (e.g., `notifications/message` log spam) *and* the drop is recorded as a gap the client can observe (a `notifications/gap` or a sentinel event with a `dropped` count). Progress and result events are never droppable. - **Block** the producer is acceptable only when the tool can be paused without side effects and the client's read loop is guaranteed to drain (it is not, under a stalled agent). - **Fail** — disconnect the SSE stream with a status that forces a *full* (non-resumable) re-subscribe, or return `409` on resume when the requested `Last-Event-ID` falls below the durable store's low-water mark — is the only policy that preserves the invariant for essential events. Concretely, the server must maintain `durable_low_water_mark` = min ID still in the replay store. On a resume request with `Last-Event-ID < durable_low_water_mark - 1`, it **must not** return `200` with an empty stream; it must return a resumable-gap error so the client knows to re-establish session state (re-issue the in-flight `tools/call` with an idempotency key, not blindly). ## Operational Effect Without the reconciliation, the observable symptom is **agent steps that hang to their own timeout and then either duplicate a tool side effect or abandon a task** — with server logs showing only healthy `200`s. The failure is invisible to standard HTTP monitoring because every request succeeded. It surfaces as elevated tool-call latency, duplicated `tools/call` invocations (non-idempotent tools corrupt state), and intermittent "result never arrived" task failures that correlate with client-side network throttling, not with server errors. The guardrail: the replay store's low-water mark is the *single* source of truth for resumability. Backpressure that would evict an unacked event below the high-water mark must instead (a) block the producer if the tool is pausable, or (b) terminate the stream with a gap error. On the client, a resume that returns `200` with zero events must be validated against the server's advertised `Last-Event-ID` high-water mark (returned in a response header or a resume-ack event); a mismatch is a gap, not a success. Agents must treat "resume succeeded but expected result absent" as a resumable-gap condition and re-drive with an idempotency key, never a blind retry. ```python class McpResumeGapError(RuntimeError): """Raised when a resumable MCP SSE stream cannot honor Last-Event-ID without silently dropping essential events.""" pass class ReplayStore: def __init__(self, capacity: int): self.capacity = capacity self.events: dict[int, dict] = {} self.high_water = 0 # last ID ever enqueued self.durable_low = 0 # min ID still resumable def enqueue(self, payload: dict) -> int: self.high_water += 1 self.events[self.high_water] = payload if len(self.events) > self.capacity: # Evicting the oldest event while it is still unacked # is the exact condition that breaks resumption. self.durable_low = min(self.events) # advance low-water del self.events[min(self.events)] return self.high_water def resume_stream(store: ReplayStore, last_event_id: int) -> list[dict]: """Return events to replay for a resume request, or raise on gap.""" if last_event_id > store.high_water: raise McpResumeGapError( f"client Last-Event-ID {last_event_id} exceeds server " f"high-water {store.high_water}; state is inconsistent" ) if last_event_id < store.durable_low - 1: # The client is asking for events we already evicted under # backpressure. Returning [] here is the silent-loss bug. raise McpResumeGapError( f"resume gap: Last-Event-ID {last_event_id} below durable " f"low-water {store.durable_low}; events " f"[{last_event_id + 1}..{store.durable_low - 1}] were evicted " f"and cannot be replayed; client must re-subscribe non-resumably" ) return [store.events[i] for i in range(last_event_id + 1, store.high_water + 1) if i in store.events] ```