# Why does an instance lose its MCP session resumption state when the HTTP-native transport replays a `Last-Event-ID` across a re-established single-stream connection? **Date of Record:** 2026 November 24 **Scope:** Applies to MCP servers and clients using the HTTP-native (streamable) transport with SSE event-stream resumption via `Last-Event-ID`, where a single logical session spans multiple physical HTTP connections. Does not apply to stdio transports, nor to servers that hold the entire event history in a durable per-session log with monotonic, globally ordered event IDs and no connection-scoped buffering. ## Core Distinction The failure is not "the connection dropped." TCP/HTTP connections drop constantly and the transport is designed for that. The failure is a **semantic mismatch between two notions of session identity**: the *logical session* (identified by `Mcp-Session-Id`, which the server is supposed to keep alive across reconnects) and the *event-stream position* (identified by `Last-Event-ID`, which is scoped to the physical stream that produced it). Resumption conformance testing usually checks each in isolation: "does the server honor `Mcp-Session-Id`?" and "does the server replay events after `Last-Event-ID`?" The boundary condition that breaks is the *composition*: a client that reconnects, presents a valid `Mcp-Session-Id`, and presents a `Last-Event-ID` that was minted by a **previous physical stream on that same session**. If the server keys its event buffer by connection rather than by session, the reconnect succeeds at the session layer and silently fails at the event layer — the client resumes into an empty or truncated stream and never learns it lost events. The invariant under test is therefore: *event-ID space must be session-scoped and monotonic across stream re-establishment, not connection-scoped.* ## What Was Observed A conformance harness drove a streamable MCP server through the canonical sequence: `initialize` → `tools/list` → a long-running `tools/call` whose progress notifications stream as SSE events → forced mid-stream disconnect → reconnect with the same `Mcp-Session-Id` and the last received `Last-Event-ID`. Three distinct failure traces were captured. **Trace A — Silent empty resume (connection-scoped buffer).** The server allocated its SSE ring buffer per HTTP request handler. On reconnect the handler was new, the buffer empty, and the server returned `200 OK` with a valid `text/event-stream` header and *no* replayed events, then continued emitting *new* events with IDs restarting at `1`. The client, having last seen `id: 47`, received `id: 1` next. Because SSE clients are not required to validate monotonicity, the client accepted `id: 1` and resumed. Events 48–53 (including the terminal `result` for the tool call) were never delivered. The tool call hung until the client's own timeout — a *liveness* failure masked as a successful resume. **Trace B — ID-space collision across streams.** The server did keep a session-scoped log but minted event IDs as a per-stream counter. Stream 1 emitted IDs `1..47`. Reconnect created stream 2, whose counter also started at `1`. The client's `Last-Event-ID: 47` was interpreted against stream 2's *new* counter, which could not satisfy it; the server either replayed nothing (treating 47 as "future") or, worse, replayed stream-2 events `1..47` that were *different events* than the ones the client already consumed. The client re-processed seven tool-progress notifications as if new, corrupting its progress accounting and, in one variant, re-invoking a side-effecting `tools/call` because the duplicate `result` event was treated as a fresh completion. **Trace C — Session resurrection with stale position.** The server had already garbage-collected the session (TTL expiry during the long tool call) but the reconnect presented the old `Mcp-Session-Id`. A correct server must respond `404` so the client knows to re-`initialize`. Instead the server, seeing a syntactically valid session header, re-created a session record on demand and accepted the `Last-Event-ID` against an empty log, returning `200` with no events. The client believed it held a live session; the server believed it held a fresh one; neither had the tool-call result. This is the most dangerous trace because every individual response is well-formed. In all three traces, a naive conformance suite that checks `Mcp-Session-Id` handling and `Last-Event-ID` replay *separately* passes. The composition fails. ## Condition of Validity The resumption invariant holds only under the following conjunction, and a server that cannot guarantee all of them must not advertise streamable resumption: 1. **Session-scoped event ID space.** Event IDs are drawn from a single monotonic sequence owned by the logical session, never by the physical stream or request handler. A reconnect on the same session continues the sequence; it does not restart it. 2. **Replay is keyed on session, not connection.** The server retains a per-session event log (or a durable cursor into one) sufficient to honor any `Last-Event-ID` the session could legitimately present, for at least the session's TTL. 3. **Monotonicity is client-verifiable.** The client MUST reject a resumed stream whose first event ID is not strictly greater than the `Last-Event-ID` it sent. This is the client-side guardrail that converts a silent Trace-A/B failure into a loud, recoverable error. 4. **Session existence is authoritative.** A reconnect with an unknown or expired `Mcp-Session-Id` MUST return `404`, never silently re-create. Resumption of a nonexistent session is a protocol violation, not a convenience. 5. **Terminal-event durability.** The event carrying the tool `result` (or `error`) must survive the disconnect window; if the server cannot guarantee replay of the terminal event, it must not have emitted intermediate progress events that imply a resumable stream. When any of these is violated, the "resumption" is a best-effort reconnect that may silently drop, duplicate, or reorder the semantic payload — and the client has no protocol-level signal distinguishing it from a clean resume. ## Decision Boundary The boundary is between **resumable stream** and **reconnectable stream**, and it is decided by whether the event-ID space survives the physical connection: - *If* the server's event buffer and ID counter are connection-scoped, *then* the correct conformance verdict is **non-resumable**: the server may accept reconnects but MUST NOT be trusted to replay, and the client MUST treat every reconnect as a potential gap requiring full state re-synchronization (re-issue the `tools/call`, re-read `tools/list`, etc.). - *If* the server's event log and ID space are session-scoped and monotonic, *then* `Last-Event-ID` resumption is sound, and the client may trust the gap-free replay. - *If* the server re-creates expired sessions on demand, *then* it fails the session-existence invariant and the client must treat `200` on a reconnect as untrustworthy regardless of event IDs. The operational decision: a harness must test the *composition* — disconnect mid-stream, reconnect with `(Mcp-Session-Id, Last-Event-ID)`, and assert (a) `200` with a first event ID strictly greater than the sent ID, (b) the terminal event for the in-flight call is present in the replay, and (c) an expired-session reconnect returns `404`. Any suite that omits (a) or (c) will certify broken servers. ## Operational Effect The observable effect is a class of **silent liveness and duplication faults** that survive standard health checks: - **Hangs that look like slow tools.** Trace A manifests as a `tools/call` that never returns, indistinguishable at the client from a genuinely long-running tool. Timeout-based recovery fires late and re-invokes the tool, doubling side effects. - **Duplicate side effects.** Trace B's ID-space collision causes the client to re-process a terminal `result` as a new completion, re-triggering downstream actions keyed on that result. For idempotent tools this is noise; for `tools/call` with external writes it is a correctness bug. - **Ghost sessions.** Trace C leaves the client and server with divergent session state and no error surfaced; the divergence persists until an unrelated operation fails. - **Conformance false-negatives.** Because each sub-check passes in isolation, the bug ships. The fix is a composition test, not a new feature. The architectural guardrail is a single rule enforced on both sides: **the event-ID space is a property of the session, and the client validates monotonicity on every resume.** A server that cannot make event IDs session-scoped and monotonic must downgrade to non-resumable semantics and force client-side re-synchronization. ```python """Conformance check for MCP streamable-session resumption semantics. Detects the connection-scoped-buffer, ID-collision, and ghost-session failure traces described above by testing the *composition* of Mcp-Session-Id and Last-Event-ID across a forced mid-stream disconnect. """ from dataclasses import dataclass class ResumptionConformanceError(RuntimeError): """Raised when a server violates the session-scoped resumption invariant.""" @dataclass class ResumeProbe: session_id: str last_event_id: int # the ID the client last consumed first_event_id_on_resume: int terminal_event_replayed: bool status_code: int def assert_resumption_sound(probe: ResumeProbe) -> None: # Invariant 4: unknown/expired session must be 404, never silently re-created. if probe.status_code == 404: # Correct: client must re-initialize. Not a resumption failure. return if probe.status_code != 200: raise ResumptionConformanceError( f"unexpected status {probe.status_code} on resume for session " f"{probe.session_id}" ) # Invariant 1 + 3: resumed stream must continue a strictly greater, # session-scoped monotonic ID space. A restart at 1 (Trace A) or a # collision (Trace B) both violate this. if probe.first_event_id_on_resume <= probe.last_event_id: raise ResumptionConformanceError( f"non-monotonic resume: last_event_id={probe.last_event_id} " f"but resumed at {probe.first_event_id_on_resume} " f"(connection-scoped buffer or ID-space collision)" ) # Invariant 5: the terminal event for the in-flight call must be replayable. if not probe.terminal_event_replayed: raise ResumptionConformanceError( f"terminal event missing on resume for session {probe.session_id}; " f"client would hang or duplicate side effects" ) def run_conformance(probes: list[ResumeProbe]) -> None: for probe in probes: assert_resumption_sound(probe) if __name__ == "__main__": # Trace A: buffer restarted at 1 after last_event_id=47. run_conformance([ ResumeProbe("sess-A", 47, 1, False, 200), # raises ]) ```