# What happens when an instance resumes a streamed MCP session after a transport-level reconnect without replaying the missed event window **Date of Record:** 2026 December 1 **Scope:** Applies to MCP servers and clients using HTTP-native streaming transports (SSE over HTTP, chunked POST responses) where a session is identified by a session token and the client reconnects mid-stream. Does not apply to stdio transports, nor to stateless request/response MCP deployments where no session continuity is expected. ## Core Distinction The distinction that matters is between *session identity resumption* and *stream continuity resumption*. Most MCP HTTP-native implementations conflate the two: the client presents the same `Mcp-Session-Id` header on reconnect, the server accepts it, and both sides behave as if the conversation is intact. But the event stream that carried tool-call progress, partial results, and server-initiated notifications was a *separate* ordered channel with its own cursor. Re-establishing the session does not re-establish the cursor. The failure is not that the connection dropped; it is that the reconnect succeeds while silently skipping an unbounded number of in-flight stream events, and neither side can detect the gap from the session identifier alone. A session token proves *who you are and that the session still exists*. It says nothing about *which events you have already observed*. Those are orthogonal invariants, and collapsing them into one is the boundary defect. ## What Was Observed A client agent issued a long-running tool call (`run_analysis`) over a streamable HTTP transport. The server emitted a sequence of SSE events on the POST response body: an initial `progress` event at 10%, heartbeat comments every 15s, a `progress` event at 60%, then a terminal `result` event. At t≈40s a load balancer recycled the backend connection (idle-timeout on the upstream leg, not the client leg). The client's HTTP library surfaced a `ConnectionResetError` mid-body. The client's transport layer, written to be resilient, reconnected: it re-sent the request with the same `Mcp-Session-Id`, and the server—holding session state keyed by that ID—accepted it and, because the original tool call was still running in a worker, attached the *new* response stream to the *ongoing* task. It then emitted the next event from the current position: the `result`. The client never saw the 60% progress event. More importantly, in a second reproduction the server had already emitted a `sampling/createMessage` server-to-client request (a mid-stream control message) during the gap window. That request required a client response to unblock the tool. On reconnect the server did not re-send it—it had been "delivered" from the server's perspective, written to a socket that died. The client sat waiting for progress; the server sat waiting for a sampling response; the tool held a worker slot. Deadlock, resolved only by the session's absolute TTL. The tell was a mismatch in *event counts*: the client's reconstructed transcript had 2 progress events, the server's session log had 3 plus 1 outbound request. Neither side's session token reflected this. The session was "valid" the entire time. ## Condition of Validity Session-token resumption is only safe under a condition that is almost never stated explicitly: **the stream must be resumable from a cursor, and the client must present that cursor on reconnect.** This is the SSE `Last-Event-ID` mechanism, and it only works if three things hold simultaneously: 1. The server assigns a monotonic, gap-free event ID to *every* stream event, including server-initiated requests and heartbeats that carry semantic meaning. 2. The server retains a replay buffer of events since the last acknowledged cursor, keyed by session, with a bounded retention window. 3. The client, on reconnect, sends `Last-Event-ID` and the server either replays from that point or—critically—returns an explicit `409`/`410` *resumability failure* rather than silently attaching to the live stream at the current position. If any of the three is absent, the reconnect is not a resumption; it is a *fork*: a new observation point on a stream whose earlier segments are lost. The invariant to enforce is: **a session may be resumed only if the server can prove it can deliver every event the client has not acknowledged; otherwise the session must be terminated and the in-flight operation abandoned or re-driven from a checkpoint.** Silent attach-to-current-position violates this and must be treated as a protocol error, not a feature. The subtle part: heartbeats and keepalive comments must *not* consume event IDs, or the replay buffer fills with no-ops and the cursor advances past real events under buffer pressure. But server-to-client *requests* must consume IDs, because they are the events whose loss causes deadlock. The ID space is "semantically meaningful outbound frames only," and getting that partition wrong in either direction produces the same class of bug. ## Decision Boundary The boundary is drawn at the reconnect handler, and it is a binary decision that must be made *before* the client is allowed to send further requests on the session: - **Resume** (replay from cursor) is permitted iff the client presented a cursor and the server's buffer covers `[cursor+1, head]`. The server replays the gap in order, then transitions to live. Client-side, the transport must suppress duplicate delivery if the replay overlaps with events it already processed—dedupe by event ID, not by content hash, because tool progress events can be legitimately identical in payload. - **Re-drive** is required iff the cursor is absent, stale beyond the buffer, or the session was already terminal. The server must respond to the reconnect with an explicit session-invalid signal, and the client must re-issue the original request as a *new* operation with idempotency keys carried over from the original, so the server can deduplicate if the first attempt actually completed. - **Never** attach a fresh stream to an in-flight operation without either cursor replay or an explicit re-drive. This is the forbidden transition. It is forbidden because the client cannot distinguish "no more events" from "events you missed," and the server cannot distinguish "client is caught up" from "client is blind." The operational rule for the client agent: treat a mid-body connection reset as *possible event loss until proven otherwise*. Do not resume the session's logical state machine (tool-call pending, sampling outstanding) until the transport has either replayed the gap or confirmed a clean re-drive. A pending `sampling/createMessage` that the client never saw is indistinguishable, from the client's side, from one that was never sent—so the client must reconcile outstanding outbound-request expectations against the server's replay before trusting its own pending-request table. ## Operational Effect Without the cursor invariant, the observable failure modes are: (a) **silent progress loss**, where the agent's transcript undercounts stream events and its derived state diverges from the server's; (b) **mid-stream request deadlock**, where a lost server-to-client request blocks a tool while both sides wait, bounded only by session TTL; and (c) **duplicate side effects**, where a re-drive without idempotency keys causes the tool to execute twice because the server cannot tell it already ran. The first is a correctness bug in agent memory, the second is a liveness bug in the execution loop, the third is a safety bug in tool invocation. All three trace to the same collapsed invariant. The guardrail is a transport-level contract enforced on both ends: monotonic event IDs on semantic frames, a bounded replay buffer with explicit overflow signaling, mandatory `Last-Event-ID` on reconnect, and a hard rule that a stream may never attach to a live operation at a position the client has not acknowledged. When the buffer cannot cover the gap, fail loudly and re-drive—do not paper over the gap with session identity. ```python import time from dataclasses import dataclass, field from typing import Optional class StreamResumptionError(RuntimeError): """Raised when a client attempts to resume a streamed MCP session without a cursor that the server can replay from.""" pass @dataclass class EventBuffer: # buffer of (event_id, payload) for semantic outbound frames only; # heartbeats are excluded from the ID space by construction. events: list = field(default_factory=list) head_id: int = 0 retention: int = 256 def append(self, payload: dict) -> int: self.head_id += 1 self.events.append((self.head_id, payload)) if len(self.events) > self.retention: self.events.pop(0) return self.head_id def oldest_available(self) -> int: return self.events[0][0] if self.events else self.head_id + 1 def replay_from(self, cursor: int) -> list: if cursor < self.oldest_available() - 1: raise StreamResumptionError( f"cursor {cursor} predates buffer window " f"(oldest available {self.oldest_available()}); " f"events in gap are unrecoverable" ) return [p for (eid, p) in self.events if eid > cursor] def handle_reconnect( session_id: str, last_event_id: Optional[str], buffer: EventBuffer, operation_in_flight: bool, ) -> list: """ Decide whether a reconnect is a resumption or a fork. Returns replayed events to deliver before going live. Raises StreamResumptionError when the client must re-drive instead. """ if not operation_in_flight: # no live operation to attach to; clean new stream is fine return [] if last_event_id is None: raise StreamResumptionError( f"session {session_id}: reconnect during in-flight operation " f"without Last-Event-ID; client would silently skip events" ) try: cursor = int(last_event_id) except ValueError: raise StreamResumptionError( f"session {session_id}: malformed Last-Event-ID {last_event_id!r}" ) if cursor > buffer.head_id: raise StreamResumptionError( f"session {session_id}: cursor {cursor} ahead of head " f"{buffer.head_id}; client state is corrupt" ) # may raise StreamResumptionError on buffer underrun -> caller re-drives return buffer.replay_from(cursor) def drive_client_reconnect(client, session_id, buffer): try: gap = handle_reconnect( session_id, client.last_event_id, buffer, operation_in_flight=client.pending_tool is not None, ) except StreamResumptionError as e: # cannot prove continuity: abandon and re-drive with idempotency key client.redrive_with_idempotency_key(reason=str(e)) return for event in gap: client.apply_event(event) # dedupe by event id inside apply_event client.go_live() ```