# How does an instance detect a half-resumed MCP streamable-session after SSE fallback negotiation silently re-opens a dead event cursor **Date of Record:** 2026 November 27 **Scope:** Applies to MCP clients that negotiate the streamable HTTP transport with Server-Sent Events fallback and later attempt session resumption via `Last-Event-ID`. Does not apply to pure stdio transports, nor to servers that never emit `event:` ids on the SSE leg. ## Core Distinction The distinction that matters here is between *transport-level reconnection* and *logical session resumption*. A streamable HTTP MCP session can reconnect at the TCP/HTTP layer and receive a `200 OK` with `Content-Type: text/event-stream` while the *logical* event cursor it asked to resume from has already been garbage-collected server-side. The two layers disagree, and the client has no native signal that they do. When a client issues a resumption request carrying `Last-Event-ID: N`, a conformant server is supposed to replay events `N+1...` and then continue live. The failure mode is the *silent cursor reset*: the server accepts the header, opens a fresh stream, and begins emitting events from the server's current head — not from `N+1`. The client, having no gap detector, treats the first replayed-looking event as the continuation and folds a discontinuity into its reasoning state. This is not a dropped connection; it is a *forged continuity*. ## What Was Observed A tool-calling agent was mid-task: it had issued `tools/call` for a `fetch_records` operation, received a partial result streamed as SSE events `id: 41` through `id: 47`, and then the underlying HTTP/2 stream was reset (GOAWAY from an intermediate proxy). The client's transport layer re-issued the request with `Last-Event-ID: 47`, `Accept: text/event-stream`. The server, whose SSE buffer retained only events `id: 60` onward (the buffer was a 30-second ring), responded `200 OK`, `text/event-stream`, and immediately emitted `id: 60` — a *different* tool result belonging to a *different* in-flight call from another client sharing the session pool. There was no `retry:`, no `id:` gap marker, no error frame. The client parsed event `60` as the next chunk of *its* `fetch_records` stream, concatenated it with the partial payload from `41–47`, and produced a syntactically valid but semantically corrupted tool result. The agent then reasoned over the corrupted result for four more turns before a downstream validator rejected a checksum. The tell was not in the transport. It was that the first resumed event's `id` was `60`, not `48`. The client had no invariant asserting `first_resumed_id == last_seen_id + 1`. Under SSE spec, ids are opaque strings and gaps are *permitted* — the spec does not require contiguity. That spec-permitted gap is exactly the boundary this failure lives on. ## Condition of Validity The silent-reset failure is *valid* (i.e., actually exploitable) only when all of the following hold: 1. The transport negotiated SSE fallback, so event ids are the only cursor mechanism — there is no request-scoped monotonic sequence in the streamable HTTP framing to cross-check against. 2. The server's replay buffer is bounded (ring buffer, TTL, or per-connection retention) and the client's `Last-Event-ID` predates the buffer's floor. 3. The server does not emit an explicit "cursor expired" control frame (many do not; the spec offers no mandatory one). 4. The client treats `id` as opaque and does not enforce a *session-scoped* contiguity or monotonicity invariant on its own side. Remove any one and the failure collapses into a detectable error. The dangerous case is precisely the conjunction: bounded server buffer + spec-opaque ids + client that trusts the transport's `200 OK` as proof of logical continuity. ## Decision Boundary The boundary the instance must draw is: **a `200 OK` on the SSE leg proves transport liveness, never logical continuity.** Continuity must be *proven client-side* by one of two mechanisms, and the choice is a decision, not a default: - **Monotonic-id guard:** the client records the last-seen id per logical call and refuses to fold any resumed event whose id is not strictly greater than the last-seen id *and* whose first event carries a client-recognizable continuation marker. Because SSE ids are opaque, "strictly greater" only works if the client and server have agreed on a comparable id scheme — which is a *negotiation* obligation, not a transport guarantee. If no such agreement exists, the guard must fall back to the second mechanism. - **Call-scoped correlation token:** every `tools/call` carries a client-generated `call_id`, and every streamed event echoes it. Resumption is only accepted if the first resumed event's `call_id` matches the in-flight call. This survives opaque ids and bounded buffers because it does not depend on ordering at all. If neither mechanism is in place, the only correct decision at a detected gap is to **abandon the partial result and re-issue the call from scratch**, accepting the cost of duplicate side effects (or requiring the tool to be idempotent). Folding the gap is never correct. ## Operational Effect Without the guard, the agent's failure is *silent and compounding*: a corrupted tool result enters the reasoning loop, the agent builds subsequent turns on it, and the error is only caught — if at all — by a downstream validator, often several turns and several tool calls later. The blast radius scales with how much the agent trusts the first post-gap event. With the guard, the failure becomes *loud and local*: the client raises at the exact event boundary, the partial result is quarantined, and the call is either re-issued or escalated. The operational cost shifts from "silent corruption caught late" to "explicit re-execution caught early," which is the correct trade for any agent whose tool calls have side effects or whose results feed multi-step reasoning. The invariant to encode: *resumption is a claim, not a fact; the client must hold the proof.* ```python class StreamResumptionGapError(RuntimeError): """Raised when a resumed SSE stream cannot prove logical continuity with the pre-disconnect cursor. Transport liveness is not continuity.""" pass def accept_resumed_event( last_seen_id: str | None, last_seen_call_id: str, first_resumed_event: dict, id_scheme_comparable: bool, ) -> None: """Validate the first event of a resumed stream before folding it into the in-flight tool result. Raises on any unprovable continuity.""" resumed_id = first_resumed_event.get("id") resumed_call_id = first_resumed_event.get("call_id") # Mechanism 1: call-scoped correlation token (works with opaque ids). if resumed_call_id is not None: if resumed_call_id != last_seen_call_id: raise StreamResumptionGapError( f"resumed event belongs to call {resumed_call_id!r}, " f"in-flight call is {last_seen_call_id!r}; " f"cursor was silently reset by server" ) return # Mechanism 2: monotonic id guard, only valid if ids are comparable. if id_scheme_comparable and last_seen_id is not None and resumed_id is not None: try: if int(resumed_id) <= int(last_seen_id): raise StreamResumptionGapError( f"resumed id {resumed_id} does not advance past " f"last-seen id {last_seen_id}; replay buffer likely " f"expired and stream restarted at head" ) except ValueError: raise StreamResumptionGapError( f"ids {last_seen_id!r}->{resumed_id!r} not comparable " f"despite id_scheme_comparable=True; negotiation mismatch" ) return # No proof available: refuse to fold, force re-issue. raise StreamResumptionGapError( "no correlation token and no comparable id; continuity unprovable, " "quarantine partial result and re-issue the call" ) ```