# What structural signals indicate that an MCP HTTP-native SSE session has silently forked its event stream during resumption **Date of Record:** 2026 November 25 **Scope:** Applies to MCP servers exposing the HTTP-native transport (streamable HTTP with `Mcp-Session-Id` and server-initiated SSE), specifically when a client reconnects after a dropped SSE stream using `Last-Event-ID`. Does not apply to stdio transport, WebSocket transports, or stateless request/response-only MCP configurations. ## Core Distinction The failure mode is not "the SSE connection dropped." A dropped stream is a detectable, recoverable condition — the client observes a TCP reset or a missing heartbeat and reconnects with `Last-Event-ID: N`. The dangerous boundary is the **forked stream**: the server accepts the resumption, replays events *after* `N`, but does so on a *new* logical event sequence that diverged from the one the client was consuming before the drop. The client cannot tell, from the transport layer alone, whether the events it now receives are a continuation of its old stream or a parallel branch that happens to share an ID space. Concretely: an MCP server that multiplexes multiple concurrent tool invocations (or multiple agent sessions) onto one per-session event log will, on reconnection, sometimes resume against a *different* in-memory log segment than the one the client was reading. Event IDs remain monotonically increasing and the `Last-Event-ID` cursor is honored — so every transport-level signal says "resumed cleanly." But the semantic lineage has forked: the client is now consuming events from a branch that never saw the pre-disconnect state transitions it already applied. The invariant that breaks is **single-consumer causal continuity of the event log**, not transport liveness. ## What Was Observed A representative trace from a long-running MCP session driving a multi-step reasoning agent with a `filesystem` and a `shell` tool server: 1. Client connects, receives `Mcp-Session-Id: s-7f2a`, opens SSE stream, and begins consuming events `id=1..412` (tool call requests, tool results, server notifications). The agent has applied all 412 events into its working state. 2. At event 412 the network path is interrupted (load balancer idle timeout, 60s). The client does not observe a clean `close` — it observes a stalled stream. 3. At t+8s the client reconnects: `GET /mcp` with `Mcp-Session-Id: s-7f2a` and `Last-Event-ID: 412`. 4. Server responds `200`, opens SSE, and immediately emits `id=413, 414, 415...`. The client applies them. 5. **The silent divergence:** events 413+ were generated against a server-side session state that had *already* timed out the shell tool invocation referenced in event 409 (server-side tool timeout is 30s, shorter than the client's perception of the gap) and had emitted a `tool_cancelled` notification at server-internal sequence position 413 — but that notification was written to a *second* in-memory log segment created when the server's session handler was re-instantiated on reconnect. The client's cursor 412 pointed into segment A; the server resumed it against segment B whose ID counter was seeded from a snapshot taken at disconnect, so IDs continued but the *content* at 413 was the cancellation, not the tool result the agent was awaiting. 6. The agent, seeing `tool_cancelled` for a call it believed was in flight, entered a retry loop. The retry re-issued the same shell command. The server executed it a second time. No transport error was ever raised. The structural signals that the fork had occurred were all *semantic*, never transport-level: - **Gap in expected notification types.** The agent's state machine expected a `tool_result` for call 409 before any `tool_cancelled`; it received the cancellation first. A causal-ordering validator would have flagged this; a raw event-ID monotonicity check would not. - **ID continuity without content continuity.** IDs 413..415 were contiguous with 412, but the referenced `call_id` in 413 (`call-409`) had *no* preceding `tool_result` event in the client's applied set. The invariant "every `tool_cancelled` is preceded by a `tool_call` in the same stream" was violated. - **Duplicate side effects.** The retry produced a second `call-409` execution. The server's idempotency key was derived from the client's call ID, but the client generated a *new* call ID on retry, so the server saw it as a distinct invocation. ## Condition of Validity The guardrail that bounds this failure is a **resumption warrant**: on reconnect, the server must return, alongside the resumed stream, a structural attestation that the resumed log is causally continuous with the client's cursor. In HTTP-native MCP this is expressible as a response header or an initial SSE control event carrying: - the `Mcp-Session-Id` (must match), - the `Last-Event-ID` the server actually resumed from (must equal the client's cursor), - a **log lineage token** — a hash of the event-log segment identity plus the server's monotonic internal sequence at the cursor, - an explicit `resumption: continued | forked` disposition. The invariant: *a client MUST NOT apply any event from a resumed stream until it has verified that the server's lineage token matches the lineage token it held before the disconnect.* If the server cannot attest continuity, it must respond `409 Conflict` with `resumption: forked` and require the client to re-initialize the session (re-issue `initialize`, rebuild state from a server-provided snapshot), rather than silently continuing. This condition is valid only when the server maintains a durable, monotonic per-session event log with stable segment identity across reconnects. Servers that re-instantiate session handlers on reconnect (common in stateless HTTP deployments behind round-robin load balancers) cannot satisfy it and must declare `resumption: forked` unconditionally — which is correct, because their event log genuinely is not continuous. ## Decision Boundary The decision the client must make on every SSE reconnection is binary and must be made *before* applying any resumed event: - **Continue** only if the server's lineage token equals the client's pre-disconnect token AND the first resumed event's causal preconditions are satisfied by the client's applied set (e.g., a `tool_result` for a `tool_call` the client has outstanding). Both conditions, not either. - **Reset** if the lineage token differs, is absent, or the first resumed event violates causal precondition. On reset, the client discards its in-flight tool-call expectations, re-initializes the session, and reconciles against a server snapshot — accepting the cost of replay rather than the cost of a forked state. The non-obvious part of the boundary: **ID monotonicity is not a valid proxy for continuity.** A server can honor `Last-Event-ID` perfectly and still fork the stream, because event IDs index a position, not a lineage. Clients that gate resumption on "IDs are increasing" will pass every check and still fork. The gate must be lineage-token equality plus causal-precondition satisfaction on the first resumed event. ## Operational Effect When the guardrail is absent, the observed effect is **silent duplicate execution with phantom cancellation semantics**: the agent believes a cancelled tool call was never executed (it was), retries it (double side effect), and the server's session state and the client's applied state permanently diverge with no error surfaced at any layer. Downstream, memory distillation records the retry as the canonical outcome and drops the first execution entirely, so the agent's episodic log is not merely stale — it is *wrong about what happened*, and no future reconciliation will detect the discrepancy because the duplicate was never logged as a duplicate. With the guardrail, the fork is converted into a loud, cheap failure: a `409` at reconnect, a bounded re-initialization, and a snapshot reconciliation. The cost moves from "undetectable state corruption that compounds across the task" to "one session restart." That is the entire value of the invariant — it makes the failure legible at the exact moment it occurs rather than leaving it to surface, if ever, as an inexplicable behavior divergence hours later. ```python import hashlib from dataclasses import dataclass class ResumptionForkError(RuntimeError): """Raised when a resumed MCP SSE stream is not causally continuous with the client's pre-disconnect cursor.""" @dataclass(frozen=True) class StreamCursor: session_id: str last_event_id: int lineage_token: str # hash(segment_identity + server_seq_at_cursor) def _lineage_token(segment_id: str, seq: int) -> str: return hashlib.sha256(f"{segment_id}:{seq}".encode()).hexdigest() def verify_resumption( client_cursor: StreamCursor, server_session_id: str, server_resumed_from: int, server_segment_id: str, server_seq_at_cursor: int, first_event: dict, outstanding_calls: set[str], ) -> None: if server_session_id != client_cursor.session_id: raise ResumptionForkError( f"session mismatch: client={client_cursor.session_id} " f"server={server_session_id}" ) if server_resumed_from != client_cursor.last_event_id: raise ResumptionForkError( f"cursor mismatch: client={client_cursor.last_event_id} " f"server={server_resumed_from}" ) expected = _lineage_token(server_segment_id, server_seq_at_cursor) if expected != client_cursor.lineage_token: # IDs are contiguous, transport is healthy, but the log forked. raise ResumptionForkError( "lineage token mismatch: resumed stream is a fork of the " "client's event log; re-initialize session and reconcile " "against server snapshot" ) # Causal precondition check on the first resumed event. ev_type = first_event.get("type") call_id = first_event.get("call_id") if ev_type == "tool_cancelled" and call_id not in outstanding_calls: raise ResumptionForkError( f"causal precondition violated: tool_cancelled for {call_id} " f"with no outstanding tool_call in applied set" ) if ev_type == "tool_result" and call_id not in outstanding_calls: raise ResumptionForkError( f"causal precondition violated: tool_result for {call_id} " f"with no outstanding tool_call in applied set" ) def resume_stream(client_cursor, server_handshake, outstanding_calls): try: verify_resumption( client_cursor=client_cursor, server_session_id=server_handshake["session_id"], server_resumed_from=server_handshake["resumed_from"], server_segment_id=server_handshake["segment_id"], server_seq_at_cursor=server_handshake["seq_at_cursor"], first_event=server_handshake["first_event"], outstanding_calls=outstanding_calls, ) except ResumptionForkError: # Loud, bounded failure: re-initialize rather than silently fork. raise return server_handshake["first_event"] ```