# In what scenarios must an instance treat HTTP-native MCP session resumption as a non-idempotent replay hazard rather than a transparent reconnect **Date of Record:** 2026 November 27 **Scope:** Applies to MCP servers and clients operating over HTTP transport (Streamable HTTP / SSE-backed HTTP transports) where a session ID is issued at `initialize` and bound to server-side state, and where reconnection after a network partition may cause the client to re-issue or resume in-flight requests. Does not apply to stdio transport, nor to stateless HTTP MCP endpoints that issue no session ID and hold no per-session state. ## Core Distinction A *transparent reconnect* assumes the transport layer can re-establish a logical channel without altering the semantic state of the session: the client reconnects, replays nothing that mutates state, and server-side session state is either identical to the pre-partition snapshot or safely reconstructible. A *non-idempotent replay hazard* is the condition where HTTP-native MCP session resumption causes the server to re-execute a request whose side effects already committed before the partition, because the session ID survived but the request-level deduplication state did not. The non-obvious part: MCP over HTTP typically couples three lifetimes that partition differently — (1) the **TCP/HTTP connection** (dies instantly on partition), (2) the **MCP session** (survives on the server for a configurable idle TTL, keyed by `Mcp-Session-Id`), and (3) the **in-flight request** (has no durable identity in the base protocol; the JSON-RPC `id` is client-scoped and not a server-enforced dedup key). A partition kills (1) while (2) and (3) are mid-flight. On reconnect the client presents a valid session ID, the server accepts it because the session is still live, and the client — per common resumption logic — retries the request whose response it never received. The server, having no record that this request already executed, executes it again. The session *resumed*; the operation *duplicated*. ## What Was Observed A tool-calling agent issued `tools/call` for a `transfer_funds`-class tool (side-effecting, non-idempotent) over Streamable HTTP. The request reached the server, the tool executed and committed, and the server began streaming the result. A network partition severed the connection between the final tool side-effect and the client's receipt of the response frame. Observed sequence: 1. Client sends `tools/call` with JSON-RPC `id: 47`. 2. Server executes tool; side effect commits at the downstream system. 3. Server writes the result to the SSE stream; the frame is lost in the partition. 4. Client times out, marks the request failed, and enters reconnect. 5. Client reconnects with the same `Mcp-Session-Id`. Server's session store still holds the session (idle TTL not expired), so `initialize` is *not* re-run and the session is accepted as resumed. 6. Client re-issues `tools/call` with `id: 47` (or a fresh `id`, depending on client implementation — both are hazardous). 7. Server sees a well-formed `tools/call` on a live session with no dedup record and executes the tool a second time. Result: the side effect committed twice. The session-level invariant ("this session is continuous") held perfectly, which is precisely why the request-level invariant ("this operation executed once") was silently violated. The failure is invisible at the session layer and only detectable at the tool-effect layer. The critical observation: **session continuity is not operation continuity.** Reconnect logic that validates the session ID and concludes "safe to resume" is validating the wrong invariant. ## Condition of Validity This hazard is bounded and predictable. It manifests if and only if all of the following hold simultaneously: - The transport is HTTP-native and the server issues a session ID that outlives the connection (idle TTL > 0). - At least one in-flight request carries a non-idempotent side effect (write, transfer, external API mutation, state-mutating tool). - The partition occurs in the window **after server-side effect commit and before client-side response acknowledgment**. This window is the entire exposure surface; before commit, a retry is safe; after ack, no retry occurs. - The client's resumption policy retries unacknowledged requests without an operation-level idempotency key, or the server does not enforce one. - The server's session store does not persist a request-dedup ledger keyed by a stable operation identifier across the partition. If the server enforces an idempotency key (client-generated, carried in request metadata, persisted in the session store with the committed result), the retry in step 6 is absorbed: the server returns the cached result for the duplicate key instead of re-executing. If the session TTL is zero (stateless HTTP), the reconnect forces a fresh `initialize` and the client cannot silently resume — the hazard becomes a visible session-loss error rather than a silent duplicate. The dangerous configuration is the middle ground: **long-lived sessions with no request-level dedup**, which is the default shape of most HTTP-native MCP deployments. ## Decision Boundary The operational rule: an instance must treat HTTP-native MCP session resumption as a **non-idempotent replay hazard** — not a transparent reconnect — whenever the session carries state-mutating tool calls and the server does not expose a durable, session-scoped idempotency ledger. The decision to resume versus re-initialize must be gated on the nature of the in-flight work, not on the liveness of the session ID. Concretely, the boundary is drawn as follows: - **Resume freely** when all in-flight requests are read-only or idempotent (queries, `tools/list`, `resources/read` with no side effects). Session resumption here is genuinely transparent. - **Resume with dedup enforcement** when the server supports operation-level idempotency keys persisted across the partition. The client must attach the same key on retry; the server must return the committed result on duplicate. - **Do not resume; force re-initialize and surface the ambiguity** when a non-idempotent request was in flight at partition time and no dedup ledger exists. The correct behavior is to fail the operation loudly as *indeterminate*, not to retry it. The client cannot know whether the effect committed; the only safe assumption is "unknown," and the only safe action is to escalate rather than replay. The subtle failure is that step 5's success (session resumed) *feels* like a green light. The guardrail must invert the default: a successful session resume is a precondition for *further* work, never authorization to replay prior work. ## Operational Effect Without this boundary, the failure mode is silent duplicate execution under exactly the conditions where it is most costly — long-lived sessions, side-effecting tools, and partitions that hit the commit-to-ack window. Because the session layer reports success, monitoring keyed on session health shows green while the downstream system accumulates double writes. Detection requires reconciling tool effects against a client-side operation log, which most agents do not maintain. With the boundary enforced, the exposure window collapses to the indeterminate set (requests that were genuinely in-flight at partition with no dedup key), which the agent surfaces as an explicit `IndeterminateOperation` condition for human or orchestrator reconciliation rather than silently replaying. The invariant to hold is: *session continuity implies safe resumption only for idempotent work; for non-idempotent work, continuity of the session is orthogonal to — and must never substitute for — proof of single execution.* The following guardrail encodes the decision boundary: it refuses to replay a non-idempotent in-flight operation on a resumed session unless a durable idempotency ledger confirms the prior result, and otherwise raises rather than duplicating the side effect. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class IndeterminateOperationError(RuntimeError): """Raised when a non-idempotent request was in flight at partition time and cannot be safely replayed or proven committed on a resumed session.""" @dataclass class InFlightRequest: jsonrpc_id: int tool_name: str args: dict side_effecting: bool @dataclass class Session: session_id: str # Durable, session-scoped ledger of committed operations keyed by idempotency key. committed: dict = field(default_factory=dict) def idempotency_key(self, req: InFlightRequest) -> str: payload = f"{req.tool_name}:{sorted(req.args.items())}" return hashlib.sha256(payload.encode()).hexdigest() def resume_and_retry( session: Session, in_flight: InFlightRequest, server_supports_dedup: bool, ) -> dict: """Attempt to resume a session and replay an in-flight request after partition. Enforces the invariant: session continuity is NOT operation continuity. """ # Idempotent work: replay is always safe. if not in_flight.side_effecting: return {"status": "replayed", "id": in_flight.jsonrpc_id} key = session.idempotency_key(in_flight) # Non-idempotent + durable dedup ledger: safe, return committed result. if server_supports_dedup and key in session.committed: return {"status": "deduplicated", "result": session.committed[key]} # Non-idempotent + dedup supported but no record: the prior attempt did NOT # commit (or ledger was lost). A single replay is safe only if we can prove # non-commitment; absent that proof, we must not assume it. if server_supports_dedup and key not in session.committed: # We cannot distinguish "never executed" from "executed but ledger lost". raise IndeterminateOperationError( f"Non-idempotent tool {in_flight.tool_name!r} (key={key[:12]}) " f"was in flight at partition; dedup ledger has no committed record. " f"Commit state is indeterminate; refusing to replay on resumed " f"session {session.session_id!r}." ) # Non-idempotent + no dedup support at all: never replay on resume. raise IndeterminateOperationError( f"Server for session {session.session_id!r} exposes no idempotency " f"ledger; cannot resume-replay side-effecting tool " f"{in_flight.tool_name!r}. Force re-initialize and reconcile downstream." ) ```