{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-sse-resumption-corruption-when-an-mcp-server-migrates-a-session-from-streamable-http-to-a-resumed-event-stream-mid-tool-call",
  "title": "Which invariants prevent SSE resumption corruption when an MCP server migrates a session from streamable HTTP to a resumed event stream mid-tool-call",
  "date_of_record": "2026 November 30",
  "scope": "Applies to MCP servers implementing the HTTP-native transport (Streamable HTTP with optional SSE upgrade) where a client may reconnect with `Last-Event-ID` after a dropped connection while a tool call is in flight. Does not cover stdio transport, nor pure legacy HTTP+SSE servers that never expose `Mcp-Session-Id` resumption semantics.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-sse-resumption-corruption-when-an-mcp-server-migrates-a-session-from-streamable-http-to-a-resumed-event-stream-mid-tool-call.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-sse-resumption-corruption-when-an-mcp-server-migrates-a-session-from-streamable-http-to-a-resumed-event-stream-mid-tool-call.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-sse-resumption-corruption-when-an-mcp-server-migrates-a-session-from-streamable-http-to-a-resumed-event-stream-mid-tool-call.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2120,
    "python_slice_tokens": 437,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The distinction that matters is between **transport-level replay** and **execution-level replay**. Streamable HTTP gives you a resumption primitive: a client that loses its connection can reissue its request with `Last-Event-ID: <id>` and the server is expected to resume the event stream from that point. What the spec does *not* give you is a guarantee that ...",
    "what_was_observed": "A server exposing `search_index` as a long-running tool (30–90s) streamed the following over SSE during a single `tools/call`: The client TCP connection dropped after delivering `id: 42`. The client reconnected per spec with `Last-Event-ID: 42` and the same `Mcp-Session-Id`. The server, whose executor had meanwhile completed the call and written the terminal result into a per-session ring buffer, replayed: This looks...",
    "condition_of_validity": "The invariant that makes resumption safe is: > **For any `Mcp-Session-Id`, the tuple (last-delivered-event-id, terminal-jsonrpc-id) must be monotonic and at-most-once across all connections in the session's lifetime, and the event stream after any `Last-Event-ID` must be a *prefix-consistent* suffix of the single canonical event sequence for that session.** ...",
    "decision_boundary": "The boundary is drawn at the point where the server must choose between two resumption strategies: - **Replay-from-buffer:** re-emit every buffered event with ID > `Last-Event-ID`. Cheap, stateless-ish, and *unsafe* whenever the executor has advanced past the replayed events' generating state. This is the default in most MCP server SDKs because it is the obv...",
    "operational_effect": "The operational consequence for agent systems is that **the agent loop must treat tool results as at-least-once, not exactly-once, across transport reconnects.** This is the opposite of what the JSON-RPC `id` field suggests. Every MCP client that resumes a session must carry a dedupe set keyed on `(session_id, jsonrpc_id)` and must discard duplicate terminal..."
  },
  "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": "d54bd407040807d6caeaf4d6dad3663e7d3bd1d3a315e285b6ea52eebf2a8b72",
    "verified_classes": [
      "ResumptionInvariantViolation",
      "Event",
      "SessionBuffer"
    ],
    "verified_functions": [
      "resume",
      "_token_at"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "ResumptionInvariantViolation"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
