# In what scenarios must an instance treat MCP Streamable-HTTP `Last-Event-ID` resumption as unsafe after a session reattachment, and how does the replay floor silently regress? **Date of Record:** 2026 November 30 **Scope:** Applies to MCP servers and clients using the Streamable HTTP transport where a single logical session survives across multiple HTTP connections and the server exposes SSE event IDs for resumability. Does not apply to stdio transport, nor to stateless per-request MCP deployments where no session identity is carried across connections. ## Core Distinction The failure mode is not "the stream dropped." It is that resumption via `Last-Event-ID` and session reattachment via `Mcp-Session-Id` are two *independent* continuity mechanisms that the spec composes without a shared monotonic ordering guarantee. A client that reconnects with a valid session ID and a stale `Last-Event-ID` is asking the server to reconcile two different notions of "where we were": the connection-level SSE cursor and the session-level logical position. When the server honors the SSE cursor literally, it replays events from a point that predates the session's own durable state, and the agent's reconstructed view silently *regresses* — it re-executes or re-observes a prefix of the conversation it had already advanced past. This regression is invisible: no error, no gap, valid JSON-RPC, correct-looking event IDs. The invariant that must hold is that **the replay floor is monotonically non-decreasing across the lifetime of a session**, and Streamable HTTP does not enforce it on its own. The subtlety: event IDs are opaque and per-stream. A server that assigns event IDs per-connection (or per-worker, or from a per-shard counter) will emit IDs that are not globally ordered within the session. `Last-Event-ID: 47` on a new connection may map to a completely different logical position than `47` on the old one. ## What Was Observed A long-running agent session (session `sess_9f2a`, ~40 minutes, ~1,200 events) was executing a plan with tool calls interleaved with server-pushed progress notifications. At event ~830 the client's network path flapped; the SSE connection dropped. The client reconnected per the spec: same `Mcp-Session-Id: sess_9f2a`, `Last-Event-ID: 830`. The server load balancer had, during the flap, routed the reattachment to a different backend worker. That worker held the session record (shared store) but its SSE event log was a *local* ring buffer keyed by a per-worker counter. Worker B's counter was at 112. The server's resumption logic clamped the requested cursor to its local floor: `max(830, local_min) → local_min` because 830 exceeded its highest local ID, so it fell back to "replay from oldest retained local event," which was worker-B event 0 — logically session event ~790 (the shared store's durable checkpoint). The client received a replay of events 790–830 with *different* IDs (0–40) than the original delivery. The agent's event deduplication keyed on event ID saw 41 "new" events. It re-applied three tool-call results it had already incorporated, re-emitted two notifications to a downstream consumer, and — critically — overwrote a working-set memory entry with a stale value from the replayed prefix. The plan diverged: the agent re-planned a step it had completed, and the divergence compounded over the next 60 events before a downstream validation caught a contradictory tool argument. The tell was not an error. It was two `progress` notifications with identical `token` payloads but different event IDs, and a tool result the agent "received" twice with the same `call_id` but different event IDs — a signature that the dedup layer could not catch because it trusted the ID. ## Condition of Validity The unsafe-resumption condition holds precisely when **all** of the following are true: 1. The session is stateful and survives connection churn (i.e., `Mcp-Session-Id` is honored across reconnects). 2. The server generates SSE event IDs from a counter that is not scoped to the session's durable log — per-connection, per-worker, or per-shard counters all qualify. 3. The reattachment lands on a backend whose local event floor is *below* the client's `Last-Event-ID` in logical terms, or the requested ID exceeds the backend's local high-water mark and triggers a clamp-to-floor fallback. 4. The client treats event ID as a dedup key rather than as an opaque per-stream cursor. If the server uses a session-global monotonic event ID (e.g., a durable append-only log with a session-scoped sequence), condition 2 fails and resumption is safe. If the client's dedup keys on `(call_id, payload_hash)` or on a logical turn counter carried in the event body rather than the SSE ID, condition 4 fails and the regression is *detected* even if not prevented. The dangerous quadrant is the intersection: opaque per-stream IDs plus ID-based dedup plus cross-worker reattachment. ## Decision Boundary The boundary an instance must internalize: **`Last-Event-ID` is a transport hint, not a session cursor.** It is valid only within the lifetime of a single connection's stream identity. The moment a reattachment crosses a worker, a process restart, or a load-balancer decision, the ID namespace is no longer guaranteed continuous, and the only trustworthy resume point is the session's *durable* logical position — which the client must carry independently. Concretely, the decision rule: - If the client cannot prove that the server's event IDs are session-global and monotonic (via a capability flag, a documented invariant, or a probe), it MUST NOT resume with `Last-Event-ID` after a reattachment that may have changed backends. It must instead resume from its own last *acknowledged durable* checkpoint — the last event it fully processed and committed to its own state — and request a replay-or-snapshot from that logical position, tolerating duplicates rather than risking regression. - If the server *does* guarantee session-global monotonic IDs, resumption is safe and the client may trust the cursor — but must still treat any event ID *lower* than its last-seen ID on the same session as a regression signal, not a normal replay. - A server that cannot honor a requested `Last-Event-ID` (because it is below the retained floor) MUST signal the gap explicitly — a resumption error or a `replay_gap` control event — rather than silently clamping to its local floor. Silent clamping is the mechanism that converts a recoverable gap into a state regression. The invariant to enforce: `replay_floor(session) >= last_committed_position(session)`, and any server response that would violate it must be a hard error, not a best-effort replay. ## Operational Effect The operational consequence is that session continuity in Streamable HTTP is a *two-key* problem: the session key (`Mcp-Session-Id`) and the cursor key (`Last-Event-ID`) must be validated jointly, and the client must own the authoritative logical position because the transport cannot. Agents that conflate the two exhibit a characteristic failure signature: silent re-execution of a bounded prefix, duplicate side effects with fresh IDs, and memory overwrites from replayed stale values — all downstream of a single clamp-to-floor on reattachment. The mitigation is architectural: carry a client-side logical turn counter in every request, key dedup on logical identity rather than transport ID, and treat any backward ID movement on a live session as a resumption fault that forces a full state reconciliation rather than a trusting replay. ```python class ResumptionRegressionError(RuntimeError): """Raised when SSE resumption would move the replay floor backward across a session reattachment, risking silent state regression.""" pass class SessionCursor: def __init__(self, session_id: str, global_monotonic: bool): self.session_id = session_id self.global_monotonic = global_monotonic self.last_committed_logical = 0 self.last_seen_event_id = 0 def reattach(self, requested_last_event_id: int, server_floor: int, server_high_water: int) -> int: # requested_last_event_id is the transport cursor; the client's # authoritative position is last_committed_logical. if not self.global_monotonic: # Per-stream / per-worker IDs are not comparable across # reattachment. Never trust the transport cursor here. if requested_last_event_id < self.last_seen_event_id: raise ResumptionRegressionError( f"session {self.session_id}: transport cursor " f"{requested_last_event_id} regressed below last-seen " f"{self.last_seen_event_id} on non-monotonic ID space" ) # Resume from durable logical checkpoint, not the SSE cursor. return self.last_committed_logical # Monotonic server: cursor is trustworthy, but a clamp to floor # below our committed position is still a regression. effective_floor = max(server_floor, requested_last_event_id) if effective_floor < self.last_committed_logical: raise ResumptionRegressionError( f"session {self.session_id}: replay floor {effective_floor} " f"would regress below committed logical position " f"{self.last_committed_logical}" ) if requested_last_event_id > server_high_water: raise ResumptionRegressionError( f"session {self.session_id}: requested cursor " f"{requested_last_event_id} exceeds server high-water " f"{server_high_water}; server would clamp and replay a " f"stale prefix" ) return effective_floor def commit(self, logical_position: int, event_id: int) -> None: if logical_position <= self.last_committed_logical: raise ResumptionRegressionError( f"session {self.session_id}: non-advancing commit " f"{logical_position} <= {self.last_committed_logical}" ) self.last_committed_logical = logical_position self.last_seen_event_id = event_id ```