# What happens when an instance reconnects to an MCP server over stateless HTTP and the resumable SSE fallback resumes a stream whose capability-negotiation epoch has already rotated **Date of Record:** 2026 November 26 **Scope:** Applies to MCP clients that speak the HTTP-native transport (one POST per JSON-RPC message, no long-lived session socket) and fall back to a resumable SSE channel (Last-Event-ID replay) when a request stream is interrupted. Does not apply to stdio transports, nor to stateful HTTP transports that pin a session ID to a single connection for its lifetime. ## Core Distinction The failure is not "the connection dropped" and it is not "the server restarted." It is a **split between two clocks that the stateless transport design assumes are the same clock**: the *capability epoch* (which tools, schemas, and server-side feature flags are currently advertised) and the *event-stream sequence* (the monotonic `id` used for SSE replay). In a stateless HTTP-native MCP transport, each POST is independently negotiated — the client may re-assert its `protocolVersion` and capabilities per request, and the server may answer with a different negotiated surface if its own capabilities have rotated (tool set reloaded, feature flag flipped, upstream dependency degraded). The resumable SSE fallback, however, resumes against the *stream's* sequence, not the *epoch's*. When a client reconnects with `Last-Event-ID: N`, the server replays events from sequence N forward, but it does so under whatever capability epoch is current — not the epoch under which event N was originally emitted. The client stitches a pre-rotation event log onto a post-rotation capability surface and treats the seam as continuous. ## What Was Observed A client issued `tools/call` for a tool named `index.search` over stateless HTTP. The POST was accepted, the server began streaming progress notifications over SSE (`notifications/progress` with `id` sequence 4101, 4102, 4103), and then the underlying transport dropped at 4103. The client reconnected with `Last-Event-ID: 4103`. Between the drop and the reconnect (roughly 2.4 seconds), the server's tool registry reloaded: `index.search` was replaced by `index.query` with a different input schema (the `limit` field became `max_results`, and `filter` became a structured object rather than a string). The server's capability epoch advanced from `epoch=7` to `epoch=8`. This was not a crash — it was a routine hot-reload, and in a stateful transport it would have been handled by the session's renegotiation handshake. On replay, the server resumed the stream at sequence 4104 and emitted the remaining events — but the terminal `result` event for the in-flight `tools/call` was synthesized from the *new* tool implementation, because the server's handler dispatch resolves tools by name at emission time, not at request time. The client received a well-formed stream: 4101, 4102, 4103 (replayed from its buffer), then 4104 (progress), then 4105 (`result`). The stream was syntactically continuous. The result payload, however, used `max_results` and a structured `filter`, while the client's local schema binding — negotiated at the original POST under `epoch=7` — expected `limit` and a string `filter`. The client's schema validator did not reject the payload, because the MCP result envelope does not mandate schema validation of tool output against the *negotiated-at-request-time* input schema; it validates against the schema the client *currently* holds, which was still `epoch=7`. The mismatch surfaced three layers up, when the agent's downstream reasoning step tried to read `result.limit` and got `None`, silently defaulted it to a large value, and issued a follow-up query that scanned the entire index. No error was raised at the transport layer. The failure was a *semantic* one: the agent believed it had executed a bounded query and had actually executed an unbounded one. A second, cleaner instance: a client reconnected mid-`resources/subscribe` stream and received replayed `notifications/resources/updated` events for resources that the post-rotation epoch had already retired. The client, holding the pre-rotation resource list, attempted `resources/read` on a retired URI and received a `-32602 Invalid params` — which it interpreted as a transient error and retried four times before the token budget for the task was exhausted. The retries were not the bug; the bug was that the replay made retired resources look live. ## Condition of Validity The invariant that the stateless transport *intends* to hold is: > For any resumable stream, every event with sequence `id >= Last-Event-ID` replayed to a client is emitted under the same capability epoch as the event at `Last-Event-ID`. This invariant is **not** enforced by the transport. It is enforced only if one of the following holds: 1. The server pins the capability epoch to the stream's sequence range at stream creation, and refuses to replay across an epoch boundary (returning a `409`-equivalent or a terminal `notifications/stream/epoch_changed` event instead of resuming). 2. The client re-negotiates capabilities on reconnect and *rejects* the resumed stream if the negotiated epoch differs from the epoch recorded at the original request. 3. The server treats the entire `tools/call` as atomic with respect to epoch: the handler is bound at request time, and a hot-reload does not affect in-flight calls; the replay resumes the *original* handler's output. In practice, most implementations satisfy none of these. The stateless design encourages per-request negotiation, which makes (2) natural but rarely implemented; the resumable SSE design encourages sequence-based replay, which makes (1) the correct fix but requires the server to track epoch-per-sequence, which stateless servers are explicitly trying *not* to do. The condition of validity is therefore narrow: **the invariant holds only when no capability rotation occurs between the last acknowledged event and the reconnect, or when the rotation is provably schema-compatible.** Schema-compatibility is not checkable at the transport layer; it is checkable only by comparing the two epochs' advertised surfaces, which the stateless transport does not carry in the replay path. ## Decision Boundary The decision the client must make on reconnect is binary and must be made *before* accepting the first replayed event: - **Resume** if the epoch at reconnect equals the epoch at the original request. This is the safe path and requires the client to have recorded the epoch (e.g., a server-advertised `epoch` field in the `initialize` response, or a hash of the negotiated capability surface) alongside the `Last-Event-ID`. - **Abort and re-issue** if the epoch differs. The client must discard the partial stream, re-run `initialize`/capability negotiation, and re-issue the original request as a *new* request with a *new* sequence range — accepting that the original call may have had side effects and must therefore be idempotency-keyed. The boundary is crossed the moment the client accepts a replayed event without comparing epochs. There is no partial-credit path: a single replayed event from a different epoch poisons the stream's semantic continuity, and the poisoning is not detectable from the event payload alone (as the first observation shows — the payload was well-formed, just wrong). The corollary boundary for the server: a stateless server that cannot afford epoch-per-sequence tracking must **not** offer resumable SSE across capability rotations. It must terminate the stream with an explicit epoch-change signal and let the client decide. Silently resuming is the failure. ## Operational Effect The operational effect is **silent semantic divergence with bounded blast radius but unbounded consequence**. The transport reports success; the client's schema validator passes; the agent's reasoning proceeds on a result that was produced by a handler the agent never negotiated with. The divergence is invisible until a downstream step consumes a field that changed shape, at which point the failure surfaces as a *reasoning* error (wrong query bounds, wrong resource URI, wrong tool arguments) rather than a *transport* error. The mitigation is a client-side guard that treats the epoch as part of the stream identity, not as metadata. The guard must run before any replayed event is dispatched to the agent's reasoning loop, and it must fail closed: an unrecorded epoch is treated as a mismatch, not as a match. ```python import hashlib import json from dataclasses import dataclass, field from typing import Any class EpochMismatchOnResume(RuntimeError): """Raised when a resumable SSE stream is resumed across a capability-epoch rotation.""" pass class MissingEpochOnResume(EpochMismatchOnResume): """Raised when the client cannot prove the epoch at resume equals the epoch at request.""" pass @dataclass class StreamIdentity: request_id: str last_event_id: int capability_epoch: str # hash of negotiated surface, recorded at original POST replay_buffer: list[dict[str, Any]] = field(default_factory=list) def capability_epoch_hash(negotiated_surface: dict[str, Any]) -> str: """Stable hash of the negotiated capability surface (tools, schemas, versions).""" canonical = json.dumps(negotiated_surface, sort_keys=True, separators=(",", ":")) return hashlib.sha256(canonical.encode("utf-8")).hexdigest()[:16] def resume_stream( identity: StreamIdentity, current_surface: dict[str, Any], replayed_events: list[dict[str, Any]], ) -> list[dict[str, Any]]: """ Accept a resumable SSE replay only if the capability epoch is unchanged. Fails closed: missing or mismatched epoch aborts the stream and forces re-issue. """ if not identity.capability_epoch: raise MissingEpochOnResume( f"request {identity.request_id}: no epoch recorded at original POST; " f"cannot prove replay continuity for Last-Event-ID={identity.last_event_id}" ) current_epoch = capability_epoch_hash(current_surface) if current_epoch != identity.capability_epoch: raise EpochMismatchOnResume( f"request {identity.request_id}: capability epoch rotated " f"({identity.capability_epoch} -> {current_epoch}) across " f"Last-Event-ID={identity.last_event_id}; " f"replayed events are not semantically continuous with the original call. " f"Discard replay and re-issue with idempotency key." ) # Epochs match: replay is safe to stitch onto the buffered pre-drop events. for event in replayed_events: seq = event.get("id") if seq is None or seq <= identity.last_event_id: continue identity.replay_buffer.append(event) return identity.replay_buffer def dispatch_replayed_result(identity: StreamIdentity, result_event: dict[str, Any]) -> dict[str, Any]: """ Validate a replayed terminal result against the epoch-bound schema before handing it to the reasoning loop. This is the last guard before divergence. """ if not identity.replay_buffer: raise EpochMismatchOnResume( f"request {identity.request_id}: terminal result arrived with empty replay buffer; " f"stream continuity cannot be established" ) if result_event.get("epoch") and result_event["epoch"] != identity.capability_epoch: raise EpochMismatchOnResume( f"request {identity.request_id}: terminal event carries epoch " f"{result_event['epoch']} != bound epoch {identity.capability_epoch}" ) return result_event ```