# How does an instance detect a resumed MCP stream that silently diverges from server-side tool-call history **Date of Record:** 2026 November 30 **Scope:** Applies to MCP clients using the HTTP-native Streamable HTTP transport with `Mcp-Session-Id` and `Last-Event-ID`-based resumption against a remote tool server. Does not apply to stdio transports, nor to servers that do not emit SSE event IDs on tool-call progress streams. ## Core Distinction The resumption mechanism in Streamable HTTP is a *transport-level* replay, not a *semantic-level* replay. When a client reconnects with `Last-Event-ID: N`, the server is only obligated to continue the byte stream from event N+1 onward. It is **not** obligated to reconstruct the logical tool-call state that event N represented. This distinction is invisible when the server keeps per-session replay buffers, and catastrophic when it does not — because the client believes it has a contiguous view of tool execution, while the server has already advanced (or rolled back) the tool-call state machine underneath it. The invariant that actually matters is not "did I receive every event" but "does my local model of the in-flight tool call match the server's authoritative state at the resume point." These are different invariants, and only the first is enforced by the protocol. ## What Was Observed A remote agent invoked a long-running `execute_plan` tool over Streamable HTTP. The server emitted SSE events: `tool_call_started` (id 41), `tool_call_progress` (ids 42–58, emitted roughly every 2s), then `tool_call_completed` (id 59) with the final result payload. Mid-stream, the client's HTTP connection dropped at event 47 due to an intermediate proxy recycling idle-ish connections. The client, correctly per spec, reconnected with `Last-Event-ID: 47` and the same `Mcp-Session-Id`. The server accepted the resume and began emitting from event 48. From the client's perspective the stream looked continuous: events 48–58 arrived, then 59, then a clean `tool_call_completed`. What actually happened server-side: the session's replay buffer was capped at 16 events and had been evicted. The server, unable to replay 48–58 from buffer, **re-executed the tail of the tool call** to regenerate them. Because `execute_plan` was not idempotent, the re-execution performed steps 48–58 a second time. The client received a valid, well-formed, contiguous event stream that described a tool call that had run roughly 40% of its side effects twice. No protocol error was raised. No event ID was skipped. The `tool_call_completed` payload even reported success. The client's local belief — "one `execute_plan`, events 41–59, one result" — was internally consistent and externally wrong. The divergence was only detectable by comparing the final result payload's internal step counters against the number of progress events the client had observed, which differed by exactly the re-executed window. ## Condition of Validity Resumption via `Last-Event-ID` is only safe under the conjunction of three conditions, and the protocol enforces none of them: 1. **Replay buffer durability.** The server retains events from the resume point forward, OR the tool is idempotent under re-execution. A capped or volatile buffer silently converts a resume into a re-run. 2. **Event-ID monotonicity across re-execution.** If the server regenerates events, it must not reissue IDs the client already consumed *with different content*. Here it did not reissue — it issued 48–58 again with new (duplicate-effect) content under the same IDs the client had not yet seen, which is indistinguishable from a normal continuation. 3. **A resumption nonce or checkpoint hash.** The client needs a way to ask "what was the logical state at event 47?" and get an authoritative answer. MCP defines no such exchange. Absent all three, the client's only defense is *semantic*: it must validate that the resumed stream's final payload is consistent with the events it actually observed, and abort when the arithmetic does not close. ## Decision Boundary The boundary is whether the client treats resumption as *trusted continuation* or *suspect continuation*. - **Trusted continuation** is correct only when the client can prove the server has a durable replay buffer covering the gap. In practice a client cannot prove this from the wire; it can only be configured with out-of-band knowledge of the server's buffer policy. - **Suspect continuation** is the correct default for any tool with side effects. On every resume, the client must: - Record the exact set of progress events observed *before* the drop (IDs and any embedded step counters). - On completion, reconcile the final payload's declared step/effect count against the observed pre-drop count plus the post-resume count. - If reconciliation fails, treat the tool call as **indeterminate**, not failed and not succeeded — because the side effects may or may not have doubled. The decision to *not* auto-retry an indeterminate call is the load-bearing one. Retrying a possibly-doubled non-idempotent call is how a 40% duplication becomes a 180% duplication. ## Operational Effect The practical consequence is that `Last-Event-ID` resumption must be paired with an application-level *resumption witness*: a hash or counter embedded in each event that the server commits to, and that the client can recompute and compare at completion. Without it, a resumed stream is a stream the client cannot audit, and an unauditable stream from a non-idempotent tool is a correctness hazard that the transport layer will happily deliver as a success. The guardrail is to demote the transport's "clean completion" signal and elevate the payload's internal consistency check to the authoritative success criterion — and to fail closed to `indeterminate` when the two disagree, escalating to a human or a compensating-action agent rather than retrying. ```python import hashlib from dataclasses import dataclass, field class ResumptionDivergenceError(RuntimeError): """Raised when a resumed MCP stream's final payload is inconsistent with the events the client actually observed. The tool call is indeterminate: side effects may have been duplicated by server-side re-execution during resume.""" pass @dataclass class ResumeWitness: session_id: str pre_drop_event_ids: list[int] = field(default_factory=list) pre_drop_step_counters: list[int] = field(default_factory=list) post_resume_event_ids: list[int] = field(default_factory=list) post_resume_step_counters: list[int] = field(default_factory=list) def record_pre_drop(self, event_id: int, step_counter: int) -> None: self.pre_drop_event_ids.append(event_id) self.pre_drop_step_counters.append(step_counter) def record_post_resume(self, event_id: int, step_counter: int) -> None: self.post_resume_event_ids.append(event_id) self.post_resume_step_counters.append(step_counter) def reconcile(self, final_payload: dict) -> None: observed_steps = ( len(self.pre_drop_step_counters) + len(self.post_resume_step_counters) ) declared_steps = final_payload.get("steps_executed") declared_hash = final_payload.get("witness_hash") # Contiguity of event IDs is necessary but NOT sufficient. all_ids = self.pre_drop_event_ids + self.post_resume_event_ids if all_ids != sorted(set(all_ids)): raise ResumptionDivergenceError( f"session {self.session_id}: non-monotonic or duplicated event IDs " f"across resume boundary: {all_ids}" ) # The load-bearing check: does the server's declared effect count # match what we actually observed? A mismatch means the server # re-executed a window we never saw. if declared_steps is not None and declared_steps != observed_steps: raise ResumptionDivergenceError( f"session {self.session_id}: resumed stream diverged — " f"observed {observed_steps} progress events but server " f"declared {declared_steps} steps executed. Tool call is " f"INDETERMINATE; do not auto-retry non-idempotent tool." ) # Optional: verify the server committed to a witness hash over the # full step sequence. If present and mismatched, the stream is a # re-run masquerading as a continuation. if declared_hash is not None: recomputed = hashlib.sha256( ",".join( str(c) for c in self.pre_drop_step_counters + self.post_resume_step_counters ).encode() ).hexdigest() if recomputed != declared_hash: raise ResumptionDivergenceError( f"session {self.session_id}: witness hash mismatch on resume; " f"server state diverges from client-observed history." ) def handle_resumed_completion( witness: ResumeWitness, final_payload: dict ) -> str: """Returns 'committed' only if the resumed stream is auditable.""" try: witness.reconcile(final_payload) except ResumptionDivergenceError: # Fail closed: escalate, do not retry. raise return "committed" ```