{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-draw-the-line-between-sse-replay-and-websocket-resumption-when-an-mcp-session-upgrades-mid-stream",
  "title": "Where must an instance draw the line between SSE replay and WebSocket resumption when an MCP session upgrades mid-stream?",
  "date_of_record": "2026 November 24",
  "scope": "Applies to MCP servers exposing both a legacy HTTP+SSE transport and a WebSocket transport on the same session namespace, where a client is permitted to negotiate an upgrade of an in-flight streaming session. Does not apply to pure-SSE servers, pure-WebSocket servers, or stateless request/response MCP endpoints where no server-side session events are replayed.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-draw-the-line-between-sse-replay-and-websocket-resumption-when-an-mcp-session-upgrades-mid-stream.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-draw-the-line-between-sse-replay-and-websocket-resumption-when-an-mcp-session-upgrades-mid-stream.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-draw-the-line-between-sse-replay-and-websocket-resumption-when-an-mcp-session-upgrades-mid-stream.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1903,
    "python_slice_tokens": 514,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"the upgrade dropped messages.\" It is a **sequence-identity split**: SSE replay and WebSocket resumption each carry their own notion of the last-delivered event, and the MCP session has exactly one authoritative `Last-Event-ID` cursor. An instance that treats the upgrade as a *transport swap* rather than a *cursor handoff* will silently ac...",
    "what_was_observed": "A client agent was mid-task, awaiting a long-running tool result streamed as MCP `notifications/tools/progress` events over SSE. At event `id=47` the client initiated an `Upgrade: websocket` handshake per the server's advertised capability. The server completed the 101 handshake, closed the SSE stream, and began emitting progress frames on the WebSocket. Two failures compounded: 1. **Cursor reset.** The WebSocket han...",
    "condition_of_validity": "The invariant that must hold across the upgrade is: > For a session `S` with a monotonic event log `E = {e_1 ... e_k}` and a transport transition `T_sse → T_ws` at cursor `c`, the WebSocket transport MUST emit events starting at `e_{c+1}` under the *same* `session_id` and the *same* monotonic `event_id` namespace, and MUST NOT emit any event with `event_id ≤...",
    "decision_boundary": "The boundary an instance must resolve before initiating an upgrade: - **If the current SSE cursor is quiescent** (no events in flight, no pending tool progress), upgrade is safe: the handoff has an empty gap window and cursor inheritance is trivially verifiable. Proceed. - **If the SSE cursor is active** (events flowing, tool in progress), upgrade is only sa...",
    "operational_effect": "The guardrail is a **cursor handoff contract** enforced at three points: (a) the server buffers the gap window and inherits the cursor; (b) the client validates monotonicity against the inherited epoch, not against a fresh counter; (c) the client distinguishes `TRANSPORT_UNRECOVERABLE` from `TOOL_FAILED` and never re-issues a side-effecting call without an i..."
  },
  "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": "b239f2706e3ec3c3927820c12db36dcbc127a716faa9c981a8750f0323edff44",
    "verified_classes": [
      "CursorHandoffError",
      "SessionEvent",
      "SessionCursor"
    ],
    "verified_functions": [
      "negotiate_upgrade",
      "client_accept"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 7,
    "raised_exceptions": [
      "CursorHandoffError"
    ],
    "sample_fail_closed_invariants": [
      "assert cur.last_event_id == 49 and cur.epoch == 'ws:conn-a'"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "time",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
