# How does an instance detect a silently truncated MCP SSE stream when HTTP-native transport reports a clean 200 and the session resume nonce has already been consumed? **Date of Record:** 2026 November 30 **Scope:** Applies to MCP clients using HTTP-native transport where the server streams Server-Sent Events over a long-lived POST response and supports session resumption via `Last-Event-ID`. Does not apply to stdio transport or to stateless request/response MCP servers that emit a single JSON body. ## Core Distinction A clean HTTP completion and a complete MCP response are not the same event. HTTP-native MCP transport multiplexes a single logical tool-call response across an SSE event stream whose termination is signaled by the *transport layer* (connection close, chunked-encoding terminator) while the *protocol layer* signals completion by a JSON-RPC response object carrying the matching `id`. The failure mode examined here is the gap between these two signals: the transport closes cleanly — status 200, valid terminating chunk, no RST — but the final JSON-RPC frame never arrived, because the server's streaming generator was cut by an upstream idle timeout, a load-balancer drain, or a process recycle *between* the last event flush and the response frame. The non-obvious part is the interaction with resumption. The client's `Last-Event-ID` is a monotonic cursor. When the server accepts a resume request, it *consumes* the nonce and advances its own cursor to the requested position. If the client had already advanced its local `Last-Event-ID` past the last event it actually *processed* (for example, because it optimistically recorded the ID upon receipt rather than upon successful JSON parse and dispatch), the resume reattaches at a position where the missing response frame is permanently behind the cursor. The stream resumes, delivers only keepalive comments, and closes again — cleanly. The client sees two consecutive 200s and no error, but the JSON-RPC `id` it is waiting on will never arrive. ## What Was Observed A tool invocation (`tools/call`, `id: 4177`) against an MCP server behind a 60-second ALB idle timeout. Trace: 1. Client POSTs the JSON-RPC request; server responds `200` with `Content-Type: text/event-stream`. 2. Server emits `event: message`, `id: 1`, `data: {"jsonrpc":"2.0","method":"notifications/progress",...}` for a long-running tool. Client records `Last-Event-ID: 1`. 3. Server emits `id: 2`, a partial progress notification. Client records `Last-Event-ID: 2`. 4. At t+60s the ALB drains the connection. The server's generator is interrupted before it can flush the terminal `data: {"jsonrpc":"2.0","id":4177,"result":...}` frame with `id: 3`. 5. Client observes a clean EOF (chunked terminator received, no error event). The HTTP library reports success. 6. Client's response-future for `id: 4177` is still pending. Its watchdog fires and issues a resume: `GET` with `Last-Event-ID: 2`. 7. Server resumes at cursor 3 — the position of the *never-emitted* response frame. Its replay buffer contains nothing at or after 3, so it streams only `: keepalive` comments and closes at the next idle boundary. 8. Second clean EOF. Client's future for `id: 4177` remains pending. No error is raised anywhere; the only symptom is a hung tool call and a rising pending-request gauge. The critical state error was in step 3: the client advanced its cursor to `2` on *receipt* of the progress event, but the response frame that the server would have assigned `id: 3` was generated from the same request context. Because the server's resume semantics are "replay strictly after the given cursor," and because the response frame was allocated `id: 3` before the connection died but never written, the cursor `2` is exactly one short of the hole. A resume at `2` should have replayed `3`; it did not, because the server's replay buffer is bounded and had already evicted the unflushed frame's slot. The client cannot distinguish "no events after 2" from "events after 2 were lost." ## Condition of Validity The invariant that fails is: *a JSON-RPC response `id` is delivered at most once and its non-arrival is observable.* Under HTTP-native SSE with cursor-based resumption, non-arrival is only observable if the client maintains a *separate* liveness clock per pending request ID and treats stream termination without the matching frame as a *soft failure requiring explicit re-issue*, not as a resumable condition. The failure is bounded by three conditions, all of which must hold to trigger it: - The server assigns event IDs to *outbound frames* (progress, logs, response) from a single monotonic sequence, so a response frame's ID is reserved before it is written. - The replay buffer is bounded and evicts by time or count, so a reserved-but-unwritten frame can be evicted before it is flushed. - The client advances `Last-Event-ID` on receipt rather than on successful dispatch, and treats a clean EOF as "resume from cursor" rather than "the request may be lost." If any one is absent, the hole is either not creatable (unbounded buffer), not silent (server emits an explicit `event: error` before close), or not durable (client re-issues from scratch instead of resuming). ## Decision Boundary The client must decide, on every clean stream termination, between two actions: - **Resume**: reattach with `Last-Event-ID`, valid only if the client can prove the pending response frame is at or after the cursor *and* the server's replay buffer still covers it. - **Re-issue**: send a fresh JSON-RPC request with a new `id`, valid whenever the above cannot be proven. The boundary is crossed the moment the client cannot bound the replay buffer's horizon. Since the client has no protocol-level way to query buffer depth, the safe rule is: *resume only for progress/notification continuity; re-issue for any request whose terminal response frame is outstanding.* Resumption is a transport-continuity mechanism, not a request-completion mechanism, and conflating the two is the defect. A second boundary: the client must not advance `Last-Event-ID` for an event until that event has been fully parsed and dispatched. An event that fails JSON parse must not advance the cursor, or the client will skip it on resume — the same hole, one layer up. ## Operational Effect Left unguarded, the effect is a class of hung tool calls that never surface as errors. Pending-request gauges climb, agent loops stall waiting on a future that will never resolve, and retry logic keyed on exceptions never fires because no exception is raised. The agent's reasoning loop treats the tool call as still in flight indefinitely, consuming context budget on a stalled step until an outer timeout (if any) aborts the whole task — a failure that looks like model indecision but is a transport-completion bug. The guardrail is a per-request completion watchdog decoupled from the stream's own liveness: track each outstanding JSON-RPC `id`, and on clean EOF without its frame, escalate to re-issue rather than resume. The code below encodes that boundary as an explicit exception raised by the dispatch path. ```python import json from dataclasses import dataclass, field class MCPStreamCompletionError(RuntimeError): """Raised when an SSE stream closes cleanly but a pending JSON-RPC response frame was never delivered, and resumption cannot prove coverage of the missing frame.""" @dataclass class PendingRequest: rpc_id: int cursor_at_send: int dispatched: bool = False @dataclass class StreamSession: last_event_id: int = 0 # IDs advanced only after successful parse+dispatch pending: dict = field(default_factory=dict) def on_event(self, raw_event_id: int, data: str) -> None: try: frame = json.loads(data) except json.JSONDecodeError: # Do NOT advance cursor on parse failure; resume must replay it. raise MCPStreamCompletionError( f"unparseable event {raw_event_id}; cursor held at {self.last_event_id}" ) if frame.get("id") in self.pending: self.pending[frame["id"]].dispatched = True del self.pending[frame["id"]] self.last_event_id = raw_event_id def on_clean_eof(self) -> str: """Return 'resume' or 'reissue'. Raises if the choice is unsafe.""" if not self.pending: return "resume" # nothing outstanding; continuity only # Outstanding response frames exist. We cannot prove the server's # replay buffer still covers them, so resumption is unsafe. stuck = list(self.pending) raise MCPStreamCompletionError( "clean EOF with pending response frames " f"{stuck} at cursor {self.last_event_id}; " "resume cannot prove coverage — caller must re-issue with fresh ids" ) ```