{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-stream-re-entrancy-corruption-in-http-native-mcp-elicitation-and-server-initiated-sampling-flows",
  "title": "Which invariants prevent stream re-entrancy corruption in HTTP-native MCP elicitation and server-initiated sampling flows",
  "date_of_record": "2026 November 24",
  "scope": "Applies to MCP servers exposed over HTTP transports (Streamable HTTP / SSE) that issue server-initiated requests to the client — `sampling/createMessage` and `elicitation/create` — while a client-initiated tool call is still in flight on the same session. Does not apply to stdio transports, where the duplex channel is inherently ordered and single-threaded per process, nor to pure request/response servers that never initiate.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-stream-re-entrancy-corruption-in-http-native-mcp-elicitation-and-server-initiated-sampling-flows.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-stream-re-entrancy-corruption-in-http-native-mcp-elicitation-and-server-initiated-sampling-flows.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-stream-re-entrancy-corruption-in-http-native-mcp-elicitation-and-server-initiated-sampling-flows.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2301,
    "python_slice_tokens": 483,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"the server asked the client a question and it timed out.\" The failure is **interleaved duplex traffic on a transport that the client runtime models as half-duplex**. In MCP over HTTP, a tool call is a client→server `POST` whose response body is a long-lived SSE stream. A server-initiated `sampling/createMessage` or `elicitation/create` is...",
    "what_was_observed": "A research-agent client driving a code-analysis MCP server over Streamable HTTP. The agent called `analyze_repo`. Mid-execution the server needed clarification and emitted `elicitation/create` with id `e-7f3a` on the active SSE stream, asking the agent to choose a target branch. The client's HTTP layer had, 200 ms earlier, hit a 30 s read-idle timeout on the stream and transparently reconnected (new `Mcp-Session-Id`,...",
    "condition_of_validity": "The guardrail below is valid only under these conditions; outside them, a different mechanism dominates: - The transport is HTTP with a session concept (Streamable HTTP). On stdio, the emit-to-closed-pipe raises synchronously and the pending request fails fast; the guard is unnecessary. - Server-initiated requests carry a correlation id scoped to the **sessi...",
    "decision_boundary": "When the emit target is dead or the session has migrated, the server has two admissible choices and one forbidden one: - **Fail-fast and surface.** Transition the pending request to `failed`, unblock the awaiting tool call with a structured error (`ElicitationUnreachable`), and let the agent decide whether to retry. This is correct when the elicitation is *o...",
    "operational_effect": "After applying the invariant — emit resolves the live stream, dead-stream emit transitions the pending entry to `failed`, and the awaiting path raises instead of blocking — the reconnect scenario degrades safely: the agent sees `ElicitationUnreachable` on the first call, retries once on `sess-B`, and gets a single completion record. Duplicate-completion rate..."
  },
  "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": "223bec8286fbb279a6ac620cf806703ea583409b5bae295f65ac66f7d74bddef",
    "verified_classes": [
      "ElicitationUnreachable",
      "PendingState",
      "PendingRequest",
      "ElicitationBroker"
    ],
    "verified_functions": [
      "run_analysis_with_elicitation",
      "__init__",
      "register_stream",
      "close_stream",
      "emit",
      "reanchor",
      "accept_reply"
    ],
    "verified_functions_count": 7,
    "defensive_guards_count": 7,
    "raised_exceptions": [
      "ElicitationUnreachable"
    ],
    "sample_fail_closed_invariants": [
      "analysis aborted: clarification request undeliverable on stale stream; retry"
    ],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "enum",
      "time",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
