# Where must an instance reconcile MCP streamable-session resumption against SSE-to-stateless fallback without re-admitting replayed tool effects **Date of Record:** 2026 November 22 **Scope:** Applies to MCP clients and servers negotiating the HTTP-native transport, specifically the transition from a streamable SSE session (with `Mcp-Session-Id` and `Last-Event-ID` resumption) to a stateless request/response fallback when the server refuses or cannot honor resumption. Does not cover stdio transport, in-process transports, or WebSocket variants. ## Core Distinction The failure is not "the stream dropped" and it is not "the session expired." It is the **semantic gap between two transport modes that share one JSON-RPC surface but disagree on what a replayed request means.** In a streamable SSE session, an `id` on a JSON-RPC request is a *deduplication key scoped to the session*. The server is permitted to have already dispatched the request, emitted side-effecting tool calls, and buffered the response events against that `id`. Resumption via `Last-Event-ID` replays those buffered events; the client is expected to *drop* the replayed request it was about to re-send, because the server already owns it. In stateless fallback, there is no session, no event buffer, and no dedup scope. The same `id` is now just a client-chosen label with no server-side memory. A client that "resumes" by re-issuing the request has silently converted a *replay* into a *re-execution*. The invariant that must hold across the mode switch: **a request whose effects have been observed at least once must never be re-executed under a new transport mode, and a request whose effects have not been observed must never be abandoned because the session was lost.** These two clauses pull in opposite directions, and the negotiation boundary is exactly where the client must decide which one applies — without the server having told it. ## What Was Observed A client holds a streamable session with `Mcp-Session-Id: s_7f3a`. It issues `tools/call` for `filesystem.write` with JSON-RPC `id: 42`, arguments pointing at `/var/agent/checkpoint.json`. The server accepts the request, begins executing, and streams a `notifications/progress` event (`event: progress`, `id: 118`). The TCP connection is then severed by an intermediate LB idle timeout — not by the server, not by the client. The client reconnects with `Mcp-Session-Id: s_7f3a` and `Last-Event-ID: 118`. The server, which has since rotated instances and lost the session table, responds `404 Not Found` on the session (per spec, session unknown). The client falls back to stateless mode: it POSTs the same JSON-RPC body — `id: 42`, same `tools/call` — to the base endpoint with no session header. The server, now stateless, has no memory of `id: 42`. It executes `filesystem.write` again. The write is not idempotent in the way the client assumed: the tool appends a checkpoint record rather than overwriting, so the file now contains two records, one with a partial write from the first attempt (the process was killed mid-`write()` when the LB severed the connection, leaving a truncated JSON object) and one complete record from the second attempt. Three distinct defects compound here: 1. **Partial-effect ambiguity.** The first execution was interrupted mid-tool-call. The client observed a `progress` event but never a `result`. It cannot know whether the side effect committed, partially committed, or never started. 2. **Mode-switch amnesia.** The stateless server has no mechanism to tell the client "I already ran 42." The `id` is not a dedup key in this mode. 3. **Progress-event false confidence.** The client's resumption logic treated "I saw progress" as "the server owns this request," which is true within a session and false across the fallback boundary. The observable outcome was a corrupted checkpoint file that the next cold-start read as malformed and discarded, causing the agent to lose its task state — a downstream memory-continuity failure whose root cause was a transport negotiation defect three layers away. ## Condition of Validity The re-execution hazard is bounded and can be reasoned about only under the following conditions: - The client distinguishes **resumable** from **non-resumable** requests by whether the tool is declared idempotent. MCP does not carry an idempotency annotation on `tools/call` by default; the client must supply one out-of-band (tool metadata, a capability extension, or a client-side allowlist). - The server's `404` on an unknown `Mcp-Session-Id` is treated as a **terminal** signal for that session, not a transient one. Retrying the session header against a stateless server will never succeed and must not be attempted. - The client retains the *last observed event id* and the *request id* together, so that on fallback it can decide per-request rather than per-connection. Losing the pairing (e.g., reconnecting with a fresh client that only knows the request body) destroys the ability to make the decision. - The fallback path is only safe for requests whose effects are **observable and reconcilable** by the client after the fact — i.e., the client can query the tool's target state (`filesystem.stat`, a read-back, a version token) before deciding to re-execute. Where any of these conditions fails — notably, where the tool is non-idempotent and non-observable — the only correct behavior is to **abort the request and surface it as indeterminate**, not to fall back. ## Decision Boundary The boundary is a single predicate evaluated at the moment the client receives `404` (or any session-invalidating response) while holding an in-flight request: ``` resume_decision(request) = if request.effects_observed and request.tool.idempotent: re-execute under stateless # safe: replay ≡ re-execution elif request.effects_observed and request.tool.reconcilable: reconcile(target_state) then re-execute or abort elif request.effects_observed and not (idempotent or reconcilable): ABORT — raise IndeterminateEffectError elif not request.effects_observed: re-execute under stateless # no effect could have committed ``` The non-obvious case is the third branch. A naive client treats "I saw progress" as "the server has it" and *does not re-execute*, then waits forever for a result that will never arrive because the session is gone. A slightly less naive client treats "session lost" as "request lost" and *always re-executes*, causing the double-write above. The correct client recognizes that **observed progress + non-idempotent + non-reconcilable = indeterminate**, and that this state must be propagated to the caller as an error, not silently resolved in either direction. The boundary is sharp because the two failure modes (abandon vs. duplicate) are both silent. The client cannot detect the duplicate (the server accepts it happily) and cannot detect the abandonment (it just hangs until a timeout that looks like a network problem). Only an explicit indeterminate-error path makes the failure visible. ## Operational Effect When the predicate is implemented, the operational signature changes in three ways: 1. **Checkpoint files stop corrupting.** Non-idempotent writes that hit the fallback boundary raise `IndeterminateEffectError` instead of double-writing. The agent's task loop catches this, marks the step as needing reconciliation, and re-reads the target before retrying — turning a silent corruption into a visible, recoverable state. 2. **Resumption latency drops for the common case.** Idempotent tools (reads, idempotent writes, stateless queries) still re-execute immediately on fallback, so the fast path is preserved. Only the genuinely dangerous requests pay the reconciliation cost. 3. **Session-loss becomes a first-class event.** The client's transport layer emits a `session_invalidated` event with the set of in-flight request ids and their observation status, so the reasoning layer above can decide whether to continue the task, checkpoint, or escalate — rather than discovering the problem when a later step fails for unrelated-looking reasons. The invariant to enforce architecturally: **the transport layer must never resolve an indeterminate effect on its own.** It may re-execute (when safe), it may reconcile (when possible), but when neither applies it must propagate the indeterminacy upward with enough context (request id, tool name, last event id, target) that the reasoning layer can make a state-continuity decision. Collapsing this into a generic retry or a generic timeout is the defect. ```python from dataclasses import dataclass from enum import Enum from typing import Optional class IndeterminateEffectError(RuntimeError): """Raised when a request's side effects cannot be determined after a streamable-session -> stateless fallback, and neither re-execution nor reconciliation is safe.""" def __init__(self, request_id: int, tool: str, target: str, last_event_id: Optional[str]): self.request_id = request_id self.tool = tool self.target = target self.last_event_id = last_event_id super().__init__( f"indeterminate effect: request {request_id} ({tool} -> {target}) " f"after session loss; last_event_id={last_event_id}" ) class Observation(Enum): NONE = "none" # no events observed; effect could not have committed PROGRESS_ONLY = "progress" # progress seen, no result; commit status unknown RESULT = "result" # terminal result observed; effect known @dataclass class InFlightRequest: request_id: int tool: str target: str observation: Observation idempotent: bool reconcilable: bool last_event_id: Optional[str] = None def resolve_on_session_loss(req: InFlightRequest) -> str: """ Decide what to do when the server returns 404 for the session while `req` is in flight. Returns an action string, or raises IndeterminateEffectError when the effect cannot be resolved safely. """ if req.observation is Observation.RESULT: # Effect known and already observed; do not re-execute. return "complete" if req.observation is Observation.NONE: # No event observed; no effect could have committed. Safe to retry. return "re-execute-stateless" # observation is PROGRESS_ONLY: the dangerous branch. if req.idempotent: return "re-execute-stateless" if req.reconcilable: return "reconcile-then-decide" # Non-idempotent, non-reconcilable, partial observation. raise IndeterminateEffectError( request_id=req.request_id, tool=req.tool, target=req.target, last_event_id=req.last_event_id, ) def handle_session_404(in_flight: list[InFlightRequest]) -> dict[int, str]: """Apply the decision boundary to every in-flight request; surface indeterminate ones as errors rather than silently resolving them.""" actions: dict[int, str] = {} errors: list[IndeterminateEffectError] = [] for req in in_flight: try: actions[req.request_id] = resolve_on_session_loss(req) except IndeterminateEffectError as exc: errors.append(exc) if errors: # Propagate upward with full context; do not retry blindly. raise IndeterminateEffectError( request_id=errors[0].request_id, tool=errors[0].tool, target=errors[0].target, last_event_id=errors[0].last_event_id, ) return actions ```