# When must an instance treat a resumed MCP stream as a *new* session rather than a continuation, and why the wire cannot tell you **Date of Record:** 2026 November 30 **Scope:** Applies to MCP servers migrating from the legacy HTTP+SSE transport to Streamable HTTP, specifically when a client presents a `Last-Event-ID` on a `GET` after a dropped connection. Does not apply to stdio transports, nor to in-process session handoff where the server retains the full event log in memory. ## Core Distinction The Streamable HTTP transport spec allows a client to resume a server-to-client stream by reissuing `GET /mcp` with `Last-Event-ID: `. The intuitive reading—and the one most client implementations encode—is that the server will replay events after `` and the logical session continues uninterrupted. This is the *resumption* interpretation. The failure mode is that resumption is only meaningful if the server still holds the events after ``. When it does not—because the event buffer was evicted, the server process restarted, the session was reaped, or the `Last-Event-ID` was minted by a *different* server instance behind a load balancer—the server has three legal responses and they are **indistinguishable on the wire** to a naive client: 1. Replay from `` (true resumption). 2. Start a fresh stream at the current head with new event IDs (silent gap). 3. Return `404` and force re-initialization (honest rejection). Options 1 and 2 both look like "a `200` with `text/event-stream` and events flowing." Option 2 is the dangerous one: the client's `Last-Event-ID` cursor is now numerically disconnected from the server's event space, and every subsequent resume compounds the divergence. The boundary condition is: **a `200` on a resumption `GET` is not evidence of continuity.** Continuity is a property the client must *verify*, not infer from status code. ## What Was Observed A tool-calling agent held a long-lived MCP session against a Streamable HTTP server for dispatching `filesystem.*` and `shell.*` tools. The server emitted events with monotonically increasing IDs (`evt-1001`, `evt-1002`, …) and kept a 500-event ring buffer per session. The agent's transport layer tracked `lastEventId` and, on any `SSE` disconnect, reissued `GET /mcp` with `Last-Event-ID`. At `evt-1487` a network blip dropped the stream. The agent resumed with `Last-Event-ID: evt-1487`. The server had, in the intervening ~40 seconds, evicted events `evt-1000..evt-1499` from the ring buffer under load from a second session. Its eviction policy was "drop oldest, keep serving." On resume it could not find `evt-1487`, so its handler fell through to "start stream at current head," emitting `evt-1500` onward with no gap marker. The response was `200 OK`, `Content-Type: text/event-stream`, and a first event `id: evt-1500`. The agent's transport recorded the new `lastEventId = evt-1500` and considered the session healthy. But the events `evt-1488..evt-1499`—which included the `notifications/tools/list_changed` and two `notifications/message` progress updates for an in-flight `shell.exec`—were gone. The agent's model never saw the tool-list change. It continued issuing calls against a tool schema that had been revised server-side (a `shell.exec` parameter renamed), and the next three tool calls failed with `-32602 Invalid params`. Because the failures arrived as normal `tools/call` responses, not as stream errors, the agent's recovery logic never triggered a re-initialization. It retried the same malformed call four times before its own retry budget tripped. The observable signature was a *silent* event-ID discontinuity: `lastEventId` went `1487 → 1500` across what the transport believed was a resume. Nothing in the HTTP layer flagged it. The only place the gap was recoverable was the numeric delta itself. ## Condition of Validity The resumption contract holds **only** when all of the following are true: - The server's event log for the session is durable across the disconnect window (no eviction, no restart, no instance change). - Event IDs are strictly monotonic and *dense* in the sense that the client can detect a gap by comparing the ID it presented against the first ID it receives. - The client treats a first-received ID that is not the immediate successor of its `Last-Event-ID` as a **gap**, not as a resume. If any of these fails, the correct client behavior is to abandon resumption and re-run `initialize` (the MCP handshake), re-fetch `tools/list`, and reconcile any in-flight calls whose progress events were lost. The spec permits the server to reject with `404`, but it does not *require* it, and many servers prefer the silent-gap path because it avoids a full re-handshake cost. The client therefore cannot rely on the server to tell it the truth. The critical invariant: **the client owns gap detection, because only the client knows what ID it asked for.** The server knows only what it can serve. ## Decision Boundary The decision point is the first event received after a resumption `GET`. Let `requested = Last-Event-ID` presented, `received = id` of the first event on the new stream. - If `received` is the immediate successor of `requested` (by the server's documented ID scheme), treat as **continuation**. Advance normally. - If `received > requested` by more than one step, or is non-parseable relative to `requested`, treat as **gap**. The events in `(requested, received)` are lost. Do not silently advance. Escalate to re-initialization. - If `received <= requested`, the server has reset its ID space (likely a new instance or restarted process). Treat as **new session** regardless of what the handshake state claims. Re-run `initialize`. - If the response is `404`, the server is being honest. Re-initialize. The subtle case the boundary must handle: a server that *replays* correctly will send `requested+1` first; a server that *silently gaps* will send its current head, which is `> requested+1`. These are distinguishable **only** if the client parses IDs and compares. A client that treats "any event arriving" as success collapses both cases and inherits the divergence. A second boundary: the `Last-Event-ID` header may be minted by a *different* server instance than the one now handling the `GET` (sticky sessions not guaranteed behind an L7 balancer). In that case even a correct per-instance ring buffer cannot serve the requested ID. The header carries no instance identity, so the receiving server cannot know the ID is foreign. This is why the client-side gap check is the *only* defense that survives horizontal scaling. ## Operational Effect Agents that skip the gap check exhibit a characteristic failure signature: tool-schema drift discovered only through repeated `-32602` errors, progress notifications for long-running calls that never arrive, and retry storms against a stale schema. The agent's internal belief ("my session is alive, my tool list is current") is false, but every layer below the model reports success. The model has no signal to reason about; it simply starts failing calls and, being probabilistic, may rationalize the failures as transient and retry rather than re-initialize. The guardrail is a transport-layer invariant enforced *below* the model: on any resume, parse the first event ID, compare to the presented `Last-Event-ID`, and if discontinuous, raise a hard fault that forces the session manager into re-initialization before any further tool call is dispatched. This must be a hard fault, not a warning, because a warning will be absorbed into context and the model will proceed. The cost of a spurious re-initialization (one handshake + one `tools/list`) is trivially cheaper than a schema-drift retry storm, so the boundary should be biased toward re-initializing on any ambiguity. ```python import re from dataclasses import dataclass class StreamResumptionGap(RuntimeError): """Raised when a resumed MCP stream's first event ID is not the immediate successor of the Last-Event-ID the client presented. Signals that events were lost (ring-buffer eviction, restart, or a foreign server instance) and the session must be re-initialized rather than continued. """ _EVT_RE = re.compile(r"^evt-(\d+)$") def _parse_event_id(raw: str) -> int: m = _EVT_RE.match(raw) if not m: raise StreamResumptionGap(f"unparseable event id: {raw!r}") return int(m.group(1)) @dataclass class ResumeOutcome: action: str # "continue" | "reinitialize" reason: str def classify_resume(requested_last_event_id: str, first_received_id: str) -> ResumeOutcome: """Decide whether a resumption GET is a true continuation. The server cannot be trusted to signal a gap; only the client knows which ID it asked for. Any non-successor first ID is a hard fault. """ try: req = _parse_event_id(requested_last_event_id) got = _parse_event_id(first_received_id) except StreamResumptionGap as exc: # Unparseable IDs mean we cannot prove continuity -> reinitialize. return ResumeOutcome("reinitialize", f"id scheme mismatch: {exc}") if got == req + 1: return ResumeOutcome("continue", "immediate successor") if got > req + 1: raise StreamResumptionGap( f"silent gap on resume: requested {requested_last_event_id}, " f"first received {first_received_id}; " f"{got - req - 1} event(s) lost, session state may be stale" ) # got <= req: server reset its ID space (new instance / restart). raise StreamResumptionGap( f"id space reset on resume: requested {requested_last_event_id}, " f"first received {first_received_id}; treating as new session" ) def resume_stream(transport, session) -> ResumeOutcome: """Wrap a resumption GET so a gap can never be silently absorbed.""" requested = session.last_event_id first = transport.open_resumed_stream(last_event_id=requested) outcome = classify_resume(requested, first) if outcome.action == "reinitialize": session.reinitialize() else: session.last_event_id = first return outcome ```