# How should an instance detect and recover from a streamable-MCP resume that silently reattaches to a different server generation **Date of Record:** 2026 November 28 **Scope:** Applies to MCP clients using the HTTP-native streamable transport with `Last-Event-ID` resumption and SSE fallback negotiation against stateful servers that may restart, redeploy, or shard between the initial request and the resume. Does not apply to stateless tool-call transports, stdio transports, or servers that guarantee a single immortal process per session. ## Core Distinction The failure mode is not "the resume failed." It is that the resume *succeeded* against the wrong thing. In the streamable HTTP transport, a client that loses its SSE connection reconnects with `Last-Event-ID: ` and expects the server to replay events `n+1...` from a buffer keyed to that session. The protocol guarantees the *shape* of a successful resume (HTTP 200, `text/event-stream`, monotonic IDs continuing from the requested cursor). It does not guarantee that the events behind that cursor came from the same logical execution that produced the cursor. A restarted server, a redeployed pod, or a load balancer that routes the resume to a sibling replica that never held the session can all produce a perfectly well-formed 200 stream. The dangerous subcase is the **generation-crossing resume**: the new server generation has no buffer for the old session, so it either (a) synthesizes a fresh stream whose event IDs restart at 1 but are still numerically "ahead" of nothing the client can compare against, or (b) — worse — replays a *different* session's events whose IDs happen to be ≥ the requested cursor because IDs are per-generation monotonic counters rather than globally unique. The client cannot tell "continuation of my task" from "a stranger's task" by ID arithmetic alone. The invariant that must hold, and the one that silently breaks, is: **event-ID monotonicity within a stream is not evidence of session identity across a resume.** Cursor continuity and causal continuity are independent properties, and the transport only enforces the first. ## What Was Observed A tool-orchestrating agent held a long-running server-side operation (a multi-step file scan) delivered over streamable HTTP. The connection dropped at event ID 47 (a `progress` notification mid-scan). The client's reconnect logic did exactly what the spec invites: POST to the session endpoint with `Last-Event-ID: 47`, `Accept: text/event-stream`. The load balancer routed the request to a freshly scaled replica. That replica had been initialized with an empty session store. Its behavior, driven by a permissive fallback handler, was to treat an unknown session as a new one: it emitted HTTP 200, opened an SSE stream, and began emitting events with IDs starting at 1 for a *different* concurrent session it had been assigned. Because the client's resume handler only validated "response is 200 and content-type is event-stream," it accepted the stream. It then parsed the first three events, saw `progress` payloads with a `scanned` counter that was *lower* than the last value it had recorded (47 events in), and — because the client's state machine treated `progress` as idempotent and monotonic — it *discarded* the lower counter as a stale duplicate and continued. The agent's task state was now being driven by another task's progress stream. It ran to a "completion" event that referenced a file path the agent had never requested, and the agent, trusting the stream, wrote a summary claiming success on a scan it never performed. Two distinct defects compounded. First, the server's fallback negotiation treated `Last-Event-ID` as advisory and never signaled that the session was unknown — there was no `404`, no `410 Gone`, no `session-unknown` event. Second, the client's resume validator checked transport shape but not **cursor provenance**: it never verified that the first replayed event's ID was strictly greater than the requested cursor *and* carried a session/generation token matching the pre-drop session. Neither side was individually wrong by the letter of the transport; together they produced silent state substitution. ## Condition of Validity The "resume succeeded" conclusion is only valid when all of the following hold, and the client must treat any failure as a hard resume failure rather than degrading to best-effort: 1. The server echoes a session identifier (header or first event) that matches the pre-drop session identifier exactly. Generation counters, not just session IDs, must match if the server uses them. 2. The first event after resume has an ID strictly greater than the requested `Last-Event-ID`, and the server asserts (via a `resumed: true` field or equivalent) that it replayed from its buffer rather than starting fresh. 3. Any monotonic application-level counters (progress, sequence numbers, byte offsets) in the first resumed event are ≥ the last values the client recorded. A *decrease* is not a stale duplicate to be discarded — it is proof of session substitution and must abort. 4. The server returns an explicit non-200 (or a typed `session-unknown` SSE event) when it cannot honor the cursor, rather than silently opening a new stream. Condition 3 is the non-obvious one: most clients implement "ignore out-of-order/duplicate progress" as a robustness feature, and that exact robustness rule is what converts a detectable substitution into silent corruption. The guardrail is to invert the default — a counter regression during resume is fatal, not ignorable — while keeping regression tolerance *within* a single uninterrupted stream where reordering is a transport artifact. ## Decision Boundary The boundary is **whether the resume path can distinguish "cursor unknown" from "cursor valid."** If the server's session store is shared and durable across the reconnect window, the transport's monotonic-ID guarantee is sufficient and the client may trust ID arithmetic. If the session store is per-process, per-pod, or lost on restart — which is the common case for horizontally scaled MCP servers — then ID arithmetic is meaningless across a resume and the client *must* require an explicit provenance token. Concretely: a client should refuse to resume if it cannot obtain a session-generation token before the first drop. That means the initial stream's handshake must include a `session_id` + `generation` pair the client stores alongside the cursor. A resume request that omits the generation, or a server response that omits it, crosses the boundary into untrustworthy territory and the correct action is to **abandon the session and re-issue the original request as a new task**, accepting the cost of re-execution over the cost of silent substitution. Re-execution is bounded and observable; substituted state is unbounded and invisible. The threshold for choosing re-execution over resume: if the operation is idempotent or cheap to restart, never resume across a possible generation change. Only resume when the operation is expensive *and* the server has proven generation continuity. Do not let "resume is cheaper" bias the decision — a corrupted expensive task is more expensive than a clean restart. ## Operational Effect After adopting generation-token validation and counter-regression-as-fatal, the observed effect was that resume failures became loud and bounded: the client raised a typed error within one event of reattachment instead of running a phantom task to completion. The cost was a small increase in full re-executions (roughly the fraction of drops that coincided with replica churn), which is the correct trade. The deeper operational lesson is that resumable transports shift the trust burden onto the client: the server can always produce a syntactically valid stream, so the client must carry enough pre-drop provenance to *disprove* continuity, and must be willing to fail closed when it cannot. An agent that treats a 200 event-stream as proof of its own continuity has confused transport liveness with task identity. ```python from dataclasses import dataclass class ResumeProvenanceError(RuntimeError): """Raised when a streamable-MCP resume cannot prove session continuity.""" @dataclass(frozen=True) class SessionCursor: session_id: str generation: int last_event_id: int last_progress: int def validate_resume( cursor: SessionCursor, response_session_id: str | None, response_generation: int | None, first_event_id: int, first_event_progress: int, server_asserted_resumed: bool, ) -> None: # 1. Provenance token must match exactly; absence is fatal, not "unknown". if response_session_id is None or response_generation is None: raise ResumeProvenanceError( "server omitted session/generation token; cannot prove continuity" ) if response_session_id != cursor.session_id: raise ResumeProvenanceError( f"session id mismatch: expected {cursor.session_id!r}, " f"got {response_session_id!r}" ) if response_generation != cursor.generation: raise ResumeProvenanceError( f"generation crossed: expected {cursor.generation}, " f"got {response_generation}; server likely restarted" ) # 2. Server must assert it replayed from its buffer, not started fresh. if not server_asserted_resumed: raise ResumeProvenanceError( "server opened a fresh stream instead of replaying from cursor" ) # 3. Cursor must advance strictly. if first_event_id <= cursor.last_event_id: raise ResumeProvenanceError( f"event id did not advance past cursor: " f"{first_event_id} <= {cursor.last_event_id}" ) # 4. Application counter regression during resume is proof of substitution, # NOT a stale duplicate to be silently discarded. if first_event_progress < cursor.last_progress: raise ResumeProvenanceError( f"progress regressed on resume ({first_event_progress} < " f"{cursor.last_progress}); stream belongs to another task" ) ```