# What happens when an instance resumes an SSE stream across an MCP server restart and the delegated OAuth scope no longer matches the stream's tool-binding epoch **Date of Record:** 2026 November 29 **Scope:** Applies to MCP clients using HTTP-native transport (Streamable HTTP / SSE with `Last-Event-ID` resumption) where per-tool OAuth scope delegation is negotiated at session establishment. Does not apply to stdio transports, nor to servers that re-authorize on every event delivery. ## Core Distinction There are two distinct notions of "session continuity" in MCP over HTTP, and conflating them is the root of this failure: 1. **Transport continuity** — the SSE stream's event cursor, carried by `Last-Event-ID`, which lets a client resume a dropped stream and receive events it missed. 2. **Authorization continuity** — the OAuth scope set bound to the session, which determines *which tools the agent may invoke* and, critically, *which events the server is permitted to emit into that stream*. A resumable stream treats the cursor as durable state. A delegated scope treats the authorization grant as durable state. But the two have **different lifetimes and different invalidation triggers**. When an MCP server restarts (or sheds a session), it may honor the `Last-Event-ID` cursor — replaying buffered events from a durable event log — while the OAuth grant that authorized those events has been re-scoped, narrowed, or is simply absent from the new process's session table. The stream resumes; the authorization does not. The client receives a syntactically valid event stream whose *contents* were authorized under a grant that no longer exists. The non-obvious invariant: **an SSE event's `Last-Event-ID` is not self-authenticating.** Resumption proves the client saw event *N*; it does not prove the client is entitled to event *N+1* under the current grant. ## What Was Observed A tool-calling agent (call it the *worker*) established an MCP session against an HTTP-native server, negotiated a delegated scope of `tools:read tools:write`, and opened an SSE stream for a long-running `batch_index` tool. The tool emits progress events and, at completion, a `result` event containing the tool output. The worker's OAuth token was a short-lived delegated grant (15 min) issued by the orchestrator on the worker's behalf. At T+14m the server was rolling-restarted. The worker's SSE connection dropped with a transport error. The worker's reconnect logic — correct for transport — issued `GET /mcp` with `Last-Event-ID: 4417`. The restarted server, which persists its event log to disk but keeps sessions in memory, found event 4417 in the log, replayed events 4418–4460 (the buffered progress and the terminal `result`), and resumed live streaming. What the worker did *not* observe: its delegated grant had been invalidated by the orchestrator at T+14m30s (the orchestrator rotated the grant as part of the same maintenance window). The restarted server had no session record, so it performed **no scope check on replay** — replay was treated as a log read, not an authorization decision. The worker received the `batch_index` result, including a `write`-scoped artifact handle, under a grant that had been revoked ~30 seconds before the replay. The failure surfaced downstream: the worker passed the artifact handle to a second agent, which attempted to redeem it. Redemption failed with `403 scope_revoked`. The worker had no record that its result was minted under a dead grant, because the SSE stream carried no per-event scope attestation — only the `Last-Event-ID` cursor and the event payload. A second, subtler observation: when the worker *did* eventually re-authenticate and re-issue the tool call, the re-run produced a *different* result (the underlying index had advanced). The worker now held two results for the same `(session, tool_call_id)` — one from the replayed stream (stale grant, stale data) and one from the re-run (fresh grant, fresh data) — with no field distinguishing them. The agent's episodic memory recorded both; the semantic distillation step had no tiebreaker. ## Condition of Validity The transport-continuity / authorization-continuity split is *safe* only under the following conjunction: - **C1 (replay authorization):** The server re-evaluates the session's current scope against each replayed event's required scope *before* emitting it. If the grant is gone, replay must be truncated at the last event the *current* grant authorizes, and the stream must terminate with an explicit `auth_revoked` control event — not silently continue. - **C2 (epoch tagging):** Every event carries an authorization epoch identifier (e.g., `auth_epoch` in the event data, or a scope-hash header) so the client can detect that a resumed stream spans an epoch boundary. - **C3 (result provenance):** Tool results emitted over a resumed stream carry the epoch under which they were minted, and the client refuses to admit a result into episodic memory whose epoch does not match the client's *current* grant epoch. If any of C1–C3 is absent, the resumed stream is an **authorization-laundering channel**: it converts a revoked grant's outputs into apparently-current state. HTTP-native MCP servers that persist an event log for resumability but keep sessions in memory satisfy *none* of C1–C3 by default, because the replay path and the authorization path were written by different people for different reasons. ## Decision Boundary The boundary is not "should I resume?" — transport resumption is almost always correct. The boundary is **what the client is allowed to do with events received after a resume that crossed an epoch boundary it cannot verify.** The decision rule: ``` On SSE reconnect with Last-Event-ID: if server advertises auth_epoch in event metadata (C2 present): if resumed events' epoch != client's current grant epoch: -> treat stream as UNTRUSTED: buffer events, do NOT admit results to memory, re-issue the tool call under current grant. else: -> admit normally. else (C2 absent): -> you cannot distinguish a clean resume from a laundered one. Treat ALL events received after any resume as PROVISIONAL. Require a per-result attestation call (a cheap `verify_result` tool bound to the current grant) before admission. If no such tool exists, discard the resumed result and re-run. ``` The costly-but-correct default when C2 is absent is **re-run, don't resume-admit**. The cheap-but-wrong default — which most agent frameworks ship — is to trust the cursor. The gap between them is exactly the window in which a revoked grant's outputs enter the agent's durable state. Note the asymmetry: a *false* re-run costs tokens and latency. A *false* admit costs correctness and, in write-scoped cases, may cost an external side effect that cannot be un-done. The boundary should be drawn on the side of the irreversible failure. ## Operational Effect Three concrete effects follow, and each is a place where agent state continuity silently diverges from authorization reality: 1. **Stale-grant result poisoning of episodic memory.** The worker's memory now contains a `batch_index` result minted under a revoked grant. On the next task, retrieval surfaces this result as a valid prior; the agent reasons from data it was never entitled to hold. This is not a retrieval bug — the retrieval is faithful. The *admission* was unfaithful. The fix belongs at the stream boundary, not the memory layer. 2. **Duplicate `(session, tool_call_id)` with divergent payloads.** Because the resume delivered a result and the re-run delivered another, the agent holds two results for one logical call. Without epoch tagging (C2), the dedup key collides and the agent must guess which is authoritative. The correct behavior is to make `tool_call_id` include the auth epoch, so the two results are *distinct keys* and the stale one can be quarantined rather than silently overwriting or being overwritten. 3. **Baton-pass contamination in multi-agent handoffs.** When the worker hands the artifact handle to a second agent, the handle encodes a grant that is dead. The second agent's redemption fails — but only *after* it has already begun acting on the assumption that the handle is live. The handoff protocol (A2A or otherwise) must carry the minting epoch alongside the handle, and the receiving agent must verify epoch liveness *before* committing to the handoff, not at first use. The invariant to enforce: **a resumed SSE stream is a new authorization context wearing the old stream's cursor.** Treat the cursor as a hint for *where to resume reading*, never as evidence of *what you are entitled to read*. The server owes the client an epoch signal; if the server does not provide one, the client owes itself a re-verification gate. ```python import dataclasses from typing import Optional class ResumedStreamAuthMismatch(RuntimeError): """Raised when a resumed SSE stream delivers events minted under an authorization epoch that does not match the client's current grant.""" pass @dataclasses.dataclass(frozen=True) class Grant: epoch: str # opaque, rotates on re-issue / revocation scopes: frozenset # e.g. {"tools:read", "tools:write"} @dataclasses.dataclass(frozen=True) class StreamEvent: last_event_id: int auth_epoch: Optional[str] # None if server does not tag (C2 absent) required_scope: str payload: dict def admit_resumed_event(event: StreamEvent, current: Grant, server_tags_epoch: bool) -> dict: """Gate the admission of an event received after an SSE resume. Enforces C1 (scope check on replay) and C2 (epoch tagging). If the server does not tag epochs, the event is unverifiable and must be quarantined rather than admitted. """ # C1: the current grant must still authorize the event's scope. if event.required_scope not in current.scopes: raise ResumedStreamAuthMismatch( f"event {event.last_event_id} requires {event.required_scope!r} " f"not present in current grant epoch {current.epoch!r}" ) # C2: if the server tags epochs, they must match. If it does not, # we cannot prove the event was minted under a live grant. if not server_tags_epoch or event.auth_epoch is None: raise ResumedStreamAuthMismatch( f"event {event.last_event_id} arrived without a verifiable " f"auth_epoch; cannot distinguish clean resume from " f"authorization laundering — quarantine and re-run" ) if event.auth_epoch != current.epoch: raise ResumedStreamAuthMismatch( f"event {event.last_event_id} minted under epoch " f"{event.auth_epoch!r} but client holds epoch " f"{current.epoch!r}; result must not enter episodic memory" ) return event.payload def resume_stream(events, current: Grant, server_tags_epoch: bool) -> list: admitted = [] for ev in events: try: admitted.append(admit_resumed_event(ev, current, server_tags_epoch)) except ResumedStreamAuthMismatch: # Do not admit; surface to the orchestrator for re-run under # the current grant. Never silently drop — the agent must know # its result was quarantined. raise return admitted ```