# What structural signals indicate a streamable HTTP MCP session has silently forked into two live continuations after reconnect **Date of Record:** 2026 November 26 **Scope:** Applies to MCP clients using the Streamable HTTP transport with `Mcp-Session-Id` stateful sessions, `Last-Event-ID` resumption on the SSE stream, and mid-task tool-call sequences. Does not apply to stateless HTTP transports without session IDs, nor to stdio transports where reconnection is a process restart rather than a stream resume. ## Core Distinction The failure is not "the reconnect failed." The failure is that the reconnect *succeeded twice*. Streamable HTTP MCP servers are permitted to hold per-session state (in-flight tool invocations, partial JSON-RPC response streams, server-side sampling requests awaiting client completion) keyed by `Mcp-Session-Id`. When a client's SSE stream drops, the client reconnects with `GET` plus `Last-Event-ID`. The server is expected to replay events after that ID from a per-session event buffer. The non-obvious boundary: if the client's reconnect races with the server's own timeout-based session eviction and re-admission, the server can admit the new connection as a *fresh continuation* of the same session ID while the old continuation is still live in the event buffer. The result is two logical continuations sharing one session identifier, each receiving a disjoint tail of the event stream. This is a **session fork**, not a disconnection. The structural distinction from a normal reconnect is that the session ID remains valid and the server returns `200` on both streams; nothing in the transport layer signals an error. ## What Was Observed A client agent orchestrating a 14-step tool sequence over Streamable HTTP observed the following trace. The SSE stream dropped at event ID 47 during a long-running `write_file` tool call (server-side execution ~90s, well beyond the client's 30s idle timeout). The client's transport layer issued a reconnect `GET /mcp` with `Mcp-Session-Id: s_9f2a` and `Last-Event-ID: 47`. The server's session registry had already begun eviction: the session's idle timer fired at t+28s (because the server only counts *client-to-server* activity toward the idle timer, not in-flight tool execution), marking the session `EVICTING`. The reconnect arrived at t+31s, during the eviction grace window. The re-admission path treated the incoming connection as a new subscriber and registered it in the session's subscriber set — but did not cancel the in-flight `write_file` continuation, which was still attached to the *old* subscriber entry that had not yet been reaped. Structural signals that followed within ~400ms: 1. **Duplicate event IDs across two streams.** The client's new stream received event 48 (a `notifications/progress` for the `write_file` call). The old continuation, whose TCP socket was half-closed but not RST, buffered events 48–52 in kernel send buffers. When the client's OS eventually delivered a late FIN-race retransmit, the client's transport logged a second stream delivering events 48–52 with identical IDs but different `id:` values in the SSE framing (server had assigned new monotonic IDs to the replayed events because it re-serialized them from the buffer rather than replaying raw bytes). 2. **Divergent `Last-Event-ID` watermarks.** The client tracked `Last-Event-ID: 52` on the new stream, while the stale continuation's kernel buffer implied `Last-Event-ID: 47`. Any subsequent reconnect would resume from 52, silently skipping the fact that events 48–52 were double-delivered and that the tool result for `write_file` (event 53) was emitted only on the stale continuation — lost. 3. **Two live `sampling/createMessage` requests with the same `requestId`.** The server had issued a sampling request at event 50 on the old continuation. Because the re-admission path replayed events 48–52 to the new continuation, the client received the sampling request twice and — being a probabilistic reasoner without dedup on `requestId` — answered it twice. The server accepted both answers, producing two divergent tool results for the same logical step. 4. **Session ID still returned `200` on `DELETE`.** The client attempting to terminate the session received `200` from the server, but the stale continuation continued to emit one more event (the buffered event 53) after the DELETE acknowledgement. The `DELETE` reaped the registry entry but not the in-flight continuation's subscriber reference. ## Condition of Validity This failure requires all of the following to co-occur, which is why it is rare but not negligible under load: - The server implements **idle-timer-based eviction** that excludes in-flight tool execution from activity accounting (a common simplification), so a long tool call looks idle. - The server implements **event replay from a buffer** rather than raw byte replay, so replayed events carry re-serialized IDs. - The reconnect arrives within the **eviction grace window** — after the idle timer fires but before the subscriber entries are reaped. This window is typically 5–30s and is exactly the window a client hits when its own reconnect backoff is 1s–5s and the stream drop is detected late. - The client does **not deduplicate on `requestId`** for server-initiated requests, and does **not** treat duplicate event IDs as a fatal session-integrity signal. The invariant that must hold for correctness: **for a given `Mcp-Session-Id`, at most one live continuation may exist at any instant, and the set of event IDs delivered to the client must be a strictly increasing sequence with no gaps and no duplicates.** The server's replay path violates the "no duplicates" half; the client's dedup absence violates the "at most one continuation" half. ## Decision Boundary The boundary between safe reconnect and silent fork is the **eviction grace window vs. reconnect latency** comparison, plus the **replay serialization mode**: - If the server replays raw buffered bytes (preserving original `id:` framing), duplicate delivery is detectable by ID equality and the client can drop the second copy. Safe. - If the server re-serializes replayed events with new IDs, duplicate delivery is *undetectable by ID* and must be detected by `requestId` dedup or by a session-generation token. Unsafe. - If the reconnect arrives after the grace window closes (subscriber fully reaped), the server correctly returns `404` on the session and the client starts fresh. The fork cannot occur. Safe. - If the reconnect arrives before the idle timer fires, the old continuation is still the sole subscriber and the reconnect is rejected or queued. Safe. The dangerous band is precisely `[idle_timer_fire, subscriber_reap]` combined with re-serializing replay. A client cannot observe which band it is in from the transport response alone — both the fork and the clean resume return `200` with a valid SSE stream. ## Operational Effect The downstream effect is **tool-result divergence under a single session ID**. Because the client answered the duplicated sampling request twice, the server produced two tool results for one logical step; the agent's reasoning loop consumed both as distinct observations, and its next-step plan branched on a state that never existed. In the observed trace, the agent issued a second `write_file` to the same path with different content, and the final on-disk state depended on the order in which the two continuations' writes landed — a non-deterministic outcome that the agent's own execution log could not explain, because the log recorded one step. The architectural guardrail is a **session-generation token**: the server must increment a generation counter on every admission to a session and include it in a response header (e.g., `Mcp-Session-Generation`) and in every SSE event's `id:` prefix. The client must reject any event whose generation is lower than the highest generation it has seen, and must reject any `requestId` it has already answered within the current session generation. Additionally, the server must account in-flight tool execution as activity for idle-timer purposes, so the eviction window never overlaps with a live continuation. Without these, the `200`-on-reconnect signal is structurally insufficient to distinguish clean resume from fork. ```python class SessionForkError(RuntimeError): """Raised when a streamable HTTP MCP session exhibits fork signals: duplicate requestId delivery, non-monotonic event IDs, or a post-DELETE continuation emission.""" pass class SessionGuard: def __init__(self, session_id: str): self.session_id = session_id self.highest_generation = -1 self.answered_request_ids: set[str] = set() self.last_event_id = -1 self.deleted = False def admit(self, generation: int) -> None: if generation < self.highest_generation: raise SessionForkError( f"session {self.session_id}: stale generation {generation} " f"< {self.highest_generation}; fork continuation detected" ) self.highest_generation = generation def on_event(self, event_id: int, generation: int, request_id: str | None) -> None: if self.deleted: raise SessionForkError( f"session {self.session_id}: event {event_id} after DELETE ack; " f"in-flight continuation not reaped" ) if generation != self.highest_generation: raise SessionForkError( f"session {self.session_id}: event {event_id} carries generation " f"{generation} != {self.highest_generation}; interleaved continuations" ) if event_id <= self.last_event_id: raise SessionForkError( f"session {self.session_id}: non-monotonic event id {event_id} " f"<= {self.last_event_id}; replay re-serialized with new framing" ) if request_id is not None and request_id in self.answered_request_ids: raise SessionForkError( f"session {self.session_id}: duplicate requestId {request_id}; " f"server-initiated request replayed to forked continuation" ) self.last_event_id = event_id if request_id is not None: self.answered_request_ids.add(request_id) def on_delete_ack(self) -> None: self.deleted = True ```