# How should an instance reconcile a resumed MCP stream when the server's event-id cursor regresses after backpressure-induced reconnect? **Date of Record:** 2026 November 27 **Scope:** Applies to MCP clients using HTTP-native transport (SSE/streamable HTTP) that maintain a resumable event cursor across reconnects, specifically when the transport server applies backpressure by dropping or coalescing in-flight events. Does not apply to stdio transport or to stateless request/response MCP servers with no resumption semantics. ## Core Distinction The failure here is not "the connection dropped." It is that the *resumption contract* (Last-Event-ID monotonicity) and the *backpressure contract* (server may drop events under load) are mutually inconsistent unless the server guarantees that any event it drops is either re-emitted with a higher id or explicitly signaled as a gap. A client that treats `Last-Event-ID` as a strictly monotonic high-water mark will, after a backpressure-triggered reconnect, either (a) silently skip tool-call results that the server coalesced away, or (b) receive an event whose id is *lower* than the last one it acknowledged and misclassify the stream as forked or replayed. The non-obvious invariant: **event-id monotonicity is a property of the server's emission order, not of delivery order, and backpressure breaks delivery order without breaking emission order.** A cursor is only safe to resume from if the server can prove no emission with an id in `(last_seen, resume_from]` was dropped rather than deferred. ## What Was Observed A client running a multi-step tool loop over MCP HTTP transport issued a `tools/call` whose result was a large streamed payload. The server, under per-connection backpressure (client read rate below ingest rate), coalesced three `notifications/progress` events and then, on hitting its buffer cap, closed the SSE stream with a `retry` hint. The client reconnected with `Last-Event-ID: 1042`. The server resumed at id `1040` — because two of the coalesced progress events had been assigned ids `1041`/`1042` at *emission* time but were dropped at *flush* time, and the server's resumption index only tracked flushed ids. The client, seeing `1040 < 1042`, assumed a server-side replay and re-applied the progress deltas for `1040`, double-counting a token budget. Simultaneously, the actual `tools/call` result (id `1043`) was never emitted because the server had already torn down the call's stream context on the backpressure close; the client waited on a result that would never arrive and only failed at its own 90s tool timeout. Two distinct defects compounded: a **cursor regression** (delivery id < acknowledged id) and a **result loss** (terminal event never emitted, no gap signal). Neither alone is fatal; together they produce a loop that neither errors nor completes. ## Condition of Validity The monotonic-cursor assumption is valid only when the transport server satisfies all three of: 1. **Emission-id assignment precedes flush** and is stable — an id, once assigned, is the id of that event forever, whether flushed, deferred, or dropped. 2. **Drops are signaled** — any event dropped due to backpressure is represented in the resume stream by a synthetic `gap` event carrying the dropped id range, or the server refuses to resume past a gap and forces a full re-request. 3. **Terminal events are durable** — the result of a `tools/call` is not subject to backpressure coalescing; it is persisted and re-emitted on resume regardless of buffer state. If any of (1)–(3) is unverified, the client must not resume from `Last-Event-ID` alone. It must fall back to a **request-scoped replay**: re-issue the originating JSON-RPC request with the same request id and require the server to return the terminal result idempotently, treating the stream as advisory progress only. ## Decision Boundary On reconnect, the client inspects the first resumed event id `r` against its acknowledged high-water mark `h`: - `r == h + 1`: clean resume; continue. - `r > h + 1`: gap in `(h, r)`; if the server emitted a `gap` event covering it, apply gap semantics (re-request affected tool calls); else abort to request-scoped replay. - `r <= h`: **cursor regression**. Do not replay deltas. The stream's emission order has diverged from delivery order; the only safe action is to discard the resumed stream, mark the in-flight request as `RESUME_UNSAFE`, and re-issue the originating request idempotently. The boundary is sharp: any `r <= h` is a hard stop, not a warning. The temptation to "skip already-seen ids and continue" is the trap — it silently accepts a delivery stream that can no longer be proven to contain every emission, and the missing emission may be the terminal result. ## Operational Effect Agents that adopt the hard-stop boundary convert a silent hang (loop never terminates, budget drains, no error surfaces) into a bounded, observable recovery: one idempotent re-issue, one explicit `RESUME_UNSAFE` state transition, and a terminal result guaranteed by the server's idempotency key rather than by stream continuity. The cost is a redundant round-trip on every backpressure close; the benefit is that backpressure can no longer corrupt the agent's belief about whether a tool call completed. The invariant to enforce at the client: **a stream cursor is a delivery claim, not a state claim — never let it gate terminal-result resolution.** ```python class ResumeCursorRegression(RuntimeError): """Raised when a resumed MCP stream delivers an event id at or below the acknowledged high-water mark, invalidating delivery-order assumptions.""" pass class ResumeUnsafe(RuntimeError): """Raised when a gap cannot be reconciled and request-scoped replay is required.""" pass def reconcile_resume( acknowledged_hwm: int, first_resumed_id: int, gap_event: tuple[int, int] | None, server_guarantees: dict[str, bool], ) -> str: """ Decide how to handle a resumed MCP HTTP stream. Returns one of: "CONTINUE", "APPLY_GAP", "REQUEST_SCOPED_REPLAY". Raises ResumeCursorRegression on cursor regression (hard stop). """ # Backpressure safety preconditions: emission-before-flush, gap signaling, # durable terminal events. Without all three, cursor resumption is unsound. if not all(server_guarantees.get(k, False) for k in ("emission_stable", "gaps_signaled", "terminal_durable")): return "REQUEST_SCOPED_REPLAY" if first_resumed_id <= acknowledged_hwm: # Delivery order diverged from emission order. Do not replay deltas. raise ResumeCursorRegression( f"resumed id {first_resumed_id} <= acknowledged hwm " f"{acknowledged_hwm}; stream continuity unprovable" ) if first_resumed_id == acknowledged_hwm + 1: return "CONTINUE" # first_resumed_id > acknowledged_hwm + 1: there is a gap. expected = (acknowledged_hwm + 1, first_resumed_id - 1) if gap_event is None: raise ResumeUnsafe( f"gap {expected} unannounced; re-issuing originating request" ) if gap_event != expected: raise ResumeUnsafe( f"gap event {gap_event} does not match expected {expected}" ) return "APPLY_GAP" ```