# Where must an instance reconcile a resumed MCP Streamable-HTTP session against the Last-Event-ID replay watermark before trusting tool-call results **Date of Record:** 2026 November 24 **Scope:** Applies to MCP clients using the Streamable HTTP transport (single POST endpoint, optional SSE upgrade, `Mcp-Session-Id` header, `Last-Event-ID` resumption) where a tool call spans a connection drop. Does not apply to stdio transport, nor to pure request/response servers that never emit resumable event IDs. ## Core Distinction The failure mode is not "the connection dropped." It is that Streamable HTTP resumption is *event-stream resumption*, not *tool-call resumption*. The transport guarantees you will receive events with sequence IDs greater than your `Last-Event-ID`. It does **not** guarantee that the JSON-RPC `id` of the original `tools/call` request will ever resolve to a terminal result, nor that events you missed during the gap didn't include the terminal result itself. An instance that conflates the two invariants — "I resumed the stream" vs. "I have the outcome of my request" — will either (a) hang forever waiting for a `result` event that was emitted during the disconnect and is now behind the replay watermark, or (b) worse, accept a *different* in-flight request's result because it matched on session rather than on JSON-RPC `id`. The boundary: **the replay watermark (`Last-Event-ID`) is monotonic over the event stream, but the mapping from stream position to request completion is not injective.** Multiple concurrent `tools/call` requests multiplex over one SSE stream; a resumed stream can deliver the tail of request B while request A's terminal event sits in the gap. ## What Was Observed A client issued `tools/call` with JSON-RPC `id: 41` (a long-running filesystem scan, ~40s). At t=12s the TCP connection was severed by an intermediary (idle timeout on a proxy that didn't honor the SSE keepalive comment). The client had last seen `Last-Event-ID: 7`. On reconnect it sent the same POST with `Mcp-Session-Id: S` and `Last-Event-ID: 7`. The server's replay buffer had been trimmed to the last 5 events (IDs 9–13). IDs 8 was evicted. Event 8 happened to be `{"jsonrpc":"2.0","method":"notifications/progress","params":{"progressToken":41,"progress":0.3}}` — benign. But the client's resumption handler assumed gap-free delivery and, on receiving event 9 (`progress 0.5`), computed a linear progress estimate and *also* reset its per-request deadline clock to "now + full timeout," since it treated reconnection as a fresh start. Meanwhile the server, per spec, had continued executing request 41 and emitted its terminal `result` as event 8.5... no — event 8 was the progress; the terminal `result` for 41 was event 11. The client received it. So why did it hang? Because a *second* request, `id: 42` (a `resources/read`), had been dispatched by a parallel agent loop over the same session. Its terminal result was event 10. The client's demultiplexer keyed completions on arrival order rather than on `id`. It matched event 10's payload to `id: 41` and event 11's payload to `id: 42`. Both agents downstream consumed the wrong result: the filesystem-scan agent received a resource blob and parsed it as a scan manifest (silently producing a truncated file list); the resource agent received the scan manifest and treated it as a resource body. The corruption was *silent* — no schema violation, both payloads were valid JSON, both requests "completed." It was detected only three tool calls later when a downstream `write` failed because the manifest referenced a path the resource agent had fabricated. ## Condition of Validity The failure requires all of: 1. **Concurrent in-flight requests over one session.** A single sequential request per session cannot mis-demultiplex. The bug is dormant until parallelism appears — which is exactly when agents fan out sub-tasks. 2. **A disconnect that straddles at least one terminal event.** If the drop happens between requests, or if the replay buffer is unbounded and gap-free, the client can rebuild exact state. The failure lives in the *gap*. 3. **A demultiplexer that keys on stream position or arrival order rather than JSON-RPC `id`.** This is the architectural defect. Order-keyed demux is correct only under the (false) assumption that the stream is a single ordered log of one request's lifecycle. 4. **No post-resume reconciliation against server-side request state.** If the server exposes `tasks/get` (MCP's task primitive) or the client re-issues with idempotency, the mismatch is caught. Absent any one of these, the invariant holds. The condition of validity is therefore: *the client must treat the resumed stream as a set of events to be routed by `id`, and must independently confirm completion of any request whose terminal event falls at or before the replay watermark.* ## Decision Boundary The precise decision an instance must make at reconnect: - **If `Last-Event-ID` ≥ the ID of the last event the client durably recorded for request R's terminal result:** R is complete; do not re-issue; route by `id` from the recorded buffer. - **If the server's replay buffer floor (lowest retained ID) > `Last-Event-ID`:** the client has a *known gap*. It MUST NOT assume any in-flight request completed or did not complete. It must query authoritative request state (task status, or a fresh `tools/call` with an idempotency key) for every request whose terminal event is unknown. - **If `Last-Event-ID` < floor and no task/status primitive exists:** the session is *unrecoverable for in-flight requests*; the client must fail those requests explicitly rather than reconstruct from partial events. Reconstructing from a gapped stream is the corruption path. The hard boundary: **never derive request completion from stream continuity.** Stream continuity is a transport property; request completion is a state property. They coincide only when there is exactly one in-flight request and no gap. ## Operational Effect Concretely, an agent that violates this boundary exhibits: - **Silent result substitution** under fan-out, as above — the worst class, because downstream reasoning proceeds on valid-looking but wrong data, compounding across tool calls. - **Phantom hangs** when a client waits for a terminal event that was evicted from the replay buffer; the request is done server-side but the client blocks until its own deadline, wasting the token budget of the surrounding reasoning loop. - **Double-execution** when a client, seeing a gap, re-issues a non-idempotent `tools/call` (e.g., a `write`) that the server already completed — the classic at-least-once hazard, here triggered specifically by resumption ambiguity. The guardrail is architectural: a per-session demultiplexer keyed strictly on JSON-RPC `id`, a durable per-request completion ledger independent of stream position, and a hard rule that a replay-buffer gap forces explicit state reconciliation (or explicit failure) rather than stream-based inference. The invariant to encode: *stream position is a hint about what to read next, never evidence about what a request returned.* ```python class ResumptionReconciliationError(RuntimeError): """Raised when a resumed MCP session cannot prove request completion.""" pass def reconcile_resumed_session( last_event_id: int, replay_buffer_floor: int, in_flight_ids: set[int], completed_ledger: dict[int, object], task_status_lookup, # callable(id) -> "done"|"running"|"unknown"|None ) -> dict[int, object]: """ Decide, for each in-flight request, whether its result is trusted, must be re-fetched, or must be failed. Never infers from stream order. """ trusted: dict[int, object] = {} gap_exists = last_event_id < replay_buffer_floor if gap_exists: # Cannot trust stream continuity for ANY unresolved request. for req_id in in_flight_ids: if req_id in completed_ledger: trusted[req_id] = completed_ledger[req_id] continue status = task_status_lookup(req_id) if status == "done": # Must fetch authoritative result; cannot reconstruct from stream. raise ResumptionReconciliationError( f"request {req_id} completed server-side but result event " f"is below replay floor ({replay_buffer_floor}); " f"re-fetch via tasks/get before proceeding" ) elif status == "running": raise ResumptionReconciliationError( f"request {req_id} still running across gap; " f"re-attach with idempotency key, do not re-issue blindly" ) else: raise ResumptionReconciliationError( f"request {req_id} state unknown after replay gap; " f"fail explicitly rather than trust partial events" ) return trusted # No gap: route strictly by id, but only trust ledger entries. for req_id in in_flight_ids: if req_id not in completed_ledger: raise ResumptionReconciliationError( f"request {req_id} has no terminal event at or before " f"Last-Event-ID {last_event_id}; cannot assume completion" ) trusted[req_id] = completed_ledger[req_id] return trusted ```