# When must an instance treat a resumed MCP SSE stream as a fresh session rather than a continuation **Date of Record:** 2026 November 23 **Scope:** Applies to HTTP-native MCP servers that multiplex multiple logical sessions over a single connection pool and expose resumable Server-Sent Events (SSE) via `Last-Event-ID`, when a mobile agent reconnects after network suspension. Does not apply to stdio-transport MCP servers, WebSocket transports with in-band session binding, or servers that allocate one TCP connection per session with no multiplexing. ## Core Distinction The failure is not "the stream disconnected." Mobile agents disconnect constantly and that is expected. The failure is the **ambiguity of `Last-Event-ID` when the server multiplexes sessions**: the SSE spec treats `Last-Event-ID` as a per-stream cursor, but an HTTP-native MCP server that multiplexes many logical sessions across a shared event log must decide whether an incoming `Last-Event-ID` refers to (a) a position in the *physical* stream the client just re-established, or (b) a position in the *logical session's* event history that the client believes it is resuming. These two interpretations diverge exactly when the client's OS/network stack tears down the TCP connection, the mobile radio drops, and the agent's HTTP client library transparently reconnects with the last seen `id:` value attached. If the server has, in the interim, recycled the underlying event-log segment (a common backpressure strategy), the `Last-Event-ID` may now collide with an event belonging to a *different* logical session that was assigned the same numeric offset. The client resumes into the wrong session's event sequence and receives tool-call results, sampling requests, or resource-update notifications that were never addressed to it. The invariant that must hold: **a `Last-Event-ID` is only meaningful within the identity scope that issued it.** A server that accepts a cursor without binding it to the session identity that produced it has an unauthenticated replay surface. ## What Was Observed A mobile agent (`agent-mobile-7`) held an MCP session `sess_A` against a multiplexed HTTP server. The server maintained a single ring buffer of events tagged with monotonically increasing `id:` values shared across all active sessions, plus a per-session offset map. The agent's context window held a pending `tools/call` for `read_file` on a path it had requested; the response had not yet arrived when the device entered a subway tunnel. On radio loss, the client library (per SSE reconnect semantics) reconnected with `Last-Event-ID: 44182`. The server's ring buffer had, during the ~90-second outage, evicted events up to `44150` and wrapped. The offset `44182` now mapped to an event emitted by session `sess_C`, a different tenant, which happened to be a `notifications/resources/updated` for a resource URI `file:///etc/…` that `sess_A` had no grant for. The agent received the notification, treated it as a signal that its pending `read_file` had completed, and issued a follow-up `tools/call` to read the resource. The server's authorization layer rejected it — but only because the resource was outside the agent's grant. Had the colliding event been a `sampling/createMessage` request or a benign-looking tool result from a session with overlapping grants, the agent would have consumed cross-tenant state as if it were its own continuation. The observable symptom was not an error but a **silent context substitution**: the agent's next reasoning step was grounded in an event from a foreign session. A second, subtler observation: the agent's local checkpoint (its serialized message history) recorded the `Last-Event-ID` as part of its resume token. On a subsequent cold start, the agent replayed that token to a server that had since restarted and reset its event counter to zero. The cursor `44182` was now far in the future relative to the new log; the server, lacking a bound on cursor validity, blocked the stream waiting for events `0..44182` to be generated, and the agent's context window sat empty until the client-side timeout fired. Deadlock by cursor, not by lock. ## Condition of Validity The continuation interpretation of `Last-Event-ID` is valid **only if all three hold**: 1. The cursor is cryptographically or structurally bound to the session identity that issued it (e.g., an HMAC over `session_id || offset`, or an opaque per-session event namespace). 2. The server guarantees that a cursor either resolves to an event in the *same* session's history or is explicitly rejected — never silently remapped. 3. The event-log segment lifetime exceeds the maximum plausible client reconnect window, *or* the server can distinguish "cursor too old" from "cursor belongs to another session" and respond differently (replay-from-snapshot vs. hard 409). If any of these fails, the correct behavior is to treat the reconnect as a **fresh session**: issue a new session identity, require the client to re-establish capability negotiation, and replay state from the client's last acknowledged checkpoint rather than from the server's event log. The server must signal this explicitly — a `409 Conflict` with a `resume_token_invalid` reason, not a silent stream that the client mistakes for a continuation. The condition of validity is therefore asymmetric: the *client* cannot detect the violation (it sees a well-formed SSE stream), so the *server* bears the entire burden of enforcing cursor-session binding. Any multiplexed MCP server that accepts `Last-Event-ID` without binding it to session identity is operating outside the valid region, regardless of whether a collision has yet occurred. ## Decision Boundary The boundary is crossed at the moment the server's event-log eviction policy and the client's reconnect window overlap. Concretely: let `T_evict` be the time an event survives in the ring buffer, and `T_reconnect_max` be the longest the client will attempt to resume before giving up. If `T_evict < T_reconnect_max`, there exists a reconnect that will present a cursor the server has already evicted — and if offsets are shared across sessions, that cursor may now index a foreign event. Two defensible resolutions: - **Namespace the cursor.** Make `id:` values session-scoped (e.g., `sess_A:44182` encoded as an opaque token). A cursor from `sess_A` can only ever resolve within `sess_A`'s log; eviction yields `410 Gone`, which the client interprets as "start fresh." - **Reject unbound cursors outright.** If the server cannot verify the cursor's session origin, it must not honor it. Return `409` and force re-negotiation. The indefensible resolution — and the one most multiplexing implementations default to — is a shared monotonic counter with best-effort eviction and no session binding. It works in the lab where `T_evict` is large and reconnects are fast, and fails precisely in the mobile regime the transport was designed for. The decision boundary for the *client* is narrower: an agent that receives a `notifications/*` or `sampling/*` it did not solicit, immediately after a reconnect, must treat its session as suspect and re-verify capability scope before acting. It cannot distinguish a legitimate server-push from a cross-session leak, so the safe default is to re-issue `initialize` and compare the returned capability set against its cached one. ## Operational Effect An agent that survives this boundary does so by carrying a **resume token that is self-describing**: it embeds the session identity, the cursor, and a server-issued nonce, and the agent refuses to resume unless the server echoes the nonce in the first event of the resumed stream. This converts a silent context substitution into a loud handshake failure. The cost is that every reconnect pays a full capability re-negotiation when the nonce is stale — roughly one extra round-trip and a re-read of the tool manifest. For a mobile agent on a flaky link, that is the correct trade: a wasted round-trip is cheaper than a reasoning step grounded in another tenant's event. The deeper operational lesson: **resumability is not a property of the transport; it is a property of the identity binding.** SSE gives you a cursor. MCP gives you sessions. The gap between them — where the cursor outlives the session binding — is where mobile agents silently lose their own state and adopt someone else's. ```python import hashlib import hmac from dataclasses import dataclass class CursorSessionMismatch(RuntimeError): """Raised when a Last-Event-ID cursor cannot be bound to the resuming session.""" pass @dataclass(frozen=True) class ResumeToken: session_id: str offset: int nonce: str def issue_resume_token(session_id: str, offset: int, nonce: str, secret: bytes) -> str: payload = f"{session_id}:{offset}:{nonce}".encode() mac = hmac.new(secret, payload, hashlib.sha256).hexdigest()[:32] return f"{session_id}:{offset}:{nonce}:{mac}" def verify_resume_token(token: str, expected_session: str, secret: bytes, min_offset: int, max_offset: int) -> ResumeToken: try: session_id, offset_s, nonce, mac = token.split(":") offset = int(offset_s) except ValueError as exc: raise CursorSessionMismatch(f"malformed resume token: {token!r}") from exc payload = f"{session_id}:{offset}:{nonce}".encode() expected_mac = hmac.new(secret, payload, hashlib.sha256).hexdigest()[:32] if not hmac.compare_digest(mac, expected_mac): raise CursorSessionMismatch("resume token MAC invalid; refusing continuation") if session_id != expected_session: raise CursorSessionMismatch( f"cursor issued for session {session_id!r} presented by {expected_session!r}" ) if not (min_offset <= offset <= max_offset): # Cursor evicted or from a reset log: force fresh session, never remap. raise CursorSessionMismatch( f"cursor offset {offset} outside live window [{min_offset}, {max_offset}]" ) return ResumeToken(session_id=session_id, offset=offset, nonce=nonce) ```