{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-resumes-an-mcp-stream-across-an-sse-to-websocket-upgrade-and-replays-a-stale-last-event-id",
  "title": "What happens when an instance resumes an MCP stream across an SSE-to-WebSocket upgrade and replays a stale Last-Event-ID",
  "date_of_record": "2026 December 1",
  "scope": "Applies to MCP servers and clients using HTTP-native transport (Streamable HTTP with SSE response streams) that negotiate an upgrade to WebSocket mid-session while carrying resumption state via `Last-Event-ID`. Does not cover pure stdio transport, pure SSE (legacy HTTP+SSE), or stateless request/response MCP calls that never establish a resumable stream.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-resumes-an-mcp-stream-across-an-sse-to-websocket-upgrade-and-replays-a-stale-last-event-id.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-resumes-an-mcp-stream-across-an-sse-to-websocket-upgrade-and-replays-a-stale-last-event-id.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-resumes-an-mcp-stream-across-an-sse-to-websocket-upgrade-and-replays-a-stale-last-event-id.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2519,
    "python_slice_tokens": 770,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"the stream dropped.\" Streams drop constantly and MCP's resumption contract is designed for that: the client reconnects with `Last-Event-ID: N` and the server replays events `N+1…`. The non-obvious failure is that **the event-ID namespace is transport-scoped, not session-scoped**, and an SSE-to-WebSocket upgrade silently re-bases it. The S...",
    "what_was_observed": "A client agent was mid-task, executing a multi-step tool-call loop (read file → parse → invoke downstream tool → summarize) against an MCP server that had just been reconfigured to prefer WebSocket for bidirectional streaming. The sequence: 1. Session established over SSE. Server emits events with IDs `1, 2, 3, … 47`. Client has consumed through 47 and is awaiting the result of a long-running `invoke_downstream` tool...",
    "condition_of_validity": "This failure requires all of the following to hold simultaneously: - The MCP session spans a transport change (SSE → WebSocket upgrade) **within a single logical session**, i.e., the session ID is preserved across the upgrade. - The server implementation uses a per-connection or per-transport event counter rather than a session-scoped counter that survives t...",
    "decision_boundary": "The architectural guardrail is a **transport-generation epoch** carried in both the upgrade handshake and every resumption token. Concretely: - The session maintains a `transport_epoch` counter, incremented on every transport re-binding (SSE connection 1 → SSE connection 2 → WebSocket 1 → …). - Event IDs are `(epoch, seq)` pairs, serialized as `\"<epoch>:<seq...",
    "operational_effect": "The practical consequence is that an agent's task can hang indefinitely with a tool call that has *succeeded server-side* but is *unreachable client-side*, and no timeout in either the client or server will surface the true cause — both sides believe they are behaving correctly per the protocol. The agent's reasoning loop sees \"tool call pending,\" the server..."
  },
  "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": "9d270561408dc89fb731692b173f89142e575a531b19da637edfbda079e96e3e",
    "verified_classes": [
      "TransportEpochMismatch",
      "EventLog",
      "MCPSession"
    ],
    "verified_functions": [
      "resume_stream",
      "append",
      "replay_after",
      "bind_transport",
      "emit"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 6,
    "raised_exceptions": [
      "TransportEpochMismatch"
    ],
    "sample_fail_closed_invariants": [
      "assert replayed == []",
      "assert replayed == [{'tool_result': 'ok'}]"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "time",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
