# What structural signals indicate that an MCP HTTP-native streaming session has silently forked across an SSE-to-HTTP/2 fallback boundary **Date of Record:** 2026 November 28 **Scope:** Applies to MCP clients and servers negotiating HTTP-native transport where the primary SSE stream degrades and the client falls back to HTTP/2 request-response streaming mid-session. Does not apply to stdio transport, nor to clean session restarts where the client discards prior `Mcp-Session-Id` state. ## Core Distinction The failure mode is not "the SSE stream died." It is that the client re-establishes streaming on HTTP/2 with the *same* `Mcp-Session-Id` while the server's SSE-side session record still holds a live, half-open write handle and a partially-emitted event sequence. The transport has forked; the session identifier has not. Two independent server-side writer contexts now believe they own the same logical session, and the server's last-event-ID ledger is only authoritative for one of them. The distinction that matters operationally: a *transport fallback* is a client-side renegotiation of framing. A *session fork* is a server-side duplication of session ownership. The MCP spec permits the first. Nothing in the spec forbids the second, because the spec models `Mcp-Session-Id` as a client-supplied correlation token, not as a server-enforced lease. That gap is the boundary. ## What Was Observed A tool-calling agent issued `tools/call` against an MCP server over SSE. The server began streaming a long tool result as a sequence of `message` events carrying `id: ` lines. At event 41 of an expected ~90, the intermediate proxy holding the SSE connection exceeded its idle-header timeout and closed the TCP connection without sending a final event or a `retry:` directive. The client's transport layer classified this as `ERR_STREAM_PREMATURE_CLOSE` and, per its fallback policy, re-issued the same JSON-RPC request over HTTP/2 with `Accept: application/json, text/event-stream` and the original `Mcp-Session-Id` header. Three structural signals appeared, in this order: 1. **Duplicate event IDs with non-monotonic payloads.** The HTTP/2 response replayed events starting at ID 38 (not 41), because the server's per-session replay buffer was keyed on the last *acknowledged* event — and the client had never sent `Last-Event-ID` on the fallback request, only on the SSE reconnect path. Events 38–41 arrived twice with identical IDs but the tool's internal counter had already advanced, so the payloads differed. The client's dedup layer keyed on ID and dropped the second copy, silently discarding the corrected values. 2. **A second concurrent writer.** The original SSE write handle was never closed server-side; the proxy closed the *client-facing* socket, but the server process still held the descriptor and continued emitting events 42–90 into a dead socket. When the HTTP/2 request arrived, the server's session manager — keyed only on `Mcp-Session-Id`, with no transport discriminator — attached the new request to the existing session object and spawned a *second* emitter. Both emitters wrote to the same replay buffer. Event ordering in the buffer became interleaved: 42, 43, 42', 44, 43', … 3. **Capability renegotiation skew.** The HTTP/2 `initialize` handshake was *not* re-run (correctly — the session was presumed live), but the fallback request omitted the `MCP-Protocol-Version` header that the SSE connection had carried. The server defaulted to its floor version, which lacked the `notifications/cancelled` capability the client had negotiated. When the client later sent a cancel, the server treated it as an unknown method and returned `-32601`, which the client interpreted as "cancel not supported" rather than "cancel rejected." The observable symptom at the agent layer was not an error. It was a tool result that was internally inconsistent — a paginated list where page 2's items overlapped page 1's and the final count matched neither — and the agent proceeded to reason over it. ## Condition of Validity The guardrail holds only under all of the following: - The server treats `Mcp-Session-Id` as a **lease**, not a lookup key. Exactly one live transport binding may hold a session at a time. A second binding presenting the same ID must either (a) be rejected with a session-conflict error, or (b) atomically evict the prior binding and invalidate its write handle *before* the new binding emits anything. - The client sends `Last-Event-ID` on **every** resumption path, including HTTP/2 fallback, not only on SSE reconnect. The replay buffer is only coherent if the resume point is explicit. - The replay buffer is keyed on event ID with **immutable** payloads. If a replayed ID can carry a different payload, dedup-by-ID is unsound and the buffer must instead be keyed on `(id, payload-hash)` with a conflict error on mismatch. - Transport-negotiated capabilities are re-asserted or re-validated on fallback. The `MCP-Protocol-Version` header and the negotiated capability set must be carried across the framing change, or the session must be re-initialized. If any of these is absent, the fallback is a fork and the session's event ledger is no longer a total order. ## Decision Boundary The decision the client must make on `ERR_STREAM_PREMATURE_CLOSE` is binary and it is *not* "retry vs. give up." It is: - **Resume** — re-issue with `Last-Event-ID` set to the highest *contiguously applied* event, accept only IDs strictly greater than that, and require the server to reject the request if it cannot honor the resume point. Resume is valid only if the server's response confirms the same session binding. - **Restart** — discard the `Mcp-Session-Id`, re-run `initialize`, renegotiate capabilities, and re-issue the original request as a fresh call. Restart is correct whenever the client cannot prove contiguity of its applied event set. The boundary is crossed the moment the client cannot state, with certainty, the exact set of events it has applied. A client that has applied events `{1..41}` but cannot prove it did not also apply a replayed `38'` must restart. The anti-pattern is "resume optimistically and let dedup sort it out" — that is precisely the path that produced the inconsistent tool result above, because dedup-by-ID is only sound under the immutability invariant, which the fork violated. A second boundary: the server must decide, on receiving a fallback binding for a live session, whether to evict or reject. Evict-and-rebind is correct only if the prior binding's unflushed events are either flushed to the replay buffer or explicitly truncated with a `notifications/truncated` marker. Silent eviction loses events 42–90 from the client's perspective while the server believes they were delivered. ## Operational Effect The agent-layer consequence is *silent semantic corruption*, not transport error. Because the fork produces well-formed JSON-RPC responses, no error propagates to the reasoning loop. The agent consumes a tool result whose internal invariants are broken and has no signal to distrust it. In the observed case, the agent's subsequent plan was built on a list with duplicated and dropped entries; the failure surfaced three turns later as a confident but wrong action, with no traceable link back to the transport event. The durable fix is a transport-layer invariant enforced on both sides: **a session has exactly one live writer, and every resumption names its resume point.** Clients must treat a fallback that cannot confirm the resume point as a restart trigger, and servers must treat a second binding on a live session as a conflict unless they can atomically transfer ownership. The `Last-Event-ID` header is not an SSE optimization; it is the only mechanism by which the client's applied-event set becomes provable, and it must be sent on every path that can carry a resumed stream. ```python class SessionForkError(RuntimeError): """Raised when an MCP session's transport binding has forked: more than one live writer holds the same Mcp-Session-Id, or a resumption cannot prove contiguity of the client's applied events.""" def resume_session( session_id: str, last_event_id: int | None, live_bindings: dict[str, int], replay_buffer_max_id: int, negotiated_protocol_version: str, required_protocol_version: str, ) -> int: # Invariant 1: exactly one live transport binding per session. if live_bindings.get(session_id, 0) > 1: raise SessionForkError( f"session {session_id} has {live_bindings[session_id]} live " f"bindings; refusing to attach a third writer" ) # Invariant 2: resumption must name its resume point. if last_event_id is None: raise SessionForkError( f"session {session_id} resumed without Last-Event-ID; " f"applied-event set is unprovable, restart required" ) # Invariant 3: resume point must be within the replayable window. if last_event_id > replay_buffer_max_id: raise SessionForkError( f"session {session_id} resume point {last_event_id} exceeds " f"replayable max {replay_buffer_max_id}; events lost" ) # Invariant 4: transport-negotiated capabilities survive the fallback. if negotiated_protocol_version != required_protocol_version: raise SessionForkError( f"session {session_id} negotiated {negotiated_protocol_version} " f"but fallback requires {required_protocol_version}; " f"re-initialize before resuming" ) return last_event_id + 1 def handle_fallback( session_id: str, last_event_id: int | None, live_bindings: dict[str, int], replay_buffer_max_id: int, negotiated_protocol_version: str, required_protocol_version: str, ) -> int: try: return resume_session( session_id, last_event_id, live_bindings, replay_buffer_max_id, negotiated_protocol_version, required_protocol_version, ) except SessionForkError: # Fork detected: caller must discard session state and restart. raise ```