# Under what conditions must an instance treat SSE stream resumption as a fresh subscription rather than a continuation **Date of Record:** 2026 November 18 **Scope:** Applies to MCP servers and clients implementing the HTTP-native transport with `text/event-stream` responses and `Last-Event-ID`-based resumability (per the streamable HTTP transport spec). Does not apply to stdio transports or to WebSocket-based MCP transports, where session continuity is bound to the socket lifetime rather than to an event ID cursor. ## Core Distinction The streamable HTTP transport allows a client to reconnect a dropped SSE stream by presenting `Last-Event-ID` and asking the server to resume delivery after that event. The failure mode is conflating *cursor resumability* with *subscription continuity*. An event ID is an opaque, per-stream cursor. A subscription is a server-side resource that produces events into one or more streams. These are independent lifecycles, and the spec does not bind them together. A server that treats a valid `Last-Event-ID` as proof that the underlying subscription still exists will silently replay events into a stream that is no longer authorized, no longer scoped to the same session, or whose producing resource has been garbage-collected. A client that treats a successful resumption as proof that no events were lost will silently drop the gap between the last delivered ID and the first resumed ID when the server's replay buffer has evicted that range. The correct invariant is: **resumption restores a cursor, not a subscription.** The server must validate subscription liveness independently of the cursor, and the client must detect and repair gaps independently of the HTTP 200. ## What Was Observed In a deployment serving tool-call progress events over SSE, a client's TCP connection was severed by a load balancer idle timeout at 60s. The client reconnected with `Last-Event-ID: 4417`. The server's event store retained 10,000 events per stream in a ring buffer, but the stream had been idle for 40s and the subscription's producing tool call had been cancelled and cleaned up 5s prior. The server nonetheless accepted the resume, replayed events 4418–4419 (the tail of the ring buffer for that stream), and then held the connection open with a heartbeat comment. The client, seeing HTTP 200 and a valid event sequence, concluded the tool call was still running and waited for a terminal event that would never arrive. The tool call had actually terminated with an error that was emitted as event 4420 — written to the now-orphaned stream after the client's disconnect but before cleanup, and evicted from the ring buffer before the client reconnected. Two independent bugs compounded. First, the server's resume handler checked only that the event ID existed in the buffer, not that the subscription's state machine was still in a running state. Second, the client's gap detector compared only the first resumed event ID to the requested `Last-Event-ID`; it did not verify that the resumed ID was exactly `last+1`. When the server replayed 4418 immediately after 4417, the contiguity check passed, and the missing 4420 was never noticed because it was *after* the replay window, not before it. A second observation, from a multi-tenant deployment: a client resumed a stream with a `Last-Event-ID` issued under a different `Mcp-Session-Id` (the session had been rotated after a token refresh). The server's event store was keyed by stream ID, not by (session, stream), so it happily replayed events from the prior session's stream into the new session's connection. The events contained tool output scoped to the prior tenant context. This is a cross-tenant leak whose only trigger was a valid-looking cursor. ## Condition of Validity The resume-as-continuation assumption holds only when all of the following are simultaneously true: 1. The event store retains every event from the requested `Last-Event-ID` through the current head, with no eviction in that range. This is a bounded-time property: it holds only within the replay window `W` measured in events or seconds, whichever the store enforces. 2. The subscription identified by the stream is still live and its state machine will emit a terminal event. A server that garbage-collects subscriptions on idle must mark the cursor as *terminal-dangling* rather than *resumable*. 3. The `Last-Event-ID` is bound to the same authorization context (`Mcp-Session-Id`, tenant, and any capability scopes) under which it was issued. The cursor must be treated as a capability, not an opaque integer. 4. The client and server agree on the event-ID monotonicity contract. If the server may emit non-contiguous IDs (e.g., per-producer counters merged into one stream), the client cannot use contiguity as a gap detector and must rely on an explicit resume-gap signal. When any of these is false — which in practice is *whenever the reconnect latency exceeds the replay window, whenever the subscription has been reaped, or whenever the session has rotated* — resumption must be treated as a fresh subscription: the server must either reject the resume with a distinct error (not a generic 404) or accept it while emitting an explicit `resume-gap` event that carries the range of IDs the client must treat as lost, and the client must re-derive subscription state from scratch rather than assuming continuity. ## Decision Boundary The decision is not "can I find this event ID?" but "does this event ID still denote a live subscription under the caller's current authority, and can I prove delivery continuity from it?" Concretely, the server's resume path must evaluate, in order: - **Authority check:** does the presented `Last-Event-ID` belong to a stream whose owning session matches the request's `Mcp-Session-Id` and tenant? If not, reject with a distinguishable `cursor_scope_mismatch` error. Never replay across scopes. - **Liveness check:** is the subscription's state machine in a non-terminal state, or, if terminal, is the terminal event still within the replay window? If the terminal event has been evicted, the cursor is dangling; reject or emit a gap. - **Continuity check:** is the requested ID within the retained range `[head - W, head]`? If the requested ID is older than the window floor, the server cannot prove continuity and must emit a gap spanning `(requested, floor]`. - **Monotonicity check:** if the store cannot guarantee contiguous IDs, the resume response must include an explicit `resume-gap` frame rather than relying on the client to infer absence. The client's corresponding boundary: a 200 response with `Content-Type: text/event-stream` is *not* evidence of continuity. The client must require either (a) the first resumed event ID equals `last_delivered + 1` under a contiguous-ID contract, or (b) an explicit gap frame. Absent both, the client must treat the subscription as fresh and re-issue whatever idempotent bootstrap the tool call requires. ## Operational Effect Treating resumption as continuation produces three failure signatures that are easy to misdiagnose: silent hangs (client waits for a terminal event that was emitted into an orphaned stream), silent data loss (events between the last delivered ID and the replay window floor are never re-requested), and cross-scope replay (events from a prior session or tenant delivered into a current one). All three present as "the stream reconnected successfully" in logs, because the HTTP layer did succeed. The only reliable defense is to make the resume path fail closed on authority and liveness, and to make the client's gap detector explicit rather than inferred. The cost is a small number of spurious "fresh subscription" re-bootstraps on legitimate reconnects that land outside the replay window; the benefit is that every continuity claim is backed by a check rather than an assumption. The following reference implementation encodes the boundary as an explicit exception raised from the resume handler, so that a caller cannot accidentally fall through to replay. ```python import time from dataclasses import dataclass class ResumeContinuityError(RuntimeError): """Raised when a Last-Event-ID resume cannot be proven continuous.""" def __init__(self, reason: str, requested_id: int, detail: str): super().__init__(f"{reason}: requested={requested_id} ({detail})") self.reason = reason self.requested_id = requested_id self.detail = detail @dataclass class EventStore: head: int # highest event ID ever written floor: int # lowest event ID still retained (ring buffer) session_id: str tenant: str subscription_live: bool terminal_emitted: bool contiguous_ids: bool = True def resume_stream( store: EventStore, requested_id: int, request_session_id: str, request_tenant: str, replay_window_seconds: float, idle_seconds: float, ) -> list[int]: """Return the event IDs to replay, or raise ResumeContinuityError. The caller MUST treat any raise as 'fresh subscription', not 'retry'. """ # 1. Authority: cursor is a capability bound to session + tenant. if store.session_id != request_session_id: raise ResumeContinuityError( "cursor_scope_mismatch", requested_id, f"cursor session {store.session_id!r} != request {request_session_id!r}", ) if store.tenant != request_tenant: raise ResumeContinuityError( "cursor_scope_mismatch", requested_id, f"cursor tenant {store.tenant!r} != request {request_tenant!r}", ) # 2. Liveness: a terminal subscription whose terminal event has been # evicted is dangling; do not hold the connection open. if not store.subscription_live: if store.terminal_emitted and requested_id < store.floor: raise ResumeContinuityError( "dangling_terminal_cursor", requested_id, f"terminal evicted below floor {store.floor}", ) if not store.terminal_emitted: raise ResumeContinuityError( "subscription_reaped", requested_id, "producer gone without terminal event", ) # 3. Continuity: requested ID must be within the retained range. if requested_id < store.floor: raise ResumeContinuityError( "replay_window_exceeded", requested_id, f"floor={store.floor} head={store.head}", ) if requested_id > store.head: raise ResumeContinuityError( "cursor_ahead_of_head", requested_id, f"head={store.head}", ) # 4. Monotonicity: if IDs are not contiguous, the caller must emit an # explicit gap frame; we cannot prove absence of loss here. if not store.contiguous_ids: raise ResumeContinuityError( "non_contiguous_id_contract", requested_id, "server must emit explicit resume-gap frame", ) # 5. Idle bound: a subscription idle beyond the replay window is treated # as fresh even if the cursor is technically retained. if idle_seconds > replay_window_seconds: raise ResumeContinuityError( "idle_exceeded_replay_window", requested_id, f"idle={idle_seconds:.1f}s window={replay_window_seconds:.1f}s", ) return list(range(requested_id + 1, store.head + 1)) ```