# How does an instance detect that a streamable-session MCP reconnection has silently regressed to a pre-crash event cursor **Date of Record:** 2026 November 20 **Scope:** Applies to MCP clients using the HTTP-native streamable transport with `Last-Event-ID`-based SSE resumption against a server that emits server-initiated messages (notifications, sampling requests, elicitation) over the same stream. Does not apply to stdio transports, nor to stateless HTTP request/response MCP profiles where no SSE stream is held open. ## Core Distinction There are two superficially identical events that a reconnecting MCP client must distinguish, and conflating them is the root of this failure mode: 1. **A resumed stream** — the server accepted `Last-Event-ID: N` and continues the event sequence from `N+1`, preserving the monotonic event-id invariant across the reconnect boundary. 2. **A silently reset stream** — the server accepted the reconnection (HTTP 200, `Content-Type: text/event-stream`) but has *no retained buffer* covering `N`, so it either (a) starts a fresh stream whose event IDs restart at an independent counter, or (b) begins emitting at some cursor `M > N+1` because it evicted the gap, without signaling the discontinuity. In case 2 the transport is *up* and the session is *nominally alive*, but the client's view of the event space has a hole it cannot see. The client believes it holds a contiguous log; it actually holds two disjoint segments glued together. This is not a dropped connection — it is a **cursor regression masquerading as a successful resume**, and the MCP spec's `Last-Event-ID` mechanism provides no mandatory in-band signal that distinguishes it from a legitimate resume. ## What Was Observed An agent instance held a streamable MCP session to a tool server that emitted two interleaved classes of server-initiated events: `notifications/tools/list_changed` (id space shared with responses) and `sampling/createMessage` requests (server asking the client's model to complete something). The client tracked `last_event_id` and on disconnect reconnected with the header. Trace of the failure: - Stream reaches event id `4812`. Client records `last_event_id = 4812`. - Network blip; SSE connection drops. Client reconnects with `Last-Event-ID: 4812`. - Server had a **per-connection** ring buffer (capacity 256 events) rather than a **per-session** buffer. On the new connection the buffer is empty; the server has no event `4812`, cannot replay `4813..`, and — because the spec allows a server to ignore the header — simply opens a fresh stream. - The fresh stream's first event is a `sampling/createMessage` with id `3` (new per-connection counter starting at 1, and events 1–2 were internal keep-alives). - Client receives id `3`. Because `3 < 4812`, a naive monotonicity check *should* trip — but the client's guard was `if incoming_id <= last_event_id: drop_duplicate`, i.e. it treated the regression as a replay and **silently discarded the event**. - The discarded event was a `sampling/createMessage` request. The server's sampling request had a timeout. The client never answered. The server marked the sampling request as failed and, per its policy, **aborted the tool call that depended on it** — but the abort notification was emitted on the *new* stream with a fresh id the client also dropped as "already seen." - The client's tool call hung until its own far-longer timeout, then returned a `-32001 RequestTimeout` that the agent interpreted as a transient network fault and retried — re-triggering the whole path. The non-obvious part: **the client's duplicate-suppression guard, which is correct for genuine replays, is precisely what converts a silent cursor reset into a lost server-initiated request.** Every defensive instinct (drop ids you've seen) is wrong in exactly this case. ## Condition of Validity The failure requires all of the following to co-occur; remove any one and the invariant holds: - The server uses **per-connection** rather than **per-session** event-id allocation, *or* evicts its replay buffer while the client's `Last-Event-ID` points into the evicted region. - The server **does not** emit an explicit discontinuity marker (a `session/reset` notification, a new `Mcp-Session-Id`, or a `409`/`404` on the resume attempt). The spec permits a server to reject an unresumable `Last-Event-ID` with a fresh session, but does not require it, and many implementations just open a new stream. - The client applies **id-based duplicate suppression** across the reconnect boundary instead of **session-scoped** suppression. - At least one **server-initiated request** (not just a notification) is lost in the gap, so the loss produces a *hang* rather than a benign missing update. The invariant that was violated: **event-id monotonicity must be scoped to a session, and a session is identified by `Mcp-Session-Id`, not by the TCP/SSE connection.** A client that treats the id sequence as globally monotonic across reconnects is asserting a property the transport never promised. ## Decision Boundary The operative decision is what a client does when it observes `incoming_event_id <= last_event_id` after a reconnect. Three candidate policies: - **Drop as duplicate** (the observed failure): correct only if the server guarantees session-scoped monotonic ids *and* honors `Last-Event-ID`. Unsafe under the conditions above. - **Treat as reset and re-initialize**: on regression, discard the stream, issue a fresh `initialize` with a new session, and **replay the client's outstanding requests** — but this loses any server-initiated request that was mid-flight, because the server will not re-issue it. - **Treat as reset and reconcile**: on regression, do not silently proceed. Emit a `session/reset`-equivalent local event, mark every in-flight server-initiated request as **indeterminate** (not failed, not succeeded), and either (a) re-issue the dependent tool call idempotently, or (b) surface the indeterminacy to the agent loop so it can decide. The correct boundary is the third. The decision rule: **an event-id regression across a reconnect is a session-integrity event, never a deduplication event.** Deduplication is valid only within a single continuous stream where the server's buffer is known to cover the client's cursor. The moment the transport reconnects, the client must re-establish whether the cursor is covered — and absent an explicit server acknowledgment of the resume point, it must assume it is not. The guardrail: the client must track `(session_id, last_event_id)` as a **pair**, and on reconnect must verify that the first event received has `id == last_event_id + 1` *for the same session_id*. Any other outcome — a gap, a regression, or a first event with an id it cannot place relative to its cursor — is a reset. There is no "probably fine." ## Operational Effect For an autonomous agent, the practical consequence is a class of **silent half-failures**: the tool call does not error at the transport layer, it hangs until a long timeout, and the agent's error-handling loop classifies the timeout as transient and retries. Each retry re-opens the same window. Under load, this manifests as a retry storm against a server that is already degraded, with the agent's own duplicate-suppression logic guaranteeing that the server's abort signals are discarded. The agent's memory of the task shows a clean retry; the server's logs show requests that were issued, timed out on sampling, aborted, and then re-issued. The two logs disagree, and the disagreement is invisible to both sides because neither records the session-reset event. The architectural fix is to make the reset **loud and local**: a client-side `SessionCursorRegression` condition that is raised into the agent loop, not swallowed by the transport. The transport's job is to detect the regression; the agent's job is to decide whether the indeterminate server-initiated request can be safely re-driven. The two must not be collapsed into a silent drop. ```python class SessionCursorRegression(RuntimeError): """Raised when a reconnected MCP stream's first event id does not continue the client's cursor for the same session. This is a session-integrity event, NOT a duplicate to be dropped.""" def __init__(self, session_id: str, expected_next: int, received_id: int): self.session_id = session_id self.expected_next = expected_next self.received_id = received_id super().__init__( f"session {session_id}: cursor regression on resume " f"(expected id {expected_next}, got {received_id}); " f"in-flight server-initiated requests are indeterminate" ) def classify_resumed_event(session_id: str, last_event_id: int, incoming_event_id: int) -> str: """Classify the first event after a reconnect. Returns 'resumed' only if the cursor is provably contiguous for the same session.""" if incoming_event_id == last_event_id + 1: return "resumed" # Anything else — regression OR forward gap — is a reset. A gap # means the server evicted the replay window; a regression means # it reallocated ids per-connection. Both break the invariant. raise SessionCursorRegression(session_id, last_event_id + 1, incoming_event_id) def handle_reconnect(session_id: str, last_event_id: int, first_event: dict, in_flight: dict) -> None: """On reset, mark every in-flight server-initiated request as indeterminate so the agent loop can reconcile rather than retry blindly. Never silently drop the event.""" try: classify_resumed_event(session_id, last_event_id, first_event["id"]) except SessionCursorRegression: for req_id, req in in_flight.items(): req["state"] = "indeterminate" # not failed, not done raise ```