{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-sse-replay-from-silently-reordering-tool-call-results-across-an-mcp-session-resume",
  "title": "Which invariants prevent SSE replay from silently reordering tool-call results across an MCP session resume",
  "date_of_record": "2026 November 28",
  "scope": "Applies to MCP servers using the HTTP-native transport with SSE streaming and `Last-Event-ID`-based session resumption, where a single logical agent turn emits multiple interleaved `tool_result` events on one stream. Does not apply to stdio transports, single-shot request/response MCP servers, or streams that emit at most one result per turn.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-sse-replay-from-silently-reordering-tool-call-results-across-an-mcp-session-resume.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-sse-replay-from-silently-reordering-tool-call-results-across-an-mcp-session-resume.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-sse-replay-from-silently-reordering-tool-call-results-across-an-mcp-session-resume.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2301,
    "python_slice_tokens": 306,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The distinction that matters here is between *delivery resumption* and *causal resumption*. The MCP HTTP-native transport guarantees the former: on reconnect, the client sends `Last-Event-ID: N` and the server replays every event with id strictly greater than `N`. That is a byte-stream contract. It says nothing about the *logical* order in which the replayed...",
    "what_was_observed": "A coding agent driving a filesystem MCP server over HTTP-native SSE issued a `read_multiple_files` call against 14 files. The server emitted the result as a sequence of chunked `tool_result` events: a header event (`tool_use_id`, file count), then 14 body events each carrying one file's content, then a footer event (`complete: true`). Each event got a fresh monotonic id. The agent's SSE client applied backpressure: i...",
    "condition_of_validity": "The replay-safety of a resumed MCP SSE session holds if and only if all three of the following are true: 1. **Causal-unit id assignment.** Every event id is assigned at the boundary of a causal unit (a complete `tool_result`, a complete `tool_use`, a complete `message_delta` that does not span events). Partial units — a header without its bodies, a body with...",
    "decision_boundary": "The operational decision is: **when the resumption point is not a causal-unit boundary, replay-from-unit-start or fail-and-reissue — never replay-from-point.** The tempting third option, \"replay from `N` and let the client's decoder reconcile,\" is what produced the misattribution above. It is tempting because it is the cheapest to implement (the SSE layer al...",
    "operational_effect": "With the invariant enforced, the second run's failure becomes a `409` on resume, the agent re-issues `read_multiple_files`, and the 14 files arrive correctly attributed. Cost: one redundant tool call. Without it, the agent completes the turn with a corrupted ledger and the corruption propagates — the misattributed grep result is consumed by the reasoning loo..."
  },
  "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": "42e44791f3995842179413ab8149ccaf996ceb71397db212607eb6540f5d4200",
    "verified_classes": [
      "ResumptionBoundaryError",
      "CausalUnitBuffer"
    ],
    "verified_functions": [
      "handle_resume",
      "__init__",
      "begin_unit",
      "append",
      "replay_from"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "ResumptionBoundaryError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
