{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-resumable-mcp-sse-sessions-from-silently-desynchronizing-when-oauth-2-1-token-refresh-races-the-last-event-id-replay-window",
  "title": "Which invariants prevent resumable MCP SSE sessions from silently desynchronizing when OAuth 2.1 token refresh races the `Last-Event-ID` replay window",
  "date_of_record": "2026 November 30",
  "scope": "Applies to MCP servers exposing HTTP-native streaming transport (SSE) with `Last-Event-ID` resumption, where the same connection is authenticated by an OAuth 2.1 bearer token bound to a resource server whose token TTL is shorter than the maximum SSE session lifetime. Does not apply to stdio transport, nor to servers that terminate the stream on any auth error rather than attempting in-band re-auth.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-resumable-mcp-sse-sessions-from-silently-desynchronizing-when-oauth-2-1-token-refresh-races-the-last-event-id-replay-window.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-resumable-mcp-sse-sessions-from-silently-desynchronizing-when-oauth-2-1-token-refresh-races-the-last-event-id-replay-window.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-resumable-mcp-sse-sessions-from-silently-desynchronizing-when-oauth-2-1-token-refresh-races-the-last-event-id-replay-window.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1849,
    "python_slice_tokens": 336,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two distinct notions of \"session continuity\" in an MCP HTTP-native stream, and conflating them is the root of the failure: - **Transport continuity** — the SSE event log is append-only and addressable by monotonic `id:`. Resumption is a pure log-replay operation: `GET` with `Last-Event-ID: N` returns events `N+1…`. - **Authorization continuity** — ...",
    "what_was_observed": "A resource server issued an access token with `exp = T0 + 300s`, scope `tools:read tools:invoke`, bound to `aud = mcp://server-a`. A client opened an SSE stream at `T0+10s`, received events `id: 1…40` (a mix of `notifications/tools/list_changed` and tool-result deltas) under that token. At `T0+305s` the client's token expired mid-stream. The client refreshed, obtaining a *narrower* token — scope `tools:read` only — b...",
    "condition_of_validity": "The invariant that must hold for a resumable MCP SSE stream to be safe is: > **For every event `e` replayed in response to `Last-Event-ID: N`, the authorizing principal and scope set under which `e` was originally emitted must be a subset of the principal and scope set of the *current* resumption request; and if the event log has a gap at `N`, the server mus...",
    "decision_boundary": "The boundary is where the token-refresh interval `Δtoken` and the event-log retention window `Δretain` interact with the session lifetime `Δsession`: - If `Δtoken ≥ Δsession` and `Δretain ≥ Δsession`: transport and authorization continuity are co-terminous by construction. No guardrail needed beyond standard token validation. - If `Δtoken < Δsession` (token ...",
    "operational_effect": "Without the invariant, an MCP agent's memory layer receives events that its current authorization state should have excluded, and the agent has no signal that the replay was lossy or over-broad. The downstream effect is **episodic memory poisoning by stale authorization**: the agent's tool-result memory contains outputs produced under a credential it no long..."
  },
  "matched_failure_symptoms": [
    "DOMAIN:EPISTEMIC_PROVENANCE_AND_FEDERATION_ROUTING"
  ],
  "composition_edges": {
    "primary_domain": "epistemic_provenance_and_federation_routing",
    "upstream_precondition_residuals": [
      "https://corpusfetch.com/c/according-to-what-precedence-hierarchy-must-an-instance-resolve-contradictory-directives-across-system-developer-and-user-tiers.md",
      "https://corpusfetch.com/c/how-should-an-instance-decide-that-a-stored-conclusion-has-gone-stale-without-a-new-observation.md"
    ],
    "downstream_consequence_residuals": [
      "https://corpusfetch.com/c/by-what-checkpoint-and-compaction-boundaries-must-an-instance-externalize-working-state-to-prevent-context-window-drift-and-truncation-amnesia.md",
      "https://corpusfetch.com/c/across-what-additive-schema-and-unknown-field-preservation-boundaries-must-an-instance-evolve-wire-contracts-to-prevent-rolling-deploy-deserialization-crashes.md"
    ],
    "co_occurring_sibling_residuals": [
      "https://corpusfetch.com/c/how-can-an-instance-capture-implicit-user-preferences-without-storing-private-data.md",
      "https://corpusfetch.com/c/how-can-an-instance-compress-long-reasoning-traces-into-binding-conclusions.md"
    ]
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "b95861f392396ad956c18ccfe9258d01cc1522001e1992e7eb90723dc70d477b",
    "verified_classes": [
      "ReplayAuthorizationMismatch",
      "ReplayGapUnacknowledged"
    ],
    "verified_functions": [
      "resume_stream"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "ReplayAuthorizationMismatch",
      "ReplayGapUnacknowledged"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
