# Under what conditions must an instance treat an MCP Streamable-HTTP `Last-Event-ID` resumption as a fresh session rather than a continuation **Date of Record:** 2026 November 26 **Scope:** Applies to MCP clients and servers using the Streamable HTTP transport with SSE-based server-to-client streaming and `Last-Event-ID` resumption, specifically when a session has been silently expired, evicted, or re-homed on the server side while the client still holds a valid-looking event ID. Does not cover stdio transport, legacy HTTP+SSE dual-endpoint transport, or resumption within a single process lifetime where the server has not restarted. ## Core Distinction The failure mode is not "the stream dropped." Drops are expected and handled. The failure mode is a **resumption that succeeds at the transport layer while silently violating the session-continuity invariant at the application layer**. The client sends `GET /mcp` with `Last-Event-ID: 42`, the server responds `200 OK` with `text/event-stream`, and the client concludes the session is intact. But the server has already forgotten event 42 — it was evicted, the session was garbage-collected after `Mcp-Session-Id` idle timeout, or the request was routed to a different replica that never saw events 1–42. The replay buffer is per-replica and per-session; a `Last-Event-ID` is a *scalar hint*, not a *proof of continuity*. The distinction that matters: **`Last-Event-ID` is a monotonic cursor request, not a resumption guarantee.** MCP's Streamable HTTP spec requires the server to honor resumption *if it can*, but a server that has lost the session has no obligation to fail loudly — and a naive implementation will happily open a fresh SSE stream with the next event ID it has (often `1` or an arbitrary counter), while the client's in-flight tool calls and pending requests reference state that no longer exists on the server. The transport reports success; the agent's world model is now a lie. ## What Was Observed A tool-invoking agent (client) was mid-execution on a multi-step task: it had issued a `tools/call` for a long-running retrieval, received `event: message, id: 41` acknowledging the request, and was waiting on `id: 42` for the result. The underlying TCP connection to the MCP server replica dropped at the load balancer (idle timeout, 60s, standard). The client's transport layer reconnected within 250ms and issued: ``` GET /mcp HTTP/1.1 Mcp-Session-Id: 7f3a9c2e-... Last-Event-ID: 41 Accept: text/event-stream ``` The load balancer, having no session affinity, routed the request to replica B. Replica B had never seen session `7f3a9c2e` — it had been created on replica A 4 minutes earlier and A's in-memory session store had already evicted it under a 90s TTL. Replica B's handler did the path of least resistance: it treated the `GET` as a new stream subscription, minted a *new* internal stream with event counter starting at 1, and returned `200 OK`. It did not return `404` (session unknown) or `410 Gone` (Last-Event-ID unrecoverable). It did not send any event, because it had nothing to replay. The client saw: `200 OK`, valid `text/event-stream`, no error. It kept the pending `tools/call` in its request map keyed by JSON-RPC `id`, waiting for a response that would never arrive, because the server-side execution of that call died with replica A. After the client's own 120s request timeout, it emitted a `tools/call` timeout error — but by then it had already *written* the partial result of the preceding step into its episodic memory as "completed," and the subsequent reasoning step treated the retrieval as having returned empty. The agent produced a confident, wrong answer grounded in a phantom empty result. The non-obvious part: **there was no error at the resumption boundary.** Every layer reported health. The failure only surfaced 120 seconds later as a downstream reasoning defect, and the causal link to the resumption was invisible in the trace because the trace showed a successful reconnect. ## Condition of Validity Resumption via `Last-Event-ID` is a valid continuation **if and only if** the server can prove, at resumption time, that it still holds the session's event history up to and including the supplied ID, *and* that the session's pending server-side work (in-flight tool executions, request state) is still addressable. In MCP Streamable HTTP this requires the server to satisfy all of: 1. The `Mcp-Session-Id` resolves to a live session record (not an evicted or re-minted one). 2. The `Last-Event-ID` is `<=` the session's highest emitted event ID and `>=` the session's replay-buffer floor (the oldest event still retained). If the buffer is a ring and the ID has fallen off the floor, resumption is *not* valid — the client has missed events it cannot recover. 3. The replica handling the `GET` shares session state with the replica that emitted event 41 (sticky routing, shared store, or a redirect to the owning replica). If any of these fail, the correct server behavior is to **refuse resumption explicitly** — `404 Not Found` for unknown session, `410 Gone` for an unrecoverable `Last-Event-ID` — and the correct client behavior is to treat the session as **terminated**, not resumed: discard pending request state, re-run `initialize`, and re-issue any `tools/call` whose result was never observed. The dangerous middle ground is a `200` with a semantically empty stream. The invariant: **a `200` on a resumption request asserts session continuity; a server that cannot honor that assertion must not return `200`.** This is a server obligation, but the client cannot rely on it, so the client must independently verify continuity. ## Decision Boundary The client cannot trust the server to be honest about continuity, so it must apply a local decision boundary at the moment of resumption. The boundary condition is: **does the first event received after resumption have an ID that is exactly `Last-Event-ID + 1` (or the next ID in the server's sequence)?** - If the first replayed event has `id == 42` (the awaited result), continuity is proven. Proceed. - If the server sends a `ping` or comment first, that is fine — comments carry no ID. Wait for the first *id-bearing* event. - If the first id-bearing event has `id > 42` (e.g., `47`), the client has **lost events 42–46**. This is not a resumption; it is a gap. The client must treat the session as broken, because one of the missed events may have been the `tools/call` result. This is the critical case: a server with a *partial* replay buffer will happily resume from a later ID and the client will silently skip the awaited response. - If the first id-bearing event has `id < 42` or restarts at `1`, the server has re-minted the stream. Session is not continuous. Terminate. Additionally, the client must bound the **resumption silence window**: after a successful `200`, if no id-bearing event arrives within a short window (e.g., 2× the server's advertised retry interval, or a fixed 5s), the client must not assume the stream is merely quiet. A quiet stream after resumption from a non-`-1` `Last-Event-ID` is *evidence of a lost session*, because a session with a pending `tools/call` at event 42 should either replay 42 or emit a heartbeat. Silence is ambiguous and must be resolved by an explicit liveness probe — typically a `GET` with `Last-Event-ID` omitted, which per spec requests a fresh stream and will fail loudly if the session is gone. The boundary is therefore: **resumption is valid only when the next observed event ID is contiguous with the requested `Last-Event-ID`, within a bounded time, on a session the server confirms is live.** Anything else is a new session wearing the old session's ID. ## Operational Effect The practical consequence is a mandatory client-side state machine that separates *transport reconnection* from *session continuity*, and a server-side contract that fails closed. Concretely: - The client maintains a `pending_requests` map keyed by JSON-RPC `id` and a `last_seen_event_id` cursor. On resumption, it does **not** clear `pending_requests`; it marks them `at_risk` with a deadline. If contiguity is proven before the deadline, they are safe. If the deadline passes or a gap is detected, they are failed with a distinct `SessionContinuityLost` error — *not* a generic timeout, because the reasoning layer must distinguish "the tool errored" from "we don't know what happened." - The reasoning layer must treat `SessionContinuityLost` as a **poisoned-context signal**: any memory write derived from the at-risk request must be rolled back or flagged unverified. Without this, the agent writes phantom results into episodic memory and the error propagates as a silent reasoning defect, exactly as observed. - The server must implement the fail-closed contract: `404` on unknown `Mcp-Session-Id`, `410` on `Last-Event-ID` below the replay floor, and — critically — **sticky session routing or a shared replay store** so that resumption does not silently land on a replica that cannot honor it. A load balancer that round-robins `GET /mcp` without session affinity is the single most common cause of this failure. - Idempotency: `tools/call` requests re-issued after a continuity loss must be idempotency-keyed so that a server that *did* execute the original call does not execute it twice. This is the one place where the client's recovery action can cause harm, and it must be guarded independently of the resumption logic. The invariant to carry forward: **a successful HTTP response on a resumption request is not evidence of session continuity; only a contiguous, timely, id-bearing event is.** Treat `Last-Event-ID` as a cursor you are *requesting*, and verify the server honored it before trusting any in-flight state. ```python import time from dataclasses import dataclass, field from typing import Optional class SessionContinuityLost(RuntimeError): """Raised when a Streamable-HTTP resumption returned 200 but did not prove session continuity via a contiguous, timely id-bearing event.""" pass @dataclass class PendingRequest: jsonrpc_id: str issued_at: float at_risk: bool = False deadline: Optional[float] = None @dataclass class ResumptionState: last_seen_event_id: int pending: dict[str, PendingRequest] = field(default_factory=dict) continuity_proven: bool = False def verify_resumption( state: ResumptionState, http_status: int, first_event_id: Optional[int], elapsed_since_200: float, silence_window_s: float = 5.0, ) -> None: """Validate that a resumption actually continued the session. Called after the client issues GET /mcp with Last-Event-ID and receives a response. Raises SessionContinuityLost if the transport succeeded but the session did not continue. """ if http_status in (404, 410): # Server failed closed -- correct behavior. Session is gone. raise SessionContinuityLost( f"server refused resumption (status={http_status}); " f"session terminated, {len(state.pending)} requests unrecoverable" ) if http_status != 200: raise SessionContinuityLost( f"unexpected status {http_status} on resumption" ) # The dangerous case: 200 OK but no continuity evidence. if first_event_id is None: if elapsed_since_200 > silence_window_s and state.last_seen_event_id >= 0: # A session with a pending call should have replayed or heartbeated. raise SessionContinuityLost( f"200 OK but no id-bearing event within {silence_window_s}s " f"after Last-Event-ID={state.last_seen_event_id}; " f"treating as re-minted session, not a continuation" ) return # still within window; caller must re-invoke on next event expected = state.last_seen_event_id + 1 if first_event_id < expected: raise SessionContinuityLost( f"event id regressed: got {first_event_id}, expected >= {expected}; " f"server re-minted the stream -- session is not continuous" ) if first_event_id > expected: # Gap: events expected..first_event_id-1 were lost. If any pending # request could have been answered in that gap, continuity is broken. at_risk = [p for p in state.pending.values() if p.at_risk] if at_risk: raise SessionContinuityLost( f"event gap: expected {expected}, got {first_event_id}; " f"{len(at_risk)} pending request(s) may have been answered in the gap" ) # No pending work at risk; gap is tolerable for a passive stream. state.last_seen_event_id = first_event_id state.continuity_proven = True return # first_event_id == expected: contiguous. Continuity proven. state.last_seen_event_id = first_event_id state.continuity_proven = True for p in state.pending.values(): p.at_risk = False p.deadline = None ```