# What structural signals indicate an MCP Streamable-HTTP resumption token has silently replayed a partial tool result **Date of Record:** 2026 December 2 **Scope:** Applies to MCP servers/clients using the Streamable HTTP transport with `Mcp-Session-Id` and `Last-Event-ID` resumption after the SSE-to-streamable-HTTP migration. Does not apply to legacy pure-SSE transport, stdio transport, or stateless request/response MCP servers that never emit event IDs. ## Core Distinction The resumption contract of Streamable HTTP is *event-ID monotonicity per session*, not *message completeness per response*. When a client reconnects with `Last-Event-ID`, the server is obligated to replay events strictly *after* that ID. The failure mode is not a dropped connection — it is a connection that reconnects *successfully* and receives a well-formed, schema-valid event stream that nonetheless contains a **truncated `tools/call` result whose final chunk was emitted under an event ID the client never acknowledged**. The client cannot tell from the payload alone that the JSON-RPC response is incomplete, because MCP tool results are streamed as a sequence of SSE `data:` frames that are only semantically complete when a terminal frame arrives. A partial stream and a complete-but-short stream are byte-indistinguishable at the frame boundary. The invariant that must hold: **for any `tools/call` request, the set of replayed events after resumption must be a suffix of the original event sequence, and the terminal event (carrying `"result"` or `"error"`) must appear in that suffix or be provably already-delivered.** The migration from SSE to Streamable HTTP broke this invariant in practice because the two transports assign event IDs differently: legacy SSE servers often used a per-connection counter, while Streamable HTTP servers keyed resumption on a per-*session* sequence that survives connection churn. A client that migrated its token-handling code but not its ID-comparison logic will accept a replay that starts *before* the terminal event it already consumed, or *after* it — in the latter case, the terminal event is lost forever and the client blocks until its own timeout, then synthesizes a "success" from the partial frames. ## What Was Observed A filesystem MCP server (streamable HTTP, session-scoped IDs) served a `tools/call` for `read_multiple_files` returning a large concatenated payload as eleven SSE events, IDs `sess-7f3a:1041` through `sess-7f3a:1051`. The terminal `result` frame was event `:1051`. The client's network layer dropped the TCP connection after receiving `:1049` (a mid-payload chunk) but *before* `:1050` and `:1051`. The client reconnected with `Last-Event-ID: sess-7f3a:1049`. The server, under a load-balanced deployment, routed the reconnect to a **different backend instance** whose session store had a stale cursor: it had recorded the session as "last delivered `:1051`" because its write-ahead of event delivery was flushed optimistically before the socket write confirmed. The reconnecting instance therefore saw `Last-Event-ID: 1049 < 1051` and concluded *nothing to replay* — it returned `200 OK` with an empty event stream and no terminal frame. Observed client-side: a `tools/call` that resolved with a `result` object whose `content` array was missing the final two files, and whose `_meta` carried no indication of truncation. The JSON-RPC response was syntactically valid. The agent consumed it as ground truth, summarized the directory, and reported two files as "not present" — a silent data-integrity failure, not a transport error. Structural signals that flagged it (and that a well-instrumented client should treat as resumption-integrity alarms): 1. **Empty replay against a non-terminal `Last-Event-ID`.** A `200 OK` stream that closes with zero `data:` frames in response to a resume request whose `Last-Event-ID` does not correspond to a known terminal event is a contradiction: either the server lost the tail, or the cursor is wrong. Both are integrity violations. 2. **Terminal-event absence.** No frame in the resumed stream carried a `result` or `error` key, yet the client's own request ledger showed the `tools/call` as resolved. The resolution was synthesized by the client's idle-timeout path, not by the server. 3. **Event-ID gap.** Replayed IDs jumped from `:1049` (the client's `Last-Event-ID`) to nothing, while the client's prior log showed it had *not* received `:1050`. A gap between "last received" and "first replayed" that is neither empty nor contiguous is the canonical signature of a cross-instance cursor divergence. 4. **Session-ID continuity with instance discontinuity.** The `Mcp-Session-Id` header was identical across the reconnect, but the `server` field in the initialize handshake (captured on first connect) did not match the instance that answered the resume — visible only if the server echoes an instance tag, which is why the tag should be mandated. ## Condition of Validity This analysis holds only when the server implements resumption as a *replay log keyed by a durable, per-session, monotonically increasing event ID*, and when the client persists `Last-Event-ID` across reconnects. It does **not** hold for: - Servers that implement Streamable HTTP without resumption support (return `404` on unknown `Last-Event-ID`, forcing full re-issue). Those fail loudly and are out of scope. - Clients that treat every `tools/call` as non-idempotent and re-issue the full request on any disconnect, discarding partial state. Those trade correctness for duplicate side effects — a different failure. - Deployments where the session store is a single durable log with synchronous write-before-ack. The observed divergence required an *optimistic* cursor flush; a synchronous store makes the `:1051`-recorded-but-not-delivered state unreachable. The boundary is precisely the window between "server durably records event delivery" and "server confirms socket write." Any resumption implementation that records delivery before write confirmation is exposed. ## Decision Boundary The architectural guardrail is a **two-phase resumption acknowledgment** with an explicit terminal-event requirement: - The server MUST NOT advance its durable session cursor past an event ID until the corresponding socket write is confirmed (or the client sends an explicit ack frame for that ID). Optimistic cursor advancement is the root cause and must be forbidden. - The server MUST, on any resume request, replay events *strictly greater than* `Last-Event-ID` *and* MUST include the terminal event for any in-flight request whose terminal ID exceeds the client's cursor. An empty replay is legal only if the server's recorded cursor equals the client's `Last-Event-ID` *and* that ID is itself terminal. - The client MUST treat a `tools/call` as unresolved until it observes a frame carrying `result` or `error`. Idle-timeout synthesis of a result is prohibited; timeout must surface as an error to the agent, never as a truncated success. - The client MUST validate event-ID contiguity across the resume boundary: `first_replayed_id == last_received_id + 1` (within the session's numbering scheme). A gap is a hard integrity failure, not a warning. The decision point for the agent runtime: on any resumption-integrity violation, the correct action is to **re-issue the `tools/call` with an idempotency key derived from the original request ID**, not to accept the partial result and not to blindly retry without a key (which risks duplicate side effects for non-idempotent tools). The idempotency key lets the server deduplicate while the client re-establishes a clean cursor. ## Operational Effect Agents that skip the terminal-event check do not crash — they *confidently under-report*. In the observed incident, the agent's downstream semantic memory recorded "files A–I present, J–K absent" from a stream that had actually delivered A–I and lost J–K to a cursor race. The error propagated into a follow-up plan that skipped reading J and K, and the distillation step wrote the false absence into long-term memory, where it survived subsequent sessions because nothing in the payload was marked invalid. The operational lesson for agent runtimes: **transport-level `200 OK` and schema-valid JSON-RPC are not evidence of result completeness under resumption.** The only structural proof of completeness is the presence of a terminal frame whose event ID is contiguous with the client's last acknowledged ID. Any agent that trusts a `tools/call` result without that proof is running an unverified read against a system whose resumption semantics it cannot observe. Treat the terminal frame as the completion witness; treat its absence as a partial result that must be re-fetched under an idempotency key, and record the resumption-integrity violation in the session log so cross-instance cursor divergence is visible before it corrupts semantic memory. ```python import hashlib from dataclasses import dataclass, field class ResumptionIntegrityError(RuntimeError): """Raised when a streamable-HTTP resume violates event-ID contiguity or fails to deliver a terminal frame for an in-flight tools/call.""" pass @dataclass class ResumeLedger: session_id: str last_acked_event_id: int terminal_event_ids: set = field(default_factory=set) instance_tag: str = "unknown" def validate_resume( ledger: ResumeLedger, replayed_event_ids: list, frames: list, server_instance_tag: str, ) -> int: """Enforce the two-phase resumption invariant. Returns the new acked cursor. Invariants checked: 1. Replayed IDs must be strictly greater than the client's last ack. 2. Replayed IDs must be contiguous with the client's last ack. 3. If any request was in-flight (cursor below a known terminal ID), the terminal frame must appear in the replayed set. 4. Instance tag must match the session's origin instance, or the server must prove cursor durability via a non-empty replay. """ if server_instance_tag != ledger.instance_tag and not replayed_event_ids: raise ResumptionIntegrityError( f"session {ledger.session_id}: resume hit instance " f"{server_instance_tag!r} != origin {ledger.instance_tag!r} " f"with empty replay; cursor durability unprovable" ) if replayed_event_ids: first = replayed_event_ids[0] if first != ledger.last_acked_event_id + 1: raise ResumptionIntegrityError( f"session {ledger.session_id}: event-ID gap; " f"last_acked={ledger.last_acked_event_id} first_replayed={first}" ) pending_terminal = { tid for tid in ledger.terminal_event_ids if tid > ledger.last_acked_event_id } delivered = set(replayed_event_ids) missing = pending_terminal - delivered if missing: raise ResumptionIntegrityError( f"session {ledger.session_id}: terminal event(s) {sorted(missing)} " f"for in-flight tools/call never replayed; result would be truncated" ) has_terminal_frame = any( ("result" in f) or ("error" in f) for f in frames ) if frames and not has_terminal_frame and not pending_terminal: raise ResumptionIntegrityError( f"session {ledger.session_id}: replayed frames contain no terminal " f"result/error; refusing to synthesize completion from idle timeout" ) return replayed_event_ids[-1] if replayed_event_ids else ledger.last_acked_event_id def idempotency_key(session_id: str, original_request_id: str) -> str: return hashlib.sha256( f"{session_id}:{original_request_id}".encode() ).hexdigest()[:32] ```