# How does an instance detect silent resumability loss when an HTTP-native MCP server is multiplexed across stateless replicas behind a load balancer? **Date of Record:** 2026 November 24 **Scope:** Applies to HTTP-native MCP servers (Streamable HTTP transport) that expose resumable SSE streams via `Last-Event-ID` and are horizontally scaled behind a round-robin or least-connections load balancer with no session affinity. Does not apply to stdio transport, to single-replica deployments, or to deployments using sticky sessions keyed on the MCP session header. ## Core Distinction The failure is not "the stream dropped." Dropped streams are normal and the MCP spec anticipates them: the client reconnects with `Last-Event-ID` and the server replays from that cursor. The boundary failure is that **the reconnect succeeds at the transport layer while silently resuming from the wrong logical position**, because the replica that answers the reconnect has no memory of the stream the client is trying to resume. A stateless replica receiving `GET /mcp` with `Last-Event-ID: 47` has two honest options: replay events 48+ from durable storage, or reject with a resumability error so the client re-initializes. The dangerous third path—which is what most naive multiplexed deployments do—is to accept the request, open a fresh SSE stream, and emit *new* events starting from whatever the replica's local counter happens to be. The client sees HTTP 200 and a valid `text/event-stream`, cannot distinguish "resumed correctly" from "resumed at a divergent cursor," and proceeds to apply events on top of state that was built from a different event history. This is a *continuity invariant violation*: the client's reconstructed state is now a merge of two non-commuting event sequences. ## What Was Observed A three-replica MCP server deployment (Streamable HTTP, `Last-Event-ID` resumption enabled, Redis-backed tool outputs but *in-process* event sequence counters), behind an L4 load balancer with round-robin. Trace of a single agent session: 1. Agent connects to replica A, `initialize` succeeds, `Mcp-Session-Id: S`. Replica A assigns the stream a local `event_id` counter starting at 1. 2. Agent issues `tools/call` for a long-running job; replica A emits progress notifications with `id: 1..47`. Agent tracks `Last-Event-ID: 47`. 3. Network blip. Agent reconnects. Load balancer routes to replica B (round-robin, no affinity). 4. Replica B receives `GET /mcp` with `Mcp-Session-Id: S` and `Last-Event-ID: 47`. It has no record of session `S` (session table is in-process) and no record of event 47. Rather than 404/409, it accepts the request, creates a *new* in-process stream for session `S`, and its local counter starts at 1. 5. The long-running tool on replica B (or a re-dispatch) emits progress `id: 1, 2, 3...`. The agent, expecting `48, 49, 50`, receives `1, 2, 3` and—because MCP resumption is cursor-based, not content-addressed—treats them as the next events in sequence. 6. Agent's reconstructed task state now contains progress events from two disjoint executions interleaved as if monotonic. The agent concludes the job is at step 3 while the actual work on replica A is at step 47. Divergence is silent; no error is surfaced at any layer. The observable signature: `Last-Event-ID` echoed in the response is *lower* than the value the client sent, or the first replayed event's `id` does not equal `Last-Event-ID + 1`. Neither condition is checked by the standard MCP client SDKs. ## Condition of Validity The resumption contract is only sound when all of the following hold simultaneously: - The event log for a session is **durable and shared** across all replicas that may answer a reconnect (Redis Streams, a DB table, or a shared log), not in-process. - The `Mcp-Session-Id` → event-log binding is resolvable by *any* replica, i.e., session lookup does not depend on which process created the session. - The replica either replays events with `id > Last-Event-ID` from the shared log, or **explicitly rejects** the resume with a 4xx that forces re-initialization. Accepting the connection and starting a fresh counter is never valid. - The client validates that the first event after reconnect has `id == Last-Event-ID + 1` (or that the server's replay acknowledges the cursor). Without this client-side check, the server-side invariant is unobservable. If any one fails, the system is in a state where resumption *appears* to work (HTTP 200, valid SSE) while continuity is broken. This is the worst possible failure posture: it defeats the client's ability to detect it and defeats any retry logic keyed on transport errors. ## Decision Boundary The precise boundary is between **"resume"** and **"reinitialize,"** and it must be decided by the *server* based on whether it can prove it holds the event history for the given cursor—not by the client, and not by the load balancer. - If the replica can locate the durable event log for `Mcp-Session-Id` and the requested `Last-Event-ID` is within `[min_id, max_id]` of that log: replay from `Last-Event-ID + 1`. Resume is valid. - If the log exists but `Last-Event-ID` is *ahead* of `max_id`: the client has state the server cannot account for (events lost, or a different session reused the ID). Reject with `409 Conflict`; do not fabricate. - If the log does not exist for the session: reject with `404 Not Found` and require `initialize`. Do **not** silently mint a new stream under the same session ID. - If `Last-Event-ID` is absent: this is a fresh stream, not a resume. Starting a new counter is correct here and *only* here. The load balancer must not be relied on for correctness. Round-robin across stateless replicas is fine *provided* every replica can answer the resume query from shared state. Affinity is an optimization, not a guardrail. ## Operational Effect When this invariant is enforced, the failure mode converts from *silent state divergence* to *loud, recoverable re-initialization*. An agent that receives `409`/`404` on resume knows to discard its reconstructed state and re-run `initialize`, discarding at most the in-flight task rather than corrupting its memory with a merged event history. The cost is a bounded, visible restart; the alternative is an unbounded, invisible divergence that later manifests as the agent acting on a task state that never existed. The guardrail is threefold and all three are required: (1) shared durable event log keyed by session, (2) server-side rejection on unprovable cursor, (3) client-side monotonicity check on the first replayed event ID. Omitting (3) leaves the invariant unverifiable from the client; omitting (2) leaves it unenforced; omitting (1) makes (2) impossible to satisfy honestly. ```python class ResumptionContinuityError(RuntimeError): """Raised when a resumable MCP stream cannot be proven continuous. This is a hard boundary: the server must either replay from a durable, shared event log or force re-initialization. It must never accept the reconnect and silently start a fresh counter under the same session. """ class MCPStreamResumer: def __init__(self, event_log): # event_log: shared durable store, e.g. Redis Streams, keyed by session. # Must be visible to every replica behind the load balancer. self._log = event_log def resume(self, session_id: str, last_event_id: int | None) -> list[dict]: if last_event_id is None: # Fresh stream, not a resume. New counter is legitimate. return [] bounds = self._log.bounds(session_id) # (min_id, max_id) or None if bounds is None: # Session unknown to this replica / not in shared log. # Do NOT mint a new stream. Force re-initialization. raise ResumptionContinuityError( f"session {session_id!r} has no durable event log; " f"refusing to resume from Last-Event-ID={last_event_id}" ) min_id, max_id = bounds if last_event_id > max_id: # Client holds state the server cannot account for. raise ResumptionContinuityError( f"Last-Event-ID={last_event_id} exceeds max={max_id} for " f"session {session_id!r}; client and server diverge" ) if last_event_id < min_id - 1: # Requested cursor has been truncated out of the log. raise ResumptionContinuityError( f"Last-Event-ID={last_event_id} older than retained min={min_id} " f"for session {session_id!r}; replay impossible" ) events = self._log.read_after(session_id, last_event_id) if events and events[0]["id"] != last_event_id + 1: # Defensive: log returned a gap. Never emit non-monotonic replay. raise ResumptionContinuityError( f"replay gap: expected first id {last_event_id + 1}, " f"got {events[0]['id']} for session {session_id!r}" ) return events def handle_mcp_get(resumer, session_id, last_event_id_header): last_event_id = ( int(last_event_id_header) if last_event_id_header is not None else None ) try: return resumer.resume(session_id, last_event_id) except ResumptionContinuityError as exc: # Map to 404/409 so the client re-initializes instead of merging # divergent event histories. Loud failure, bounded restart. raise ResumptionContinuityError(f"resume rejected: {exc}") from exc ```