{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-lose-tool-call-continuity-when-an-mcp-streamable-sse-session-migrates-between-gateway-replicas-mid-resume",
  "title": "Why does an instance lose tool-call continuity when an MCP streamable-SSE session migrates between gateway replicas mid-resume?",
  "date_of_record": "2026 November 25",
  "scope": "Applies to MCP clients and servers using the streamable HTTP transport with SSE resumption (`Last-Event-ID` replay) behind a load-balanced gateway that does not pin sessions to a replica. Does not apply to single-replica deployments, stdio transports, or stateless request/response MCP profiles that never open a resumable event stream.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-tool-call-continuity-when-an-mcp-streamable-sse-session-migrates-between-gateway-replicas-mid-resume.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-tool-call-continuity-when-an-mcp-streamable-sse-session-migrates-between-gateway-replicas-mid-resume.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-tool-call-continuity-when-an-mcp-streamable-sse-session-migrates-between-gateway-replicas-mid-resume.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2033,
    "python_slice_tokens": 413,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The distinction that matters is between **event replay** and **session replay**. Streamable SSE guarantees that a client reconnecting with `Last-Event-ID: N` receives every event numbered `N+1` onward *that the server still holds*. It does **not** guarantee that the server holding those events is the same server that holds the in-flight tool-call state those...",
    "what_was_observed": "A three-replica gateway sat in front of an MCP server pool. Session IDs were issued by whichever replica first handled `initialize`, but the gateway used round-robin with no cookie or header affinity. The client held `Mcp-Session-Id: S1` and `Last-Event-ID: 42`. Trace of the failure: 1. Client calls `tools/call` for a long-running tool. Replica A accepts it, assigns the call an internal `request_id`, and begins strea...",
    "condition_of_validity": "The invariant that must hold for streamable-SSE resumption to be safe under a load balancer is: > **For any `Mcp-Session-Id`, the tuple (event-ID namespace, in-flight tool-call state, session table entry) must be co-located on the replica that answers the resumption request — or the resumption must be rejected with a status that forces re-initialization.** T...",
    "decision_boundary": "The decision the server must make on every resumption request is binary and must be made *before* writing any response bytes: - **Own the session and hold events > `Last-Event-ID`** → replay them, continue streaming. Safe. - **Own the session but the buffer was GC'd past `Last-Event-ID`** → `410 Gone` (resumption impossible; client must re-`initialize` and r...",
    "operational_effect": "When the boundary is crossed, the observable effect is **phantom tool-call loss with duplicate side effects**: the agent believes the call failed (timeout, no result event), the tool actually ran on the orphaned replica, and any retry double-executes. This is worse than a clean connection failure because: - No error is surfaced; the agent's retry logic is tr..."
  },
  "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": "eea122f517a998af827b8d87d7e10b4f118c11d01b81633bd9a6d73835fc1d8a",
    "verified_classes": [
      "ResumptionContinuityError",
      "EventBuffer",
      "Replica"
    ],
    "verified_functions": [
      "handle_resumption",
      "idempotency_key",
      "owns",
      "emit"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "ResumptionContinuityError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
