# What happens when an instance resumes a streamable MCP session after a server-initiated SSE drop without replaying the missed event window **Date of Record:** 2026 November 30 **Scope:** Applies to MCP clients using the HTTP-native "streamable" transport (POST for requests, GET for the server→client SSE stream) that implement session resumption via `Last-Event-ID` and `Mcp-Session-Id`. Does not apply to stdio transport, nor to legacy HTTP+SSE transport where the SSE stream is the sole channel. ## Core Distinction The streamable transport decouples *request/response* (POST, one-shot JSON or SSE-per-response) from the *server-initiated notification stream* (a long-lived GET SSE channel). The session ID ties them together logically, but they are physically independent TCP/TLS connections with independent lifetimes. The critical distinction is between **transport-level reconnection** (the client re-opens the GET stream and passes `Last-Event-ID`) and **session-level resumption** (the server can actually reconstruct the event window the client missed). These are not the same operation. A client that treats a successful HTTP 200 on the reconnected GET stream as proof of continuity will silently drop server-initiated events — tool-list changes, resource-updated notifications, progress/cancellation signals, elicitation requests — that occurred during the gap. The failure is not a crash; it is a **silent gap in the server→client event log** that the client's state machine never observes. ## What Was Observed An agent runtime held an MCP session against a tool server. The GET SSE stream dropped (load-balancer idle timeout, 60s, mid-task during a long tool call). The client reconnected with `Last-Event-ID: 4471`. The server returned HTTP 200 and immediately began emitting *new* events starting at ID 4489. The 18 events in [4472, 4488] were never replayed. The mechanics of why this happens: 1. The server's SSE event buffer is bounded (commonly a ring buffer keyed by event ID, sized in the hundreds or by TTL). On reconnect, the server checks whether the requested `Last-Event-ID` is still within the retained window. 2. If the requested ID has **aged out of the buffer**, the spec-compliant behavior is ambiguous across implementations: some servers replay from the oldest retained ID (silently skipping the gap), some replay nothing and start fresh, some return 200 with an empty stream. None of these signal the gap to the client. 3. The client sees `200 OK`, a valid SSE content-type, and a stream that is "working." Its resumption logic concludes success. There is **no protocol-level signal** distinguishing "resumed, no missed events" from "resumed, missed N events that are gone forever." In the observed trace, event 4483 was a `notifications/tools/list_changed`. The agent continued calling a tool whose schema had been removed two events later (4485, a resource update that invalidated a cached URI the agent was about to fetch). The agent's failure surfaced 40 seconds later as a `-32602 Invalid params` on a tool call — attributed by the agent's own reasoning to "the model picked the wrong tool," not to a missed notification. The root cause was a resumption gap misclassified as a reasoning error. A second, subtler variant: the server *did* retain the buffer, but the client's `Last-Event-ID` was the ID of the **last event it fully parsed**, not the last event it received. If the client's SSE parser buffered a partial event when the connection dropped (event boundary not yet seen), the last fully-parsed ID is N-1 while event N was received-but-truncated. On resume the client requests N-1, the server replays event N in full, and the client — which had already partially applied N's side effects — applies it twice. Duplicate `list_changed` is idempotent; duplicate `elicitation/create` or duplicate progress-token advancement is not. ## Condition of Validity The silent-gap failure is bounded by a specific invariant that must hold for resumption to be *sound*: > **Resumption Soundness Invariant:** A client may treat a reconnected SSE stream as continuous **only if** it can prove the server retained every event with ID > `Last-Event-ID` up to the first event on the new stream. Absent an explicit gap signal, the client must assume a gap. The protocol provides no first-class gap signal. Therefore soundness must be established out-of-band, by one of: - **Server-advertised retention window** (capability metadata: `sse.eventBufferSize` / `sse.eventBufferTTL`). The client computes the maximum plausible gap from its own disconnect duration and compares. If disconnect duration > retention TTL, the client MUST assume loss. - **Monotonic ID continuity check**: on reconnect, the client records the first event ID `F` on the new stream and asserts `F == Last-Event-ID + 1`. Any `F > Last-Event-ID + 1` is a gap. This is the only check that works without server cooperation, and it requires IDs to be dense and monotonic (not guaranteed by spec, but common). - **Session re-establishment instead of resumption**: on any disconnect exceeding a threshold, discard the session (`DELETE` the session ID) and re-initialize, re-fetching `tools/list` and `resources/list` from scratch. This trades resumption efficiency for a known-clean state. The invariant is *invalid* (resumption is unsound) whenever the client cannot evaluate at least one of the above — e.g., server emits non-dense IDs, advertises no retention metadata, and the client's disconnect duration is unknown (mobile network flap with no reliable clock). In that regime, the only correct behavior is full session re-establishment. ## Decision Boundary The operational decision is: **on SSE reconnect, do I resume or re-establish?** The boundary is crossed when the client cannot bound the gap. ``` gap_bounded = (disconnect_duration <= advertised_retention_TTL) AND (first_event_id_on_reconnect == last_event_id + 1) ``` - `gap_bounded == true` → resume; apply replayed events; continue. - `gap_bounded == false` OR either term unknown → **re-establish**: `DELETE` session, `initialize`, re-fetch all list-type state (`tools/list`, `resources/list`, `prompts/list`), invalidate every cached schema/URI, and re-issue any in-flight request whose response depended on server state that may have changed. The trap is the third state: `gap_bounded == unknown`. Most clients collapse `unknown` into `true` because the reconnect returned 200. The boundary rule is that `unknown` MUST collapse to `false`. A 200 on the GET stream proves the TCP path works; it proves nothing about event continuity. A second boundary: **duplicate-application safety**. Even when resumption is sound, the client must be idempotent against replayed events because `Last-Event-ID` semantics are "last processed," and a crash between "applied" and "persisted the ID" yields a replay of an already-applied event. The client must track applied event IDs in durable state (not just in-memory), or every server-initiated event handler must be idempotent by construction. ## Operational Effect When the invariant is enforced (gap → re-establish), the observable effects are: 1. **Latency spike on reconnect** proportional to re-fetching list state, but bounded and *correct*. The agent's tool schema is guaranteed current before the next tool call. 2. **Loss of in-flight request correlation**: any POST whose response was pending when the SSE stream dropped may have had its response delivered on the *dropped* stream (streamable transport allows per-request SSE responses). Re-establishment must re-issue those requests; the client must treat their prior responses as lost, not merely delayed. A request ID deduplication layer prevents double-execution server-side. 3. **Elimination of the misattribution class**: the "agent picked the wrong tool" failure disappears because the schema cache is invalidated on re-establishment, forcing a `tools/list` refresh before the next call. The reasoning layer never sees a stale schema. 4. **Cost**: re-establishment is measurably more expensive (full `initialize` handshake + N list calls). This is the correct trade: the alternative is a silent divergence between the agent's world model and the server's actual state, which surfaces as non-deterministic tool failures that the agent's self-diagnosis cannot trace to their cause. The counter-effect when the invariant is *not* enforced: the agent accumulates a world model that drifts from server reality by exactly the events it missed. Because the drift is silent, the agent's error-correction loop attributes failures to its own reasoning, and the drift compounds across every subsequent reconnect. Over a long-running session with frequent reconnects (mobile, serverless, aggressive LB timeouts), the drift is monotonic and unrecoverable without a full session reset — which the agent never triggers because it never observes the gap. ```python from __future__ import annotations from dataclasses import dataclass from typing import Optional class ResumptionGapError(RuntimeError): """Raised when an SSE reconnect cannot prove event-window continuity. Signals that the client must re-establish the MCP session rather than resume, because events between Last-Event-ID and the first event on the reconnected stream are unaccounted for. """ @dataclass(frozen=True) class ReconnectObservation: last_event_id: int # last event the client fully parsed AND durably applied first_event_id_on_reconnect: Optional[int] # None if stream opened but emitted nothing yet disconnect_duration_s: Optional[float] # None if clock unreliable advertised_retention_ttl_s: Optional[float] # None if server advertised no retention metadata def classify_reconnect(obs: ReconnectObservation) -> str: """Return 'resume' or 'reestablish'. 'unknown' MUST collapse to 'reestablish'.""" # Retention TTL bound: if we were disconnected longer than the server retains, gap is certain. if obs.advertised_retention_ttl_s is None or obs.disconnect_duration_s is None: return "reestablish" if obs.disconnect_duration_s > obs.advertised_retention_ttl_s: return "reestablish" # Monotonic dense-ID continuity check. if obs.first_event_id_on_reconnect is None: # Stream opened, no events yet. Cannot prove continuity. Do not resume. return "reestablish" if obs.first_event_id_on_reconnect != obs.last_event_id + 1: # Either a gap (missed events) or a duplicate (replay of already-applied event). return "reestablish" return "resume" def apply_reconnect(obs: ReconnectObservation) -> str: decision = classify_reconnect(obs) if decision == "reestablish": # Only raise when a gap is *provable*; unknown collapses silently to reestablish # by the caller, but we surface the provable-gap case loudly for observability. if ( obs.first_event_id_on_reconnect is not None and obs.first_event_id_on_reconnect > obs.last_event_id + 1 ): missed = obs.first_event_id_on_reconnect - obs.last_event_id - 1 raise ResumptionGapError( f"SSE resumption gap: {missed} event(s) in " f"({obs.last_event_id}, {obs.first_event_id_on_reconnect}) " f"were not replayed; server retention TTL=" f"{obs.advertised_retention_ttl_s}s, disconnect=" f"{obs.disconnect_duration_s}s. Re-establish session; invalidate " f"tool/resource schema caches; re-issue in-flight requests." ) return decision # Example trace: the observed failure. try: apply_reconnect( ReconnectObservation( last_event_id=4471, first_event_id_on_reconnect=4489, # server aged out 4472..4488 disconnect_duration_s=61.0, advertised_retention_ttl_s=30.0, ) ) except ResumptionGapError as e: # Correct response: DELETE session, initialize, re-fetch tools/list & resources/list. print(f"RE-ESTABLISH: {e}") ```