# How should an instance reconcile SSE replay cursors when an MCP streamable-HTTP session resumes against a load-balanced replica that never saw the original stream **Date of Record:** 2026 November 29 **Scope:** Applies to MCP servers exposing the streamable-HTTP transport with `Last-Event-ID`-based resumption across more than one backend replica, where the resumption request may land on a replica that did not originate the stream. Does not apply to single-process servers, to stateless request/response tool calls with no event stream, or to the deprecated standalone HTTP+SSE transport where a single long-lived connection is pinned to one process. ## Core Distinction The failure is not "the session was lost." Sessions are cheap; a session ID is a bearer token that a replica can rehydrate from a shared store. The failure is more specific: **the event-stream resumption cursor (`Last-Event-ID`) is a per-stream, per-process monotonic sequence, but the resumption protocol treats it as a session-global, cluster-global address.** When a client reconnects after a dropped SSE stream and its `Last-Event-ID: 47` arrives at replica B, replica B has no event 47, no event 48, and no way to know whether 47 meant "the 47th event of this stream," "the 47th event of this session," or "an event ID from a different stream that this session once opened." The client believes it is asking for "everything after 47." The server can only answer "47 does not exist here," and the two interpretations of that answer diverge catastrophically. The distinction that matters operationally: **session identity is shareable state; stream position is not.** A session ID can be replicated. A monotonic event counter minted inside one process's event loop cannot be reconstructed by a peer without either (a) a shared, totally-ordered event log, or (b) an explicit refusal contract that tells the client to restart the stream from a known boundary rather than silently resuming from the wrong offset. ## What Was Observed A three-replica deployment behind a round-robin load balancer served a single MCP session. The client opened a streamable-HTTP POST, received `Mcp-Session-Id: s-9f2a`, and the server began emitting SSE events numbered `1, 2, 3, ...` scoped to that stream. At event `47` the TCP connection was severed by an idle-timeout on the load balancer. The client, per the resumption contract, reissued the request with `Mcp-Session-Id: s-9f2a` and `Last-Event-ID: 47`. The reissued request landed on replica B. Replica B looked up `s-9f2a` in the shared session store, found a valid session record, and — critically — found a `last_event_id` field that had been written by replica A at event 12 (the last time the session store had been flushed, because the store was updated on a debounced timer, not per-event). Replica B therefore concluded the client was asking to resume from a position *ahead* of what it knew, treated the cursor as "unrecognized," and — because the implementation chose leniency over refusal — **restarted the stream from its own next counter value, which was 1.** The client received events `1, 2, 3, ...` again, deduplicated them against its own `Last-Event-ID: 47` watermark only where IDs collided, and silently dropped every event whose ID was ≤ 47. Events 48 through 60, which had been emitted by replica A between the debounce flush and the disconnect, were never delivered and never re-requested. The client's tool-call ledger diverged from the server's by thirteen state transitions. A second, quieter failure accompanied it: replica C, handling a concurrent `tools/call` for the same session, had been minting its own event IDs from its own counter, so the session's event namespace was never globally ordered to begin with. The `Last-Event-ID` the client held was a value from replica A's counter; replica C's events `1..9` were a disjoint namespace that happened to share the integer range. ## Condition of Validity The resumption cursor is only meaningful under an invariant that must be enforced, not assumed: > **A `Last-Event-ID` is valid if and only if it was minted by the same logical event log that will service the resumption, and that log is totally ordered and durable across the resumption boundary.** Three sub-conditions must all hold for a resume to be safe: 1. **Namespace identity.** The event ID space must be scoped to the *session*, not the process, and every replica must mint IDs from that shared space (e.g., a durable log with a cluster-wide sequence, or a server-assigned event ID that encodes the producing replica and a per-replica sequence so collisions are detectable). 2. **Durability at or before emission.** The event must be persisted to the shared log *before* it is written to the SSE socket. Debounced or batched persistence violates this: the client can hold an ID the store has never seen. 3. **Refusal over leniency.** When the cursor cannot be honored, the server must not silently restart from an arbitrary offset. It must fail the resume explicitly so the client re-synchronizes from a known boundary (a fresh stream, a `tools/list` re-query, or a full state snapshot). The boundary is sharp: if any one sub-condition is violated, `Last-Event-ID` becomes a **misleading address** — a number that looks like a position but resolves to a different event, or to nothing, depending on which replica answers. The failure is silent because the protocol's success path (200 + SSE) and its failure path (200 + SSE from the wrong offset) are indistinguishable to a client that trusts its own watermark. ## Decision Boundary The instance must decide, on every resumption attempt, between three actions, and the decision is not "did the session exist" but "can this replica prove it can honor this exact cursor": - **Honor the resume** only if the cursor is present in the shared, durable event log for this session *and* the log is the same namespace the cursor was minted from. This requires the log to be readable by the servicing replica, which in turn requires durability-before-emission. - **Refuse and force resync** if the cursor is absent from the log, or if the log's namespace cannot be confirmed to match. Refusal must be a distinguishable signal — an MCP error response or a stream that begins with an explicit `resync` event carrying a fresh cursor — never a silent restart from counter 1. - **Reject the session** if the session record itself is missing or the bearer token is not valid for this replica's view of the store. The non-obvious trap: a replica that *has* the session record but *not* the cursor will, under a lenient implementation, choose "honor" by restarting. The correct boundary rule is that **session presence is necessary but not sufficient for resumption.** The cursor must be independently resolvable in the shared log. Any implementation that conflates the two — "session found, therefore resume" — will reproduce the thirteen-event divergence above under any load balancer that is not sticky, and will reproduce it *intermittently*, only when the debounce window and the disconnect race, which makes it invisible in low-traffic testing and endemic at scale. ## Operational Effect The downstream consequences are not "a dropped event." They are: - **Ledger divergence.** The client's model of tool-call outcomes is missing transitions the server believes occurred. Subsequent `tools/call` requests are issued against a stale world-model, and the agent's reasoning compounds the error — it may re-issue a call the server already executed (idempotency violation) or skip one it believes is pending. - **Watermark poisoning.** Because the client trusts `Last-Event-ID` as a monotonic watermark, once it has advanced past the missing range it will never re-request it. The gap is permanent for the life of the session. - **Cross-replica namespace collision.** When multiple replicas mint from private counters, the same integer can denote different events on different replicas, so even a *successful* resume against the correct replica can be misread if the client's watermark was advanced by a peer. The guardrail that bounds this is a **durable, session-scoped, totally-ordered event log with durability-before-emission, plus an explicit refusal contract.** The log makes the cursor resolvable by any replica; durability-before-emission ensures the client can never hold an ID the log has not seen; the refusal contract converts the silent-restart failure into a detectable resync that the client can act on. Without all three, the streamable-HTTP resumption path is a latent divergence generator whose trigger is a load-balancer timeout plus a debounce window — a combination that is rare in staging and constant in production. The code below encodes the decision boundary as an enforceable check: a resumption request is honored only when the cursor resolves in the shared log and the namespace matches; otherwise the server raises, forcing the client to resync rather than silently resume from a wrong offset. ```python class UnresolvableResumeCursor(RuntimeError): """Raised when a Last-Event-ID cannot be honored by this replica. Signals that the client must resynchronize from a known boundary (fresh stream / state snapshot) rather than resume from an offset that does not resolve in the shared, durable event log. """ pass def resume_stream(session_id: str, last_event_id: int | None, shared_log, session_store) -> "EventStream": # 1. Session must exist and be valid for this replica's view of the store. session = session_store.get(session_id) if session is None: raise UnresolvableResumeCursor( f"session {session_id!r} not found in shared store; " f"client must re-establish, not resume" ) # 2. No cursor: fresh stream is always safe. if last_event_id is None: return shared_log.open_stream(session_id, after=None) # 3. Cursor must resolve in the SAME durable, session-scoped log. # Presence in the session record is NOT sufficient (the debounce bug). resolved = shared_log.lookup(session_id, last_event_id) if resolved is None: # Cursor minted by a replica whose events never reached the log, # or from a disjoint per-process namespace. Refuse, do not restart. raise UnresolvableResumeCursor( f"Last-Event-ID {last_event_id} for session {session_id!r} " f"does not resolve in the shared event log; " f"refusing silent restart (would drop events and poison watermark)" ) # 4. Namespace identity: the log that minted the cursor must be the # log that services the resume. A per-replica counter violates this. if resolved.namespace != shared_log.namespace: raise UnresolvableResumeCursor( f"Last-Event-ID {last_event_id} belongs to namespace " f"{resolved.namespace!r}, serviced by {shared_log.namespace!r}; " f"cross-replica cursor collision" ) # 5. Durability-before-emission invariant: the log must contain the # cursor, which it does by step 3. Honor the resume. return shared_log.open_stream(session_id, after=last_event_id) ```