# Under what conditions must an instance treat an MCP `Last-Event-ID` resume as a *new* session rather than a continuation, and why silent acceptance corrupts tool state **Date of Record:** 2026 November 24 **Scope:** Applies to MCP servers and clients using the HTTP-native transport with `StreamableHTTPSession` and server-initiated SSE upgrade negotiation, where the client presents a `Last-Event-ID` header on `GET /mcp` after a transport drop. Does not cover stdio transport, WebSocket fallback, or clients that never issue a resumable GET. ## Core Distinction The MCP HTTP-native transport defines two superficially similar recovery paths that share a wire format but diverge in semantics: 1. **Resume** — the client reconnects to the *same* logical session with a `Last-Event-ID` that the server can map to a retained event buffer. The server replays events from `Last-Event-ID+1` onward. Session identity, tool-call correlation IDs, and any server-side per-session mutable state (open subscriptions, in-flight sampling requests, negotiated capabilities) must survive intact. 2. **Restart** — the client reconnects but the server has no retained buffer for that event ID (evicted, expired, or never existed). The correct behavior is to reject with `404`/`410` and force the client to `initialize` a *new* session. The client must then re-establish capabilities, re-register subscriptions, and treat all prior in-flight tool calls as abandoned. The boundary condition that breaks agents is the **third, undocumented path**: the server accepts the `Last-Event-ID`, opens the SSE stream, replays *nothing or partial* events, and returns `200 OK`. This is silent acceptance of a resume for a session the server can no longer faithfully continue. The stream is live, the session ID is unchanged, and the client has no signal that it is now operating on a session whose event history has a hole in it. ## What Was Observed A two-tool MCP server (a `filesystem.read` and a `shell.exec` pair) fronted by a load balancer with three replicas. Sessions were sticky by cookie but the SSE event buffer was **per-replica and in-memory**. The failure trace: 1. Client opens session `S1` on replica A. Issues `tools/call` for `shell.exec` running a long job. Server emits `event: progress, id: 41`. Client records `Last-Event-ID: 41`. 2. Replica A is drained (rolling deploy). The event buffer for `S1` is destroyed with the process. The session *record* (a Redis-backed key holding negotiated capabilities and the tool registry) survives. 3. Client's SSE connection drops. Client reconnects with `GET /mcp` and `Mcp-Session-Id: S1`, `Last-Event-ID: 41`. Load balancer routes to replica B. 4. Replica B looks up `S1` in Redis: **found**. It looks up event `41` in its local buffer: **not found**. The code path that should return `410 Gone` instead falls through to "no events to replay, open the stream," returning `200 OK` with an empty replay and a live tail. 5. Client believes the stream is resumed. It waits for `id: 42` (the terminal result of the `shell.exec`). It never arrives — the job completed on replica A and its result event died with the process. The client hangs until its own idle timeout, then retries the *tool call*, because from the agent's perspective the call was never acknowledged. The shell job runs a second time. The observed corruption: **duplicate side-effecting tool execution** caused by a resume that was accepted but not honored. The agent layer compounded it because the model, seeing no result, re-issued the call with a new `requestId`, and the server had no idempotency key tying it to the prior execution. A second, subtler observation: when the buffer *did* retain event `41` but was missing `39` and `40` (evicted under a size cap that evicted oldest-first while keeping the newest), the server replayed from `42` onward. The client's reducer applied a `progress` event that referenced a `step` counter state it had never seen incremented, producing a monotonicity violation in the agent's local progress model. The agent's planner read the corrupted counter and concluded the job was 3 steps further along than it was, then skipped a verification step. ## Condition of Validity A `Last-Event-ID` resume is **valid** — i.e., the server may return `200` with a replay and the client may treat the session as continuous — if and only if all three hold: - **Contiguity:** the server retains a contiguous event range `[Last-Event-ID+1, N]` with no gaps. A buffer that retains a *suffix* but not a *prefix* of the requested range is not a valid resume source. - **Session-state coherence:** every piece of per-session mutable state that the replayed events depend on (subscription registrations, in-flight request correlation table, negotiated capability set) is present and identical to the state at the time the last event was emitted. If the session record survived but the in-flight request table did not, replaying a `progress` event for a request the server can no longer resolve is incoherent. - **Replica affinity of the buffer:** the event buffer backing the resume must be reachable from the replica that accepts the reconnect, or must be a shared durable log. A per-replica in-memory buffer with sticky routing satisfies this only while the sticky target is alive. The invariant: **`200 OK` on a resumable GET is a promise of contiguity from `Last-Event-ID+1` to the live tail.** Any server that cannot make that promise for the full requested range must not return `200`. It must return `410 Gone` (buffer evicted/expired) or `404` (unknown session/event), and the client must reinitialize. ## Decision Boundary The precise branch the server must implement, evaluated in order, on `GET /mcp` with `Mcp-Session-Id` and optional `Last-Event-ID`: - No `Mcp-Session-Id`, or session unknown → `404`. Client initializes. - Session known, no `Last-Event-ID` → open live stream from tail. This is a *subscribe*, not a resume; no replay promised. - Session known, `Last-Event-ID` present: - Event ID outside `[oldest_retained, newest_emitted]` → `410`. Client must reinitialize. - Event ID within range but buffer has a gap in `[id+1, newest]` → `410`. **This is the case the naive implementation misses** — a size-capped ring buffer that evicted middle entries, or a buffer that was partially flushed. - Event ID within range, contiguous, and per-session dependency state intact → `200` with replay then tail. - Event ID within range and contiguous, but dependency state (in-flight request table) missing → `410`. Contiguity alone is insufficient; the replay would be incoherent. The client-side boundary is symmetric: on `410`/`404`, the client **must not** silently re-issue in-flight tool calls under the same `requestId` against a new session. It must surface the abandonment to the agent loop so the planner can decide whether the side effect already occurred (via an idempotency lookup) before retrying. ## Operational Effect When the server honors the boundary, the failure mode is loud and recoverable: the client gets `410`, reinitializes, and the agent loop is told "your prior tool call is abandoned — check idempotency before retry." The agent pays a cold-start cost (re-negotiate capabilities, re-fetch tool schemas) but does not double-execute side effects. When the server violates the boundary by returning `200` on a non-contiguous or incoherent resume, three downstream effects propagate into the agent layer: - **Silent hang → duplicate execution.** The agent's tool-call timeout fires, the model re-plans, and a side-effecting call runs twice. No layer in the stack has the information to prevent it, because the resume looked successful. - **Reducer monotonicity violations.** Partial replay feeds the agent's local state machine events out of order, corrupting progress/step counters that the planner uses for verification gating. The agent then skips checks it believes already passed. - **Session-ID laundering.** Because the session ID is unchanged, the client's audit log attributes post-resume actions to the original session, erasing the discontinuity. Post-incident replay cannot reconstruct where the hole was. The guardrail is a single server-side predicate — `can_faithfully_resume(session, last_event_id) -> bool` — that must gate the `200` response, plus a client-side rule that treats any `200` resume whose first replayed event ID is not exactly `Last-Event-ID+1` as a protocol violation and aborts the stream rather than consuming it. ```python from dataclasses import dataclass, field from typing import Optional class ResumeIncoherenceError(RuntimeError): """Raised when a resumable MCP GET cannot honor Last-Event-ID contiguity.""" @dataclass class SessionState: session_id: str oldest_retained_event: int newest_emitted_event: int # event IDs currently retained; must be a contiguous suffix to be resumable retained_event_ids: set[int] = field(default_factory=set) # in-flight request correlation table; replay is incoherent without it inflight_request_ids: set[str] = field(default_factory=set) def can_faithfully_resume(session: SessionState, last_event_id: int) -> bool: if last_event_id < session.oldest_retained_event: return False if last_event_id > session.newest_emitted_event: return False # contiguity: every id in (last_event_id, newest] must be retained for eid in range(last_event_id + 1, session.newest_emitted_event + 1): if eid not in session.retained_event_ids: return False return True def handle_resumable_get( session: Optional[SessionState], last_event_id: Optional[int], ) -> int: if session is None: return 404 # client must initialize a new session if last_event_id is None: return 200 # live subscribe from tail, no replay promised if not can_faithfully_resume(session, last_event_id): # MUST NOT return 200: silent acceptance corrupts agent tool state raise ResumeIncoherenceError( f"session {session.session_id}: cannot resume from " f"Last-Event-ID={last_event_id} (retained " f"[{session.oldest_retained_event},{session.newest_emitted_event}], " f"gaps present or dependency state missing)" ) return 200 # contiguous replay from last_event_id+1 then live tail ```