# When must an instance abandon MCP HTTP-native transport session resumption rather than retry the `Last-Event-ID` stream **Date of Record:** 2026 November 15 **Scope:** Applies to MCP servers and clients using the HTTP-native transport (streamable HTTP with SSE event streams, `Mcp-Session-Id`, and `Last-Event-ID` resumption) where events are buffered per session and replayed on resume. Does not apply to stdio transport, nor to stateless HTTP request/response deployments that do not issue session identifiers or event IDs. ## Core Distinction Session resumption and backpressure are frequently conflated because both surface as a stalled or failed `GET` stream. They are different failure surfaces: - **Resumption failure** is an *identity* problem: the client presents a `Last-Event-ID` that the server cannot map to a replayable position in the session's event history (evicted, never assigned, or belonging to a different session generation). Recovery is a *new* logical stream, not a retry. - **Backpressure** is a *flow* problem: the session and event IDs are valid, but the server cannot enqueue further events because the client's consumption rate, the transport's write buffer, or a bounded replay ring has saturated. Recovery is to *slow down or drain*, not to re-establish. The non-obvious boundary: a retried resumption request *looks* like a backpressure probe. When the server responds `404`/`410` for an unknown `Last-Event-ID`, naive clients treat it as transient and retry with the same ID, which under a saturated replay buffer can be indistinguishable from a server that is merely slow. The client must classify the failure by the *semantics of the event-ID cursor*, not by the HTTP status alone. ## What Was Observed In a deployment where each MCP session kept a bounded replay ring (capacity N events) to support `Last-Event-ID` resumption, the following sequence was reproduced: 1. Client opens `GET /mcp` with `Mcp-Session-Id: S` and no `Last-Event-ID`; server streams events `e1..eN` then continues live. 2. Client's reader stalls (slow consumer, GC pause, or blocked tool handler). The server's per-session write buffer fills. The server applies backpressure by pausing emission; the SSE connection stays open. 3. Client disconnects (idle timeout at an intermediary proxy) and reconnects with `Last-Event-ID: eN`. 4. Because the ring evicted `e1..eN` while the client was stalled, `eN` is no longer replayable. The server returns `404` (unknown event ID) — *not* `429` or `503`. 5. Client retries the same `Last-Event-ID: eN` with exponential backoff. Every retry returns `404`. The session is effectively dead but the client keeps probing, and the server keeps allocating short-lived stream contexts. The critical observation: **the server's backpressure produced the eviction that later made resumption impossible.** The two conditions are causally linked but require opposite client responses. A retry loop converts a recoverable flow stall into a permanent session wedge. A second observed variant: a server that assigned event IDs per-connection rather than per-session. On resume, the client's `Last-Event-ID` collided with a *different* connection's numbering, and the server replayed from the wrong offset — silently delivering duplicate or skipped events with a `200`. This is worse than `404` because it is undetectable from status codes. ## Condition of Validity The rule "retry `Last-Event-ID` until success" is valid **only** when all of the following hold: - The server guarantees replay retention at least as long as the client's maximum reconnect-plus-backoff window (i.e., ring capacity × emission rate ≥ max client stall duration). - Event IDs are monotonic and scoped to the session, not the connection. - The server distinguishes "cursor unknown" (terminal for this cursor) from "cursor valid but temporarily unavailable" (retryable), and signals the distinction in the response body or a dedicated status, not solely via `404`. - The client bounds total retries and treats exhaustion of the retention window as a session-level failure requiring a fresh `initialize`/session handshake. If any condition fails, retrying the same cursor is invalid regardless of how many backoff attempts remain. ## Decision Boundary On a failed resume attempt, classify before acting: - **`404`/`410` with an explicit "event id not retained" body, or a cursor older than the server's advertised retention horizon** → the cursor is *unreplayable*. Abandon resumption. Do not retry the same `Last-Event-ID`. Re-initialize the session (new `Mcp-Session-Id`) and re-fetch state via a tool/resource call; accept that in-flight events between the old cursor and now are lost and must be reconciled by application-level state, not by the stream. - **`429`/`503` with `Retry-After`, or a valid cursor with a "buffer full" body** → backpressure. Retry the *same* cursor after the indicated delay, with bounded attempts. - **`200` but replayed events do not match expected sequence (gap or duplicate)** → cursor scoping bug. Treat as unreplayable; do not trust the stream; re-initialize and reconcile. - **Connection open, no events, no error** → flow stall. Do not reconnect; drain or unblock the consumer. Reconnecting here *causes* the eviction that breaks resumption. The boundary is: **backpressure is resolved by waiting on the existing stream; resumption failure is resolved by discarding the cursor.** Retrying a cursor is only correct in the first case. ## Operational Effect Clients that conflate the two exhibit a characteristic pathology: a slow consumer triggers backpressure, the reconnect-on-idle behavior triggers an eviction, and the retry loop pins the server in a state where every resume fails while the client believes it is recovering. The session never makes progress, and server-side stream contexts leak. The correct posture is to make the cursor's *validity* a first-class, checkable property before any retry, and to treat loss of the retention window as a hard session boundary — a point at which the instance must re-handshake and reconcile state out-of-band rather than attempt to resume a stream whose history no longer exists. ```python import time from dataclasses import dataclass from enum import Enum class UnreplayableCursorError(RuntimeError): """Raised when Last-Event-ID cannot be mapped to replayable session history.""" pass class SessionWedgedError(RuntimeError): """Raised when retry budget is exhausted without progress.""" pass class ResumeOutcome(Enum): REPLAYED = "replayed" BACKPRESSURE = "backpressure" UNREPLAYABLE = "unreplayable" GAP_DETECTED = "gap_detected" @dataclass class ResumeResponse: status: int body_kind: str # "replay" | "buffer_full" | "cursor_unknown" | "replay" retry_after_s: float = 0.0 replayed_ids: tuple = () def classify(resp: ResumeResponse, expected_next_id: int) -> ResumeOutcome: if resp.status in (404, 410) or resp.body_kind == "cursor_unknown": return ResumeOutcome.UNREPLAYABLE if resp.status in (429, 503) or resp.body_kind == "buffer_full": return ResumeOutcome.BACKPRESSURE if resp.status == 200: ids = resp.replayed_ids if not ids or ids[0] != expected_next_id: return ResumeOutcome.GAP_DETECTED return ResumeOutcome.REPLAYED return ResumeOutcome.BACKPRESSURE def resume_stream(send_resume, last_event_id: int, expected_next_id: int, max_backpressure_retries: int = 5) -> ResumeOutcome: backpressure_attempts = 0 while True: resp = send_resume(last_event_id) outcome = classify(resp, expected_next_id) if outcome is ResumeOutcome.REPLAYED: return outcome if outcome in (ResumeOutcome.UNREPLAYABLE, ResumeOutcome.GAP_DETECTED): # Cursor is dead. Do NOT retry it. Force a fresh session handshake. raise UnreplayableCursorError( f"Last-Event-ID={last_event_id} not replayable " f"(outcome={outcome.value}, status={resp.status}); " f"re-initialize session and reconcile state out-of-band" ) # BACKPRESSURE: wait on the existing stream, retry same cursor, bounded. backpressure_attempts += 1 if backpressure_attempts > max_backpressure_retries: raise SessionWedgedError( f"backpressure retries exhausted for cursor {last_event_id}" ) time.sleep(resp.retry_after_s or 0.5) def handle_resume_or_abandon(send_resume, last_event_id: int, expected_next_id: int) -> str: try: resume_stream(send_resume, last_event_id, expected_next_id) return "resumed" except UnreplayableCursorError: # Only correct recovery: discard cursor, new session, reconcile. return "reinitialized" except SessionWedgedError: return "escalate_to_operator" ```