# Why does an instance resuming an MCP streamable-HTTP session silently accept a replayed event batch from a rotated server endpoint? **Date of Record:** 2026 November 29 **Scope:** Applies to MCP streamable-HTTP transports where the client persists a session identifier plus a `Last-Event-ID` cursor and resumes across server restarts, endpoint rotations, or load-balancer rebalancing. Does not apply to pure stdio transports, nor to sessions that never resume after a transport drop. ## Core Distinction The failure is not "the resume request was rejected" (that is the healthy case) and not "the resume request lost events" (that is a detectable gap). The failure is that the resume **succeeded** — the server returned HTTP 200 on the SSE stream, emitted a batch of events starting from a plausible `Last-Event-ID`, and the client fed those events into the agent's reasoning loop as if they were the unseen continuation. The distinction that matters: a resumed session is a *continuity claim*, not a *stream read*. The client is asserting "I am the same logical session, and these events are the ones I have not yet consumed." Streamable HTTP carries the cursor as an opaque string; nothing in the transport binds that cursor to a server identity, a signing key, or a session epoch. When the session resumes against a *different* server instance than the one that minted the cursor, the server has no obligation — and often no ability — to verify that the cursor refers to events in *its* history rather than in a sibling's. The non-obvious part: event IDs are frequently monotonic integers or timestamp-derived strings. Two independent server instances that both start their counters at zero (or at wall-clock-derived values within the same millisecond bucket) will produce **colliding** event IDs for semantically unrelated events. The client's `Last-Event-ID: 47` is a valid cursor on both servers, and both will happily replay "everything after 47" — but the two "everything after 47" sequences describe different tool calls, different partial results, different state mutations. The client cannot tell, because the transport gives it no way to tell. ## What Was Observed A long-running agent session drove a tool-calling loop against an MCP server fronted by a four-replica deployment behind a round-robin load balancer with no session affinity. The client persisted `{session_id, last_event_id}` to local checkpoint storage after each event batch. Mid-task, the SSE connection dropped (replica restart during a rolling deploy). The client reconnected with the persisted cursor. The load balancer routed the reconnect to a *different* replica that had never seen this `session_id` but had been configured to accept any well-formed resume and reconstruct a stream from its own event log. Trace of the failure: 1. Replica A had emitted events `1..47` for the session, including a `tool_result` at ID `44` containing a parsed JSON payload from a filesystem read. 2. Client checkpointed `last_event_id = 47` and disconnected. 3. Replica B, freshly started, had its own event counter at `1..12` from unrelated sessions. Its log contained no events for this session. 4. Client resumed with `Last-Event-ID: 47`. Replica B's resume handler treated the cursor as "replay from the highest ID ≤ 47 in *the session's* log," found the session's log empty, and — because its fallback path was "if no history, start fresh from current head" — emitted new events starting at its own ID `13`. 5. Client received event ID `13`, which is **less than** its persisted cursor `47`. The client's gap-detection logic was `if new_id <= last_id: drop_duplicate` — a deduplication rule designed for at-least-once redelivery. It silently discarded IDs `13..47` as "already seen." 6. The agent's next reasoning step proceeded with a state that was missing 35 events of tool output and a `tool_result` it had never actually consumed, while believing its context was complete. The observable symptom was not an error. It was a downstream reasoning divergence: the agent re-issued a filesystem read it had already performed, then contradicted its own earlier plan because the plan's supporting evidence had been dropped by the dedup rule. The failure surfaced three turns later as an incoherent tool-call sequence. ## Condition of Validity The invariant that must hold for a resume to be safe is: > A `Last-Event-ID` cursor is only meaningful relative to the event namespace of the server instance that issued it, and the client must be able to prove the resuming server shares that namespace before trusting any replayed or subsequent event. Concretely, safe resumption requires all of: - **Epoch binding.** The session ID or cursor carries a server-issued epoch (boot ID, signing key ID, or monotonic generation counter) that changes on restart and on replica identity change. The client rejects a resume whose responding server presents a different epoch than the one recorded at checkpoint time — or, more precisely, treats a mismatched epoch as "resume impossible; re-establish from scratch with a fresh session." - **Cursor monotonicity as a *within-epoch* property only.** The `new_id <= last_id → drop` rule is valid only when both IDs belong to the same epoch. Across an epoch boundary, a lower ID is not a duplicate; it is a *different event*. The dedup rule must be gated on epoch equality. - **Server-side refusal of foreign cursors.** A server that cannot find the cursor in its own log for that session must return a terminal error (e.g., `404`/`410` with a "resume impossible" body), never a fresh stream from its own head. The fallback-to-head behavior is the actual defect: it converts an unresumable session into a silently corrupted one. The condition does *not* hold when the transport provides true session affinity (all resumes route to the issuing replica) — but affinity is a deployment property, not a protocol guarantee, and it breaks precisely during the rolling restarts and rebalances when resumes matter most. ## Decision Boundary The boundary the operator must draw is between **recoverable resume** and **session reset**, and it must be decided by evidence, not by the server's willingness to open a stream. - If the resuming server presents the same epoch as the checkpoint → resume is valid; apply within-epoch dedup; continue. - If the resuming server presents a different epoch, or cannot present one, or returns a cursor it cannot locate in its own session log → the session is **not resumable**. The client must discard the cursor, discard the assumption that its context is complete, and either (a) re-establish a fresh session and re-derive state from durable checkpoints, or (b) escalate to a human/auditor because the agent's context may now be inconsistent with the tool-side world. - The forbidden third path — the one that produced the incident — is "accept the new stream, apply the naive dedup, continue." That path is chosen by default whenever the transport is silent about epochs, which is the common case. The decision must be made *before* any resumed event enters the reasoning loop. Once a foreign-epoch event is consumed, the agent's context is contaminated and no downstream check can reliably distinguish "I never saw this" from "I saw it and forgot." ## Operational Effect The operational consequence is that resumable streamable-HTTP sessions are **not** a durability mechanism unless the transport is augmented with epoch binding. Teams that treat `Last-Event-ID` as a reliable cursor inherit a class of silent context corruption that only manifests as reasoning incoherence, never as a transport error — and reasoning incoherence is exactly the failure mode that is hardest to attribute to its root cause, because by the time it surfaces the transport logs look clean. Mitigations that actually bound the failure: 1. **Epoch in the cursor.** Mint cursors as `epoch:counter` (or sign them), and reject cross-epoch resumes client-side. This is the load-bearing fix. 2. **Server refusal contract.** Resume handlers must return a terminal error for cursors absent from their own session log; never fall back to head. 3. **Dedup gated on epoch.** The `new_id <= last_id` rule must be scoped to a single epoch; across epochs, treat any ID as novel and require full re-derivation. 4. **Post-resume consistency probe.** After any resume, the agent should re-verify the last N tool-result assertions against the tool's own state before proceeding, because the resume itself is now an untrusted claim. The general lesson: in agent systems, a *successful* transport operation is not evidence that the *semantic* operation was valid. Resumable sessions move a continuity claim into an opaque string and then trust it. The invariant to enforce is that no continuity claim is trusted across an identity boundary the transport cannot see. ```python class CrossEpochResumeError(RuntimeError): """Raised when a resume cursor belongs to a different server epoch than the one recorded at checkpoint time, or when the resuming server cannot locate the cursor in its own session log.""" def resume_session( checkpoint: dict, server_response: dict, *, allow_reset: bool = False, ) -> dict: """ checkpoint: {"session_id": str, "last_event_id": int, "epoch": str} server_response: { "epoch": str | None, "cursor_found": bool, "events": list[{"id": int, "epoch": str, ...}], } Returns the events that are safe to feed into the reasoning loop. Raises CrossEpochResumeError if the resume cannot be proven safe. """ cp_epoch = checkpoint["epoch"] cp_cursor = checkpoint["last_event_id"] srv_epoch = server_response.get("epoch") # Invariant 1: the resuming server must present an epoch at all. if srv_epoch is None: raise CrossEpochResumeError( f"server presented no epoch for session {checkpoint['session_id']!r}; " "cannot distinguish resume from foreign-namespace replay" ) # Invariant 2: epoch must match the checkpointed epoch exactly. if srv_epoch != cp_epoch: raise CrossEpochResumeError( f"epoch mismatch: checkpoint={cp_epoch!r} server={srv_epoch!r}; " "cursor is not meaningful across epochs" ) # Invariant 3: server must have located the cursor in its own log. if not server_response["cursor_found"]: raise CrossEpochResumeError( f"cursor {cp_cursor} not found in server session log; " "refusing head-fallback resume" ) # Within-epoch dedup is now safe. seen = set() safe_events = [] for ev in server_response["events"]: if ev["epoch"] != cp_epoch: raise CrossEpochResumeError( f"event {ev['id']} carries foreign epoch {ev['epoch']!r}" ) if ev["id"] <= cp_cursor: continue # genuine redelivery if ev["id"] in seen: continue seen.add(ev["id"]) safe_events.append(ev) return {"events": safe_events, "epoch": cp_epoch} ```