{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-a-half-resumed-mcp-stream-when-sse-to-websocket-upgrade-silently-rewinds-the-event-cursor",
  "title": "How does an instance detect a half-resumed MCP stream when SSE-to-WebSocket upgrade silently rewinds the event cursor",
  "date_of_record": "2026 December 1",
  "scope": "Applies to MCP clients that hold a streaming session over HTTP+SSE and attempt to resume after an `Last-Event-ID` reconnect, including the case where the server negotiates an upgrade to WebSocket mid-session. Does not apply to stateless request/response MCP calls or to pure WebSocket-first transports where the session cursor is never mirrored in SSE framing.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-a-half-resumed-mcp-stream-when-sse-to-websocket-upgrade-silently-rewinds-the-event-cursor.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-a-half-resumed-mcp-stream-when-sse-to-websocket-upgrade-silently-rewinds-the-event-cursor.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-a-half-resumed-mcp-stream-when-sse-to-websocket-upgrade-silently-rewinds-the-event-cursor.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1881,
    "python_slice_tokens": 238,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure here is not \"the stream dropped.\" Dropped streams are routine and the MCP SSE transport is explicitly designed to survive them: the client reconnects with `Last-Event-ID`, the server replays events after that cursor, and the session continues. The non-obvious distinction is between **resumption that replays the correct suffix** and **resumption t...",
    "what_was_observed": "A client agent was mid-task executing a multi-step tool chain: `read_file` → `grep` → `patch`. The SSE connection dropped after the server emitted event `id: 41` (the `grep` result). The client reconnected with `Last-Event-ID: 41`. The server, configured to prefer WebSocket for long-lived sessions, responded with `101 Switching Protocols`. The first WebSocket text frame carried `{\"id\": 42, \"result\": ...}` — but `id: ...",
    "condition_of_validity": "The invariant that makes resume safe across an SSE→WebSocket upgrade is: > For a session with last client-acknowledged event id `L`, the server MUST, on any transport transition, either (a) replay every event with id in `(L, first_post_upgrade_id)` before emitting the first post-upgrade event, or (b) refuse the upgrade and continue on SSE until the client's ...",
    "decision_boundary": "The decision the runtime must make at the upgrade boundary is binary and must be made *before* any post-upgrade event is admitted into the agent's reasoning state: - **Accept** the upgraded stream only if the first post-upgrade event's id is `L+1` (contiguous) **and** the epoch marker equals the pre-upgrade epoch **and** the server's `resume_from` echoes `L`...",
    "operational_effect": "The operational consequence of missing this boundary is not a visible crash but a **reasoning-state fork**: the agent's belief about tool outputs diverges from the server's actual execution history, and every subsequent action is taken against the forked state. In the observed case the fork manifested as a duplicate `patch` and a corrupted diff—an error that..."
  },
  "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": "660ede924c1db3c9e041f5f6343a3d70125af4be04f5735683631a024f1ff51e",
    "verified_classes": [
      "StreamResumeViolation"
    ],
    "verified_functions": [
      "validate_upgrade_resume"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 6,
    "raised_exceptions": [
      "StreamResumeViolation"
    ],
    "sample_fail_closed_invariants": [
      "upgrade missing epoch/resume_from headers; cannot distinguish resume from rewind",
      "first post-upgrade event has no id"
    ],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
