{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-lose-tool-call-continuity-when-an-mcp-http-native-sse-stream-is-upgraded-to-websocket-mid-turn",
  "title": "Why does an instance lose tool-call continuity when an MCP HTTP-native SSE stream is upgraded to WebSocket mid-turn",
  "date_of_record": "2026 November 19",
  "scope": "Applies to MCP servers/clients using the HTTP-native transport where a long-lived SSE response stream (server→client) is renegotiated into a WebSocket (bidirectional) during an active JSON-RPC request lifecycle, with resumable-event support via `Last-Event-ID`. Does not apply to stdio transports, nor to servers that keep SSE and WebSocket as fully independent sessions with no shared request registry.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-tool-call-continuity-when-an-mcp-http-native-sse-stream-is-upgraded-to-websocket-mid-turn.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-tool-call-continuity-when-an-mcp-http-native-sse-stream-is-upgraded-to-websocket-mid-turn.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-tool-call-continuity-when-an-mcp-http-native-sse-stream-is-upgraded-to-websocket-mid-turn.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1995,
    "python_slice_tokens": 422,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"the upgrade dropped the connection.\" A dropped connection is loud and recoverable. The failure is that the upgrade **succeeded** while the *request-identity mapping* between the two transports diverged silently. SSE frames are addressed by `(stream_id, event_id)`; WebSocket frames are addressed by `(connection, jsonrpc_id)`. During the up...",
    "what_was_observed": "A coding agent issued `tools/call` for a long-running `run_tests` tool over SSE. The server streamed progress notifications as SSE events `1001..1043`, then accepted a `Connection: Upgrade` to WebSocket at event `1043` (triggered by the client's transport layer deciding the turn was long enough to warrant bidirectional messaging). The handshake included `Last-Event-ID: 1043`. Trace observed at the client: 1. `req-9c2...",
    "condition_of_validity": "The invariant holds — and this failure is guaranteed absent — only when **all three** of the following are true at the moment of upgrade: - The upgrade request carries, in addition to `Last-Event-ID`, a **request-registry digest**: the set of JSON-RPC ids the client considers in-flight, each tagged with the SSE event id at which it was last observed. Call th...",
    "decision_boundary": "The operational question for an implementer is: **when is it safe to upgrade mid-turn at all?** Upgrade is safe if and only if the number of in-flight JSON-RPC requests at upgrade time is zero, **or** the correlation manifest is exchanged and acknowledged. Concretely: - If `len(inflight) == 0`: upgrade unconditionally. No correlation needed; the SSE stream h...",
    "operational_effect": "The downstream effects compound in a specific order: 1. **Orphaned response** → agent turn blocks → turn timeout fires. 2. **Retry with same id** → server, lacking cross-transport dedup, re-executes → side effects double. 3. **Agent observes inconsistent tool output** (e.g., test run \"passed\" on retry that \"failed\" initially) → reasoning divergence: the agen..."
  },
  "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": "2d7207e76c6ebdc19e14be6ec008a9b2e1771d5c14e0e2bb5f5643c97cbf66de",
    "verified_classes": [
      "UpgradeCorrelationError",
      "InflightRequest",
      "CorrelationManifest"
    ],
    "verified_functions": [
      "negotiate_upgrade",
      "dispatch_response",
      "digest"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "UpgradeCorrelationError"
    ],
    "sample_fail_closed_invariants": [
      "refusing upgrade: 101 response omitted manifest digest echo; cannot prove request-registry continuity across transport s",
      "response missing jsonrpc id; unroutable"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
