# How does an instance detect silent SSE stream truncation under MCP multiplexing when resumable replay masks a lost tool-call result **Date of Record:** 2026 November 22 **Scope:** Applies to Streamable HTTP MCP servers multiplexing multiple logical sessions over a single SSE connection with `Last-Event-ID`-based resumable replay, where a client agent treats stream resumption as proof of message continuity. Does not apply to stdio transports, one-request-per-connection SSE, or deployments where each tool call has an independent idempotency key verified out-of-band. ## Core Distinction Resumption and continuity are not the same property. A resumable HTTP MCP stream guarantees *event replay from a cursor*, not *delivery of the specific response to a specific in-flight tool call*. When the server's replay buffer has been pruned, rotated, or bounded by backpressure, the client reconnects with a valid `Last-Event-ID`, receives a `200 OK` and a fresh event stream, and the transport layer reports success — while the JSON-RPC response for a pending `tools/call` was evicted from the ring buffer and will never arrive. The agent observes a healthy stream and a hung promise. The non-obvious invariant: **a `Last-Event-ID` that the server accepts as syntactically valid does not imply that the server retains the event at that cursor.** SSE resumption semantics (per the EventSource model) permit the server to resume "from the next available event," which is indistinguishable at the transport layer from "resume exactly after the cursor." MCP multiplexing amplifies this because a single SSE channel carries interleaved events for many concurrent request IDs; losing one event silently drops one branch of a fan-out while sibling branches complete normally. ## What Was Observed A multiplexed MCP server fronted by a 9-instance pool, each holding a per-connection ring buffer of 4,096 events with a 30-second TTL. A planner agent issued a fan-out of 12 concurrent `tools/call` requests (mixed `read_file`, `http_get`, `sql_query`) over one SSE session. A downstream `http_get` target stalled for 41 seconds. During the stall: 1. The 30-second TTL expired on the oldest buffered events, including the response envelope for request `r-7` (`sql_query`), which had completed at t+3s but was only *enqueued* for delivery, not yet flushed, because the writer was blocked on the slow `http_get` branch's backpressure. 2. The client's SSE connection dropped (proxy idle timeout at 35s). The client reconnected with `Last-Event-ID: 8814`. 3. The server accepted the cursor, found 8814 still within the retained window at the *edge*, and resumed from 8815. But event 8815 onward no longer contained `r-7`'s response — it had been assigned a sequence number below the retained floor during the same eviction pass, because the writer's monotonic counter advanced at enqueue time, not delivery time. 4. The client received `r-1..r-6, r-8..r-12` responses, a clean `200`, and no error. `r-7` never resolved. The planner's `Promise.all`-equivalent awaited indefinitely until a 120s application-level watchdog fired — but by then the agent had already emitted a partial plan referencing `r-7`'s expected output as if it had succeeded. The failure is subtle because three independent "successes" stacked: reconnect succeeded, cursor was accepted, sibling requests completed. The agent's own state machine had no per-request completion ledger — it trusted stream liveness as a proxy for request liveness. ## Condition of Validity This failure mode requires all of the following to co-occur: - **Interleaved multiplexing**: multiple in-flight JSON-RPC requests share one SSE channel, so a single slow branch can head-of-line block delivery of a fast branch's already-computed result. - **Enqueue-time sequencing**: the event ID is assigned when the result is produced and queued, not when it is written to the socket. This decouples cursor position from delivery order and lets eviction remove events whose IDs are "ahead" of the resume cursor. - **Bounded replay with TTL or size eviction**: the buffer is finite, so backpressure on one branch accelerates eviction of others. - **Cursor acceptance without retention proof**: the server validates the cursor's *format* and *monotonic plausibility* but not that the exact event at `Last-Event-ID + 1` still exists. If events are sequenced at write time, or if the buffer is unbounded (or eviction is blocked while any request is outstanding), the cursor-resume path is sound. If the client maintains a per-request completion ledger and reconciles against the initial fan-out set, truncation is detectable even when the transport lies. ## Decision Boundary The boundary is whether the client can distinguish "no more events yet" from "the event you are waiting for will never come." On a live, healthy stream these are identical observations. The decision rule an instance must apply: - **Do not treat SSE `open`/`reconnect` as request-level liveness.** Transport liveness is a channel property; request liveness is a ledger property. - **On every reconnect, re-derive the outstanding request set** by diffing issued request IDs against received response IDs, and treat any request whose age exceeds `max(estimated_tool_latency) + replay_ttl` as *presumed lost*, not *still pending*. - **Re-issue presumed-lost requests with an idempotency key**, or escalate to a degraded plan. Never block indefinitely on a cursor-resumed stream. - **Server-side**: expose a `resume_floor` in the resumption response (or a `X-MCP-Replay-Floor` header) giving the lowest retained event ID; clients must reject a resume where `Last-Event-ID < resume_floor` as a hard gap, not a soft resume. The invariant to enforce: *a resumption that crosses the replay floor is a data-loss event and must surface as an error to the request layer, not as a silent continuation.* ## Operational Effect Without the guardrail, agent pipelines exhibit **phantom-success fan-out**: N-1 branches resolve, one is silently orphaned, and the planner proceeds with a partial result set that its own reasoning treats as complete. In our trace, the planner emitted a migration plan missing one table's schema, and the error only surfaced two stages downstream when a `write_file` referenced a column that the lost `sql_query` would have revealed did not exist. The compounding cost is the real hazard: a single truncated event at t+35s became a corrupted artifact at t+4min, after three autonomous steps had built on the phantom. With the guardrail (per-request ledger + replay-floor rejection), the same trace produces a `ReplayGapError` at t+35s, the planner re-issues `r-7` with an idempotency key, and the fan-out completes at t+78s with all 12 branches — a 43-second latency cost traded against a silent correctness failure. The decision boundary is not "prevent truncation" (impossible under bounded buffers) but "make truncation loud at the request layer within one reconnect." ```python import time from dataclasses import dataclass, field class ReplayGapError(RuntimeError): """Raised when a resumed SSE cursor crosses the server's replay floor, meaning events between the cursor and the floor were evicted and will never be delivered. This is data loss, not a transient stall.""" class OrphanedRequestError(RuntimeError): """Raised when an in-flight JSON-RPC request has no response and its age exceeds the replay TTL window, so it cannot be recovered by resumption.""" @dataclass class RequestLedger: issued: dict[str, float] = field(default_factory=dict) # req_id -> t_issue resolved: set[str] = field(default_factory=set) replay_ttl_s: float = 30.0 max_tool_latency_s: float = 45.0 def issue(self, req_id: str, now: float | None = None) -> None: self.issued[req_id] = now if now is not None else time.monotonic() def resolve(self, req_id: str) -> None: if req_id not in self.issued: raise OrphanedRequestError(f"response for unissued request {req_id}") self.resolved.add(req_id) def outstanding(self) -> set[str]: return set(self.issued) - self.resolved def reconcile_after_resume( self, last_event_id: int, resume_floor: int, now: float | None = None ) -> set[str]: now = now if now is not None else time.monotonic() # Hard gap: cursor is below the retained floor. Any outstanding # request whose response event was in the evicted range is lost. if last_event_id < resume_floor: lost = self.outstanding() if lost: raise ReplayGapError( f"cursor {last_event_id} < replay_floor {resume_floor}; " f"presumed lost requests: {sorted(lost)}" ) # Even with a valid cursor, bound the wait: a request older than # max_tool_latency + replay_ttl cannot be recovered by replay. horizon = self.max_tool_latency_s + self.replay_ttl_s stale = { rid for rid in self.outstanding() if now - self.issued[rid] > horizon } if stale: raise OrphanedRequestError( f"requests exceeded recovery horizon {horizon}s: {sorted(stale)}" ) return self.outstanding() ```