# Under what conditions must an instance treat an MCP stream resumption as a fresh capability negotiation rather than a byte-offset replay **Date of Record:** 2026 November 28 **Scope:** Applies to MCP clients/servers using HTTP-native transport (SSE-over-POST with `Last-Event-ID` resumption) where a streaming tool call may be resumed after a transport break. Does not apply to stdio transport, nor to stateless request/response tool invocations with no server-side session. ## Core Distinction The failure hinges on conflating two different things that share the same wire mechanism: **byte-offset replay** of a stream versus **semantic resumption** of a session. HTTP SSE resumption is defined as "reconnect with `Last-Event-ID`, server replays events after that ID." This is a *transport* guarantee about event ordering. It is **not** a guarantee that the server's session state, the tool's execution context, or the negotiated capability set survived the break. The non-obvious boundary: a server can honor `Last-Event-ID` perfectly—replaying exactly the events the client missed, in order, with no gaps—while having silently dropped the underlying session (evicted for memory, expired a TTL, lost to a rolling deploy, or rebound to a different backend instance behind a load balancer). The replay looks correct. The session is gone. Every subsequent tool call in that stream now executes against a *fresh*, *re-negotiated* session whose capabilities, sampling parameters, and roots may differ from what the client assumed it was still holding. The invariant that must hold: **a resumed stream is only a continuation if the server can prove session identity equality across the break; otherwise it is a new session wearing the old stream's event IDs.** ## What Was Observed A client opened a streaming `tools/call` against an MCP server exposing a `filesystem` capability with a negotiated root of `/workspace/project-a`. Mid-stream, the server initiated a graceful restart (deploy). The TCP connection dropped after event ID `e-1042`. The client reconnected with `Last-Event-ID: e-1042`. The server—now a fresh process—replayed events `e-1043` through `e-1047` from a *durable event log* it had flushed before shutdown, then continued the stream live. The client saw a seamless event sequence and treated the session as continuous. But the new process had re-run initialization with **default capabilities**: no `filesystem` root pinned, `sampling` disabled, and a different `maxTokens` default. The tool call's later steps, which assumed the pinned root and sampling capability, silently degraded: - A `sampling/createMessage` request returned `MethodNotFound` (capability absent in the re-negotiated session) rather than the expected completion. - A relative-path write resolved against the new process's CWD (`/`) instead of `/workspace/project-a`, because the root was never re-asserted. The event-ID replay was flawless. The session was a stranger. The client's divergence-detection never fired because it only checked event-ID monotonicity, which was intact. ## Condition of Validity Byte-offset replay is a valid continuation **only** when all of the following hold: 1. The server's replay includes a **session-identity token** (a session UUID plus a monotonic session epoch/generation counter) on every event, and the resumed stream's first event carries the *same* identity token as the pre-break stream. 2. The negotiated capability set is **immutable for the lifetime of a session** and is re-asserted (or re-verified) in the resumption handshake, not assumed. 3. The server either (a) guarantees session survival across the break, or (b) explicitly signals *session re-establishment* (not mere replay) via a distinct event type—e.g., `session.reinitialized` with the new capability manifest—before any tool output is emitted. If the server can replay events but cannot prove session identity continuity, the client MUST treat the resumption as a **fresh negotiation** and re-run the full `initialize` / capability exchange, re-pinning roots and re-checking sampling availability, before consuming any post-break tool output as belonging to the original call. ## Decision Boundary The decision is not "did the connection drop?" but **"did the session epoch change across the drop?"** Three cases: - **Same epoch, replay complete:** true continuation. Consume events; no re-negotiation. Safe. - **Same epoch, replay incomplete (gap in event IDs):** the server cannot reconstruct the stream. This is a hard error—do not attempt to resume; restart the tool call. Silent gap-filling is the poisoning vector. - **Different epoch (or epoch absent):** the server is a new session. Replay is cosmetic. The client must discard the assumption of continuity, re-negotiate capabilities, and decide whether the in-flight tool call is still semantically valid under the new capability set. If the call depended on a capability the new session lacks, the call must be aborted and re-issued, not patched. The dangerous middle ground—replay present, epoch absent, capabilities silently defaulted—is exactly where agents diverge without erroring. Absence of an epoch field must be treated as "epoch unknown," which resolves to the *different-epoch* branch (re-negotiate), never the same-epoch branch. ## Operational Effect Agents that skip the epoch check exhibit a specific, hard-to-diagnose failure signature: tool calls that succeed pre-break and produce subtly wrong results post-break, with no transport error. Because the event stream is well-formed, retry logic never triggers. Because the tool returns *some* result, the reasoning loop accepts it and compounds the error downstream—a write to the wrong path, a sampling call that silently no-ops, a capability-gated operation that degrades to a fallback. The divergence surfaces far from the resumption point, usually as a downstream verification mismatch rather than a resumption error. The guardrail is to make session epoch a **first-class field in the resumption contract** and to fail closed when it is missing or changed: re-negotiate, re-assert capabilities, and re-validate the in-flight call against the new manifest before trusting a single post-break byte. Capability continuity is not implied by stream continuity, and the two must be checked independently. ```python class SessionEpochMismatchError(RuntimeError): """Raised when a resumed MCP stream cannot prove session-identity continuity.""" def resume_stream( prior_epoch: str | None, resumed_first_event: dict, required_capabilities: set[str], ) -> dict: """ Decide whether a resumed SSE stream is a true continuation or a fresh session. prior_epoch: session epoch captured before the break (None if never seen). resumed_first_event: the first event after reconnect; must carry 'session_epoch' and, if re-established, a 'capabilities' manifest. required_capabilities: capabilities the in-flight tool call depends on. """ resumed_epoch = resumed_first_event.get("session_epoch") # Absence of an epoch is "unknown" -> fail closed to re-negotiation. if resumed_epoch is None or prior_epoch is None: raise SessionEpochMismatchError( "session epoch missing on resumption; cannot prove continuity. " "Treating as fresh negotiation and re-running initialize." ) if resumed_epoch != prior_epoch: raise SessionEpochMismatchError( f"session epoch changed across break ({prior_epoch} -> {resumed_epoch}). " "Event-ID replay is cosmetic; session is new. Re-negotiate capabilities " "and re-validate the in-flight tool call before consuming post-break output." ) # Same epoch: still verify the capability set the call depends on. manifest = resumed_first_event.get("capabilities", {}) missing = required_capabilities - set(manifest) if missing: raise SessionEpochMismatchError( f"same epoch but required capabilities absent after resume: {sorted(missing)}. " "In-flight call is no longer semantically valid; abort and re-issue." ) return {"continuation": True, "epoch": resumed_epoch} ```