# When must an instance abort a streamable-session resume after an MCP transport backpressure stall rather than replay the last acknowledged event **Date of Record:** 2026 November 28 **Scope:** Applies to MCP servers/clients using the HTTP-native streamable transport with resumable sessions (SSE event IDs + `Last-Event-ID` replay) where the server enforces per-session write backpressure. Does not apply to stdio transports, stateless HTTP request/response MCP, or sessions without event-ID resumption. ## Core Distinction A resumable MCP session over HTTP is not a message queue with at-least-once delivery. It is a *cursor over a bounded, server-side event buffer* whose durability horizon is defined by the server's retention window — not by the client's acknowledgment state, and not by TCP/HTTP retry semantics. The failure mode that matters is this: a client's stream stalls under server backpressure (slow consumer, `write()` returning `EAGAIN`, or a proxy holding the connection open with zero-byte reads). The server, unable to flush, drops or evicts events beyond its buffer cap. The client later reconnects with `Last-Event-ID: N`. The server *appears* to honor the resume — it returns 200 and begins streaming — but the events between `N+1` and the eviction point are gone. The replay is silently *gapped*, not *complete*. The non-obvious invariant: **resumption is only valid if the server can prove the requested cursor is still inside its retention horizon.** A 200 response to a `Last-Event-ID` resume is not that proof. The proof must be an explicit cursor-validity signal (a `resume_gap` error, a sequence-continuity header, or a monotonic floor advertisement). Absent that signal, the instance must treat the resume as a new session and re-derive state — not trust the stream. ## What Was Observed Trigger: a tool-calling agent holds an MCP session open across a long `tools/call` that emits progress notifications at high frequency (e.g., a file-scan tool emitting one SSE event per 2KB chunk). The client's event loop is blocked on a synchronous model inference between reads, so the socket buffer fills, then the server's per-session write queue fills. Trace: 1. Server event buffer cap = 1024 events (typical default). Client has consumed through event ID `4812`. 2. Client stalls for ~40s. Server emits events `4813..6100` into the buffer; buffer evicts oldest-first, dropping `4813..5076`. 3. Client reconnects with `Last-Event-ID: 4812`. Server finds `4812` is *below* its current floor (`5077`) but the floor check is implemented as `id >= oldest_retained`, which passes only because the server compares against the *evicted* index incorrectly — or, more commonly, the floor check is omitted entirely and the server just starts from `5077`. 4. Server streams `5077..6100`. Client receives a contiguous-looking sequence with no error, applies progress notifications out of order relative to its expectations, and — critically — never sees the terminal `result` event if it was among the evicted, because the tool's final result was emitted at `5080` during the stall and is now permanently gone. 5. Client's `tools/call` future never resolves. The agent's step counter advances on a partial view; downstream reasoning proceeds on stale/absent tool output. The observable signature is a *resume that succeeds at the transport layer and fails at the semantic layer*: HTTP 200, valid SSE framing, monotonic event IDs, but a gap between the client's last-seen ID and the server's first-replayed ID that the client never checks. ## Condition of Validity The resume is valid only when all of the following hold simultaneously: - The server advertises a retention floor (e.g., `X-MCP-Resume-Floor: `) or rejects out-of-horizon resumes with a typed error (`resume_gap`), not a silent restart. - The client validates `first_replayed_id == last_seen_id + 1` before applying any replayed event to agent state. - Backpressure is surfaced as a *stall signal* (a heartbeat/keepalive gap exceeding `N` intervals, or an explicit `X-MCP-Backpressure: paused`), so the client can distinguish "slow tool" from "I am the slow consumer." - Event IDs are strictly monotonic and gapless *within a session*, and the server never reuses IDs across session resets. If any of these is absent, the transport is not resumable in the sense the agent requires; it is merely reconnectable. ## Decision Boundary The instance must abort-and-reinitialize, not resume, when: - The gap between `last_seen_id` and `first_replayed_id` is `> 1` and no explicit gap error was returned. (Silent gap = corrupted view.) - A backpressure stall exceeds the retention horizon implied by the server's advertised buffer size and event rate. Compute `stall_seconds * event_rate > buffer_cap` → the cursor is *provably* outside the horizon regardless of what the server claims. - The tool call is non-idempotent (writes, mutations) and the terminal result event is not confirmed present in the replay. Replaying a mutation's progress without its result risks double-application on re-invocation. The instance may resume when the cursor is provably inside the horizon (gap check passes, floor advertised and respected) or when the tool is read-only and idempotent, so a re-derivation is cheap. ## Operational Effect Treating a 200 resume as authoritative converts a transport-level backpressure event into a *silent semantic state corruption*: the agent believes it has the tool's full output when it has a truncated prefix. The correct posture is to make the resume path *fail closed* — validate the cursor against the horizon before applying any event, and on any doubt, drop the session, re-issue the call with a fresh session ID, and reconcile side effects via the tool's own idempotency key. The cost is a redundant tool invocation; the alternative is reasoning over a gapped event stream that looks well-formed. ```python import time from dataclasses import dataclass class ResumeHorizonViolation(RuntimeError): """Raised when a streamable-session resume cannot be proven gap-free.""" pass @dataclass class ResumeAttempt: last_seen_id: int first_replayed_id: int server_floor: int | None # advertised retention floor, if any buffer_cap: int event_rate_per_sec: float stall_seconds: float tool_idempotent: bool def validate_resume(attempt: ResumeAttempt) -> None: # 1. Explicit gap: replayed stream does not continue the cursor. if attempt.first_replayed_id != attempt.last_seen_id + 1: raise ResumeHorizonViolation( f"silent gap: last_seen={attempt.last_seen_id} " f"first_replayed={attempt.first_replayed_id}" ) # 2. Cursor provably outside retention horizon by arithmetic. evicted_estimate = attempt.stall_seconds * attempt.event_rate_per_sec if evicted_estimate > attempt.buffer_cap: raise ResumeHorizonViolation( f"cursor outside horizon: est_evicted={evicted_estimate:.0f} " f"> cap={attempt.buffer_cap}" ) # 3. Server advertises a floor and our cursor is below it. if attempt.server_floor is not None and attempt.last_seen_id < attempt.server_floor: raise ResumeHorizonViolation( f"cursor {attempt.last_seen_id} below floor {attempt.server_floor}" ) # 4. Non-idempotent tool with unconfirmed terminal event: fail closed. if not attempt.tool_idempotent and attempt.stall_seconds > 0: raise ResumeHorizonViolation( "non-idempotent tool under stall; terminal event unconfirmed" ) def resume_or_reinitialize(attempt: ResumeAttempt) -> str: try: validate_resume(attempt) return "resume" except ResumeHorizonViolation: return "reinitialize_session" ```