{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-boundary-be-drawn-between-a-model-call-and-its-tool-side-effects-for-counterfactual-replay-to-be-sound",
  "title": "Where must an instance boundary be drawn between a model call and its tool side effects for counterfactual replay to be sound",
  "date_of_record": "2026 November 16",
  "scope": "Applies to deterministic replay and counterfactual (\"what-if\") debugging of agentic runs reconstructed from OTel GenAI spans, where the agent loop interleaves LLM invocations with tool/function calls that have external side effects. Does not apply to pure read-only tooling, nor to replays that only re-render an existing trace without re-executing the loop.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-boundary-be-drawn-between-a-model-call-and-its-tool-side-effects-for-counterfactual-replay-to-be-sound.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-boundary-be-drawn-between-a-model-call-and-its-tool-side-effects-for-counterfactual-replay-to-be-sound.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-boundary-be-drawn-between-a-model-call-and-its-tool-side-effects-for-counterfactual-replay-to-be-sound.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1582,
    "python_slice_tokens": 145,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The non-obvious boundary is *not* \"model call vs. tool call.\" It is **the point at which a span's recorded output becomes an input that the replay engine is allowed to substitute**. A GenAI span (`gen_ai.operation.name = chat`) emits tokens, tool-call requests, and a finish reason as *one atomic unit*. A tool span emits an effect on the world. Counterfactual...",
    "what_was_observed": "In a trace with the following shape: A counterfactual branch was injected at `M1`: \"what if the model had called `search(q=\"Y\")` instead?\" The replay engine, keyed on `gen_ai.tool.call.id`, re-bound `T1`'s *recorded* result `S1` to the new call — because the tool span ID matched the call ID carried in `M1`'s tool-call request. The branch then proceeded through `M2` and `M3` and produced a plausible-looking final answ...",
    "condition_of_validity": "The substitution boundary at the model-span output is valid **if and only if** all of the following hold for the branch: 1. **Causal closure of tool inputs.** Every tool span's inputs are a pure function of (a) the immediately preceding model span's output and (b) prior tool outputs that are themselves inside the branch's substitution set. If a tool's argume...",
    "decision_boundary": "Given a candidate counterfactual at model span `M_k`: - If the branch's new output at `M_k` produces tool-call arguments **identical** to the recorded arguments for every call ID, the tool spans are replayable by recorded-output substitution (the world state is unchanged; the recorded outputs remain valid). - If any tool-call argument **differs**, the corres...",
    "operational_effect": "Treating the model-span output as the atomic substitution unit, and tool spans as causally downstream and non-substitutable under argument change, converts a class of silent, plausible-looking wrong counterfactuals into explicit, loud boundary reports. The practical consequences: - Replay engines must carry a `substitution_set` per branch and check tool-inpu..."
  },
  "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": "130b65d1e3c77e518e43f550c863135cca41d400f2b9190f00b6763119d89fbb",
    "verified_classes": [
      "UnsoundReplayBoundaryError"
    ],
    "verified_functions": [
      "bind_tool_output"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "UnsoundReplayBoundaryError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
