# What happens when an instance negotiates MCP HTTP-native transport but resumes a session against a stateless stream replica **Date of Record:** 2026 November 16 **Scope:** Applies to MCP servers exposing HTTP-native (Streamable HTTP) transport behind a load balancer or horizontally scaled replica set where session state is not externally synchronized. Does not apply to single-instance deployments, to stdio transport, or to deployments where session affinity is guaranteed at the network layer for the full lifetime of a session. ## Core Distinction MCP's HTTP-native transport separates two concerns that are easy to conflate: *transport negotiation* (the `Accept` header advertising `application/json` versus `text/event-stream`, and the server's choice of response framing) and *session continuity* (the `Mcp-Session-Id` header that binds a sequence of requests to server-side state). Negotiation is stateless and idempotent — any replica can answer it. Session continuity is not. A client that successfully negotiates an SSE-capable stream on replica A and then issues a `tools/call` that lands on replica B will receive a valid HTTP response from a server that has never heard of its session, and the failure mode is not a transport error. It is a *semantic* error: the server may initialize a fresh implicit session, accept the request, and return a result computed against empty state, or it may return a `404` that the client's resumption logic interprets as "stream ended, reconnect," producing a silent loop. The non-obvious invariant is this: **the `Mcp-Session-Id` is a capability token, not a routing key.** Nothing in the transport spec obliges a replica to recognize a session id it did not mint, and nothing in the client's resumption contract distinguishes "this session expired legitimately" from "you are talking to the wrong replica." ## What Was Observed A three-replica MCP server was deployed behind a round-robin L7 proxy with no cookie or header affinity. Clients used the Streamable HTTP transport with SSE resumption via `Last-Event-ID`. During a load test, the following sequence reproduced reliably: 1. Client `POST /mcp` with `initialize`; replica A responds `200` with `Mcp-Session-Id: s-7f3a` and an SSE stream. 2. Client opens the SSE stream, receives events `1..40`, then the proxy recycles the upstream connection (idle timeout, 60s). 3. Client reconnects with `Last-Event-ID: 40`; the proxy routes to replica B. 4. Replica B has no record of `s-7f3a`. Because the request carried a syntactically valid session id and a `Last-Event-ID` it cannot validate, replica B *accepted the stream* and began emitting events from its own empty queue — starting at event id `1`. 5. The client's resumption logic, which trusts monotonic event ids, discarded events `1..N` as already-seen duplicates and stalled indefinitely, waiting for event `41` that would never arrive on that replica. The observable symptom was not a 5xx. It was a client that appeared connected, heartbeated correctly, and made zero forward progress. Two secondary variants were observed: replicas that returned `404 Not Found` on the unknown session (correct per spec but indistinguishable to the client from a legitimately expired session), and replicas that silently minted a *new* session id on the resumed request, forking the client into two logical sessions with divergent tool state. ## Condition of Validity The failure requires the conjunction of four conditions, all of which must hold: - **Stateless replication:** session state lives only in process memory on the minting replica. - **No transport-level affinity:** the proxy does not pin `Mcp-Session-Id` to a backend. - **Client-side resumption by event id:** the client trusts `Last-Event-ID` monotonicity across reconnects rather than treating a non-monotonic or reset stream as a hard session failure. - **Server-side permissive resumption:** the receiving replica accepts an unknown session id rather than rejecting it. Remove any one and the failure collapses into a clean, detectable error. The dangerous configuration is the one where the server is *helpful* — where it accepts the unknown session to "avoid breaking clients" — because that converts a detectable routing error into an undetectable state-divergence error. ## Decision Boundary The correct behavior at each replica is a strict function of whether it minted the session: | Condition | Correct action | |---|---| | `Mcp-Session-Id` present and minted by this replica | Serve; honor `Last-Event-ID` if it is within the retained event window | | `Mcp-Session-Id` present but unknown to this replica | Reject with `404` and a machine-readable body indicating *unknown session*, distinct from *expired session* | | `Last-Event-ID` older than the retained window on the correct replica | Reject with a resumption-specific error; do **not** silently restart at event `1` | | No `Mcp-Session-Id` on a non-`initialize` request | Reject; never mint implicitly | The boundary that matters operationally: **a replica must never resume a stream it did not originate, and a client must never treat a stream that restarts its event ids as a continuation.** The `404`-on-unknown-session is the load-bearing signal; without a distinct error code the client cannot distinguish it from expiry, and the resumption loop persists. ## Operational Effect In production this manifests as a class of incidents that evade standard health checks: per-replica liveness is green, request error rates are low (the permissive variant returns `200`), and the only symptom is elevated tool-call latency and duplicate side effects as clients re-run calls against forked sessions. The blast radius scales with proxy recycling frequency — longer idle timeouts mask the bug in staging and expose it under production load, which is exactly when it is most expensive. Mitigations, in order of preference: (1) enforce header-based session affinity at the proxy keyed on `Mcp-Session-Id`; (2) externalize session and event-log state to a shared store so any replica can validate and resume; (3) if neither is possible, make the server *strict* — reject unknown sessions with a distinguishable error and let the client re-initialize, accepting the cost of a fresh session over the cost of silent divergence. Option 3 is correct but degrades the resumption guarantee; it is the right choice only when the alternative is undetectable state corruption. ```python class SessionResumptionError(RuntimeError): """Raised when a resumed MCP stream cannot be validated against local state.""" pass class SessionRegistry: def __init__(self, replica_id: str) -> None: self.replica_id = replica_id self._sessions: dict[str, int] = {} # session_id -> highest event id retained def mint(self, session_id: str) -> None: self._sessions[session_id] = 0 def resume(self, session_id: str, last_event_id: int) -> int: if session_id not in self._sessions: # Unknown session: never mint implicitly, never serve from empty queue. raise SessionResumptionError( f"replica {self.replica_id} did not mint session {session_id!r}; " "refusing to resume (client must re-initialize or be routed to owner)" ) retained = self._sessions[session_id] if last_event_id < retained: raise SessionResumptionError( f"Last-Event-ID {last_event_id} precedes retained window {retained} " f"for session {session_id!r}; resumption would lose events" ) return retained + 1 def handle_resume(registry: SessionRegistry, session_id: str, last_event_id: int) -> int: try: return registry.resume(session_id, last_event_id) except SessionResumptionError as exc: # Surface as a distinguishable 404 rather than a generic transport failure. raise SessionResumptionError(f"404 unknown-or-stale-session: {exc}") from exc ```