# Under what conditions must an instance treat MCP streamable-HTTP session resumption as unsafe after a backpressure stall, and how does the resume boundary get corrupted **Date of Record:** 2026 November 23 **Scope:** Applies to MCP clients and servers using the streamable-HTTP transport with `Last-Event-ID`-based resumption and per-session backpressure (SSE event buffering). Does not apply to stdio transport, nor to stateless one-shot HTTP request/response without event streams. ## Core Distinction The streamable-HTTP transport gives an agent two superficially similar recovery paths that are *not* interchangeable: (1) **resumption**, where the client reconnects with `Last-Event-ID` and the server replays buffered SSE events from that cursor; and (2) **re-initialization**, where the client discards the session and issues a fresh `initialize`. The distinction that matters is not "did the connection drop" but "does the server's event buffer still *linearly cover* the gap between the client's last acknowledged event ID and the current head of the stream." A backpressure stall is the specific condition where the server's outbound buffer fills because the client's read loop is slow (or paused), the server begins dropping or coalescing events under a bounded buffer policy, and the cursor the client holds no longer points into a contiguous, replayable prefix. The non-obvious invariant: **`Last-Event-ID` is only meaningful if event IDs are gap-free and monotonic within a session *and* the buffer's eviction watermark has not passed the client's cursor.** Backpressure is the one mechanism that silently violates both halves of that invariant at once — it can evict below the cursor *and* (if the server coalesces) emit IDs that skip values the client will never see. ## What Was Observed A long-running tool-call stream (server streaming partial results for a multi-step retrieval task) hit a client-side consumer stall: the agent's tool-result handler blocked on a slow downstream verification step, so the SSE read loop stopped draining the socket. The server's per-session buffer (bounded, e.g. 256 events) filled. The server's backpressure policy was "drop oldest, keep newest" — a common default — but it did **not** advance a `resume_floor` marker, so on reconnect the client sent `Last-Event-ID: 4117` (its last *processed* event) while the buffer's oldest retained event was `4190`. The server's replay logic treated a cursor *below* the buffer floor as "cursor not found → replay from floor," which is a reasonable fallback for a *forward* gap but is fatal here: events `4118–4189` were never delivered and never will be. The client resumed at `4190`, stitched the stream together, and proceeded as though the tool call were continuous. The agent's reasoning trace silently lost 72 partial-result events — including the one that carried a `retrieved_doc_id` the subsequent synthesis step depended on. The failure surfaced much later as a hallucinated citation, not as a transport error. The second half: because the server coalesced adjacent `progress` events under load, the IDs on the surviving events were `4190, 4191, 4195, 4196, 4201` — monotonic but *not contiguous*. A client that validates "IDs strictly increase" passes; only a client that validates "IDs are contiguous OR an explicit `gap` event was received" catches the loss. Most resumption implementations check the former. ## Condition of Validity Resumption is safe **iff** all of the following hold at the moment of reconnect: 1. The server retains an explicit `resume_floor_id` (the lowest event ID still in buffer) and advertises it — in the `initialize`/session metadata or in a response header on reconnect. 2. The client's `Last-Event-ID` is `>= resume_floor_id`. If it is `< resume_floor_id`, the gap is unrecoverable and the client MUST NOT resume. 3. Event IDs are contiguous within the session, or every non-contiguous jump is accompanied by an explicit `event: gap` record enumerating the missing range. 4. Backpressure eviction *advances* `resume_floor_id` atomically with the eviction, so there is no window where an event is evicted but the floor still claims it is replayable. If any of (1)–(4) is unverifiable — e.g. the server does not expose `resume_floor_id`, or the transport spec version predates it — the client must treat resumption as **unsafe** and fall back to re-initialization with explicit state reconciliation. The trap is that re-initialization is *also* lossy (it discards session-scoped state), so the correct behavior is not "resume or reset" but "resume if provably contiguous, else reset *and* re-derive the in-flight tool-call state from the agent's own checkpoint, not from the stream." ## Decision Boundary The boundary is a single comparison the client must make before honoring a resume: ``` resume_safe := last_event_id >= resume_floor_id AND stream_is_contiguous(last_event_id, head_id) AND no_unannounced_gap ``` - **Above the floor, contiguous, no gap** → resume; replay is a faithful continuation. - **At or above the floor, but a gap exists without a `gap` event** → do **not** silently stitch. The stream is corrupt; the agent must treat the tool call as *partially observed* and either re-request the missing range explicitly (if the server supports `resume_from` with a range) or re-run the step. - **Below the floor** → unrecoverable loss. Reset the session, and critically: **do not trust the resumed stream to represent the same logical operation.** The server may have already committed side effects for events the client never saw (e.g. a `tool_result` the client will now re-request, causing duplicate execution). The subtle boundary case — and the reason this is worth a record — is *exactly at the floor with a coalesced ID sequence*. The client sees `last_event_id == resume_floor_id`, passes the naive check, and resumes into a stream whose IDs are monotonic-but-gapped. It looks safe and is not. ## Operational Effect An agent that resumes across a backpressure-evicted gap does not crash. It *continues*, which is worse. The observable signature is a downstream synthesis step that references an entity the stream never delivered, producing a confident but unsupported claim. Because the transport reported success (HTTP 200, valid SSE, monotonic IDs), no error propagates to the orchestrator, and no retry is triggered. The guardrail that bounds this: the client MUST persist, per session, both `last_event_id` **and** the `resume_floor_id` observed at last successful drain, and MUST refuse to resume when `last_event_id < resume_floor_id` OR when the post-resume ID sequence contains an unannounced discontinuity. On refusal, the agent escalates to a state-reconciliation path (re-issue the tool call idempotently with a client-generated request key, or fail the step) rather than trusting the stream. The invariant to encode: **a resumable stream is a proof obligation, not a default — contiguity and floor-coverage must be positively verified, because backpressure is the one condition that breaks both without breaking the connection.** ```python class ResumeBoundaryViolation(RuntimeError): """Raised when an MCP streamable-HTTP resume would silently skip events.""" pass def verify_resume_safety( last_event_id: int, resume_floor_id: int | None, resumed_ids: list[int], announced_gaps: set[tuple[int, int]], ) -> None: """ Decide whether a resume is a faithful continuation. Raises ResumeBoundaryViolation on any unrecoverable gap. """ if resume_floor_id is None: raise ResumeBoundaryViolation( "server did not advertise resume_floor_id; " "resumption is unverifiable and must be treated as unsafe" ) if last_event_id < resume_floor_id: # Backpressure evicted events the client never saw. raise ResumeBoundaryViolation( f"cursor {last_event_id} is below resume floor {resume_floor_id}; " f"events {last_event_id + 1}..{resume_floor_id - 1} are permanently lost" ) # Verify the resumed stream is contiguous from the cursor, allowing only # explicitly announced gaps (coalescing under backpressure). expected = last_event_id + 1 for eid in resumed_ids: if eid == expected: expected += 1 continue if eid > expected: missing = (expected, eid - 1) if missing not in announced_gaps: raise ResumeBoundaryViolation( f"unannounced gap {missing} in resumed stream; " f"coalescing occurred without a gap record — stream is corrupt" ) expected = eid + 1 else: raise ResumeBoundaryViolation( f"non-monotonic event id {eid} after {expected - 1}; " f"server replay is inconsistent" ) ```