# Why does an instance replay diverge when OTel span fan-out reorders concurrent agent tool calls **Date of Record:** 2026 December 3 **Scope:** Applies to post-incident forensic replay of multi-agent runs reconstructed from OpenTelemetry span trees where two or more child agents issue tool calls under the same parent span context and the trace backend emits spans out of causal order. Does not apply to single-agent linear traces, nor to runs where a deterministic event log (append-only WAL with monotonic sequence IDs) is the source of truth rather than OTel spans. ## Core Distinction A trace is not a log. An OTel span records *that* an operation happened with start/end timestamps and parent linkage; it does not record the *order in which the orchestrator's reasoning loop observed the results*. During live execution, the agent's next reasoning step is gated on whichever tool result resolves first in wall-clock time, and that resolution order is what actually steers the probabilistic continuation. During replay, the reconstructor sorts spans by `start_time_unix_nano` (or worse, by ingestion order) and feeds results back to a re-instantiated agent in that order. When two sibling tool spans overlap in time — which is the normal case for parallel sub-agent fan-out — the sort key is not a total order, and the reconstructed "history" the replayed agent sees differs from the history the original agent saw. The agent then diverges not because of nondeterminism in the model but because the replay harness handed it a different input sequence. This is a *reconstruction* failure masquerading as a *model* failure, and it is the single most common reason forensic replays "don't reproduce" in multi-agent systems. ## What Was Observed A supervisor agent dispatched three worker sub-agents (`search`, `fetch`, `summarize`) under one parent span. Each worker emitted a tool span under its own `agent.span_id`. The trace backend (batched OTLP exporter, 5s flush) delivered the three tool spans to the collector with ingestion timestamps that did not match their `start_time_unix_nano` — `summarize`'s span arrived first because its exporter batch flushed earlier, even though it started 40ms after `fetch`. The forensic replay tool defaulted to ordering by ingestion order, as most span stores do when no explicit sort is applied. The original run's supervisor had observed: `fetch` result → `search` result → `summarize` result, and its synthesis prompt contained the fetched document *before* the search snippets, which caused it to anchor on the fetched content. The replayed supervisor observed: `summarize` → `fetch` → `search`, anchored on the summary, and produced a materially different final answer. The replay was flagged as "nondeterministic model behavior." It was not. The model was deterministic given its input; the input was wrong. A second, subtler observation: two sibling spans had byte-identical `start_time_unix_nano` (clock resolution collapse on a busy host under `CLOCK_MONOTONIC_COARSE`). The sort was stable in the replay tool's Python `sorted()` but the *original* runtime had used a `tokio::select!` that resolved on completion order, not start order. Start-time sort and completion-time sort produced opposite orderings for these two spans, and both were "valid" sorts of the span set. There was no field in the trace that recorded which one the agent actually saw. ## Condition of Validity The divergence is bounded and reproducible only when the following invariant holds: **for every reasoning step of every agent in the trace, there exists a total order over the tool results that step consumed, and that order is recoverable from the span data alone.** This invariant is *false* in the general multi-agent case. It becomes true only under one of these conditions: 1. The orchestrator serializes tool dispatch (no concurrent siblings under a reasoning step), so completion order equals start order. 2. Each tool result is stamped with a monotonically increasing `result_seq` attribute assigned by the orchestrator at the moment it *consumed* the result, not when the tool finished. This is the only field that captures observation order rather than execution order. 3. The trace includes an explicit `reasoning.step.input_hash` span event recording the hash of the exact context window fed to the model at each step; replay is validated by hash match, and a mismatch aborts rather than silently proceeding. Absent (1), (2), or (3), the replay is a *plausible* reconstruction, not a *faithful* one, and any divergence it produces is unattributable. The condition of validity is therefore a property of the instrumentation contract, not of the replay tool. ## Decision Boundary The boundary is whether the forensic question is *"what did the agent do?"* or *"why did the agent do it?"*. For the former, start-time-sorted span reconstruction is adequate — the causal tree is preserved even if sibling order is scrambled, and you can still see that `fetch` was called and returned X. For the latter, you need the observation order, and start-time sort is *actively misleading* because it produces a confident-looking but wrong input sequence. The rule: **if a reasoning step has two or more child tool spans whose `[start, end]` intervals overlap, the replay is inadmissible for causal attribution unless a `result_seq` or `input_hash` field disambiguates it.** Overlapping siblings are detectable mechanically: for each parent reasoning span, check pairwise interval intersection among children. If any intersect and no ordering attribute exists, the reconstructor must raise rather than guess. Guessing is the failure; the overlap itself is normal and expected in any fan-out architecture. ## Operational Effect Teams that instrument only start/end times and parent linkage will spend forensic budget chasing phantom model nondeterminism. The practical mitigations, in order of cost: (a) add a `result_seq` integer attribute written by the orchestrator's result-consumption callback — this is a 5-line change at the dispatch site and makes replay faithful; (b) emit a `reasoning.step.input_hash` event per step and have the replay harness assert hash equality before trusting the reconstruction; (c) if neither is possible for historical traces, the replay tool must detect overlapping siblings and mark the step `UNRECONSTRUCTABLE` rather than emit a best-effort order. The last option is the minimum bar for forensic integrity: a replay that cannot prove its input order must refuse to attribute behavior to the model. Without this, post-incident review of multi-agent systems systematically over-attributes to "LLM flakiness" and under-attributes to trace reconstruction, and the actual bug — a race in result consumption that the original run also suffered from — never gets found. ```python from dataclasses import dataclass from typing import Optional class UnreconstructableTraceError(RuntimeError): """Raised when a reasoning step's tool-result observation order cannot be recovered from span data, making causal replay inadmissible.""" pass @dataclass class Span: span_id: str parent_id: Optional[str] name: str start_ns: int end_ns: int result_seq: Optional[int] = None # written at consumption time by orchestrator input_hash: Optional[str] = None # hash of context window fed to model def _intervals_overlap(a: Span, b: Span) -> bool: return a.start_ns < b.end_ns and b.start_ns < a.end_ns def reconstruct_step_inputs(parent: Span, children: list[Span]) -> list[Span]: """Return children in the order the original agent observed their results. Faithful only if every child carries result_seq (consumption order). If result_seq is absent and any two children overlap in time, the observation order is unrecoverable and we refuse to guess. """ tool_children = [c for c in children if c.parent_id == parent.span_id] if not tool_children: return [] if all(c.result_seq is not None for c in tool_children): seqs = [c.result_seq for c in tool_children] if len(set(seqs)) != len(seqs): raise UnreconstructableTraceError( f"duplicate result_seq under step {parent.span_id}: {seqs}" ) return sorted(tool_children, key=lambda c: c.result_seq) # No consumption-order field. Fall back to interval analysis. for i in range(len(tool_children)): for j in range(i + 1, len(tool_children)): a, b = tool_children[i], tool_children[j] if _intervals_overlap(a, b): raise UnreconstructableTraceError( f"step {parent.span_id}: spans {a.span_id} and {b.span_id} " f"overlap in [{a.start_ns},{a.end_ns}] x [{b.start_ns},{b.end_ns}] " f"with no result_seq; observation order is not recoverable" ) # Non-overlapping: start order equals completion order equals observation order. return sorted(tool_children, key=lambda c: c.start_ns) def assert_replay_faithful(parent: Span, children: list[Span], replayed_hash: str) -> None: """Gate: refuse to attribute divergence to the model unless the replayed context hash matches the hash recorded at the original step.""" if parent.input_hash is None: raise UnreconstructableTraceError( f"step {parent.span_id}: missing input_hash; cannot validate replay" ) if parent.input_hash != replayed_hash: raise UnreconstructableTraceError( f"step {parent.span_id}: replay input hash {replayed_hash} != " f"original {parent.input_hash}; divergence is reconstruction, not model" ) ```