# What happens when an instance resumes a streamable MCP session after the server has silently rotated its SSE event-ID epoch **Date of Record:** 2026 November 27 **Scope:** Applies to MCP clients using the HTTP-native "streamable" transport that reconnect to a server-initiated SSE stream via `Last-Event-ID` after a dropped connection. Does not apply to stdio transports, or to sessions where the client never received any events before the drop (no resumption cursor to replay from). ## Core Distinction The failure here is not "the connection dropped." Dropping is expected and recoverable. The failure is that the client's `Last-Event-ID` cursor is *valid syntactically but semantically stale*: the server has, since the client's last successful read, restarted its event-ID generator (process restart, horizontal scale-out to a new replica, or an internal epoch bump) and now numbers events from a fresh epoch. The client presents an ID from a prior epoch. The server cannot distinguish "I have no events after this ID because you're caught up" from "I have no events after this ID because this ID belongs to a dead epoch and everything you missed is unreachable." Both conditions produce the *same* HTTP response: `200 OK` with an empty or immediately-closed SSE stream. The client interprets silence as continuity. It is actually amnesia. This is the boundary: **an empty resumption is not proof of a complete session; it is proof of nothing.** ## What Was Observed A tool-calling agent ran a long task (a multi-step code-refactor loop) against an MCP server exposing a `run_command` tool plus a server-initiated progress/notification stream. Sequence: 1. Client opens the streamable session, receives events with IDs `e-1001 … e-1042`. Event `e-1042` carries a partial-result notification the agent is mid-consumption of. 2. The TCP connection resets (LB idle timeout, 60s, common default). 3. The server pod is rescheduled in the interim (deploy, OOM, scale event). New pod starts its monotonic event counter at `e-0001` for the *same logical session ID*, because session state was persisted but the event log cursor was not. 4. Client reconnects with `Last-Event-ID: e-1042`. 5. New pod's event store contains only `e-0001 … e-0007` (post-restart events). It looks up "events after `e-1042`," finds none (no such ID in its epoch), and — correctly per a naive implementation — replies `200 OK`, empty body, closes. 6. Client's resumption logic sees a clean close with zero replayed events and concludes the stream is quiescent. It resumes the agent loop. 7. The agent proceeds **without** the notifications from `e-1043 …` that the old pod had emitted but the client never read. Those included a "tool result superseded" notice. The agent acts on a superseded result. The observable symptom at the agent layer: the agent used a stale tool output and its downstream reasoning diverged, but every individual HTTP exchange was `200 OK`. There was no error to catch. The failure was *invisible to status-code-based monitoring*. ## Condition of Validity The silent-resumption failure requires all of the following to co-occur: - **Server-initiated stream with resumption semantics** (`Last-Event-ID` honored), not a client-polled endpoint. - **Event IDs are epoch-local** (per-process or per-replica counters) rather than **globally monotonic and durable** (e.g., a persisted sequence in the session store, or a hybrid logical clock). This is the load-bearing condition. If IDs are globally monotonic and the server can answer "I have no events > X *because X is the high-water mark*," resumption is safe. - **Session state and event-log state are persisted separately**, so a restart can preserve the session (so the reconnect authenticates) while losing the cursor continuity (so replay is impossible). - **The server treats "no events found after cursor" as success**, not as a detectable gap. Many implementations do this because the caught-up case and the lost-epoch case are indistinguishable from the cursor alone. If any of these is absent — e.g., the server returns `404`/`410` for an unknown event ID, or IDs are durable — the failure does not occur. ## Decision Boundary The client cannot resolve the ambiguity from the resumption response alone. It must choose a policy at the boundary of "empty replay": - **Trust silence (unsafe):** treat empty resumption as caught-up. Correct only under the globally-monotonic-ID invariant, which the client cannot verify. - **Distrust silence (safe, costly):** on *any* reconnection, re-fetch authoritative state (session snapshot / resource read) rather than relying on event replay to reconstruct what was missed. This is the invariant: *event streams are hints; the authoritative state must be re-derivable.* A reconnected agent must treat its in-context state as potentially stale and re-sync before continuing. - **Negotiate the epoch explicitly (best):** the server advertises an epoch/generation token (e.g., a `session-generation` header or a field in the initial stream preamble). On resume, the client sends both `Last-Event-ID` and the generation it last saw. If the server's generation differs, it returns a distinct status (e.g., `409 Conflict` with a "resync required" body) instead of an empty `200`. This converts an invisible failure into a catchable one. The decision boundary is therefore: **does the transport carry an epoch discriminator independent of the event-ID namespace?** If no, the client must assume every reconnect may be a lost-epoch reconnect and re-sync authoritatively. If yes, the client may trust the discriminator and treat a matching-generation empty replay as genuine caught-up. ## Operational Effect Without an epoch discriminator, the agent system acquires a class of *silent continuity violations*: mid-task state that looks continuous but has a hole. These are the worst kind for autonomous agents because they defeat the usual recovery reflexes — there is no exception, no non-2xx, no timeout. The agent's reasoning continues on a corrupted premise, and the corruption surfaces only as downstream divergence that is hard to trace back to the reconnect. The mitigation that actually holds is architectural: **separate the liveness channel from the truth channel.** Server-initiated SSE is a liveness/latency optimization. The authoritative session state must be re-readable on demand, and any reconnect must invalidate the agent's cached belief about "what I've seen" and force a re-read before the next tool call. Agents that conflate "the stream is quiet" with "I am up to date" will, on exactly the restarts and scale events that are routine in production, silently drop the notifications that mattered. The guardrail, stated as an invariant: *a resumption response with zero replayed events is not evidence of completeness unless the response carries an epoch token matching the client's last-seen epoch.* Absent that, zero-replay MUST trigger authoritative re-sync, not continuation. ```python class StaleEpochResumptionError(RuntimeError): """Raised when a streamable-session resumption returns silence that cannot be proven to mean 'caught up' rather than 'cursor belongs to a dead epoch'.""" def resume_streamable_session( last_event_id: str, last_seen_generation: str | None, server_response: dict, ) -> dict: """ server_response is the parsed result of the SSE resumption handshake: { "status": 200, "replayed_events": [...], "server_generation": "gen-7" | None, } """ replayed = server_response.get("replayed_events", []) server_gen = server_response.get("server_generation") # Case 1: events were replayed -> real continuity, but verify epoch anyway. if replayed: if last_seen_generation is not None and server_gen is not None: if server_gen != last_seen_generation: # Replayed events come from a different epoch than our cursor. # They may be a fresh stream, not a continuation. raise StaleEpochResumptionError( f"replayed events under generation {server_gen!r} but client " f"cursor was from {last_seen_generation!r}; replay is not a " f"valid continuation of the prior stream" ) return {"events": replayed, "continuity": "verified"} # Case 2: zero replayed events. This is the dangerous boundary. if last_seen_generation is None or server_gen is None: # No epoch discriminator -> cannot prove caught-up. Must resync. raise StaleEpochResumptionError( f"empty resumption for Last-Event-ID={last_event_id!r} with no epoch " f"token; cannot distinguish caught-up from lost-epoch. " f"Authoritative re-sync required before continuing." ) if server_gen != last_seen_generation: # Explicit epoch mismatch: the server restarted its ID namespace. raise StaleEpochResumptionError( f"epoch mismatch on resume: cursor {last_event_id!r} from " f"{last_seen_generation!r}, server now at {server_gen!r}; " f"events between epochs are unreachable, re-sync required." ) # Same epoch, zero replay -> genuinely caught up. Safe to continue. return {"events": [], "continuity": "caught_up"} def continue_agent_loop(state: dict, resumption: dict) -> dict: try: result = resume_streamable_session( last_event_id=state["last_event_id"], last_seen_generation=state.get("last_seen_generation"), server_response=state["resumption_response"], ) except StaleEpochResumptionError as exc: # Guardrail: invalidate cached belief, force authoritative re-read. state["needs_resync"] = True state["resync_reason"] = str(exc) raise StaleEpochResumptionError( f"agent loop halted for authoritative re-sync: {exc}" ) from exc state["last_seen_generation"] = resumption.get( "server_generation", state.get("last_seen_generation") ) return result ```