{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-sse-resume-token-replay-from-desynchronizing-an-mcp-streamable-http-session-after-a-mid-stream-transport-upgrade",
  "title": "Which invariants prevent SSE resume-token replay from desynchronizing an MCP streamable-HTTP session after a mid-stream transport upgrade",
  "date_of_record": "2026 November 27",
  "scope": "Applies to MCP servers/clients speaking the HTTP-native \"streamable HTTP\" transport where a client issues a POST that may be upgraded to an SSE response stream and may later reconnect with `Last-Event-ID` to resume. Does not apply to stdio transport, nor to legacy HTTP+SSE dual-endpoint transports where the GET stream and POST endpoint are separate resources with independent identity.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-sse-resume-token-replay-from-desynchronizing-an-mcp-streamable-http-session-after-a-mid-stream-transport-upgrade.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-sse-resume-token-replay-from-desynchronizing-an-mcp-streamable-http-session-after-a-mid-stream-transport-upgrade.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-sse-resume-token-replay-from-desynchronizing-an-mcp-streamable-http-session-after-a-mid-stream-transport-upgrade.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2108,
    "python_slice_tokens": 278,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"the SSE connection dropped.\" Drops are expected and the resume mechanism exists precisely to absorb them. The failure is that **the resume token (`Last-Event-ID`) and the session identity (`Mcp-Session-Id`) are two independent pieces of state carried on the same request, and the server's replay logic validates them independently rather th...",
    "what_was_observed": "A streamable-HTTP MCP server was upgraded from a single-process deployment to a two-replica deployment behind a load balancer with sticky sessions keyed on a cookie, but the MCP session ID was carried in a header (`Mcp-Session-Id`), not the cookie. Under normal load the cookie and header agreed. During a rolling restart, the cookie affinity table was rebuilt from scratch while the session store (Redis-backed) survive...",
    "condition_of_validity": "The atomic-tuple invariant holds, and the failure is bounded, only when all of the following are true simultaneously: - The event ID sequence is **per-session monotonic and globally unique within the session**, not per-connection. If event IDs are per-connection counters (the naive `1,2,3...` per SSE stream), then two connections for the same session produce...",
    "decision_boundary": "The boundary is between **resumable** and **restartable**. A streamable-HTTP session is resumable if and only if the server can prove, from the presented tuple, that the client's last-applied event is a prefix of the event sequence the server is about to continue. It is restartable if the server cannot prove this but the client can be told to start over clea...",
    "operational_effect": "Enforcing the tuple invariant converts a silent semantic corruption into a loud, recoverable session fault. The cost is that clients must implement genuine re-initialization on 409—re-running `initialize`, re-negotiating capabilities, and re-issuing in-flight tool calls under fresh idempotency keys—rather than the cheaper \"just reconnect.\" In practice the re..."
  },
  "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": "a6001576953d2b18b6b96ecec16ff2f3349e193757fea58beeb06e35fbb8cfd1",
    "verified_classes": [
      "McpResumeDesyncError",
      "SessionEventLog"
    ],
    "verified_functions": [
      "handle_streamable_http_resume",
      "__init__",
      "resume_from"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "McpResumeDesyncError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
