# Why does an instance replay diverge when OTel GenAI span graphs linearize concurrent tool calls into sibling spans **Date of Record:** 2026 November 24 **Scope:** Applies to deterministic-replay and causal-tracing systems that reconstruct agent trajectories from OpenTelemetry GenAI semantic-convention span graphs where a single LLM turn fans out concurrent tool calls as sibling child spans. Does not apply to strictly serial single-tool agents or to trace backends that preserve explicit parent-child causal edges through a message queue with total order. ## Core Distinction A trace is not a trajectory. The trajectory is the *causal order in which the agent's state actually mutated*; the trace is the *span graph emitted by the instrumentation*. Under OTel GenAI conventions these coincide only when tool calls are serialized. The moment an LLM turn emits parallel tool calls (function-calling with `parallel_tool_calls=true`, or an orchestrator fanning out to N sub-agents), the instrumentation flattens the causal structure into a set of sibling spans sharing one parent `gen_ai.*` LLM span. Siblings carry no ordering edge. Replay engines that reconstruct execution by walking the span tree depth-first, or by sorting siblings on `start_time_unix_nano`, silently impose an order that the runtime never guaranteed — and the reconstituted trajectory diverges from the recorded one at the first state-mutating tool whose result another tool consumed. The distinction that matters operationally: **span parentage encodes containment, not causality.** A replay engine that treats the parent-child edge as a "happens-before" edge is making an unstated assumption that holds for a serial agent and fails for a concurrent one. ## What Was Observed A research agent turn issued three parallel tool calls under one `chat` span: `search(query)`, `fetch(url_from_prior_turn)`, and `write_note(id, body)`. The runtime dispatched all three concurrently. `write_note` read a mutable `scratchpad` that `search` had been configured to append to; the actual wall-clock interleaving was `search` → `write_note` → `fetch`. The span graph recorded three siblings with `start_time` values `t0`, `t0+2ms`, `t0+1ms` (clock skew across worker processes) and end times that inverted the true completion order. Replay reconstructed the order as `search`, `fetch`, `write_note` (sort on start_time). On the recorded run, `write_note` had captured a `scratchpad` containing search results. On replay, `write_note` executed against an empty scratchpad and wrote a note with a different body hash. Every downstream step that consumed that note — a summarization span, a citation-resolution span — produced different outputs, and the divergence cascaded: by span 40 of 61, the replay's token stream had diverged at the first differing token, and the trajectory was unrecoverable. The failure was not a replay bug in the narrow sense; the replay engine faithfully executed the order it inferred. The order it inferred was not the order that happened. The tell was a checksum mismatch on a *tool output* rather than an LLM output, appearing one span *after* the last parallel fan-out. That signature — divergence originating at a mutation-consuming sibling, not at the LLM span itself — is the fingerprint of this failure class. ## Condition of Validity The invariant that must hold for sibling-span replay to be sound: > For every LLM turn that fans out N>1 tool calls, either (a) the N tool calls are provably side-effect-commutative and independent, or (b) the trace carries an explicit causal edge (`links`, a `causal.predecessor` attribute, or a sequence number assigned by the runtime dispatcher) establishing the true mutation order. Serialized agents satisfy (a) trivially (N=1). Commutative fan-outs (N independent reads) satisfy (a) by construction. The failure class is bounded to fan-outs where at least one tool mutates state another sibling reads — the "read-after-sibling-write" pattern. This is exactly the pattern that appears in agentic research, code-editing, and multi-tool orchestration, which is why it is common in practice and rare in test suites (test agents tend to use commutative fixtures). The guardrail is to make the order explicit at emission time: the dispatcher must stamp each sibling with a monotonic `dispatch_seq` and, for any tool that reads shared mutable state, record the `dispatch_seq` of the sibling whose write it observed. Absent that, no replay engine — however careful — can recover the order, because the information was never emitted. ## Decision Boundary Replay engines must decide, per fan-out, between two postures: - **Strict replay** (default for state-mutating agents): refuse to reconstruct a fan-out that contains a read-after-sibling-write without an explicit causal edge. Raise on the ambiguous fan-out rather than guess. This converts silent, cascading divergence into a loud, localized failure at the exact span where order became unrecoverable. - **Permissive replay** (acceptable for read-only or commutative fan-outs): sort siblings on a documented total order (start_time, then span_id as tiebreak) and record that the reconstruction is order-approximate. The replay output must be tagged `order_confidence=approximate` so downstream verification does not treat a matching hash as proof of identical execution. The boundary is the presence of a mutation-consumer edge. A replay engine that applies the permissive posture to a mutating fan-out is not replaying; it is re-simulating a plausible-but-unrecorded execution and calling it ground truth. ## Operational Effect When the invariant is enforced, replay divergence localizes to the ambiguous fan-out and the trace is flagged as non-replayable rather than mis-replayed. This changes the failure economics: instead of a 40-span cascade that terminates in an opaque token-level mismatch, the engine emits a single structured error naming the fan-out, the sibling spans, and the missing causal edge. The instrumentation team can then add the `dispatch_seq`/observed-write edge at emission and re-capture. When the invariant is *not* enforced, the permissive posture produces a replay that succeeds — exits zero, hashes match on the commutative spans — and diverges only on the mutation consumers, which is the most expensive possible failure shape: a green replay that is wrong. Verification pipelines that gate on "replay succeeded" then certify a trajectory that never ran, and any audit built on that certification inherits the error. ```python from __future__ import annotations from dataclasses import dataclass, field class AmbiguousFanoutError(RuntimeError): """Raised when a fan-out cannot be replayed without inventing a causal order.""" @dataclass class ToolSpan: span_id: str tool: str start_ns: int reads_state: bool = False writes_state: bool = False observed_write_seq: int | None = None # dispatch_seq of sibling write it consumed dispatch_seq: int | None = None # assigned by runtime dispatcher, if present @dataclass class Fanout: llm_span_id: str siblings: list[ToolSpan] = field(default_factory=list) def reconstruct_order(fanout: Fanout, *, strict: bool = True) -> list[ToolSpan]: """Return siblings in a causally sound order, or refuse.""" if len(fanout.siblings) <= 1: return list(fanout.siblings) # Prefer explicit causal edges emitted by the dispatcher. if all(s.dispatch_seq is not None for s in fanout.siblings): return sorted(fanout.siblings, key=lambda s: s.dispatch_seq) # Detect read-after-sibling-write: a reader whose observed write is a sibling. writers = {s.span_id for s in fanout.siblings if s.writes_state} ambiguous = [ s for s in fanout.siblings if s.reads_state and s.observed_write_seq is None and writers - {s.span_id} ] if ambiguous and strict: raise AmbiguousFanoutError( f"fan-out under llm span {fanout.llm_span_id!r} contains " f"read-after-sibling-write with no causal edge: " f"readers={[s.span_id for s in ambiguous]} " f"writers={sorted(writers)}; refusing to infer order from start_time" ) # Permissive fallback: documented total order, tagged approximate. return sorted(fanout.siblings, key=lambda s: (s.start_ns, s.span_id)) ```