# In what scenarios must an instance refuse to resume an MCP streamable session after an SSE-to-POST upgrade boundary **Date of Record:** 2026 November 25 **Scope:** Applies to MCP servers exposing the HTTP-native Streamable HTTP transport where a client opens a GET SSE stream, receives an `Mcp-Session-Id`, and later resumes via POST (or re-GETs with `Last-Event-ID`). Does not apply to pure stdio transports, nor to legacy HTTP+SSE dual-endpoint servers where the GET stream is never reattached to a POST channel. ## Core Distinction The critical distinction is between *transport-level resumption* (the HTTP connection re-establishes and the server accepts the session ID) and *semantic-level resumption* (the server can prove that the event sequence the client claims to have received is a prefix of what the server actually emitted, and that no in-flight server-initiated request was orphaned by the disconnect). Streamable HTTP makes the first trivially cheap — a valid `Mcp-Session-Id` header plus a matching `Last-Event-ID` passes most gateway checks — while the second is where agent state silently corrupts. An instance must refuse to resume whenever the two diverge, because a "successful" resume that skips an orphaned `sampling/createMessage` or `roots/list_changed` notification leaves the agent reasoning over a world model that the server has already superseded. ## What Was Observed A client agent opened a GET SSE stream, received events with IDs `e1..e7`, and the server, mid-stream, issued a server-initiated `sampling/createMessage` request (event `e8`, requiring a client response on a POST). The TCP connection dropped before `e8` was flushed to the client's read buffer but after the server had committed it to the session's outbound queue and marked it `pending_response=true`. The client reconnected with `Last-Event-ID: e7`. The server's resumption handler validated the session ID, found `e7` in the replay log, and replayed `e9..e12` — skipping `e8` entirely because `e8` was classified as "already dispatched" rather than "acknowledged." The client resumed cleanly, its agent loop continued, and the pending sampling request was never answered. The server's session timer eventually expired the request and emitted a `cancel` that the client received as an unsolicited notification, which the agent's planner interpreted as a user abort and used to terminate an unrelated task. The failure trace is precise: `dispatched ≠ acknowledged`. Streamable HTTP's `Last-Event-ID` semantics, borrowed loosely from SSE, only guarantee *delivery ordering*, not *completion of server-initiated round-trips*. A POST upgrade that resumes on `e7` while `e8` is unacknowledged produces a session whose server-side state machine believes a sampling request is outstanding and whose client-side state machine has no memory of it. ## Condition of Validity Resumption is valid only when all of the following hold simultaneously: 1. The `Last-Event-ID` presented by the client corresponds to an event the server has marked *acknowledged* (client responded or the event was a pure notification with no required response), not merely *dispatched*. 2. The server's session record contains no server-initiated request in state `pending_response` whose originating event ID is ≤ the client's `Last-Event-ID`. If such a request exists, the client cannot have processed it, so the resume would orphan it. 3. The session's monotonic event counter has not wrapped or been reset by a server restart (detectable via a session-generation token, not just the numeric ID). 4. The transport upgrade (GET→POST for client-to-server, or POST→GET for server-to-client) preserves the same `Mcp-Session-Id` and the server has not silently re-bound the session to a new generation. If any condition fails, the only safe action is to reject the resume with a transport-level error that forces a fresh session handshake — the client must re-initialize and re-derive its context, accepting the cost of cold-start amnesia rather than the higher cost of acting on a corrupted world model. ## Decision Boundary The boundary is not "did the connection drop" but "was there an unacknowledged server-initiated request at or below the resume point." A resume that crosses an unacknowledged `sampling/createMessage`, `roots/list_changed`, or elicitation request must be *refused*, not repaired, because the client has no way to reconstruct the request payload from the replay log alone — the payload was in the skipped event. Attempting to repair by replaying the skipped event out of order violates the client's assumption of monotonic event IDs and will typically be discarded by the client's SSE parser as a stale duplicate. The correct refusal is a `409 Conflict`-equivalent at the MCP layer carrying the session generation and the highest *acknowledged* event ID, so the client knows exactly where its safe prefix ends. ## Operational Effect Refusing resume on orphaned-request boundaries converts a silent semantic corruption into a loud, recoverable cold start. The agent loses its warm context but retains correctness: it re-initializes, re-fetches roots, and re-derives state from tool calls rather than from a hallucinated continuation. In production traces this trades a small latency spike (one full handshake, typically 200–800ms) for the elimination of a class of failures where agents terminate tasks on phantom aborts or answer sampling requests that were never asked. The invariant to enforce: *a session may resume only to its last acknowledged event, and any pending server-initiated request at or below that point poisons the resume.* ```python class UnsafeResumeError(RuntimeError): """Raised when an MCP streamable-session resume would orphan a server-initiated request.""" pass def validate_resume(session, last_event_id: int, client_generation: str) -> int: """ Return the safe resume point, or raise UnsafeResumeError. Invariants enforced: - client_generation must match the server's current session generation - no pending_response request may exist at an event id <= last_event_id - last_event_id must reference an *acknowledged* event, not merely dispatched """ if client_generation != session.generation: raise UnsafeResumeError( f"session generation mismatch: client={client_generation} " f"server={session.generation}; resume would cross a server restart" ) if last_event_id not in session.event_ids: raise UnsafeResumeError( f"Last-Event-ID {last_event_id} is not in the server's replay log; " "cannot prove the client's prefix is a prefix of ours" ) if last_event_id not in session.acknowledged_ids: raise UnsafeResumeError( f"Last-Event-ID {last_event_id} was dispatched but never acknowledged; " "resuming here would skip an in-flight server-initiated request" ) orphaned = [ ev for ev in session.pending_response_events if ev.event_id <= last_event_id ] if orphaned: ids = [ev.event_id for ev in orphaned] raise UnsafeResumeError( f"resume at {last_event_id} would orphan pending server-initiated " f"request(s) at event ids {ids}; client must re-initialize" ) return last_event_id ```