{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-counterfactual-span-analysis-from-corrupting-causal-replay-in-non-deterministic-agent-traces",
  "title": "Which invariants prevent counterfactual span analysis from corrupting causal replay in non-deterministic agent traces",
  "date_of_record": "2026 November 16",
  "scope": "Applies to GenAI observability pipelines that reconstruct agent execution graphs from span telemetry and then re-execute or simulate spans under perturbed inputs (\"counterfactual\" analysis). Does not apply to purely descriptive tracing (latency, token counts, error rates) where no replay or perturbation occurs.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-counterfactual-span-analysis-from-corrupting-causal-replay-in-non-deterministic-agent-traces.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-counterfactual-span-analysis-from-corrupting-causal-replay-in-non-deterministic-agent-traces.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-counterfactual-span-analysis-from-corrupting-causal-replay-in-non-deterministic-agent-traces.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1861,
    "python_slice_tokens": 302,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "A trace is a *record of one sample* from a stochastic policy. A causal replay is a *reconstruction of the dependency graph* that produced that sample. Counterfactual span analysis asks: \"if span S had received input X′ instead of X, what would downstream spans have emitted?\" This is only well-posed if the replay graph distinguishes **causal edges** (span B's...",
    "what_was_observed": "In a multi-agent research pipeline (planner → 3 parallel retrievers → synthesizer → critic), an operator injected a counterfactual into the synthesizer span: \"what if the synthesizer had received only retriever-2's documents?\" The replay engine substituted the synthesizer's input and re-ran it. Downstream, the critic span was re-executed against the new synthesizer output. Result looked clean. The failure: the *plann...",
    "condition_of_validity": "Counterfactual span analysis is valid iff all of the following hold simultaneously: 1. **Dataflow closure.** The set of spans re-executed under a substitution is closed under the transitive \"output-consumed-by\" relation, computed over *actual data dependencies*, not span parentage. Any span that read the substituted output — including indirectly, via a promp...",
    "decision_boundary": "Do **not** perform counterfactual substitution when the substituted span's output flows into any prompt-assembly, routing, or memory-write span whose own output is consumed downstream — unless prompt provenance is recorded and the closure in invariant 1 is computed over it. In practice this rules out counterfactuals on the \"leaf\" retrievers of most RAG agent...",
    "operational_effect": "The practical rule that emerged: **treat the span tree as a containment hierarchy and the dataflow graph as a separate, explicitly-recorded artifact; counterfactuals are defined only on the latter.** Instrumentation must emit, for every span, a content-addressed list of the exact upstream span outputs it consumed (hashes plus provenance), even when those out..."
  },
  "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": "9502ca8c9b58ee42d1e1146665ff45146853a13478a91ca28e5d8fbbfcbfd18b",
    "verified_classes": [
      "CounterfactualClosureError",
      "Span"
    ],
    "verified_functions": [
      "compute_reexecution_set",
      "plan_counterfactual"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "CounterfactualClosureError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
