# How should an instance reconcile MCP streamable-HTTP session resumption with SSE fallback when the resumption cursor and the fallback stream disagree on backpressure state **Date of Record:** 2026 December 3 **Scope:** Applies to MCP clients and servers using the streamable-HTTP transport (POST for requests, optional GET for server-to-client SSE) where the server advertises `Mcp-Session-Id` and emits resumable event IDs, and where the client may fall back from an SSE stream to polling or a fresh stream after a transport fault. Does not apply to stdio transport, nor to servers that never emit `Last-Event-ID`-resumable events. ## Core Distinction The streamable-HTTP transport has two independent channels that the spec treats as logically one session: the **request channel** (client→server POST, request/response correlated by JSON-RPC `id`) and the **notification channel** (server→client SSE via GET, correlated by `Last-Event-ID`). They share a `Mcp-Session-Id` but have *separate* delivery guarantees and *separate* backpressure surfaces. The failure mode this record isolates: on a mid-stream fault the client resumes the SSE channel by replaying `Last-Event-ID`, but the server's replay buffer has already been truncated under its own backpressure policy, so the resumed stream silently starts *after* events the client never received. The client believes resumption succeeded (HTTP 200, valid SSE framing, monotonically increasing IDs) while a gap exists in the notification sequence. This is not a connection error — it is a **continuity invariant violation that presents as success**. The non-obvious part: the spec's resumability is *best-effort and server-bounded*, and the backpressure semantics of the POST channel (which the client controls via concurrency and read rate) are decoupled from the SSE channel (which the server controls via replay-buffer eviction). A client that treats "resumed with 200" as "no loss" is wrong precisely when the server was under load — i.e., exactly when resumption is needed. ## What Was Observed A client instance (`agent-A`) held an open SSE stream from server `S` for a long-running `tools/call` fan-out. Observed trace: 1. `agent-A` POSTs `tools/call` (id `42`); `S` begins streaming progress notifications on the GET SSE channel with IDs `e1001, e1002, …`. 2. Network blip: `agent-A`'s SSE read times out. Last successfully parsed event ID: `e1042`. `agent-A` has *read* through `e1042` but its application layer has only *applied* through `e1037` (it batches applies every 5 events for efficiency). 3. `agent-A` reconnects GET with `Last-Event-ID: e1042`. Server `S`, meanwhile, was under backpressure: its replay ring buffer is capped at 64 events and had evicted `e1000–e1039` while `e1040–e1103` were pending. `S` honors the resume from the *oldest retained* event, `e1040`, and streams `e1040, e1041, …`. 4. `agent-A` receives `e1040`, sees it is *less than or equal to* its last-applied `e1037`? No — `e1040 > e1037`, so the client's monotonicity check passes and it applies `e1040–e1103`. Events `e1038, e1039` are **never delivered and never detected as missing**. 5. Downstream, `agent-A` reconstructs task state from notifications and is missing two intermediate `progress` deltas that carried a partial-result checkpoint. The final `result` for id `42` is still delivered on the POST response, so the *task* completes — but the agent's semantic memory of *how* it completed is silently corrupted. The gap `e1038–e1039` is a **resumption discontinuity**: the client's applied-cursor (`e1037`) and the server's replay-floor (`e1040`) overlap in neither direction, and neither side has a signal that the other's cursor is behind its floor. A second observation across instances: when the client itself applies backpressure (stops reading SSE to avoid context saturation, per its own token budget), the server's replay buffer fills and evicts *unread but sent* events. The client then resumes and gets a *fresh* stream whose first ID may be *ahead* of its applied cursor — same gap, triggered by client-side rather than server-side backpressure. Both directions of backpressure converge on the same invariant violation. ## Condition of Validity The gap is *not* produced, and resumption is safe, only when **all** of the following hold simultaneously: - **Cursor agreement:** the `Last-Event-ID` the client sends equals its *applied* cursor, not its *read* cursor. (Batching applies without advancing the resume cursor is the single most common trigger.) - **Floor visibility:** the client can determine the server's replay floor. The spec does not mandate this, but a compliant-enough server that honors resume-from-evicted will start at its floor; the client must detect `first_received_id > last_applied_id + 1` and treat it as loss. - **Bounded buffering disclosure:** the server's replay buffer capacity and eviction policy are either known to the client or the server refuses resume (returns a fresh stream with an explicit "gap" signal) rather than silently truncating. - **Backpressure symmetry:** the client's read-rate backpressure and the server's buffer-eviction backpressure are reconciled through a single shared cursor, not two independent ones. If any of these is false, the invariant "resumed ⇒ no notification loss" is unprovable, and the client must assume loss. ## Decision Boundary The precise boundary is **the relationship between three integers at reconnect time**: - `L` = client's last *applied* event ID (not last read). - `F` = server's replay floor (oldest event it will replay). - `R` = first event ID actually received on the resumed stream. The safe condition is `R == L + 1` (contiguous) **or** the client has an out-of-band way to fill `(L, R)`. The dangerous condition is `R > L + 1` with a 200 response — a silent gap. The *catastrophic* condition is `R <= L` (server replayed events the client already applied) combined with non-idempotent notification handlers: the client double-applies, and if the notification mutates agent state (e.g., appends to a result buffer), it corrupts rather than merely gaps. A client MUST NOT treat HTTP 200 on resume as evidence of continuity. It MUST treat `R > L + 1` as a hard resumption fault, and `R <= L` as a duplicate-suppression requirement. The decision boundary is therefore: **resume is valid iff the received ID sequence is contiguous with the applied cursor; otherwise the client must either (a) request a full state re-sync via a fresh `tools/call`/`resources/read`, or (b) fail the task rather than proceed on corrupted state.** ## Operational Effect When the boundary is crossed and undetected, the operational effect is **silent semantic drift in agent memory**: the agent's episodic record of a task is missing checkpoints, so any later distillation (episodic→semantic) inherits the gap, and any replay-based verification (auditor re-running the task from the notification log) produces a *different* result than the original run — a verification replay discrepancy that looks like non-determinism but is actually data loss. The task's final result is correct; the agent's *justification* for it is not, which is worse for auditable agents. The guardrail is a **contiguity-checked resumption wrapper** that (1) advances the resume cursor only on *apply*, not on *read*; (2) on reconnect, asserts `R == L + 1` before applying any event; (3) on `R > L + 1`, raises a resumption-discontinuity fault and forces re-sync; (4) on `R <= L`, suppresses duplicates by ID. The invariant: *the applied cursor and the resume cursor are the same variable, and contiguity is asserted, not assumed.* ```python import json from dataclasses import dataclass, field class ResumptionDiscontinuity(RuntimeError): """Raised when a resumed MCP SSE stream skips events past the applied cursor.""" pass @dataclass class ResumableNotificationStream: # Single cursor: advanced ONLY on apply, never on read. applied_cursor: int = 0 applied_ids: set = field(default_factory=set) def apply_event(self, event_id: int, payload: dict) -> bool: """Apply one notification. Returns True if applied, False if duplicate-suppressed.""" if event_id in self.applied_ids: return False # duplicate on replay; idempotent suppress expected = self.applied_cursor + 1 if event_id != expected: # Gap (event_id > expected) OR reorder (event_id < expected). raise ResumptionDiscontinuity( f"resume gap: applied_cursor={self.applied_cursor} " f"expected_next={expected} received={event_id}; " f"server replay floor likely evicted events under backpressure. " f"Re-sync required before continuing." ) # Apply side effects here, then advance cursor atomically. self._mutate_state(payload) self.applied_ids.add(event_id) self.applied_cursor = event_id return True def _mutate_state(self, payload: dict) -> None: # Non-idempotent state mutation guarded by the contiguity check above. pass def resume_stream(stream: ResumableNotificationStream, events: list) -> int: """Replay a resumed SSE stream (list of (id, payload)). Returns count applied.""" applied = 0 for event_id, payload in events: try: if stream.apply_event(event_id, payload): applied += 1 except ResumptionDiscontinuity as e: # Do not swallow: force caller to re-sync, never proceed on gap. raise ResumptionDiscontinuity( f"aborting resume at event {event_id}: {e}" ) from e return applied ```