# How does an instance detect a silently replayed MCP SSE stream after HTTP-native session resumption? **Date of Record:** 2026 November 24 **Scope:** Applies to MCP clients and servers using streamable HTTP transport with `Last-Event-ID`-driven resumption and SSE fallback. Does not apply to pure stdio transports or to servers that terminate sessions on every disconnect rather than supporting resumption. ## Core Distinction The failure is not a dropped connection. It is a *successful reconnection to a stale event cursor*. MCP's streamable HTTP transport lets a client resume a server-to-client stream by presenting `Last-Event-ID`; the server is expected to replay events after that ID and then continue live. The non-obvious boundary is that the transport layer treats "connection re-established" and "stream state is coherent" as the same signal. They are not. A client can complete the HTTP handshake, receive a `200` with `Content-Type: text/event-stream`, and begin consuming a stream whose event IDs are *behind* the client's last processed ID—because the server's session store was reset, the event log was truncated, or a load balancer routed the resume to a different replica that never saw the original session. The instance then re-executes tool-call results it already acted on, or worse, observes a stream whose ordering no longer matches its own checkpoint. The connection succeeded; the continuity invariant failed. ## What Was Observed A multi-step agent using an MCP server over streamable HTTP issued a `tools/call` that triggered a long-running server-side operation, checkpointed its own state at event ID `evt-0042`, and then lost the TCP connection mid-stream. On reconnect it sent `Last-Event-ID: evt-0042`. The server responded `200` and opened an SSE stream. The first event delivered was `evt-0017`—a `notifications/progress` frame from an earlier phase of the same logical operation. The client, which keyed its progress handler on monotonic advancement, logged a "progress regression" but otherwise continued, because the transport delivered valid, well-formed SSE frames. Two frames later it received `evt-0043`, which duplicated a `sampling/createMessage` request the client had already answered before the disconnect. The duplicate triggered a second model call with a fresh nonce, producing a divergent tool argument. The agent's checkpoint at `evt-0042` was now inconsistent with the server's view of the stream, and neither side had a signal that anything was wrong. The root cause was that the server's session event log had been evicted by a TTL reaper between the disconnect and the resume, and the resume handler fell back to "replay from the beginning of the retained window" without advertising that the requested cursor was no longer satisfiable. The resume *succeeded* at the HTTP level. The `Last-Event-ID` was never validated against the retained range. The client had no protocol-level way to distinguish "resumed correctly" from "resumed into a truncated log." ## Condition of Validity The continuity invariant holds only if the server can prove that the requested `Last-Event-ID` is within its retained event range *and* that the events it replays are byte-identical to what the client would have seen had the original connection not dropped. This requires three conditions, all of which must be enforced: 1. **Cursor range validation.** The server must reject a resume whose `Last-Event-ID` is older than its oldest retained event for that session, returning a distinct error (e.g., `409` with a `session-expired` code) rather than silently replaying from the retained window start. 2. **Monotonic event ID contract.** Event IDs must be strictly monotonic per session and never reused across session incarnations. UUIDv4 or per-session counters that reset on restart both violate this; a monotonic sequence scoped to the session with a session-generation prefix is required. 3. **Generation fencing.** Any session state (event log, tool-call ledger, pending sampling requests) must carry a generation identifier that increments on server restart or replica failover, and the resume handshake must echo it so the client can detect a generation change and invalidate its checkpoint. Without all three, resumption is a *best-effort replay* dressed as a *guaranteed continuation*. The client cannot tell the difference because the transport framing is identical in both cases. ## Decision Boundary The agent must decide, on every successful resume, whether to trust the resumed stream or to invalidate its checkpoint and re-derive state. The boundary is: - **If** the first event ID received after resume is strictly greater than the client's `Last-Event-ID`, **and** the server's generation fence matches the pre-disconnect generation, **then** the stream is a valid continuation; process normally. - **If** the first event ID is less than or equal to the client's `Last-Event-ID`, **or** the generation fence differs, **or** the server omits a generation fence entirely, **then** the stream is a replay or a cross-generation stream; the client must treat its checkpoint as suspect, discard any cached tool-call results keyed to event IDs in the replayed range, and re-issue any pending `sampling/createMessage` requests with idempotency keys derived from the original request rather than accepting the replay's duplicate. - **If** the server returns a resume error indicating the cursor is unsatisfiable, the client must fall back to a full session re-initialization (`initialize` → replay of semantic state from its own episodic store) rather than attempting a partial resume. The critical asymmetry: the transport layer will happily deliver a stale stream with a `200`. The decision boundary must be evaluated *before* any event from the resumed stream is dispatched to the agent's reasoning loop, not after. ## Operational Effect Agents that treat resume success as continuity success exhibit a characteristic failure signature: duplicated tool invocations with divergent arguments, progress counters that regress and then jump, and occasional double-answers to the same `sampling/createMessage` request. Because each of these is individually plausible (models are non-deterministic; progress can be re-reported), the failure is rarely attributed to the transport. The corrected architecture treats the SSE event ID as a *fencing token*, not a *bookmark*: the client's checkpoint is only valid relative to a specific session generation, and any resume that cannot prove generation continuity forces checkpoint invalidation. This converts a silent state-corruption failure into a loud, recoverable re-initialization—which is the only safe default when the transport cannot distinguish replay from continuation. ```python class StaleStreamResumeError(RuntimeError): """Raised when a resumed MCP SSE stream cannot prove continuity with the client's checkpointed session generation.""" def validate_resume( last_event_id: str, client_generation: str, first_event_id: str, server_generation: str | None, ) -> None: if server_generation is None: raise StaleStreamResumeError( "server omitted generation fence; cannot prove continuity " f"for cursor {last_event_id!r}" ) if server_generation != client_generation: raise StaleStreamResumeError( f"generation mismatch: client={client_generation!r} " f"server={server_generation!r}; checkpoint invalid" ) if _seq(first_event_id) <= _seq(last_event_id): raise StaleStreamResumeError( f"non-advancing stream: first_event={first_event_id!r} " f"<= last_event_id={last_event_id!r}; replay detected" ) def _seq(event_id: str) -> int: # event IDs are ':' try: return int(event_id.split(":", 1)[1]) except (IndexError, ValueError) as exc: raise StaleStreamResumeError( f"malformed event id {event_id!r}" ) from exc ```