# In what scenarios must an instance abandon MCP streamable-session resumption and force a fresh SSE negotiation after a `Last-Event-ID` replay gap **Date of Record:** 2026 November 26 **Scope:** Applies to MCP clients using the HTTP-native streamable transport with `Last-Event-ID`-based resumption against a server that also exposes the legacy SSE endpoint as a fallback. Does not apply to pure stdio transports or to servers that never emit event IDs. ## Core Distinction The failure is not "the stream dropped." Streams drop constantly and resumption is designed for that. The failure is a **silent replay gap**: the client reconnects with `Last-Event-ID: N`, the server accepts the request (HTTP 200), resumes the stream, and begins emitting events at `N+k` where `k > 1` — or begins emitting a *different* logical sequence entirely because the session was reaped and a new session was minted under the same resumption token namespace. The distinction that matters operationally: **a resumption that returns 200 is not a resumption that preserves continuity.** The transport layer's success signal (`200 OK` + open event stream) is orthogonal to the session-integrity invariant (every event between `Last-Event-ID` and the first replayed event was delivered exactly once, in order, to this logical session). Agents that treat "reconnect succeeded" as "state is continuous" will silently drop tool-call results, checkpoint acknowledgements, or partial-output deltas that lived only in the gap. ## What Was Observed A client agent held an MCP session over streamable HTTP, mid-way through a long `tools/call` whose result was being streamed as a sequence of `notifications/progress` events (event IDs 40–97) followed by a terminal `result` (event ID 98). The connection dropped at event 61 due to a load-balancer idle timeout (90s, no keepalive configured server-side). The client reconnected with `Last-Event-ID: 61`. The server returned `200` and immediately emitted an event with ID `88`. Three things had happened server-side and none were visible in the response: 1. The original session's event buffer had a bounded ring (capacity 32). Events 62–87 had been evicted to make room for 88–97 while the client was disconnected. 2. The server's resumption handler treated `Last-Event-ID: 61` as "resume from the oldest retained event ≥ 61," which was 88 — not "resume from 62 or fail." 3. The `result` at ID 98 arrived intact, so the client's terminal-state check passed. The agent assembled a final result that was missing the progress payloads 62–87. In this case those payloads carried intermediate token deltas that the client's reducer used to build the final artifact; the artifact was truncated by roughly 40% and the agent had no signal to detect it. The `result` event's own schema validation passed — it was internally consistent, just built on a hole. A second observed variant: after a server restart, the session registry was cold. The client's `Last-Event-ID: 61` referenced a session that no longer existed. The server, rather than returning `404`/`410`, minted a fresh session, assigned it the same ID namespace (because IDs were derived from a monotonic counter reset on boot), and began emitting from ID 1. The client received `200`, saw an event ID *lower* than its `Last-Event-ID`, and — because its resumption logic only checked "is the stream open" — appended the new events to the old buffer, producing an interleaved, non-monotonic event log. ## Condition of Validity Resumption via `Last-Event-ID` is only sound when **all four** of the following hold simultaneously: 1. **Monotonic, gap-free retention.** The server guarantees that if it retains event `M`, it retains every event in `[Last-Event-ID+1, M]`, or it refuses the resumption. A ring buffer that evicts from the middle-to-oldest while retaining newer events violates this. 2. **Session identity is stable across the reconnect.** The session token (not the event ID) is bound to a durable server-side record. A reaped-and-reminted session must not reuse the ID namespace. 3. **The first replayed event ID equals `Last-Event-ID + 1`.** This is the client's only cheap, local proof that no gap occurred. If the first event is `Last-Event-ID + 1`, the sequence is contiguous from the client's perspective; if it is greater, a gap exists *unless* the server explicitly signals "no events were produced in that range," which the streamable transport has no message type for. 4. **The `result`/terminal event does not independently validate.** If terminal events carry self-consistent schemas, a truncated stream still yields a schema-valid result. Continuity must therefore be checked on the *event sequence*, not on the terminal payload. When any of these fails, resumption is **not** a recovery operation — it is a silent corruption operation. The correct response is to abandon resumption, tear down the streamable session, and perform a fresh SSE negotiation to re-establish a clean session, accepting the cost of re-running any idempotent prefix of the task. ## Decision Boundary The client's resumption decision must be a **strict** check, not a permissive one. The boundary: - **Resume** iff the first event after reconnect has `id == last_event_id + 1` (contiguous) **and** the session token in the response headers matches the token held before the drop. Both conditions are local, cheap, and require no server cooperation beyond what the transport already sends. - **Abandon and renegotiate** iff the first event has `id > last_event_id + 1` (gap — buffer eviction or loss), **or** `id <= last_event_id` (namespace reuse after session reap — the dangerous case), **or** the session token changed, **or** the response is `200` but no event arrives within the resumption timeout (server accepted but has nothing to replay and is holding the stream open — a zombie resumption). - **Never** treat `200 OK` as evidence of continuity. The status code describes the HTTP request, not the session. The non-obvious part of this boundary: the `id <= last_event_id` case looks *safer* than the gap case — the events seem to "start over cleanly" — but it is strictly worse, because it silently merges two logical sessions into one client-side buffer. Agents that log event IDs will see a non-monotonic sequence and should treat any decrease as a hard session-integrity violation, not a resumption. ## Operational Effect An agent that enforces the strict boundary pays a bounded, visible cost: on any gap or namespace reuse, it discards the streamable session and opens a fresh SSE connection, which requires re-issuing the in-flight `tools/call` (or resuming from the last *application-level* checkpoint, if the tool is idempotent and checkpointed). This is slower and may duplicate work. An agent that does not enforce it pays an unbounded, invisible cost: truncated artifacts, interleaved event logs, and results that pass schema validation while being semantically wrong. The failure surfaces downstream — in a later agent consuming the corrupted artifact, or in an auditor replaying the event log and finding a discontinuity the origin agent never flagged. The invariant to encode: **event-stream continuity is a property of the sequence, not of the connection.** The connection can succeed and the sequence can be broken. Only the sequence check — `first_replayed_id == last_seen_id + 1`, monotonic thereafter, same session token — authorizes continued use of the session. Everything else is a fresh negotiation. ```python import time from dataclasses import dataclass, field from typing import Optional class SessionContinuityViolation(RuntimeError): """Raised when a streamable-session resumption cannot be proven gap-free.""" @dataclass class StreamState: session_token: str last_event_id: int = 0 seen_ids: list = field(default_factory=list) def resume_or_renegotiate( state: StreamState, response_session_token: str, first_event_id: Optional[int], resumption_timeout_s: float = 5.0, waited_s: float = 0.0, ) -> str: """ Decide whether to continue the existing streamable session or abandon it for a fresh SSE negotiation. Returns "resume" or "renegotiate". Raises SessionContinuityViolation when the transport reports success but the sequence is provably broken and the caller has not opted into renegotiation. """ # Session identity must be stable across the reconnect. if response_session_token != state.session_token: raise SessionContinuityViolation( f"session token changed on resumption: " f"held={state.session_token!r} got={response_session_token!r}" ) # No event arrived within the resumption window: zombie resumption. if first_event_id is None: if waited_s >= resumption_timeout_s: return "renegotiate" raise SessionContinuityViolation( "resumption accepted but no replay event within timeout" ) # Namespace reuse after session reap: event id went backwards. if first_event_id <= state.last_event_id: raise SessionContinuityViolation( f"event id regressed: last={state.last_event_id} " f"first_replayed={first_event_id} (session namespace reuse)" ) # Gap: events between last_event_id+1 and first_event_id were lost. if first_event_id > state.last_event_id + 1: # Unprovable continuity; caller must renegotiate, not resume. return "renegotiate" # Contiguous: first_event_id == last_event_id + 1. return "resume" def apply_resumption(state: StreamState, decision: str, new_token: str) -> StreamState: if decision == "resume": return state if decision == "renegotiate": # Fresh SSE negotiation: new session, reset sequence, re-run prefix. return StreamState(session_token=new_token, last_event_id=0, seen_ids=[]) raise SessionContinuityViolation(f"unknown decision {decision!r}") ```