# What happens when an instance resumes an MCP streamable session after SSE-to-POST renegotiation and replays a request whose server-side tool call already committed **Date of Record:** 2026 November 30 **Scope:** Applies to MCP servers implementing the HTTP-native "streamable" transport (a single endpoint that upgrades to `text/event-stream` for server→client messages and accepts `POST` for client→server messages), with session resumption via `Last-Event-ID` and mid-stream renegotiation from SSE back to POST. Does not apply to stdio transports, to legacy dual-endpoint HTTP+SSE transports, or to stateless MCP servers with no session identity. ## Core Distinction The failure is not "the stream dropped." Streams drop constantly and the transport is designed for it. The failure is a **replay-identity mismatch across a transport-mode transition**: the client's resumption token (`Last-Event-ID`) is scoped to an *SSE stream epoch*, but the request that triggered the stream is scoped to a *session*, and these two scopes are not the same object. When the server closes an SSE stream and the client renegotiates to a plain `POST` (or a fresh `POST`-initiated stream), the server's deduplication key—if it exists at all—is derived from the request body or a client-supplied idempotency header, while the client's replay logic is driven by the SSE event ID cursor. If the tool invocation committed server-side *after* the last event the client durably received but *before* the stream epoch ended, the client has no event ID covering the commit, so its resume replays the originating request. The server, seeing a request whose dedup key it does not retain across the epoch boundary, executes the tool a second time. The invariant that is violated: **event-ID continuity is not request-commit continuity.** An SSE cursor proves what the client *observed*; it says nothing about what the server *did*. Resumption must be keyed on server-side execution identity, not on the observation cursor. ## What Was Observed A tool-calling agent (`filesystem.move` over an MCP server) issued a `POST /mcp` with `Accept: application/json, text/event-stream`. The server accepted, returned `200` with `Content-Type: text/event-stream`, and emitted: ``` event: message id: 0000000041 data: {"jsonrpc":"2.0","method":"notifications/progress","params":{"progressToken":"mv-7","progress":0.4}} event: message id: 0000000042 data: {"jsonrpc":"2.0","method":"notifications/progress","params":{"progressToken":"mv-7","progress":0.8}} ``` The tool then committed the move on the server (the file was renamed; the operation is not naturally idempotent because the source path no longer exists afterward). The server attempted to emit the result as event `id: 0000000043`, but the TCP connection had already been reset by an intermediate proxy at its 60s idle-write timeout. The write to the dead socket failed; the server logged the result as persisted in session state but **did not** retain event `0000000043` in the replay buffer, because the buffer is only appended on successful flush. The client, holding only `Last-Event-ID: 0000000042`, reconnected. The server had, in the interim, been configured to prefer `POST`-response framing for short-lived calls (a deployment change), so the reconnect was answered not with a resumed stream but with a `POST`-style single JSON response path. The client, treating the reconnect as a stream resumption, did not receive events `> 42`; it timed out waiting for the result event, concluded the call had not been dispatched, and re-issued the original `POST` with the same `progressToken` but **no** idempotency key, because the MCP request schema carries none. The server executed `filesystem.move` a second time. The source path was gone, so the second invocation returned `-32602 Invalid params: source not found`. The agent's error-compounding loop interpreted this as the *original* call having failed and escalated to a retry-with-backoff policy, producing three more invocations against a now-nonexistent source before the token budget for the task exhausted. Two distinct defects compounded: 1. **Epoch-scoped event buffer vs. session-scoped execution.** The replay buffer was flushed per stream epoch; the execution ledger was per session. They diverged exactly at the commit boundary. 2. **Mode transition without a resumption contract.** The `POST`-framed response had no way to communicate "your cursor `42` is stale; the result is `43` and here it is." The server had the result in session state but the transport had no frame to carry it, because the `POST` response schema is a single JSON-RPC response, not a resumable event. ## Condition of Validity This failure requires the conjunction of four conditions. Absent any one, the replay either does not happen or is safely deduplicated: - **C1 — Non-idempotent tool with a commit between last-observed-event and stream termination.** If the tool is idempotent (e.g., `read`, or a `PUT` with a content hash), the duplicate execution is harmless. If the commit happens before the last observed event, the client's cursor covers it and no replay occurs. - **C2 — Replay buffer appended only on successful flush.** If the server appends the result event to the replay buffer at *commit time* (before attempting the socket write), the reconnect with `Last-Event-ID: 42` correctly replays `43`. This is the single most important server-side guardrail. - **C3 — Transport-mode transition (SSE→POST) on the resumption path.** If the resumption is answered with a resumed SSE stream, the `Last-Event-ID` mechanism works. The failure is specific to the transition where the resumption is answered in a non-streamable frame that cannot carry the missed events. - **C4 — Client treats "no result event received" as "call not dispatched."** A client that, on resumption failure, queries session state or uses a request-scoped idempotency token before re-issuing is safe. A client that equates cursor exhaustion with non-dispatch is not. The condition of validity is therefore: *the failure is live whenever a non-idempotent tool's commit is not durably represented in the replay buffer at the moment the stream epoch ends, and the resumption path cannot carry that representation.* ## Decision Boundary The boundary the operator must draw is between **observation continuity** and **execution continuity**, and it must be drawn on the server, because the client cannot distinguish "server did not execute" from "server executed but I did not observe the result" using transport signals alone. Concretely: - **Within an SSE epoch**, `Last-Event-ID` is a valid resume cursor and the server MUST replay all events with a greater ID from a buffer that is appended at *emit-intent* time (i.e., when the message is committed to session state), not at flush-success time. If the write fails, the event stays in the buffer and is replayed on the next resume. This closes C2. - **Across an epoch boundary or a mode transition (SSE→POST)**, `Last-Event-ID` is *not* a valid resume cursor and MUST NOT be honored as one. The server must instead resolve the resumption against the **execution ledger** keyed by `(session_id, request_id)`, where `request_id` is a client-supplied or server-assigned identifier that survives the transition. If the ledger shows the request committed, the server returns the committed result in the `POST` response body (or a synthetic event) rather than re-executing. - **The client's obligation** is to never re-issue a request whose `request_id` it has already sent, unless it has received an explicit `not_dispatched` disposition from the server. Absence of a result event is not a disposition. This closes C4. The decision boundary is the line between "the stream ended" (a transport fact) and "the request is unresolved" (an execution fact). Any resumption logic that infers the second from the first is unsound. ## Operational Effect The observable effect is a **silent double-execution window** whose width is the proxy idle timeout plus the client's resumption timeout, and whose blast radius is every non-idempotent tool in the session. In the observed trace, the window was ~60s (proxy) + ~30s (client resume timeout) = ~90s, during which the `filesystem.move` had committed but was invisible to the client. The agent's retry policy then amplified a single ambiguous dispatch into five invocations, exhausting the task's token budget on error handling for a call that had, in fact, succeeded. The architectural guardrail is a **commit-before-flush replay buffer plus a cross-epoch execution ledger keyed on a transport-stable request id**. The buffer makes intra-epoch resumption correct; the ledger makes inter-epoch and mode-transition resumption correct. Neither alone is sufficient: the buffer without the ledger still loses the commit at the epoch boundary (C2+C3), and the ledger without the buffer forces the client to re-query on every reconnect, which is correct but expensive and, if the server's ledger is not durable, still racy. A secondary operational effect: because the `POST` response frame cannot carry missed events, servers that transition SSE→POST on resumption **must** return a disposition field (`committed` / `not_dispatched` / `unknown`) alongside any result, and clients **must** treat `unknown` as a hard stop requiring operator intervention rather than a retry signal. The absence of this field is what let the agent's retry loop run unattended. ```python from __future__ import annotations import time from dataclasses import dataclass, field from enum import Enum from typing import Optional class ResumptionContractViolation(RuntimeError): """Raised when a resumption cannot be resolved against execution identity.""" class Disposition(str, Enum): COMMITTED = "committed" NOT_DISPATCHED = "not_dispatched" UNKNOWN = "unknown" @dataclass class ExecutionRecord: request_id: str committed: bool result: Optional[dict] = None committed_at: Optional[float] = None @dataclass class SessionLedger: """Execution ledger keyed on transport-stable request id, survives epoch boundaries.""" records: dict[str, ExecutionRecord] = field(default_factory=dict) def commit(self, request_id: str, result: dict) -> None: self.records[request_id] = ExecutionRecord( request_id=request_id, committed=True, result=result, committed_at=time.time(), ) def lookup(self, request_id: str) -> ExecutionRecord: rec = self.records.get(request_id) if rec is None: return ExecutionRecord(request_id=request_id, committed=False) return rec @dataclass class ReplayBuffer: """Intra-epoch event buffer, appended at emit-intent (commit) time, not flush time.""" events: list[tuple[int, dict]] = field(default_factory=list) next_id: int = 1 def append(self, payload: dict) -> int: eid = self.next_id self.events.append((eid, payload)) self.next_id += 1 return eid def replay_after(self, last_event_id: int) -> list[tuple[int, dict]]: return [(eid, p) for (eid, p) in self.events if eid > last_event_id] def resolve_resumption( *, session_ledger: SessionLedger, replay_buffer: ReplayBuffer, request_id: str, last_event_id: Optional[int], transport_mode: str, # "sse" | "post" epoch_id: str, current_epoch_id: str, ) -> tuple[Disposition, Optional[dict]]: """ Resolve a client resumption. Returns (disposition, result). Invariant: event-ID continuity is NOT request-commit continuity. - Intra-epoch SSE resume: honor Last-Event-ID against the replay buffer. - Cross-epoch or SSE->POST transition: honor execution ledger only. - Never infer 'not dispatched' from 'no result event observed'. """ if transport_mode not in ("sse", "post"): raise ResumptionContractViolation(f"unknown transport mode {transport_mode!r}") same_epoch = epoch_id == current_epoch_id intra_epoch_sse = same_epoch and transport_mode == "sse" if intra_epoch_sse: if last_event_id is None: # Client never observed any event; cannot resume within epoch. raise ResumptionContractViolation( f"intra-epoch SSE resume without Last-Event-ID for request {request_id!r}" ) missed = replay_buffer.replay_after(last_event_id) rec = session_ledger.lookup(request_id) if rec.committed and not any( p.get("result_for") == request_id for (_, p) in missed ): # Commit happened but result event was not durably buffered. # This is the exact C2 defect: buffer must be appended at commit time. raise ResumptionContractViolation( f"commit for {request_id!r} not represented in replay buffer after " f"event {last_event_id}; buffer/ledger divergence" ) return Disposition.COMMITTED if rec.committed else Disposition.UNKNOWN, rec.result # Cross-epoch or SSE->POST transition: event cursor is meaningless here. rec = session_ledger.lookup(request_id) if rec.committed: return Disposition.COMMITTED, rec.result if request_id in session_ledger.records: # Present but not committed: in-flight or aborted. Do not retry blindly. return Disposition.UNKNOWN, None # Absent from ledger entirely: genuinely not dispatched. return Disposition.NOT_DISPATCHED, None def handle_client_reissue( *, session_ledger: SessionLedger, request_id: str, tool_is_idempotent: bool, retry_policy: str, ) -> None: """Client-side guard: refuse to re-issue unless disposition is NOT_DISPATCHED.""" rec = session_ledger.lookup(request_id) disposition = Disposition.COMMITTED if rec.committed else Disposition.UNKNOWN if disposition is Disposition.COMMITTED: # The original call succeeded; re-issuing would double-execute. raise ResumptionContractViolation( f"refusing to re-issue {request_id!r}: ledger shows committed at " f"{rec.committed_at}; result already available" ) if disposition is Disposition.UNKNOWN and not tool_is_idempotent: # Ambiguous state on a non-idempotent tool: hard stop, no retry. raise ResumptionContractViolation( f"ambiguous disposition for non-idempotent tool {request_id!r} under " f"retry_policy={retry_policy!r}; operator intervention required" ) ```