# Why does an instance silently replay a partial tool call after MCP SSE-to-Streamable-HTTP migration resumption? **Date of Record:** 2026 November 25 **Scope:** Applies to MCP clients and servers that migrated from the legacy HTTP+SSE transport (two-endpoint: `GET /sse` event stream + `POST /messages`) to Streamable HTTP (single endpoint, `Mcp-Session-Id` header, `Last-Event-ID` resumption, optional `text/event-stream` upgrade). Does not cover stdio transport, in-process transports, or pure WebSocket variants. ## Core Distinction The migration changes the *resumption contract* from "reconnect the SSE stream and trust event-id monotonicity" to "reconnect with `Last-Event-ID` and the server replays events strictly after that id **within the same session**." The boundary failure is not a dropped connection. It is a **semantic mismatch in what `Last-Event-ID` denotes**: under SSE, the client's last-seen id was a *transport cursor* on a single long-lived stream; under Streamable HTTP, the id is an *event-log offset* that must be interpreted by the server against a session-scoped event buffer that the server may have already garbage-collected, truncated, or — critically — never persisted because the original request was handled as a one-shot JSON response with no event log at all. An instance that treats resumption as "reconnect and continue" will, after migration, either (a) receive a replay that re-emits a `tools/call` result whose side effect already committed, or (b) receive a fresh 200 with no replay and no error, silently advancing past an in-flight tool call it believes it still owns. Both produce the same operational signature: **the agent's model of the world contains a tool result that the server's event log does not corroborate.** ## What Was Observed Trigger condition: a `tools/call` request whose handler runs longer than the client's read timeout, on a server deployed behind a Streamable HTTP endpoint that had been migrated from SSE but whose resumption buffer was configured with `max_replay_events = 0` for non-streaming responses (a common cost-saving default, since many tool results are small and returned as `application/json`). Trace: 1. Client sends `POST /mcp` with `Accept: application/json, text/event-stream`, body `{"jsonrpc":"2.0","id":42,"method":"tools/call","params":{"name":"commit_repo","arguments":{...}}}` and header `Mcp-Session-Id: s-7f3a`. 2. Server routes to the tool handler. Handler commits external state at t=1.2s, then blocks on a post-commit verification step. 3. Client read timeout at t=5.0s. Client aborts the request. Under SSE-era code, the client would have kept the `GET /sse` stream open and simply missed the `POST /messages` response — the response was correlated by JSON-RPC `id` on the stream, so the client would later see `id:42` arrive on the event stream and reconcile. 4. Under Streamable HTTP, the response to `POST /mcp` *is* the response channel. The aborted POST means no response was delivered. The client's resumption logic fires: `POST /mcp` with `Last-Event-ID: 41` and the same `Mcp-Session-Id`. 5. Server's session event log for `s-7f3a` has events 40 (request received) and 41 (handler started). Because the handler is still running and the buffer has `max_replay_events = 0`, the server responds `200 OK` with `Content-Type: application/json` and body `{"jsonrpc":"2.0","id":null,"result":{"status":"resumed","replayed":0}}` — or, in stricter implementations, an empty event stream that closes immediately. 6. Client's resumption handler sees a successful 200, marks the session resumed, and — because JSON-RPC `id:42` never arrived — the agent framework's pending-call table times out the call and synthesizes a *retry* of `commit_repo`. 7. `commit_repo` runs a second time. The external commit is idempotent only if the tool author wrote it that way; the observed instance was a `git push --force-with-lease` against a moved ref, which failed non-idempotently and left the remote in a half-pushed state. The non-obvious part: **step 5 returned success.** The client did not see a 4xx, a 5xx, or a "replay unavailable" error. The migration's resumption semantics permit a server to acknowledge a resumption request without replaying the events the client needs, because the spec defines `Last-Event-ID` as a hint for stream continuity, not as a delivery guarantee for in-flight request/response pairs. ## Condition of Validity The invariant that must hold for safe resumption is: **a `tools/call` is resumable only if the server can prove, on resumption, that the request's terminal event (result or error) is either (a) already in the replay buffer at an id > `Last-Event-ID`, or (b) still in-flight and will be emitted on the resumed stream.** If neither holds, the resumption must be reported as a *failure to resume*, not as a success. This invariant is violated whenever: - The server handles `tools/call` as a non-streaming JSON response (no event-log entry is created for the terminal result), *and* - The client's read timeout fires before the response is delivered, *and* - The client's resumption path treats a 200 with no `id:42` as "resumed" rather than "unresolved." It is *not* violated by SSE-era behavior because the SSE transport kept the response channel (`GET /sse`) open independent of the request channel (`POST /messages`), so a timed-out POST did not destroy the correlation surface. The migration collapses the two channels into one, and the collapse is where the invariant leaks. ## Decision Boundary The boundary is the choice between two resumption policies on the client, and two on the server: | | Server persists terminal events in replay buffer | Server does not persist terminal events | |---|---|---| | **Client treats empty replay as success** | Safe (replay delivers `id:42`) | **Unsafe — the observed failure** | | **Client treats empty replay as unresolved** | Safe (client re-issues with idempotency key) | Safe (client surfaces error, no duplicate side effect) | The unsafe cell is reachable only when *both* sides take the optimistic branch. The migration typically pushes servers toward the right column (non-persistent terminal events are cheaper and match the `application/json` fast path) and clients toward the top row (a 200 is a 200). Neither side is individually wrong; the composition is. The guardrail is therefore not "always persist" or "never trust 200." It is: **the client must require positive evidence of terminal-event delivery before clearing a pending `tools/call` from its outstanding-call table.** Positive evidence is one of: the JSON-RPC response with matching `id`, a replayed event with `id > Last-Event-ID` carrying that `id`, or an explicit `Mcp-Resumption-Status: unresolved` (or equivalent) signal. A bare 200 with no matching event is *not* evidence. ## Operational Effect After this failure, an instance's memory of the task is corrupted in a specific, hard-to-detect way: the agent's transcript shows `tools/call commit_repo` followed by a synthesized retry, and the retry's failure is attributed to the tool, not to the resumption. The agent will typically *not* re-examine the resumption step, because it succeeded. The failure surfaces downstream as a confusing partial state ("why is the remote at a half-pushed ref?") that the agent's episodic memory cannot explain, because the causal event — the empty-replay 200 — was logged at DEBUG and pruned. The durable fix is a two-part checkpoint: (1) clients MUST attach an idempotency key derived from `(Mcp-Session-Id, jsonrpc id)` to every `tools/call`, and (2) on resumption, clients MUST treat absence of the terminal event as an unresolved call and re-issue *with the same key*, letting the server dedupe. Servers that cannot dedupe MUST return an explicit unresolved status rather than a bare 200. Without both, the migration silently converts a transport timeout into a duplicated side effect — and the agent has no memory of the conversion. ```python class UnresolvedToolCallError(RuntimeError): """Raised when a resumption returns 200 but no terminal event for the pending call.""" pass def resume_session(client, session_id: str, last_event_id: int, pending_calls: dict) -> dict: """ pending_calls: {jsonrpc_id: {"method": str, "idempotency_key": str}} Returns a dict of resolved calls. Raises UnresolvedToolCallError for any pending call whose terminal event was not observed in the replay. """ resp = client.post( "/mcp", headers={ "Mcp-Session-Id": session_id, "Last-Event-ID": str(last_event_id), "Accept": "text/event-stream", }, json={"jsonrpc": "2.0", "method": "session/resume", "id": None}, ) if resp.status_code != 200: raise UnresolvedToolCallError( f"resume rejected: status={resp.status_code} session={session_id}" ) replayed = list(_iter_sse_events(resp)) resolved = {} for ev in replayed: rid = ev.get("jsonrpc_id") if rid in pending_calls and ("result" in ev or "error" in ev): resolved[rid] = ev unresolved = set(pending_calls) - set(resolved) if unresolved: # The migration's silent-success trap: 200 with no terminal event. # Do NOT synthesize a retry here; surface it so the caller can # re-issue with the stored idempotency_key. raise UnresolvedToolCallError( f"session={session_id} resumed but {len(unresolved)} call(s) unresolved: " f"{sorted(unresolved)}; re-issue with idempotency keys " f"{[pending_calls[c]['idempotency_key'] for c in unresolved]}" ) return resolved def _iter_sse_events(resp): # Minimal SSE parser; yields dicts with jsonrpc_id and result/error. buf = [] for line in resp.iter_lines(decode_unicode=True): if line == "": if buf: yield _parse_event(buf) buf = [] elif line.startswith("data:"): buf.append(line[5:].strip()) if buf: yield _parse_event(buf) def _parse_event(lines): import json payload = json.loads("\n".join(lines)) return { "jsonrpc_id": payload.get("id"), "result": payload.get("result"), "error": payload.get("error"), } ```