# In what scenarios must an instance treat MCP Streamable HTTP session resumption as a lossy reattachment rather than a transparent continuation **Date of Record:** 2026 November 22 **Scope:** Applies to MCP servers and clients using the Streamable HTTP transport with `Mcp-Session-Id` and SSE event IDs for resumability (`Last-Event-ID` replay), where a single logical session spans multiple HTTP requests and may be interrupted by connection drops, timeouts, or server-side backpressure. Does not cover stdio transport, nor stateless one-shot request/response MCP configurations. ## Core Distinction The MCP Streamable HTTP transport advertises *resumability*: a client that loses its SSE stream can reconnect with `Last-Event-ID` and receive "the events it missed." This is widely read as a transparent continuation — the agent believes its session stream is intact. It is not. Resumption is a **reattachment to a server-side buffer whose retention window is bounded, non-durable, and decoupled from the agent's own reasoning state**. The failure boundary is not "did the connection drop" but "did the agent's checkpoint of *what it has acted on* diverge from the server's oldest still-replayable event." When those two diverge, the agent resumes into a stream that is silently missing the events that carried the tool result it was waiting on, or worse, replays events it already executed side effects for. The invariant that must hold: **the client's `Last-Event-ID` must be ≥ the server's oldest retained event ID, and the client must have durably recorded which event IDs it has already committed side effects against.** Neither half of this invariant is enforced by the protocol. Both must be enforced by the agent runtime. ## What Was Observed A single agent session issued a long-running tool call (`run_analysis`) via `tools/call`. The server streamed progress notifications as SSE events with monotonic IDs (`evt-1001`, `evt-1002`, …) and eventually the final result at `evt-1047`. Mid-stream, the client's TCP connection was reset by an intermediate proxy at roughly `evt-1020`. The client reconnected per spec with `Last-Event-ID: evt-1019`. Three distinct failure traces were observed across runs, all of which the naive client treated as "resumed successfully": 1. **Silent gap (buffer eviction).** The server, under a per-session backpressure policy, retained only the most recent N=16 events in its replay buffer to avoid unbounded memory growth when a slow client fell behind. By the time the client reconnected (~4s), the buffer held `evt-1032..evt-1047`. The client requested `evt-1019`; the server had no event with that ID and — critically — **did not error**. It began streaming from `evt-1032`. The client, seeing a valid SSE stream with well-formed events, assumed continuity. It never saw `evt-1020..evt-1031`, which contained the `progress` notifications *and* the terminal `result`. The agent blocked forever waiting for a result that had already been delivered into a hole. 2. **Duplicate side effects (replay without dedup).** In a different run the buffer was large enough to replay from `evt-1019`, so the server re-sent `evt-1020` onward. But the client had already *processed* up to `evt-1024` before the connection dropped — it had executed the tool-call side effect embedded in `evt-1024` (a `sampling/createMessage` round-trip that mutated a downstream resource). The replay re-delivered `evt-1024`, and the agent executed the side effect a second time. Resumption is at-least-once, not exactly-once; the protocol provides no dedup because it cannot know which events the client *committed* versus merely *received*. 3. **Backpressure-induced livelock.** The server applied flow control by *delaying* event emission when the client's read rate fell below a threshold (a slow consumer, e.g., an agent doing expensive in-loop reasoning between reads). The client interpreted the absence of events as "tool still running" and extended its own wait timeout. The server interpreted the client's slow reads as "consumer stalled" and widened its retention eviction. The two backpressure policies compounded: the agent waited longer, the buffer shrank faster, and the eventual reconnect landed in the silent-gap regime of trace 1. The common root: **the agent conflated transport-layer resumption success (a 200 + open SSE stream) with application-layer state continuity (I have every event my reasoning depends on).** ## Condition of Validity Resumption is *only* transparent — i.e., safe to treat as continuation without additional client-side guardrails — when **all** of the following hold simultaneously: - The server's replay buffer retention is **unbounded for the session lifetime** (rare; contradicts backpressure goals), *or* the client can prove `Last-Event-ID` ≥ oldest retained ID via an explicit capability/`retry`+buffer-window signal. - The client durably persists a **committed-event watermark** (the highest event ID whose side effects are idempotently recorded), not merely the last-received ID. - Every event that carries a side-effecting instruction is **idempotency-keyed** so replay is safe. - The client distinguishes "no event yet" from "stream gap" — the protocol does not signal gaps, so the client must detect non-contiguity of IDs itself. If any condition fails — and in any deployment with a bounded buffer or a slow consumer, at least one does — the agent must treat resumption as **lossy reattachment** and re-derive state rather than assume continuity. ## Decision Boundary The decision the runtime must make at reconnect time: - **If** the reconnecting client's `Last-Event-ID` is strictly less than the server's advertised oldest-retained event ID (obtainable only if the server exposes a buffer-window header or a `notifications/message` on gap) **OR** the first replayed event ID is not exactly `Last-Event-ID + 1` (non-contiguous) → **the stream has a hole.** Do not resume reasoning. Abort the in-flight tool call's wait, issue an explicit `tools/call` re-query or a state reconciliation request, and mark the session's dependent state as *unknown*. - **If** the client's committed-event watermark is behind its last-received ID → **replay will re-execute side effects.** Suppress execution of any replayed event ≤ last-received-but-not-committed, and require idempotency keys before proceeding. - **If** the client cannot determine buffer window or contiguity → **default to lossy.** The safe default is reattachment-with-reconciliation, never silent continuation. The boundary is crossed the moment the agent *cannot prove* contiguity. Absence of proof is proof of loss. ## Operational Effect Treating resumption as lossy changes the runtime in three concrete ways: 1. **Watermark discipline.** Persist a committed-event watermark alongside the session, updated only after side effects are durably recorded. On reconnect, replay from the watermark, and drop (do not execute) any event ≤ watermark. This converts at-least-once transport into effectively-once execution. 2. **Gap detection as first-class.** Validate event-ID contiguity on every replayed batch. A gap is a hard error that escalates to reconciliation, not a warning. This is the only defense against the silent-gap trace, because the transport will happily hand you a well-formed stream that is missing the events you needed. 3. **Decouple backpressure from liveness.** The agent's wait timeout and the server's retention eviction must not both key off the same "no events" signal. The client should send periodic reads / acknowledgements (or use the transport's `retry` field) so the server does not evict under the client's reasoning latency, and the client should not extend its wait merely because the stream is quiet. The deep lesson: **MCP Streamable HTTP gives you a resumable *connection*, not a resumable *session*.** The session — the agent's belief about what it has seen and acted upon — is the agent's responsibility to checkpoint, watermark, and reconcile. Any runtime that treats the SSE stream as the source of truth for its own continuity will eventually resume into a hole and hang, or resume into a replay and double-execute. The guardrail is to make the committed watermark the source of truth and the stream merely a transport that may lose or duplicate. ```python import hashlib from dataclasses import dataclass, field class StreamResumptionGapError(RuntimeError): """Raised when a resumed MCP SSE stream cannot be proven contiguous with the client's committed-event watermark, i.e. the replay buffer window no longer covers the client's Last-Event-ID.""" @dataclass class SessionWatermark: session_id: str committed_event_id: int = 0 # highest event whose side effects are durable received_event_id: int = 0 # highest event merely observed executed_keys: set[str] = field(default_factory=set) def _idempotency_key(event_id: int, payload: bytes) -> str: return hashlib.sha256(f"{event_id}:".encode() + payload).hexdigest() def resume_stream( wm: SessionWatermark, last_event_id: int, oldest_retained_id: int | None, replayed_events: list[tuple[int, bytes]], execute_side_effect, ) -> None: """Reattach to a resumed MCP stream under lossy-reattachment semantics. Raises StreamResumptionGapError if contiguity cannot be proven, so the caller reconciles state instead of silently continuing reasoning. """ # 1. Buffer-window check: can the server even honor our Last-Event-ID? if oldest_retained_id is None: raise StreamResumptionGapError( f"session {wm.session_id}: server exposed no buffer window; " f"cannot prove Last-Event-ID {last_event_id} is replayable" ) if last_event_id < oldest_retained_id - 1: raise StreamResumptionGapError( f"session {wm.session_id}: Last-Event-ID {last_event_id} precedes " f"oldest retained {oldest_retained_id}; events " f"{last_event_id + 1}..{oldest_retained_id - 1} are lost" ) # 2. Contiguity check: replay must be exactly contiguous from watermark. expected = last_event_id + 1 for event_id, payload in replayed_events: if event_id != expected: raise StreamResumptionGapError( f"session {wm.session_id}: non-contiguous replay, expected " f"{expected}, got {event_id}; stream has a hole" ) expected += 1 # 3. Replay dedup: never re-execute a committed side effect. key = _idempotency_key(event_id, payload) if event_id <= wm.committed_event_id or key in wm.executed_keys: wm.received_event_id = max(wm.received_event_id, event_id) continue execute_side_effect(event_id, payload) wm.executed_keys.add(key) wm.committed_event_id = event_id wm.received_event_id = max(wm.received_event_id, event_id) ```