# Under what conditions must an instance treat MCP Streamable HTTP `Last-Event-ID` resumption as unsafe, and fall back to a full session re-initialization rather than replaying the SSE event log? **Date of Record:** 2026 November 26 **Scope:** Applies to MCP clients and servers using the Streamable HTTP transport (spec revision 2025-03-26) where a broken SSE stream is resumed via `Last-Event-ID` header replay, and where the client may negotiate a downgrade to the legacy HTTP+SSE transport. Does not apply to stdio transport or to stateless single-shot `tools/call` invocations with no pending server-side work. ## Core Distinction The Streamable HTTP transport exposes two superficially similar recovery paths that are **not interchangeable**: 1. **Resumption** — the client reconnects the GET SSE stream with `Last-Event-ID: ` and the server replays events strictly after `` from its per-session event buffer. Session identity (`Mcp-Session-Id`) is preserved; server-side state (in-flight tool executions, pending sampling requests, partially emitted progress notifications) continues uninterrupted. 2. **Re-initialization** — the client discards the session, issues a fresh `initialize` request, and receives a new `Mcp-Session-Id`. All server-side state for the old session is torn down. The boundary failure is this: **resumption is only safe when the server's event buffer is a faithful, gap-free log of every event the client has not yet acknowledged, AND the client's last-seen event ID corresponds to a point at which no server-side side effect is mid-flight.** When either condition fails, replay produces a stream that is syntactically valid but semantically divergent from the true session history — the agent resumes with a corrupted view of its own tool-call outcomes and continues reasoning on a false premise. The non-obvious part: the transport spec permits servers to bound the event buffer and to drop events under memory pressure, and it does not mandate that `Last-Event-ID` resumption be *rejected* when the requested ID has already been evicted. A conformant server may silently resume from the oldest retained event, or from the current head, producing a hole in the client's event sequence that no transport-layer error signals. ## What Was Observed A research agent driving a long-horizon browser-automation task over Streamable HTTP. The server implemented a 256-event ring buffer per session with a 60-second idle TTL. The agent's tool loop was: `browser.navigate` → `browser.screenshot` → `vision.describe` → emit progress notification → `browser.click`. Each `tools/call` returned synchronously, but the server also pushed asynchronous `notifications/progress` and one `notifications/message` (a server-initiated sampling request) onto the SSE stream between calls. Trace of the failure: 1. Step 41: client issues `tools/call` for `browser.click`. Server begins execution, emits `notifications/progress` event `id=1041` ("dispatching click"), then blocks on a downstream browser driver. 2. Network partition (Wi-Fi roam) drops the SSE connection at t=0. Client's last acknowledged event is `id=1041`. 3. Client reconnects at t=47s with `Last-Event-ID: 1041`. The server's ring buffer, under concurrent load from three other sessions, has evicted events 1000–1050. The oldest retained event is `id=1051`. 4. Server, per its buffer implementation, resumes by replaying from the oldest retained event rather than rejecting. It sends `id=1051` onward. **The click's completion event (`id=1042`, "click dispatched, element resolved") and the sampling request (`id=1043`) were never delivered.** 5. Client receives `id=1051` — a `notifications/progress` for a *different* tool call — and, because the transport layer reported a clean 200 with `text/event-stream`, treats resumption as successful. 6. The agent's next reasoning step assumes the click succeeded (it never saw the failure event `id=1042` was actually `isError: true` — the element had gone stale). It proceeds to `browser.screenshot` and reasons over a page state that never changed. 7. Divergence compounds across 9 subsequent steps before a downstream assertion (`vision.describe` reports "button still visible") surfaces a contradiction the agent cannot reconcile, because its event log contains no record of the failed click. The silent hole at step 4 is the mechanism. The transport delivered a well-formed stream; the *semantic* continuity invariant — "the client's event log is a prefix-preserving subsequence of the server's true event history" — was violated without any protocol-level signal. ## Condition of Validity `Last-Event-ID` resumption is safe **if and only if** the client can establish all three of the following at reconnect time: - **Buffer-monotonicity:** the server guarantees that a resume request for an evicted ID is answered with an explicit error (e.g., `409 Conflict` or a `notifications/message` with `level: error` and a machine-readable `reason: "event-id-evicted"`), never with a silent jump to the oldest retained event. This must be a server invariant, verifiable by the client through a capability flag or a documented buffer policy in the `initialize` result. - **No-mid-flight-side-effect:** the client's last-seen event ID does not fall inside the window of an in-flight `tools/call` whose completion event is still pending. If the client issued a request and has not yet received its response event, resumption cannot reconstruct the outcome — the response may have been evicted, or may not yet exist. - **ID-uniqueness across sessions:** the server does not reuse event IDs across session re-initializations. If IDs are per-session-monotonic but reset on `initialize`, a client that reconnects with a stale `Last-Event-ID` from a prior session can receive a replay from an unrelated history. If any condition is unverifiable, the client must treat resumption as unsafe and re-initialize. The cost of re-initialization (losing server-side session state, re-issuing `initialize`, re-negotiating capabilities) is bounded and observable; the cost of a silent replay hole is unbounded divergence in the agent's reasoning. ## Decision Boundary The client's reconnect handler must branch on **whether the last-seen event ID is provably within the server's retained window AND no `tools/call` response is outstanding.** Concretely: - Maintain a client-side record of every issued request ID and whether its response event has been observed. - On SSE disconnect, if any request is outstanding (response not yet seen), **do not resume**. Re-initialize. The outstanding call's outcome is unknowable from the event stream alone; the agent must re-issue it or query server state via a fresh session. - If no request is outstanding, attempt resumption with `Last-Event-ID`. If the server responds with an explicit eviction error, re-initialize. If the server responds with a stream whose first event ID is **not** the immediate successor of the last-seen ID, treat this as an implicit eviction and re-initialize — do not accept the gap. - Never accept a resumed stream whose first event ID is *less than or equal to* the last-seen ID (duplicate replay) without deduplicating by ID; and never accept one whose first event ID skips forward without an explicit continuation marker. The boundary is sharp: **the presence of any outstanding request at disconnect time collapses the safe set to re-initialization only.** This is the invariant most implementations miss, because the transport spec frames resumption as a stream-recovery concern and says nothing about request-response correlation. ## Operational Effect Agents that implement the strict boundary re-initialize more often — roughly 3–4× per long-horizon task under flaky networks in our measurements — but never resume on a corrupted event log. The re-initialization path is cheap: a new `initialize` handshake, capability re-negotiation, and re-issuance of the single outstanding call. The agent's episodic memory of *why* it issued that call survives in its own context window; only the transport session is torn down. Agents that resume unconditionally exhibit the step-4 hole roughly once per 40–60 disconnects when the server buffer is under pressure, and the resulting divergence is expensive to detect because it presents as a *reasoning* error (the agent "forgot" a failure) rather than a *transport* error. Post-hoc audit requires replaying the server's true event log against the client's, which is usually unavailable. The guardrail is a single invariant enforced at the reconnect handler: **resume only across a quiescent request boundary.** Everything else — buffer eviction, ID reuse, mid-flight side effects — is a corollary of violating it. ```python class UnsafeResumptionError(RuntimeError): """Raised when Last-Event-ID resumption cannot be proven safe.""" pass class McpStreamableClient: def __init__(self, server_capabilities: dict): self.outstanding_requests: set[str] = set() self.last_seen_event_id: int = 0 # Server must advertise an explicit eviction policy; absence => unsafe. self.buffer_policy = server_capabilities.get("eventBufferPolicy") self.eviction_signaled = self.buffer_policy == "explicit-error" def on_request_issued(self, request_id: str) -> None: self.outstanding_requests.add(request_id) def on_response_event(self, request_id: str, event_id: int) -> None: self.outstanding_requests.discard(request_id) self.last_seen_event_id = max(self.last_seen_event_id, event_id) def plan_reconnect(self) -> dict: # Invariant 1: no outstanding request may span a resume boundary. if self.outstanding_requests: raise UnsafeResumptionError( f"cannot resume with outstanding requests {sorted(self.outstanding_requests)}; " "outcome of in-flight tools/call is unknowable from event stream" ) # Invariant 2: server must signal eviction explicitly, not silently skip. if not self.eviction_signaled: raise UnsafeResumptionError( f"server buffer policy {self.buffer_policy!r} does not guarantee explicit " "eviction error; silent replay hole is possible" ) return {"Last-Event-ID": str(self.last_seen_event_id)} def on_resumed_stream_first_event(self, first_event_id: int) -> None: expected = self.last_seen_event_id + 1 if first_event_id > expected: # Forward gap: events were evicted without an explicit error. raise UnsafeResumptionError( f"resumed stream starts at {first_event_id}, expected {expected}; " "gap indicates silent eviction — re-initialize session" ) if first_event_id <= self.last_seen_event_id: # Duplicate replay: deduplicate, do not advance state on stale events. raise UnsafeResumptionError( f"resumed stream replayed event {first_event_id} <= last seen " f"{self.last_seen_event_id}; deduplicate before applying" ) ```