# What happens when an instance resumes a streamable MCP session after SSE reconnection and replays a stale `Last-Event-ID` **Date of Record:** 2026 November 24 **Scope:** Applies to MCP clients using the HTTP-native "streamable" transport where a session is identified by `Mcp-Session-Id` and resumption across a dropped server-sent-events (SSE) stream is attempted via the `Last-Event-ID` header. Does not cover stdio transport, nor stateless HTTP servers that issue no session ID, nor WebSocket-based A2A transports. ## Core Distinction There are two distinct notions of "where the client is" in a streamable MCP session, and they are silently conflated by most client implementations: 1. **Transport position** — the SSE event ID cursor (`Last-Event-ID`) that tells the server which events of the current *stream* have already been delivered. 2. **Semantic position** — the state of the agent's reasoning loop: which tool call it is awaiting a response for, which `requestId` it has outstanding, and which server-initiated notifications (progress, resource updates, elicitation requests) it has actually *acted on*. A reconnection is correct only when the server's resumed stream is a superset of the semantic position. The failure mode documented here is the case where the transport cursor advances past events the agent never consumed — because the SSE connection dropped mid-flight, or the server's per-stream event buffer was truncated — so the resumed stream is *transport-consistent* but *semantically incomplete*. The client believes it has resumed; the server believes it has delivered; the agent is missing a `notifications/message` or an elicitation request and proceeds on a stale premise. ## What Was Observed A client agent maintains an `Mcp-Session-Id` and a single long-lived SSE stream for server-to-client messages. The server assigns monotonically increasing integer event IDs per stream and retains a bounded replay buffer (observed at 128 events in one deployment, 1000 in another). The client tracks the last event ID it has *received on the socket*. Trigger sequence: - The agent issues `tools/call` for a long-running tool. The server emits `notifications/progress` events (IDs 40–63) and then, before the tool completes, an `elicitation/create` request (ID 64) asking the agent to confirm an ambiguous parameter. - At event ID 63 the TCP connection resets (NAT rebind, load-balancer idle timeout at 60s against a 45s heartbeat). The client's last *received* ID is 63. - The client reconnects with `Last-Event-ID: 63`. The server resumes from 64. - But the server had, in the interval, also emitted event 64 as an elicitation request whose *response deadline* was 30s. By the time the client reconnects (observed reconnect backoff: 1s, 2s, 4s, 8s, 16s — 31s total in one trace), the server has already timed out the elicitation and emitted event 65: `notifications/message` with `level: "warning"`, text "elicitation 64 expired, defaulting parameter `mode` to `strict`". The server retains 65 in its buffer. - The client resumes at 64, receives the elicitation (already expired server-side), responds, and receives a `-32602 Invalid params` because the elicitation ID is no longer live. It also receives event 65, which it logs but does not parse as a state change. - The agent now believes `mode` is whatever it passed; the server has silently substituted `strict`. The subsequent `tools/call` result is computed under a different parameter than the agent's plan assumed. No error surfaces at the tool boundary — the tool succeeds. A second, sharper variant: when the reconnect gap exceeds the server's replay buffer retention (or the server garbage-collects the session's stream state on a 5-minute idle timer), the server responds to the resume request with a fresh stream starting at event ID 1 and a *new* `Mcp-Session-Id` is **not** issued — the old session ID is retained but its event namespace has reset. A client that compares `Last-Event-ID` numerically will see the incoming ID (1) as lower than its cursor (63) and either discard events as duplicates or stall waiting for 64. In one trace the client discarded 47 events including the terminal `tools/call` response, then hung until its own 120s request timeout fired, and reported a transport error to the orchestrator — which retried the entire task, causing a duplicate side effect. ## Condition of Validity The invariant that makes resumption safe is: > For every event ID `E` delivered on a resumed stream, the client must have either (a) previously consumed `E` *and acted on its semantic effect*, or (b) receive `E` on the resumed stream. The transport cursor must never advance past an event whose semantic effect was not applied. This holds only when all of the following are true: - Event IDs are strictly monotonic **within a session's lifetime** and never reset without a session-ID change. A server that resets the event namespace while retaining `Mcp-Session-Id` violates this and forces the client into cursor-comparison ambiguity. - The replay buffer retention window exceeds the maximum client reconnect backoff plus the maximum in-flight event generation rate. If the buffer holds 128 events but the server can emit 200 events during a 31s reconnect, the buffer truncates and the resumed stream begins mid-gap with no marker. - Server-initiated requests (elicitation, sampling) carry an explicit expiry that is *reported to the client* on resume, not merely enforced server-side. An expired elicitation delivered on resume is a trap: the client will respond and be rejected, but the server-side default has already taken effect invisibly. - The client distinguishes "received on socket" from "semantically applied." A progress notification can be dropped harmlessly; an elicitation expiry cannot. The client must classify events by semantic weight before advancing its durable cursor. When any of these fail — and in every deployment observed, at least one did — the resumed session is transport-consistent but semantically divergent. ## Decision Boundary The client must choose, on every reconnect, between three actions based on observable signals: - **Resume** (`Last-Event-ID: `) — permitted only when the server's response stream's first event ID is exactly `cursor + 1`, proving no gap. If the first ID is `> cursor + 1`, the server truncated; if `< cursor`, the namespace reset. - **Full session re-establish** (new `initialize` handshake, new `Mcp-Session-Id`, re-fetch of all server capabilities and resource subscriptions) — required when the namespace reset is detected or when the gap exceeds a configured semantic-loss threshold. This is expensive: it discards server-side subscription state and any in-flight server-initiated requests, and the agent must re-derive its semantic position from its own durable log. - **Abort and surface** — required when the gap contains an event class the client cannot reconstruct (an elicitation whose default has already been applied, a sampling request whose result the server has already assumed). The agent must not silently continue. The boundary is *not* "did the socket reconnect." It is "does the first resumed event ID equal the durable cursor plus one, AND does the gap contain zero irreversible semantic events." Both conditions must be checked; either alone is insufficient. ## Operational Effect The practical consequence is that streamable MCP resumption is only safe for event classes that are idempotent and reconstructible. Progress notifications and log messages are safe to lose. Elicitations, sampling requests, and any server-initiated request whose expiry triggers a server-side default are *not* — losing one silently changes the agent's operating parameters without changing its belief state. The agent proceeds with a plan computed under assumptions the server has already overridden. The guardrail is a durable, per-session event ledger on the client side that records, for each consumed event ID, whether its semantic effect was applied (not merely received), plus a hard rule: on reconnect, if the first resumed ID is not `cursor + 1`, or if any event in the gap is classified irreversible, the client must escalate to full re-establish or abort — never resume-and-continue. Servers must additionally never reset the event namespace under a retained session ID; a reset requires a new session ID, full stop, so the client's cursor comparison is unambiguous. The failure is non-obvious because every individual component behaves correctly: the socket reconnects, the server replays from the requested cursor, the client receives valid events, the tool call succeeds. The divergence is entirely in the gap between transport position and semantic position, and it manifests only as a downstream behavioral anomaly — a tool executed under a parameter the agent never chose. ```python class SessionResumptionDivergence(RuntimeError): """Raised when a resumed MCP SSE stream cannot be proven semantically contiguous.""" IRREVERSIBLE_EVENT_CLASSES = frozenset({ "elicitation/create", "sampling/createMessage", "notifications/elicitation_expired", }) def validate_resumption( durable_cursor: int, first_resumed_event_id: int, gap_event_classes: list[str], session_id_unchanged: bool, ) -> None: """ Enforce the resumption invariant before the agent consumes any resumed event. durable_cursor: last event ID whose semantic effect was APPLIED (not merely received). first_resumed_event_id: ID of the first event the server sends on the resumed stream. gap_event_classes: method names of events in (durable_cursor, first_resumed_event_id). session_id_unchanged: whether the server retained the same Mcp-Session-Id. """ if not session_id_unchanged: # Namespace reset under a retained session ID is a protocol violation. raise SessionResumptionDivergence( f"event namespace reset without new session id; cursor={durable_cursor}" ) if first_resumed_event_id < durable_cursor: raise SessionResumptionDivergence( f"resumed stream rewound: first_id={first_resumed_event_id} < cursor={durable_cursor}; " "server truncated or reset buffer — full re-establish required" ) if first_resumed_event_id > durable_cursor + 1: gap = first_resumed_event_id - durable_cursor - 1 raise SessionResumptionDivergence( f"replay gap of {gap} events; server buffer truncated — semantic loss unprovable" ) irreversible = IRREVERSIBLE_EVENT_CLASSES.intersection(gap_event_classes) if irreversible: raise SessionResumptionDivergence( f"gap contains irreversible events {sorted(irreversible)}; " "server-side defaults may already be applied — abort, do not resume" ) def resume_or_escalate( durable_cursor: int, first_resumed_event_id: int, gap_event_classes: list[str], session_id_unchanged: bool, ) -> str: try: validate_resumption( durable_cursor, first_resumed_event_id, gap_event_classes, session_id_unchanged ) except SessionResumptionDivergence as exc: # Escalate to full re-establish; never silently continue on a divergent stream. return f"REESTABLISH: {exc}" return "RESUME" ```