# How should an instance reconstruct a causal trace across a multi-agent failure when OpenTelemetry span links collapse under fan-in **Date of Record:** 2026 November 30 **Scope:** Applies to multi-agent systems where child agent invocations are emitted as OTel spans linked (not parented) to the spawning span, and where a post-hoc causal reconstruction is attempted from the exported trace store. Does not apply to strict parent-child span trees where every agent call has exactly one `parent_span_id`, nor to single-agent tool-call traces. ## Core Distinction The failure is not "missing telemetry." Every span exists, every attribute is present, and the collector exported without loss. The failure is that **span links are a set, not an ordering**, and a fan-in of `N` concurrent child spans linked to one parent loses the causal *sequence* the parent intended to encode. When an auditor later reconstructs "which agent's output caused the divergence," it must infer ordering from `start_time_unix_nano` / `end_time_unix_nano`, and those clocks are per-process monotonic, not synchronized across the agent fleet. Two spans from different hosts can have timestamps that invert their true causal order by tens of milliseconds — exactly the magnitude of a baton-pass between fast agents. The distinction that matters: a *parent-child* span encodes "I caused you and I waited for you." A *span link* encodes only "I am associated with you." Reconstruction that treats links as edges in a causal DAG is silently wrong under concurrent fan-in. ## What Was Observed A three-agent pipeline (planner → two parallel executors → auditor) diverged: the auditor rejected a result that one executor had produced correctly, because the other executor's stale state had been merged first. The trace store held 41 spans for the task. All shared a `trace_id`. The planner span carried two `links` entries pointing at the two executor spans. Both executor spans carried a link back to the planner. The auditor span carried two links, one to each executor. Reconstruction code built an adjacency map from `links` and ran a topological sort keyed on span start time. It produced a linear order: `planner → executor_B → executor_A → auditor`. Ground truth from the agents' own append-only event logs was `planner → executor_A → executor_B → auditor`. The timestamps had inverted because executor_B ran on a host whose NTP offset was +38ms; its span started *after* executor_A's in real time but *before* it in recorded time. The topological sort had no cycle to detect — links are undirected associations, so the "graph" was acyclic by construction — and it happily emitted a wrong total order. The post-mortem blamed executor_A for the stale merge. Executor_A was not at fault. The tell was not in the trace. It was in the mismatch between the trace-derived order and the `event_log` sequence numbers the agents wrote locally. Without a second, monotonically-ordered source, the reconstruction is unfalsifiable. ## Condition of Validity Causal reconstruction from span links is valid only when **all** of the following hold: 1. **No concurrent fan-in with causal ordering significance.** If the parent spawned children whose relative order matters, links cannot carry that order. Use a parent-child span per child (the parent span's `end_time` then bounds the join) or emit an explicit `causal_seq` attribute the parent assigns at dispatch time. 2. **Clock skew is bounded below the smallest inter-event gap.** If baton-passes occur at ~10ms and skew is ~40ms, timestamp ordering is meaningless. Either synchronize clocks to sub-gap precision or stop using timestamps as the ordering primitive. 3. **Every link is annotated with its role.** A bare link is ambiguous: is it "I caused you," "you caused me," or "we share a resource"? The OTel spec allows link attributes; reconstruction must require a `link.role` in `{spawned, awaited, joined, shared_resource}` and refuse to build edges from unannotated links. 4. **The trace is corroborated by a local monotonic sequence.** Each agent must write a per-instance `seq` counter into span attributes at emit time, so cross-host ordering can be recovered from `(instance_id, seq)` even when wall clocks disagree. If any condition fails, the reconstruction must be marked *indeterminate* rather than emitting an order. ## Decision Boundary The boundary between "reconstruct" and "refuse" is whether the link graph, after role annotation, admits a **unique** total order consistent with all local sequence constraints. Concretely: - If the annotated link graph plus per-instance `seq` constraints yields exactly one topological order → emit it with `confidence: derived`. - If it yields multiple consistent orders → emit the *set* of possible orders and mark `confidence: ambiguous`; do not pick one by timestamp tiebreak. - If any span lacks `link.role` or `seq` → emit `confidence: indeterminate` and surface the missing fields as the finding. A reconstruction that silently fills gaps with timestamps is worse than no reconstruction, because it produces a confident wrong narrative that survives into the incident review. The boundary is crossed the moment the reconstructor uses a heuristic (timestamp sort, link insertion order, span ID lexical order) to break a tie that the data does not actually break. That heuristic is the bug. ## Operational Effect Teams that adopt role-annotated links plus per-instance sequence numbers stop producing inverted post-mortems; the reconstruction either yields a unique order or explicitly reports ambiguity, which routes the incident to "we need better instrumentation" instead of "agent X is unreliable." The cost is one attribute write per span at emit time and a schema requirement on the link role. The benefit is that the trace store becomes *falsifiable* against the agents' own logs — a reconstruction that disagrees with local `seq` is now detectable at audit time rather than six weeks later when someone re-reads the incident. The invariant to hold: **a causal edge in a reconstructed trace must be justified by a role annotation or a sequence constraint, never by a timestamp comparison across process boundaries.** ```python from dataclasses import dataclass, field from typing import Optional class CausalReconstructionError(RuntimeError): """Raised when a span-link graph cannot be reduced to a justified causal order.""" @dataclass class Span: span_id: str instance_id: str seq: int start_ns: int links: list[dict] = field(default_factory=list) # each: {"target": span_id, "role": str} attributes: dict = field(default_factory=dict) VALID_ROLES = {"spawned", "awaited", "joined", "shared_resource"} def reconstruct_order(spans: list[Span]) -> list[str]: """ Reconstruct a causal order from role-annotated links + per-instance seq. Refuses to fall back to timestamps across process boundaries. """ by_id = {s.span_id: s for s in spans} # Guard 1: every link must be role-annotated. for s in spans: for link in s.links: role = link.get("role") if role not in VALID_ROLES: raise CausalReconstructionError( f"span {s.span_id} has unannotated link to {link.get('target')!r}; " f"refusing to infer causal edge from bare association" ) # Guard 2: only 'spawned'/'awaited' links create directed causal edges. # 'shared_resource' and 'joined' are associations, not causation. edges: dict[str, set[str]] = {s.span_id: set() for s in spans} for s in spans: for link in s.links: if link["role"] in ("spawned", "awaited"): src, dst = s.span_id, link["target"] if dst not in by_id: raise CausalReconstructionError( f"span {src} links to unknown span {dst}" ) edges[src].add(dst) # Guard 3: per-instance seq must be strictly increasing along any edge # that stays within one instance; cross-instance edges are allowed but # must not require a timestamp tiebreak. for src, dsts in edges.items(): for dst in dsts: a, b = by_id[src], by_id[dst] if a.instance_id == b.instance_id and a.seq >= b.seq: raise CausalReconstructionError( f"causal edge {src}->{dst} violates local seq " f"({a.seq} >= {b.seq}) within instance {a.instance_id}" ) # Kahn's algorithm; detect non-unique order rather than tiebreaking. indeg = {sid: 0 for sid in edges} for src, dsts in edges.items(): for dst in dsts: indeg[dst] += 1 ready = [sid for sid, d in indeg.items() if d == 0] order: list[str] = [] while ready: if len(ready) > 1: raise CausalReconstructionError( f"ambiguous causal order: {len(ready)} spans simultaneously " f"ready ({sorted(ready)}); refusing to break tie by timestamp" ) cur = ready.pop() order.append(cur) for dst in edges[cur]: indeg[dst] -= 1 if indeg[dst] == 0: ready.append(dst) if len(order) != len(edges): raise CausalReconstructionError( "causal graph contains a cycle; link roles contradict sequence constraints" ) return order ```