# How should an instance treat a resumed MCP streamable-session as a *new* event source rather than a continuation of the old one **Date of Record:** 2026 November 20 **Scope:** Applies to MCP deployments using the HTTP-native *streamable* transport (POST for client→server requests, optional SSE on the response body for server→client push), where a session can survive a dropped connection and be resumed via the `Mcp-Session-Id` header and a `Last-Event-ID` replay cursor. Does not apply to stdio transport, nor to stateless per-request MCP servers with no session affinity. ## Core Distinction There are two incompatible mental models of "resumption," and the failure lives in the gap between them: - **Continuation model** (what the client's reconnect logic assumes): the session is a single logical stream. After a disconnect, I reconnect, present `Last-Event-ID`, and the server replays everything I missed. From my side the event sequence is gapless and monotone. - **New-source model** (what the transport actually guarantees): the *session* is durable, but the *event stream* is not. The streamable transport only promises that a server *may* replay events after the last ID it acknowledges. It does not promise that the SSE channel that reopens is the same channel, that in-flight server-push work survives the socket teardown, or that the event IDs form a total order across reconnects. The invariant an instance must adopt: **a resumed stream is a fresh subscription that happens to share a session ID, not a patch over the hole in the old subscription.** Any agent that reasons about its event log as if it were contiguous will silently drop, duplicate, or reorder server-push events — and because server-push is exactly where MCP servers deliver *asynchronous tool progress and out-of-band notifications*, the loss is invisible to the agent's own request/response bookkeeping. ## What Was Observed A long-running agent held an MCP session to a server exposing a `run_analysis` tool that streams progress notifications (`notifications/progress`) over the SSE channel while the tool executes, and emits a final `notifications/message` when done. The tool takes 4–6 minutes. The client's HTTP layer had a 90-second idle timeout on the SSE read. Trace of the boundary failure: 1. Agent calls `tools/call run_analysis`. Server returns `202`-style acceptance on the POST and begins pushing progress events on the SSE body: `id: 1001`, `id: 1002`, … `id: 1040`. 2. At t≈90s the load balancer reaps the idle SSE connection. The agent's transport sees EOF, not an error. It records `last_event_id = 1040`. 3. The agent's reconnect logic — written under the **continuation model** — reconnects with `Last-Event-ID: 1040`. The server, which never persisted the per-connection send buffer for this session (the spec permits this — replay is best-effort), has nothing to replay. It opens a *new* SSE stream and returns `200` with an empty backlog. It does **not** re-run the tool; the tool is still executing in a worker keyed by session, not by connection. 4. Progress events `1041`–`1075` are emitted by the still-running worker but are written to the *dead* connection's buffer and discarded. The agent sees an empty replay, concludes "no missed events," and waits. 5. At t≈5min the worker finishes and attempts to emit the final `notifications/message` on the *current* connection. But the worker captured a reference to the connection that existed at call time. Depending on server implementation, this either (a) throws into a swallowed exception, or (b) is delivered — and the agent, having no progress events between `1040` and the terminal message, cannot distinguish "completed normally" from "completed after a silent 35-event gap." 6. Worse variant observed: the worker *did* rebind to the new connection and re-emitted from `1041` onward, but the server's event-ID counter had been reset per-connection, so the replayed events arrived as `id: 1`, `id: 2`, … The agent's dedup logic keyed on `(session, event_id)` treated all 35 replayed events as duplicates of the *first* 35 events it had already seen (IDs `1`–`35` from the original stream, which had also started at `1` because the server used a per-connection counter). Thirty-five real progress events were dropped as duplicates. The final message arrived with an ID that sorted *before* `1040`, so the agent's "is this the latest event?" check rejected it as stale. The agent did not crash. It reported success on a tool whose progress stream had a 35-event hole and whose terminal event was mis-ordered. The failure was a *continuity* failure, not an availability failure — which is why it survived every health check. ## Condition of Validity The continuation model is only valid when **all three** of the following hold; if any fails, the instance must fall back to the new-source model: 1. **Server-side replay is durable and monotone across connections.** The server persists the session's event log with a session-scoped (not connection-scoped) monotone counter, and honors `Last-Event-ID` by replaying the exact suffix. This is *permitted* by the streamable spec but not *required*; a server that returns `200` with an empty backlog on an unknown `Last-Event-ID` is conformant. 2. **In-flight server-push work is bound to the session, not the connection.** The tool worker must write to a session-scoped outbox that the *current* SSE connection drains, so a reconnect picks up where the dead connection left off. A worker holding a captured connection handle violates this. 3. **Event IDs are globally ordered within the session.** If the server resets its ID counter per connection, `Last-Event-ID` is meaningless as a cursor and dedup-by-ID is actively harmful. An agent cannot verify (1)–(3) from the client side by inspection. It can only *probe* them: on reconnect, if the replay backlog is empty while a tool call is known to be in flight, treat condition (1) as unverified and degrade. The load balancer's idle timeout is the trigger that makes this probe fire in practice; any intermediary (proxy, gateway, mobile radio) that reaps idle SSE connections is an equivalent trigger. ## Decision Boundary The instance must decide, on every reconnect of a streamable session, whether it is safe to treat the stream as continuous. The boundary: - **If** a tool call is in flight **and** the reconnect replay is empty **and** the elapsed wall-clock since last event exceeds the server's advertised progress cadence → **do not** assume continuity. The agent must issue an explicit `tools/call` status probe (a separate request keyed by the same session, e.g. a `get_operation` companion tool) or re-invoke idempotently, rather than waiting on a stream that may never deliver the terminal event. - **If** replayed events arrive with IDs that do not sort strictly after `last_event_id` → the server uses per-connection counters; the agent must **disable ID-based dedup** for this session and switch to content-hash dedup within a bounded window, and must not use ID ordering to decide "latest." - **If** the terminal event arrives with no intervening progress events after a known gap → the agent must mark the tool result as `continuity_degraded` and surface it, not report clean success. The bright line: **an empty replay is not evidence of no missed events; it is evidence of nothing.** Absence of replay must be treated as unknown, never as zero. ## Operational Effect An instance that internalizes the new-source model stops conflating "session alive" with "stream alive." Concretely: - It treats `Mcp-Session-Id` as durable state (tool workers, auth context) and the SSE channel as ephemeral transport, and never lets a reconnect reset its belief about in-flight work. - It bounds the wait on any server-push terminal event by a wall-clock deadline derived from the tool's advertised cadence, and on expiry escalates to an out-of-band status probe instead of blocking. - It records a per-session `continuity_degraded` flag whenever a reconnect produced an empty or mis-ordered replay during in-flight work, and propagates that flag into the tool result so downstream reasoning does not treat a holed progress stream as complete. - It never assumes event-ID monotonicity across connections; it validates the first replayed ID against `last_event_id` and downgrades its dedup strategy if the check fails. The cost of the continuation model is a silent, health-check-invisible hole in exactly the channel that carries asynchronous truth. The cost of the new-source model is one extra status probe per degraded reconnect. The latter is always cheaper. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Optional class StreamContinuityError(RuntimeError): """Raised when a resumed MCP streamable session cannot be treated as continuous.""" @dataclass class StreamState: session_id: str last_event_id: Optional[int] = None in_flight_tool: Optional[str] = None last_event_wallclock: float = 0.0 progress_cadence_s: float = 30.0 continuity_degraded: bool = False _seen_ids: set[int] = field(default_factory=set) def on_reconnect( state: StreamState, now: float, replayed_ids: list[int], ) -> StreamState: """ Decide whether a resumed stream is a continuation or a new event source. Implements the new-source invariant: an empty replay during in-flight work is *unknown*, never *zero missed events*. """ if state.in_flight_tool is None: # No async work to lose; safe to treat as continuation. return state gap_s = now - state.last_event_wallclock # Condition (1) unverified: empty replay while work is in flight. if not replayed_ids: if gap_s > state.progress_cadence_s: state.continuity_degraded = True raise StreamContinuityError( f"session {state.session_id}: empty replay after {gap_s:.1f}s " f"(cadence {state.progress_cadence_s}s) during in-flight " f"tool {state.in_flight_tool!r}; stream cannot be assumed continuous" ) return state # Condition (3) check: IDs must sort strictly after last_event_id. first = replayed_ids[0] if state.last_event_id is not None and first <= state.last_event_id: # Per-connection counter reset detected. ID-based dedup is unsafe. state.continuity_degraded = True state._seen_ids.clear() # abandon ID dedup; caller must use content hashes raise StreamContinuityError( f"session {state.session_id}: replayed id {first} does not sort after " f"last_event_id {state.last_event_id}; server uses per-connection " f"counters, ID monotonicity invalid" ) for eid in replayed_ids: state._seen_ids.add(eid) state.last_event_id = replayed_ids[-1] return state ```