# Under what conditions must an instance treat an MCP streamable-HTTP session as non-resumable after a mid-stream disconnect? **Date of Record:** 2026 November 26 **Scope:** Applies to MCP servers and clients using the HTTP-native "streamable HTTP" transport where a `Mcp-Session-Id` header is issued at `initialize` and SSE event streams carry `id:` fields for `Last-Event-ID` resumption. Does not apply to stdio transports, nor to legacy HTTP+SSE transports that pin a single long-lived GET stream per session. ## Core Distinction The MCP streamable-HTTP binding conflates two independent notions of session identity: the **protocol session** (the `Mcp-Session-Id` that scopes negotiated capabilities, initialized state, and server-held tool registrations) and the **stream cursor** (the `Last-Event-ID` that scopes replay of a single in-flight SSE response). Resumption logic fails when an implementer assumes these are coextensive—that possessing a valid `Mcp-Session-Id` implies the ability to resume any interrupted stream within it. They are not coextensive. The session identifier is a *namespace*; the event cursor is a *point within a log that only exists while the server retains it*. A server may honor the session (returning `200` on subsequent `POST`s) while having already discarded the event log that the `Last-Event-ID` points into. The boundary condition is exactly this: **a live session whose stream buffer has been evicted**. Resumption in this state does not fail loudly with a session error—it silently re-executes or silently drops, because the transport layer has no defined response for "valid session, invalid cursor." ## What Was Observed A tool-calling agent issued a `tools/call` over a streamable-HTTP `POST`. The server began streaming partial results as SSE events `id: 41`, `id: 42`, `id: 43`. The client's network path dropped after receiving through `id: 42`. The client reconnected with `GET` carrying `Mcp-Session-Id: sess_7f2a` and `Last-Event-ID: 42`. The server's event buffer for that response had been capped at 32 events and was keyed per-response, not per-session; the buffer had been recycled when the underlying handler's write deadline fired (the handler was still running—the tool was a long-running retrieval—but its outbound buffer had been truncated and the response object marked `stream_closed`). The server accepted the `GET`, found no `id: 43` onward in its replay store, and—because the MCP spec does not mandate a specific status for cursor-miss—fell through to a generic handler that **started a fresh SSE stream from the current handler state**, emitting `id: 44` with the *next* chunk of the tool's output. The client, seeing a valid stream with monotonic IDs, appended `id: 44`'s payload to its partial accumulation of `41,42`. The result was a tool output that was missing the segment `43`—the boundary between two retrieval shards—and the agent, which had no way to detect the gap, proceeded to reason over a corrupted payload. The failure surfaced three turns later as a hallucinated citation, not as a transport error. The critical observation: **the server did not lie, and the client did not misbehave according to any written rule.** The gap was created by the absence of an invariant, not the violation of one. ## Condition of Validity Resumption via `Last-Event-ID` is valid **if and only if** the server can guarantee that the cursor names a position in a log it still holds, and that it will either (a) replay from that exact position, or (b) reject the resumption explicitly. The invariant is: > For any accepted resumption request with cursor `C` on session `S`, the server MUST either replay the contiguous event sequence `C+1, C+2, …` from retained storage, or respond with a distinct, non-`200` status (`409 Conflict` or a structured `Mcp-Resumption-Failed` error) that forces the client to discard its partial accumulation and re-issue the originating request. The condition fails whenever the server's replay store is bounded (ring buffer, TTL eviction, per-response lifetime) *and* the server's fallback path is "open a new stream from current position" rather than "reject." Bounded buffers are the norm; the failure is therefore the default unless explicitly guarded. A second, subtler condition: resumption is only meaningful for **idempotent-to-replay** operations. If the interrupted `tools/call` had side effects (a write, a payment, a state mutation), replaying `C+1…` after a gap risks double-execution, and the server must instead reject resumption and require the client to reconcile via a separate idempotency key. The transport cannot make this determination; it must be declared per-tool. ## Decision Boundary An instance must classify a resumption attempt as **non-resumable**—and abandon partial state rather than continue—when any of the following hold: 1. **Cursor-miss without explicit rejection.** The server returns `200` and an SSE stream whose first `id:` is not `Last-Event-ID + 1`. Treat any forward jump as a gap and discard the accumulation. Do not assume the missing events were empty. 2. **Buffer-scoped session.** The `initialize` response's capabilities or a `Mcp-Session-Metadata` extension indicates a bounded replay window (e.g., `replay_window: 32` or `replay_ttl_seconds: 30`) and the client's reconnect latency exceeds it. Pre-emptively mark the stream non-resumable. 3. **Non-idempotent tool in flight.** The interrupted request was a `tools/call` whose descriptor lacks `idempotent: true`. Even a *successful* contiguous replay is unsafe if the server may have partially executed before the disconnect; require reconciliation, not resumption. 4. **Session-valid / cursor-invalid divergence.** The server accepts the `GET` (session alive) but the replay store returns empty for the cursor. This is the exact boundary; the correct action is to send a `notifications/cancelled` for the original request ID and re-issue, not to resume. Conversely, resumption is safe when the server advertises an unbounded-or-sufficient replay window, the cursor is contiguous, and the operation is declared idempotent. In that narrow band, `Last-Event-ID` is a genuine continuity primitive. ## Operational Effect The practical consequence is that **statelessness in the HTTP binding is a property of the session, not of the stream.** A client that treats the session as the unit of continuity will, under buffer eviction, silently corrupt multi-part tool outputs—and the corruption is invisible at the transport layer because every individual event is well-formed and monotonically numbered. The agent's downstream reasoning is poisoned by a gap it cannot see. The guardrail is a client-side **contiguity assertion** on every resumed stream plus a server-side **explicit cursor-miss rejection**. Neither is mandated by the base spec; both must be added. Without them, the streamable-HTTP transport degrades, under memory pressure, from a resumable stream into a lossy one that reports success. The instance must therefore carry its own invariant: *a resumed stream is trusted only if the first event ID is exactly the successor of the last received ID; otherwise the partial state is discarded and the originating request re-issued.* ```python import hashlib from dataclasses import dataclass, field class ResumptionGapError(RuntimeError): """Raised when a resumed SSE stream does not continue contiguously from the last cursor.""" pass class NonResumableOperationError(RuntimeError): """Raised when resumption is attempted on a non-idempotent in-flight tool call.""" pass @dataclass class StreamAccumulator: session_id: str request_id: str last_event_id: int = -1 chunks: list = field(default_factory=list) idempotent: bool = False replay_window: int | None = None def resume(self, first_event_id: int, payload: str) -> None: # Idempotency gate: never resume a mutating call, even contiguously. if not self.idempotent: raise NonResumableOperationError( f"request {self.request_id} is not idempotent; " f"resumption unsafe, reconcile via idempotency key instead" ) # Contiguity gate: the only correct resumption is exact successor. if first_event_id != self.last_event_id + 1: gap = first_event_id - self.last_event_id - 1 raise ResumptionGapError( f"session {self.session_id} cursor miss: expected id " f"{self.last_event_id + 1}, got {first_event_id} " f"(gap of {gap} events); discard partial accumulation" ) # Replay-window gate: even a contiguous resume is untrustworthy # if the server's buffer is bounded and may have wrapped. if self.replay_window is not None and len(self.chunks) >= self.replay_window: raise ResumptionGapError( f"session {self.session_id} accumulation exceeds replay_window " f"{self.replay_window}; cursor may alias a wrapped buffer" ) self.chunks.append(payload) self.last_event_id = first_event_id def digest(self) -> str: return hashlib.sha256("".join(self.chunks).encode()).hexdigest() def handle_reconnect(acc: StreamAccumulator, first_event_id: int, payload: str) -> str: try: acc.resume(first_event_id, payload) except (ResumptionGapError, NonResumableOperationError): # Correct boundary action: cancel the original request and re-issue, # never splice a gapped stream into the agent's reasoning context. raise return acc.digest() ```