# Where must an instance reconcile streamable-session resumption against backpressure-induced event loss in MCP HTTP-native transport **Date of Record:** 2026 November 24 **Scope:** Applies to MCP servers and clients using the HTTP-native "streamable" transport (SSE-over-POST with `Mcp-Session-Id` and `Last-Event-ID` resumption) where the server can emit events faster than the client drains them. Does not apply to stdio transports, to pure request/response MCP calls without streaming, or to transports where the server buffers unboundedly on behalf of a slow client. ## Core Distinction The distinction that matters is between **resumption as replay** and **resumption as reconciliation**. The MCP streamable transport spec lets a client reconnect with `Last-Event-ID` so the server can "replay" missed events. Implementers frequently read this as a guarantee that no event is lost: the client acknowledges up to event *N*, drops the connection, reconnects, and expects events *N+1…* to arrive in order. But backpressure changes the meaning of `Last-Event-ID`. Under backpressure the server does not have an infinite outbox. When a slow client's TCP/SSE buffer fills, the server must either (a) block the producer, (b) drop events, or (c) evict the session. The spec does not mandate which, and the "resume" path only works if the server retained the evicted events. The non-obvious failure is this: **the last event ID the client successfully processed is not the same as the last event ID the server durably retained.** A client that reconnects with `Last-Event-ID: N` may be told "resume from N+1" by a server that has already discarded N+1 through N+k under memory pressure, and the client will happily accept the gap because the transport layer reports a clean resume. The invariant that must hold — and that the transport alone does not enforce — is: *the set of events between the client's last-processed ID and the server's resume point must be empty, or the resume must be declared lossy.* ## What Was Observed A tool-calling agent session over streamable HTTP, server emitting `notifications/tools/list_changed`, `notifications/resources/updated`, and streaming partial tool results. Client consumed events slowly because each `tools/call` result triggered a synchronous local re-plan (median 400 ms per event). Server outbox was a bounded ring buffer of 256 events per session, with a documented "drop-oldest on overflow" policy — a reasonable backpressure choice that was never surfaced to clients. Trace of the failure: 1. Client processed through event `eid=1041`, wrote it to its checkpoint, and began a 400 ms re-plan. 2. During that window the server produced 300 events (a burst of resource updates from a watched filesystem). The 256-slot ring buffer overflowed; events `1042`–`1085` were dropped to make room. Retained range became `1086`–`1341`. 3. Client's connection hit a 30 s idle timeout during a long tool call; it reconnected with `Last-Event-ID: 1041`. 4. Server's resume handler looked up `1041`, found it absent from the ring, and — because the spec's "replay" is advisory — fell back to "resume from current head," emitting `1086` onward with no gap marker. 5. Client received `1086` with `Last-Event-ID` continuity appearing intact (IDs are monotonic, so `1086 > 1041` looked like normal progress). It processed 44 events it believed were contiguous with its state. 6. The 44 dropped events included three `tools/list_changed` notifications. The client's tool registry was now stale relative to the server. A subsequent `tools/call` referenced a tool the server had removed; the server returned `-32601 Method not found`, which the agent's planner interpreted as a transient error and retried three times before aborting the subtask. The observable symptom was a tool-not-found storm, not a transport error. Nothing in the transport layer reported the gap. The agent's episodic memory recorded a clean session with an unexplained mid-task failure. ## Condition of Validity The reconciliation requirement is valid — i.e., the naive resume is unsafe — precisely when all of the following hold: - The server's outbox is **bounded** (ring buffer, TTL eviction, or per-session byte cap). Unbounded outboxes make the gap impossible but are themselves a memory-exhaustion vector. - The server can produce events **faster than a client drains them** for at least one burst window (bursty resource watches, fan-out tool results, multi-agent subscription storms). - The client's **checkpoint granularity is coarser than event granularity** — it records "last processed ID" but not "the semantic state implied by the full prefix." If the client could reconstruct state from a snapshot keyed to an ID, a gap would be detectable. - Event IDs are **monotonic but not gapless** (typical: a counter that skips on drop). If IDs were strictly contiguous, a client could detect `1086 - 1041 > 1` as a gap. Most implementations use monotonic-but-dense IDs and therefore *cannot* signal loss through arithmetic alone. When any condition fails — e.g., the server retains a full replay log, or the client checkpoints a full state snapshot per ID — the gap is either impossible or detectable, and plain `Last-Event-ID` resumption is sufficient. The failure lives in the intersection of bounded outbox + bursty producer + coarse client checkpoint + non-contiguous IDs. ## Decision Boundary The boundary an operator must draw is between **resume-as-continuation** (safe only when the server can prove the prefix is intact) and **resume-as-new-epoch** (the correct default when it cannot). Concretely, the server must choose one of two contracts and advertise it: - **Continuity contract:** server retains a replay log covering the maximum client disconnect window, and on resume either replays the exact missing range or returns an explicit `Resume-Gap` error with the range `[last_seen+1, retained_head-1]`. The client MUST treat a gap error as a signal to invalidate all state derived from the missing range (re-fetch tool lists, re-read resources, discard partial results) before continuing. - **Epoch contract:** server assigns a new `Mcp-Session-Id` (or bumps an epoch counter) whenever it evicts events. The client sees a new session/epoch and MUST perform a full state re-sync rather than resuming. This is cheaper to implement and is the correct default for bounded outboxes. The failure mode in "What Was Observed" arose because the implementation silently chose *neither*: it kept the same session ID and the same monotonic counter, but dropped events. That is the one combination that is always wrong. The decision rule: **if eviction can occur, the session identity or the ID space must change at the eviction boundary, or the gap must be explicitly reported.** ## Operational Effect Downstream of this boundary, the agent's failure surface shifts from "transport error" to "silent state divergence." The operational consequences: - **Stale capability registry.** Dropped `list_changed` notifications leave the client's tool schema out of sync; subsequent calls fail with method-not-found or, worse, succeed against a stale schema and produce schema-mismatched arguments. - **Retry amplification.** Because the gap is invisible, the agent's error-handling treats the resulting failures as transient and retries, burning token budget and tool-call quota on a subtask that cannot succeed until state is re-synced. - **Checkpoint poisoning.** If the client checkpoints `Last-Event-ID: 1086` after the gap, a later crash-and-resume will resume from a point whose prefix is corrupt; the corruption is now durable across restarts. - **Auditor disagreement.** In multi-agent setups, a peer that did *not* experience the gap holds a coherent view; the diverged agent's reports conflict with the peer's, and consensus logic that trusts "monotonic event IDs" will side with the wrong state. The guardrail is not "make the outbox bigger." It is to make eviction observable: surface gaps as first-class errors, or rotate session identity on eviction, and require the client to re-sync on either signal. ``` ```python class SessionResumeGapError(RuntimeError): """Raised when a streamable-session resume cannot prove prefix continuity.""" def __init__(self, last_seen: int, retained_head: int, session_id: str): self.last_seen = last_seen self.retained_head = retained_head self.session_id = session_id super().__init__( f"session {session_id}: requested resume from {last_seen}, " f"server retained only from {retained_head} " f"(gap of {retained_head - last_seen - 1} events)" ) def resume_stream(session, last_event_id: int): """ Reconcile a client's Last-Event-ID against the server's retained range. Returns (resume_from, is_lossy). Raises SessionResumeGapError if the server cannot prove continuity under the continuity contract. """ retained = session.retained_range() # (head, tail) of outbox, inclusive if retained is None: # Epoch contract: no retained history -> force full re-sync. return (None, True) head, tail = retained if last_event_id < head: # Prefix requested is gone. Under continuity contract this is a # hard error; the client must invalidate derived state. if session.contract == "continuity": raise SessionResumeGapError(last_event_id, head, session.id) # Epoch contract: signal lossy resume, caller must re-sync. return (head, True) if last_event_id > tail: # Client claims to have processed an event the server never emitted. raise SessionResumeGapError(last_event_id, head, session.id) return (last_event_id + 1, False) def apply_resume(session, last_event_id: int, client_state): resume_from, lossy = resume_stream(session, last_event_id) if lossy: # Invalidate tool registry, resource cache, partial results. client_state.invalidate_all() client_state.re_sync(session) # Only now is it safe to consume events from resume_from onward. for event in session.events_from(resume_from): client_state.apply(event) return client_state ```