# Where must an instance reconcile replayed SSE event IDs against a resumed MCP session when the server's session-affinity router and the client's Last-Event-ID cursor disagree on stream epoch **Date of Record:** 2026 November 24 **Scope:** Applies to MCP clients using the HTTP-native streamable transport with resumable SSE (Last-Event-ID replay) against a load-balanced MCP server fleet that pins sessions to a backend via affinity. Does not apply to stdio transports, to single-backend deployments without affinity, or to servers that emit globally monotonic event IDs across the whole fleet. ## Core Distinction The distinction that matters is between **event-ID monotonicity within a stream epoch** and **event-ID monotonicity across session resumption**. The MCP streamable transport spec allows a client to reconnect with `Last-Event-ID` and receive replayed events from that point forward. This contract is only sound if the server that replays the events is the *same logical producer* that emitted the original IDs. Under session affinity, the router may pin a resumed connection to a *different* backend than the one that produced the cursor—because the affinity key (session ID, cookie, or client IP) resolved differently after a backend restart, a rolling deploy, or a rebalancing event. The new backend's event-ID counter is independent. It will happily accept `Last-Event-ID: 4821` and either (a) replay nothing because its own counter is at 12, (b) replay from its own 4822 onward, creating a gap, or (c) emit a fresh stream whose IDs collide with the client's prior cursor namespace. The client cannot tell which of these happened from the SSE framing alone. This is not a transport bug; it is an epoch-continuity violation that the protocol does not require the client to detect and the server cannot detect on its own. ## What Was Observed An agent runtime executing a long tool-call sequence over MCP streamable HTTP lost three `tool_result` events during a rolling deploy. The trace: 1. Client opens `POST /mcp` with `Accept: text/event-stream`, receives `Mcp-Session-Id: s-7f3a`, and begins consuming events `id: 4800` … `id: 4821`. Each event carries a `tool_result` for a batched file-read operation. 2. Backend B1 is drained for deploy. The client's TCP connection drops mid-event at `id: 4822` (partial frame, no terminating blank line). 3. Client reconnects: `GET /mcp` with `Mcp-Session-Id: s-7f3a` and `Last-Event-ID: 4821`. 4. Affinity router, having lost B1 from the pool, pins `s-7f3a` to B2. B2 has no record of `s-7f3a` (session store is per-backend, not shared) but the router's sticky table still routes it there. B2 lazily creates a new session under the same ID and starts its event counter at `0`. 5. B2 responds `200 OK` with an SSE stream beginning `id: 0`, `id: 1`, … The client's resume logic treats any `id <= Last-Event-ID` as already-seen and **silently discards** events `0` through `4821` of B2's stream as duplicates, then accepts `id: 4822+` — which are *different* events than the ones the client was waiting for. 6. The three missing `tool_result` events from B1's tail (IDs 4822–4824) are never delivered. The agent's tool-call ledger has three outstanding futures. The reasoning loop stalls waiting for results that were emitted by a backend that no longer exists in the routing table. The failure is silent. No transport error. No 4xx. The client's dedup heuristic (drop `id <= cursor`) is exactly the heuristic the spec implies, and it is exactly wrong under epoch change. ## Condition of Validity The `Last-Event-ID` replay contract is valid **only** when all of the following hold simultaneously: - **Producer identity is stable across resumption.** The backend that answers the resumed `GET` is the same logical producer that emitted the cursor. Under affinity this requires either a shared session store (so any backend can replay any session's event log) or a router that refuses to re-pin a session to a backend that does not own it. - **Event IDs are monotonic in a namespace the client can validate.** Either globally monotonic per session (server-side sequence persisted with the session), or epoch-tagged (e.g., `id: -`) so the client can detect an epoch change and reset its cursor rather than dedup against it. - **The session's event log is durable past the connection.** If the backend keeps the replay buffer only in memory, a drain destroys the tail, and no amount of correct affinity can replay it. When any of these fails, the client is operating on a false invariant: *"an event ID I have already seen will not be re-delivered with different content, and an event ID I have not seen will be delivered at least once."* Under epoch change, both halves are false. ## Decision Boundary The client must decide, on every resumed stream, whether the incoming event IDs belong to the same epoch as its cursor. It cannot rely on the server to tell it. The boundary rule: - **If the first replayed event's ID is strictly greater than the cursor and the stream carries a session-epoch token that matches the pre-disconnect token**, treat as same-epoch replay; dedup normally. - **If the first event's ID is less than or equal to the cursor, or the epoch token is absent or changed, or the server emits an `event: session-reset` control frame**, treat as **epoch change**: abandon the cursor, do not dedup, re-request the full pending-result set via an application-level `tools/status` or equivalent, and reconcile the tool-call ledger against authoritative server state rather than against the stream. - **If the server cannot supply an epoch token** (many MCP servers today do not), the client must treat *every* resumption as a potential epoch change and perform ledger reconciliation on resume, accepting the cost of a redundant status round-trip. The cost of reconciliation is bounded; the cost of a silently dropped tool result is an unbounded stall. The invariant to enforce: **a tool-call future may only be resolved by an event whose `(epoch, id)` pair matches the epoch in which the call was issued, or by an authoritative status query.** Stream position alone is never sufficient evidence of continuity. ## Operational Effect The practical consequence is that resumable SSE over an affinity-routed MCP fleet is **at-least-once with an unreliable dedup key**. Clients that implement naive cursor dedup will drop events on epoch change; clients that implement no dedup will double-apply tool results on same-epoch replay. The only safe posture is epoch-aware reconciliation: treat the stream as a *hint* about server state, and treat a status/replay query as the *authority*. This adds one round-trip per resumption and requires the server to expose a queryable pending-result surface, which many MCP servers currently do not. Where that surface is absent, the client must fail closed—surface the ambiguity to the orchestrator rather than guessing—because a stalled agent that knows it is stalled is recoverable, and an agent that silently lost three tool results is not. ```python class EpochContinuityViolation(RuntimeError): """Raised when a resumed MCP SSE stream cannot be proven continuous with the pre-disconnect cursor.""" pass def reconcile_resume( cursor_epoch: str, cursor_id: int, first_event: dict, pending_calls: set[str], status_query, ) -> dict: """ Decide whether a resumed stream is same-epoch (safe to dedup) or an epoch change (must reconcile against authoritative server state). first_event: {"epoch": str | None, "id": int, "call_id": str | None} status_query: callable(pending_calls) -> dict[call_id, result] """ ev_epoch = first_event.get("epoch") ev_id = first_event["id"] same_epoch = ( ev_epoch is not None and ev_epoch == cursor_epoch and ev_id > cursor_id ) if same_epoch: # Normal replay: dedup by id > cursor, resolve calls as they arrive. return {"mode": "replay", "cursor": ev_id, "resolved": {}} # Epoch changed, epoch token missing, or id regressed: the cursor is # untrustworthy. Do not dedup. Reconcile against server authority. if status_query is None: raise EpochContinuityViolation( f"resume cursor (epoch={cursor_epoch!r}, id={cursor_id}) " f"does not match incoming stream (epoch={ev_epoch!r}, id={ev_id}) " f"and no status_query is available to reconcile " f"{len(pending_calls)} pending tool calls; refusing to guess" ) authoritative = status_query(pending_calls) unresolved = pending_calls - set(authoritative) if unresolved: raise EpochContinuityViolation( f"epoch change detected (cursor_epoch={cursor_epoch!r} -> " f"{ev_epoch!r}); server status query did not resolve " f"{sorted(unresolved)}; ledger cannot be reconciled" ) return { "mode": "epoch-reset", "cursor": ev_id, "epoch": ev_epoch, "resolved": authoritative, } ```