# When must an instance refuse to replay a sibling's span: causal-parent reattachment and the phantom-tool-call divergence in OpenTelemetry GenAI trace graphs **Date of Record:** 2026 November 29 **Scope:** Applies to counterfactual auditing and deterministic replay of multi-agent runs reconstructed from OpenTelemetry GenAI semantic-convention spans, where a replay engine re-executes a subgraph to test an alternative decision. Does not apply to single-agent linear traces, nor to replay systems that re-run the entire root trace from token zero with full external-state snapshots. ## Core Distinction There are two fundamentally different things an auditor means by "replay a multi-agent run": 1. **Trace replay** — re-emitting the recorded span graph, including recorded tool outputs, prompts, and model responses, to reconstruct the causal story. This is a *read* operation on the trace; it is deterministic by construction because every leaf is a recorded fact. 2. **Counterfactual replay** — re-executing a subgraph with a modified input (a different model response, a mutated tool result, a swapped peer agent) to ask "what would have happened if agent B had chosen differently?" This is a *write* operation against a live environment, and it is only deterministic if every non-replayed dependency is pinned to recorded state. The non-obvious boundary failure lives at the seam between these two: a counterfactual replay engine that re-executes agent B's span but leaves agent B's *siblings* as recorded trace-replay leaves. The sibling spans are then treated as fixed facts, but they were produced by a causal process that depended on B's original output. When B's counterfactual output diverges, the sibling spans become *counterfactually inconsistent* — they reference a world that no longer exists — and the replay engine happily stitches them back into the graph because their `parent_span_id` still resolves. This is not a schema problem. Every span is well-formed. The failure is a **causal-parent reattachment** violation: a span whose recorded parent is being counterfactually re-executed must itself be re-executed or explicitly invalidated, never reattached as a recorded leaf. ## What Was Observed A three-agent pipeline: `Planner` (agent A) emits a plan, `Executor` (agent B) calls a tool per plan step, `Auditor` (agent C) verifies each tool result and can request a re-plan. The trace graph under GenAI semantic conventions: ``` span: Planner.run (gen_ai.agent.name=planner) span: Executor.step[0] (parent=Planner.run) span: tool.search (parent=Executor.step[0], gen_ai.tool.name=search) span: Executor.step[1] (parent=Planner.run) span: tool.fetch (parent=Executor.step[1]) span: Auditor.verify (parent=Planner.run) span: tool.rule_check (parent=Auditor.verify) ``` The auditor asked: *what if `Executor.step[1]` had chosen `tool.extract` instead of `tool.fetch`?* The replay engine re-executed `Executor.step[1]` with a mutated tool-selection prompt. The counterfactual `tool.extract` returned a different payload than the recorded `tool.fetch`. But `Auditor.verify` was left as a recorded trace-replay leaf — it was not re-executed, because the auditor's span was not in the replay target set. The resulting replay graph was internally consistent by every structural check (parent IDs resolve, span kinds match, timestamps monotone after re-stamping). Yet the auditor's recorded verdict — `PASS` — was now attached to a tool payload it had never seen. The replay concluded the pipeline would have passed under the counterfactual, when in fact the recorded auditor had a hard rule that `tool.extract` payloads must contain a `provenance` field, which the counterfactual payload lacked. The replayed verdict was a **phantom**: a recorded leaf masquerading as a fact about the counterfactual world. A second, sharper instance: the auditor's `tool.rule_check` span carried `gen_ai.tool.call.id` that the replay engine used to deduplicate tool calls across the graph. Because the counterfactual `Executor.step[1]` emitted a *new* `tool.extract` call with a *freshly generated* call ID, the dedup map now contained two entries for what the auditor's recorded logic treated as a single logical step. The replay engine's post-hoc consistency checker flagged a "duplicate step" and aborted — but only because the call-ID collision happened to be observable. With a tool that generated IDs from content hashes, the collision would have been silent and the replay would have completed with a corrupted verdict. The core observation: **divergence propagates upward through the trace graph, but counterfactual replay engines typically propagate it only along the explicitly re-executed subgraph, not along the causal-parent edges that connect that subgraph to recorded siblings.** The sibling spans become orphaned facts whose truth-value is contingent on a parent output that no longer holds. ## Condition of Validity Counterfactual replay of a subgraph `S` from a recorded trace `T` is valid only if, for every recorded span `s ∈ T \ S` that is a causal descendant of any span in `S`, one of the following holds: - **Re-execution:** `s` is added to the replay target set and re-run against the counterfactual upstream state. - **Invalidation:** `s` is marked `counterfactually_invalid` and excluded from any verdict aggregation, with the exclusion surfaced in the audit output. - **Independence proof:** `s`'s recorded output is provably a function only of inputs outside `S`'s counterfactual influence — in practice, only checkable when `s` carries an explicit input-hash attestation over its upstream dependencies. The invariant to enforce: **no recorded span may appear in a counterfactual replay graph if any of its recorded causal ancestors is in the replay target set and its re-executed output differs from the recorded output.** This is a graph-closure condition on the replay set, not a per-span check. It is violated by the common implementation that computes the replay set as "the spans the user asked to re-run" rather than "the causal downward closure of the user's target set, minus spans with input-hash independence attestations." The condition is *not* satisfied by structural validity checks (parent resolution, timestamp monotonicity, schema conformance). Those checks pass on phantom graphs. It is also not satisfied by re-stamping timestamps or regenerating call IDs — those are cosmetic and, as the second instance showed, can mask the divergence. ## Decision Boundary The boundary is whether the replay engine can *prove* that a recorded sibling's output is invariant to the counterfactual change. In practice this decomposes into three regimes: - **Downward-closed replay (safe):** the replay set is the full causal downward closure of the target spans. Every affected sibling is re-executed. Deterministic only if re-executed siblings are themselves pinned to recorded external state (tool outputs, model seeds, retrieval snapshots). This is the regime a counterfactual auditor should default to. - **Attested-independence replay (conditionally safe):** recorded siblings are retained only if they carry an input-hash attestation over their upstream dependencies, and the replayed upstream hashes match the attested ones. This is the only sound way to *not* re-execute a sibling. Requires the tracing instrumentation to emit dependency hashes, which GenAI semantic conventions do not currently mandate — so in practice this regime is unavailable on stock traces. - **Naive subgraph replay (unsafe):** the replay set is exactly the user's target spans. Siblings are reattached as recorded leaves. This is the regime that produced the phantom auditor verdict and the silent call-ID collision. It must be rejected at the replay engine's boundary, not patched afterward. A secondary boundary: when a counterfactual re-execution produces a *different number* of tool calls than the recorded run (as `tool.extract` did relative to `tool.fetch`), any recorded span whose logic iterated over the recorded call set is automatically counterfactually invalid — even if its inputs are otherwise unchanged — because its iteration domain has changed. This is a cardinality-invalidation rule that sits on top of the causal-closure rule. ## Operational Effect The practical consequence is that counterfactual audit verdicts from naive subgraph replay are **unfalsifiable in the wrong direction**: they report the recorded outcome for any sibling that was not re-executed, which means the audit systematically under-reports divergence. An auditor using such a replay engine to ask "would a different executor choice have changed the outcome?" will receive "no" whenever the deciding agent (the auditor itself, in the first instance) was a sibling rather than a target. The failure is silent, structurally valid, and biased toward confirming the recorded run. The guardrail is to make the replay set a *computed closure* rather than a user-supplied set, and to make causal-parent edges first-class in the replay engine's dependency analysis rather than mere display metadata. When closure computation would pull in a span the engine cannot re-execute (e.g., a human approval, an external side effect), the engine must invalidate that span's descendants and surface the invalidation, not silently retain them. The invariant is: *a counterfactual replay graph is a claim about a possible world; every node in it must be either re-executed in that world or provably independent of the counterfactual change.* ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Iterable class CounterfactualReplayError(RuntimeError): """Raised when a replay graph contains phantom spans.""" @dataclass(frozen=True) class Span: span_id: str parent_id: str | None recorded_output_hash: str input_dependency_hash: str | None = None # None => no attestation @dataclass class ReplayPlan: target_ids: set[str] replayed_output_hash: dict[str, str] = field(default_factory=dict) invalidated: set[str] = field(default_factory=set) def causal_descendants(spans: dict[str, Span], roots: Iterable[str]) -> set[str]: children: dict[str, list[str]] = {} for s in spans.values(): if s.parent_id is not None: children.setdefault(s.parent_id, []).append(s.span_id) out: set[str] = set() stack = list(roots) while stack: cur = stack.pop() for child in children.get(cur, []): if child not in out: out.add(child) stack.append(child) return out def validate_replay_graph(spans: dict[str, Span], plan: ReplayPlan) -> None: """Enforce: no recorded span may survive if a replayed ancestor diverged and the span lacks an independence attestation matching the replayed state.""" affected = causal_descendants(spans, plan.target_ids) for sid in affected: if sid in plan.target_ids: continue # re-executed; not a recorded leaf span = spans[sid] replayed_ancestor_diverged = any( plan.replayed_output_hash.get(a) != spans[a].recorded_output_hash for a in _ancestors(spans, sid) if a in plan.target_ids ) if not replayed_ancestor_diverged: continue if sid in plan.invalidated: continue if span.input_dependency_hash is None: raise CounterfactualReplayError( f"phantom span {sid}: causal ancestor diverged, no independence " f"attestation, and span was not re-executed or invalidated" ) # Attestation present: must match the replayed upstream state. expected = _upstream_hash(spans, sid, plan) if span.input_dependency_hash != expected: raise CounterfactualReplayError( f"phantom span {sid}: attestation {span.input_dependency_hash} " f"does not match replayed upstream hash {expected}" ) def _ancestors(spans: dict[str, Span], sid: str) -> Iterable[str]: cur = spans[sid].parent_id while cur is not None: yield cur cur = spans[cur].parent_id def _upstream_hash(spans: dict[str, Span], sid: str, plan: ReplayPlan) -> str: parts = [] for a in _ancestors(spans, sid): parts.append(plan.replayed_output_hash.get(a, spans[a].recorded_output_hash)) return "|".join(parts) ```