# Why does an instance fail to replay a multi-agent trace when OTel GenAI span timestamps are monotonic but parent-child causality is not? **Date of Record:** 2026 November 24 **Scope:** Applies to post-incident forensic replay of multi-agent runs reconstructed from OpenTelemetry GenAI semantic-convention spans where causality is inferred from span parentage and timestamps rather than from an explicit causal token. Does not apply to single-agent traces or to runs recorded with a total-order event log (e.g., a sequencer or vector-clock ledger). ## Core Distinction A trace is *temporally ordered* when every span carries a start/end timestamp that respects wall-clock monotonicity within a process. A trace is *causally ordered* when every downstream effect can be attributed to the exact upstream decision that produced it. These two properties are independent, and OTel GenAI spans give you the first almost for free while silently failing the second whenever a child span is emitted by a *different agent process* than its parent. The failure is not clock skew in the naive NTP sense. It is that multi-agent handoffs (A2A calls, MCP tool invocations brokered by a supervisor, baton-passing between peer agents) produce child spans whose `start_time` is *earlier* than the parent's `end_time` because the callee began work, emitted its own span, and only later received the causal context that OTel's `SpanContext` propagation was supposed to attach. When the replay engine topologically sorts by timestamp to reconstruct the reasoning chain, it interleaves spans from causally unrelated branches and produces a trace that *looks* valid — every span has a parent, every parent precedes its child — but attributes a tool call to the wrong agent's reasoning step. ## What Was Observed During forensic replay of a three-agent swarm (planner → retriever → verifier) handling a 41-step retrieval-augmented task, the reconstruction engine reported a clean causal chain. Manual audit against the raw span export revealed the following: - The planner emitted `gen_ai.chat` span `P7` (decision to invoke `search_docs`) with `end_time = T+412ms`. - The retriever's `gen_ai.tool` span `R3` (`search_docs` execution) had `start_time = T+388ms` — **24ms before its parent closed** — because the retriever process received the tool invocation over an async channel, started executing, and only flushed its span batch after the planner's span had already been exported with a later end timestamp by the collector's batch processor. - The verifier's `gen_ai.chat` span `V2` (claiming "retrieved evidence supports step 7") had `start_time = T+401ms`, interleaving *between* `P7` and `R3` in timestamp order, even though `V2` causally depends on `R3`'s output. Topological sort by `start_time` produced the order `P7 → V2 → R3`. The replay engine then reconstructed a narrative in which the verifier validated evidence *before* it was retrieved. The forensic conclusion — "verifier hallucinated evidence" — was wrong. The verifier had behaved correctly; the trace had lied about causality. The root cause is that OTel's batch span processor does not guarantee export ordering, and `SpanContext` propagation across process boundaries (via W3C `traceparent` headers on the A2A/MCP transport) attaches the *trace ID* and *parent span ID* but does **not** serialize the parent's completion. A child span can therefore carry a valid `parent_span_id` while its `start_time` precedes the parent's `end_time`. The span graph is a DAG by parentage; it is **not** a DAG by timestamp. Replay engines that conflate the two are the failure surface. ## Condition of Validity Timestamp-based causal reconstruction is valid **only** when all of the following hold: 1. Every span is emitted by the same process, or all processes share a synchronised monotonic clock with bounded skew smaller than the smallest inter-span gap. 2. No span is exported through a batching processor that can reorder relative to its parent's export. 3. The causal edge is always parent → child in wall-clock time, i.e., the parent's `end_time ≤ child's start_time`. In multi-agent systems, condition 3 is *systematically violated* by design: agent B can begin acting on a partial handoff before agent A finishes emitting its own span, particularly under streaming handoffs, speculative execution, or when the parent's span is closed only after the child's response is received (a synchronous RPC pattern in which the child's work is nested inside the parent's wall-clock interval but exported out of order). The invariant that must hold for replay to be sound is stronger than timestamp monotonicity: **the causal order must be recoverable from an explicit causal token, not inferred from time.** Parent span ID is necessary but insufficient, because it identifies *who* the parent is without encoding *when* the parent's decision was committed. ## Decision Boundary A replay engine must refuse to emit a causal narrative when the reconstructed order is timestamp-ambiguous. The boundary condition is: > If any child span's `start_time` is less than its parent's `end_time` (a "temporal inversion"), the trace is causally underdetermined and must be flagged, not silently sorted. The correct handling is to fall back to parentage-only ordering (a DAG walk that treats all children as concurrent with respect to each other unless an explicit `link` attribute with a causal sequence number disambiguates), and to surface the inversion as a first-class forensic finding. Silently sorting by timestamp — the default in most OTel trace UIs and in naive replay scripts — is the boundary violation. It converts an underdetermined trace into a confident false narrative, which is worse than no narrative for post-incident forensics. The guardrail: emit a `causal_ambiguity` annotation on every inverted edge, and require the forensic analyst (or an automated judge) to resolve it against an out-of-band log (agent-side sequence counters, message queue offsets) before the replay is admitted as evidence. ## Operational Effect Without the guardrail, replay produces *plausible but wrong* attributions: a verifier blamed for hallucination when it was correct, a retriever credited with a document it never returned, a planner's decision attributed to a step that had not yet occurred. These errors are invisible in the trace UI because the span graph is structurally valid. They are catastrophic in incident review because they redirect remediation to the wrong agent. With the guardrail, the inversion is surfaced, the replay engine degrades to a partial order, and the forensic conclusion is bounded to what the trace can actually support: "verifier's claim is consistent with retrieved evidence if and only if `R3` completed before `V2` began, which the trace cannot establish; cross-check against the retriever's sequence log." The remediation target shifts from "fix the verifier" to "fix the handoff instrumentation." The architectural invariant: **causal tokens must be monotonic per trace, not wall-clock timestamps.** A Lamport counter or vector clock attached to each span at emission, incremented on every causal send, makes the inversion impossible to misread — the child always carries a strictly greater causal token than its parent regardless of export order or clock skew. ```python from dataclasses import dataclass from typing import Optional class CausalReplayInversionError(RuntimeError): """Raised when a child span's start_time precedes its parent's end_time, making timestamp-based causal reconstruction unsound.""" pass @dataclass class Span: span_id: str parent_id: Optional[str] start_ms: int end_ms: int causal_token: Optional[int] = None # Lamport counter, if instrumented def reconstruct_causal_order(spans: list[Span]) -> list[Span]: by_id = {s.span_id: s for s in spans} # Guardrail 1: detect temporal inversions before any sorting. for s in spans: if s.parent_id is None: continue parent = by_id.get(s.parent_id) if parent is None: continue if s.start_ms < parent.end_ms: if s.causal_token is None or parent.causal_token is None: raise CausalReplayInversionError( f"Child {s.span_id} starts at {s.start_ms}ms, before " f"parent {parent.span_id} ends at {parent.end_ms}ms, and " f"no causal token is available to disambiguate. " f"Replay is causally underdetermined; refuse to narrate." ) if s.causal_token <= parent.causal_token: raise CausalReplayInversionError( f"Causal token violation: child {s.span_id} token " f"{s.causal_token} <= parent {parent.span_id} token " f"{parent.causal_token}. Handoff instrumentation is broken." ) # Guardrail 2: order by causal token when present; otherwise by parentage # depth, never by raw timestamp across process boundaries. def depth(s: Span) -> int: d, cur = 0, s while cur.parent_id is not None: cur = by_id[cur.parent_id] d += 1 return d return sorted( spans, key=lambda s: (s.causal_token if s.causal_token is not None else depth(s)), ) ```