# Where must an instance reconcile Last-Event-ID against a stateless MCP replica pool: silent event-stream fork on SSE resumption **Date of Record:** 2026 November 26 **Scope:** Applies to MCP servers deployed as HTTP-native, streamable-SSE transports behind a load balancer, where the server tier is horizontally scaled and stateless (no per-session affinity, no shared event ring buffer). Does not apply to single-replica deployments, to stdio transports, or to stateful servers that pin a session to a process holding the full event log. ## Core Distinction The distinction that matters is between *transport-level resumability* and *state-level resumability*. SSE gives an agent a resumption primitive — the `Last-Event-ID` header — that the client believes is a cursor into a single logical stream. On a stateless MCP server pool, that cursor is a claim about a stream that no single process owns. The stream is a *fiction* reassembled per request from whatever replica the load balancer selects. A `Last-Event-ID` value is not a pointer. It is a monotonic integer that the client and the *original* emitting replica agreed on. When the client reconnects and lands on a different replica, that replica has no way to know whether the integer refers to events it emitted, events a peer emitted, or events that were never durably recorded at all. The failure is not a dropped event. The failure is a *fork*: the client resumes from `N`, the new replica begins emitting from its own local counter at `M`, and the agent's view of the stream silently splices two divergent event histories together with no detectable seam. ## What Was Observed A tool-calling agent session over streamable HTTP MCP. The server tier is three replicas behind a round-robin LBE with no sticky sessions. Each replica maintains an in-process SSE event counter starting at 0 on process start, and a bounded in-memory ring buffer of the last 256 events for local replay. Trace: 1. Client opens `GET /mcp` with `Accept: text/event-stream`. LBE routes to replica A. Replica A emits `id: 0` (server capabilities), `id: 1` (tool list), `id: 2` (partial progress on a long tool call). Client records `Last-Event-ID: 2`. 2. Network blip. Client's SSE connection drops mid-tool-call. The tool call itself continues on replica A — it is an async task — but the client no longer receives its completion event. 3. Client reconnects with `Last-Event-ID: 2`. LBE round-robins to replica B. Replica B has never seen this session. Its local counter is at `id: 47` from unrelated traffic. It has no event `2` in its ring buffer (buffer holds events `0..46` from *other* sessions, not this one). 4. Replica B's resumption handler finds no matching event ID. Depending on implementation, one of three things happens, and all three are broken: - **Reset-and-resume:** B starts a fresh stream at its own `id: 48`. The client sees `id: 48`, assumes it missed events `3..47`, and — critically — never receives the completion event for the tool call that replica A is still executing. The tool call's result is now orphaned. - **Silent gap:** B emits new events with its own IDs starting at `48`, the client's SSE parser sees a non-contiguous jump, and because SSE spec does not mandate error on ID gaps, the parser accepts it. The agent proceeds with a tool result it never received, or blocks forever waiting on an event that was emitted to a dead socket. - **Duplicate replay:** B's ring buffer happens to contain an event with `id: 2` from a *different* session. B replays it. The client receives a tool-list event from another agent's session, misinterprets it as its own continuation, and its tool-call state machine advances on foreign data. The invariant that was assumed and violated: *a `Last-Event-ID` observed by a client refers to an event that is durably retrievable by any replica that might serve the resumption.* Stateless scaling makes this false by construction. ## Condition of Validity The resumption contract is only valid when **all three** hold: - **(a) Global event identity.** Event IDs are allocated from a single logical sequence shared across the pool (e.g., a monotonic counter in a shared store, or a Snowflake/ULID with a total order), not a per-process counter. Per-process counters are the root cause of the fork; two replicas will emit the same integer for different events, and the client cannot distinguish them. - **(b) Durable replay window.** The event log is retrievable by *any* replica for at least the maximum client reconnect backoff. An in-process ring buffer on replica A is invisible to replica B and therefore useless for resumption. The window must be externalized (Redis stream, durable queue, shared table) or the pool must be pinned. - **(c) Session-to-stream binding.** Either the LBE pins the session to the replica holding its state (sticky sessions keyed on a session ID carried in a header or cookie), or the server is genuinely stateless *and* the session state lives in a shared store so any replica can serve any resumption. "Stateless tier + in-process state" is the incoherent middle that produces the fork. If (a) holds but (b) does not, the client gets a *detectable* gap (ID jump) but cannot recover — it must re-issue the whole request. If (b) holds but (a) does not, the client gets *undetectable* corruption — the worst case, because the agent cannot know its stream was spliced. If (c) holds (pinning), (a) and (b) become optional because the same process serves the resumption. ## Decision Boundary The boundary is the choice between **pinning** and **externalizing**, and the failure mode is choosing neither while believing you chose one. - If the tier is truly stateless (no affinity), you **must** externalize both the event log and the ID allocator. The `Last-Event-ID` handler must query the shared store, and on miss it must **fail loudly** with a resumption error, not silently reset. A reset is indistinguishable from a fork to the client. - If the tier is pinned (affinity by session ID), the `Last-Event-ID` handler may use in-process state, but the LBE **must** route on the session key and **must not** fall back to round-robin on a missing key — a fallback is a silent fork. - The decision is not per-request. It is a property of the deployment topology. An agent that cannot observe the topology cannot verify which contract it is operating under, so the server must advertise it: a capability flag in the initial `initialize` response (e.g., `resumability: "durable" | "session-pinned" | "none"`) is the minimum for the client to choose correct recovery behavior. The dangerous default is the one most pool deployments ship: stateless tier, round-robin, per-process counters, ring-buffer replay. Every individual component is reasonable; the composition is a silent-fork generator. ## Operational Effect Downstream, the agent experiences this as *non-deterministic tool-call loss*: a tool executes, its result is emitted to a socket that died, and the agent — having resumed on a different replica — either waits indefinitely (if it blocks on the completion event) or proceeds with stale assumptions (if it treats the gap as success). Because the tool *did* run, side effects occurred; because the result was never delivered, the agent may retry, producing duplicate side effects. The failure is not localized to the transport — it propagates into the agent's reasoning as a phantom success or a phantom failure, and the agent has no signal to distinguish "tool never ran" from "tool ran, result lost." The guardrail is a **resumption integrity check** on the client side and a **fail-closed resumption handler** on the server side. The server must reject a `Last-Event-ID` it cannot verify against a durable log with a specific error, and the client must treat that error as "re-issue the request from scratch, do not assume prior events were delivered." The client must also validate monotonic contiguity of received IDs and abort on gaps it did not explicitly request. ```python class ResumptionForkError(RuntimeError): """Raised when a Last-Event-ID cannot be reconciled against the durable event log.""" pass class StatelessMcpReplica: def __init__(self, replica_id: str, durable_log=None, local_counter: int = 0): self.replica_id = replica_id # durable_log is None for the broken (in-process-only) topology self.durable_log = durable_log self.local_counter = local_counter def resume(self, last_event_id: int) -> list: # Broken topology: no shared log, per-process counter. if self.durable_log is None: # The dangerous silent path: reset to local counter. # We refuse it rather than fork the stream. raise ResumptionForkError( f"replica {self.replica_id} has no durable log; cannot verify " f"Last-Event-ID={last_event_id}. Refusing to reset-and-resume " f"(would splice divergent histories). Re-issue request from scratch." ) # Durable topology: verify the cursor exists in the shared log. if not self.durable_log.contains(last_event_id): raise ResumptionForkError( f"Last-Event-ID={last_event_id} not present in durable log " f"(evicted or never emitted). Cannot resume; client must restart." ) replay = self.durable_log.events_after(last_event_id) # Contiguity invariant: replay must be strictly monotonic with no gaps. expected = last_event_id + 1 for ev in replay: if ev.id != expected: raise ResumptionForkError( f"durable log gap: expected id {expected}, got {ev.id}. " f"Log is corrupt or partially replicated." ) expected += 1 return replay def handle_sse_resume(replica: StatelessMcpReplica, last_event_id: int) -> list: if last_event_id < 0: raise ResumptionForkError(f"invalid Last-Event-ID={last_event_id}") return replica.resume(last_event_id) ```