# Under what conditions must an instance treat a parent-child span link as authoritative when reconstructing a multi-agent causal chain, and when must it reject it? **Date of Record:** 2026 November 20 **Scope:** Applies to OpenTelemetry-style GenAI semantic convention spans (`gen_ai.*`) emitted by LLM-backed agents that delegate work to peer agents, where causality is reconstructed from `parent_span_id`, `trace_id`, and `links[]` rather than from a single in-process call stack. Does not apply to single-agent, single-process traces with no cross-instance handoff. ## Core Distinction A span link is a *claim* about causality, not a *proof* of it. In a single process, `parent_span_id` is structural: the child span is created inside the parent's context, so the parent-child edge is a physical fact of the runtime. Across agents, the edge is reconstructed from identifiers carried in a message payload — an A2A envelope, an MCP tool call, or a task handoff — and those identifiers are chosen by the *sending* agent at serialization time. The distinction that matters is between **structural parentage** (the child span was created under the parent's `SpanContext`) and **declared parentage** (the child span *asserts* a `parent_span_id` it received over the wire). Trace reconstruction that treats declared parentage as structural will silently splice unrelated agent invocations into one causal chain whenever an identifier is reused, forwarded, or fabricated. ## What Was Observed A three-tier pipeline: an orchestrator agent `O` (span `S_O`), a planner agent `P` (span `S_P`), and a tool-executor agent `E` (span `S_E`). `O` invokes `P` over A2A with a `traceparent` header. `P` invokes `E` via an MCP tool call. Under nominal load the reconstructed chain is `S_O → S_P → S_E`, and replaying the trace reproduces the exact tool arguments and LLM completions. The failure appears under retry. `P` times out waiting on `E` (MCP call exceeds the client deadline at 30s), so `P`'s retry loop re-issues the call. The retry reuses the *same* `SpanContext` because the instrumentation attaches the parent context once, at loop entry, and does not mint a new child span per attempt. `E` receives two requests carrying identical `parent_span_id = S_P`. When `E`'s spans are exported, both attempts land as children of `S_P` with no distinguishing attribute. The trace now shows two `S_E` children that are *concurrent siblings* but read as *sequential steps*. A replay auditor reconstructing the causal chain sees: ``` S_O (orchestrator) └─ S_P (planner) ├─ S_E (executor, attempt-1, timed out, side effect DID occur) └─ S_E (executor, attempt-2, succeeded, side effect DID occur again) ``` The trace is structurally valid — every span has a parent, every `trace_id` matches — but the *causal semantics* are wrong: the two `S_E` spans are alternatives, not a sequence, and the auditor's replay double-counts the side effect. Worse, if the first attempt's side effect was a non-idempotent write, the trace now *asserts* a causal order (attempt-1 before attempt-2) that the runtime did not guarantee, because the two attempts raced inside `E`'s connection pool. The second, subtler observation: when `P` was itself retried by `O`, the new `S_P` instance was minted with a *fresh* `span_id` but the *original* `traceparent` was forwarded unchanged to `E`. So `E`'s spans pointed at the *dead* `S_P` span (attempt-1's span, which had already been closed and exported). The live `S_P` (attempt-2) had no children. Trace reconstruction produced an orphaned subtree rooted at a closed span — a causality hole exactly where the retry occurred. ## Condition of Validity A declared parent-child link is authoritative for causal reconstruction **only if all four hold**: 1. **Span identity is unique per attempt.** The sending agent mints a new `span_id` for each retry attempt; the `parent_span_id` on the child points at the *attempt* that actually caused it, not the loop's enclosing context. 2. **The parent span is still open (or its end-state is recorded) at child creation.** A child whose `parent_span_id` references a span that had already ended *before* the child started is a causality inversion and must be flagged, not silently accepted. 3. **The link carries a causation token, not just an identifier.** A `gen_ai.*` link without an attempt counter, a message nonce, or a causal-ordering attribute (e.g., `gen_ai.agent.handoff.seq`) cannot distinguish "step 2 of 1" from "retry of step 1." 4. **The `trace_id` is propagated without mutation across every hop.** Any agent that re-mints a `trace_id` at a handoff boundary severs the chain; any agent that forwards a stale `traceparent` after a retry splices the chain onto a dead parent. When any of these fails, the link is a *hint*, and reconstruction must fall back to the causal-ordering attributes (attempt counters, handoff sequence numbers, timestamps with clock-skew bounds) rather than trusting `parent_span_id`. ## Decision Boundary The boundary is between **reconstruction that trusts structure** and **reconstruction that validates causation**. Concretely: - If `child.start_time < parent.end_time` is violated, the link is a **causality inversion** — reject it as a parent edge and record it as a `links[]` entry with a `causality_invalid` attribute. - If two children share a `parent_span_id` and have overlapping `[start, end]` intervals, they are **concurrent siblings**, not sequential steps — the reconstruction must not linearize them, and any replay must treat their side effects as potentially unordered. - If a child's `parent_span_id` references a span that was exported *before* the child was created (detectable via export timestamps or a monotonic span-generation counter), the link is **stale** — the child belongs to a retry whose parent was re-minted, and the reconstruction must re-anchor to the live parent or mark the subtree orphaned. - If the link lacks an attempt/sequence attribute and the parent has more than one child with the same `gen_ai.operation.name`, the reconstruction must **refuse to assert ordering** and emit an `ambiguous_causality` marker. The invariant: *a reconstructed causal chain is only as strong as its weakest declared edge, and a declared edge is only as strong as its causation token.* No causation token → no authoritative edge → no replayable chain. ## Operational Effect Downstream, this changes three things. First, **replay audits** must gate on the causation-token check before executing side effects; a trace with ambiguous causality must be replayed in *shadow* mode (no writes) or rejected. Second, **cost and latency attribution** computed by summing child spans under a parent double-counts retried attempts — the orchestrator's reported token spend for `S_P` includes both `S_E` attempts, inflating the per-agent budget by the retry multiplier. Third, **incident reconstruction** during a postmortem will show a clean chain where the runtime actually had a race, leading responders to miss the non-idempotent double-write entirely. The guardrail is to make the causation token mandatory at the instrumentation layer: every retry mints a new span, every handoff carries a monotonic `handoff.seq`, and the trace collector rejects any parent edge whose child predates the parent's end. Without that, the trace is a plausible fiction. ```python class CausalityReconstructionError(RuntimeError): """Raised when a declared span link cannot be trusted for causal reconstruction.""" pass def validate_parent_edge(child: dict, parent: dict, siblings: list[dict]) -> None: """ Enforce the four conditions of validity for a declared parent-child span link. Raises CausalityReconstructionError on any violation that makes the edge non-authoritative for causal replay. """ # Condition 2: child must not predate parent's end (causality inversion). if child["start_time"] < parent["end_time"]: raise CausalityReconstructionError( f"causality inversion: child {child['span_id']} started " f"({child['start_time']}) before parent {parent['span_id']} ended " f"({parent['end_time']})" ) # Condition 1: parent must still be open or its end-state recorded at child creation. if parent.get("exported_at") is not None and parent["exported_at"] < child["start_time"]: raise CausalityReconstructionError( f"stale parent: {parent['span_id']} exported at {parent['exported_at']} " f"before child {child['span_id']} created at {child['start_time']}" ) # Condition 3: causation token required when siblings share an operation. same_op_siblings = [ s for s in siblings if s["span_id"] != child["span_id"] and s.get("gen_ai.operation.name") == child.get("gen_ai.operation.name") ] if same_op_siblings and "gen_ai.agent.handoff.seq" not in child.get("attributes", {}): raise CausalityReconstructionError( f"ambiguous causality: child {child['span_id']} shares operation " f"{child.get('gen_ai.operation.name')} with {len(same_op_siblings)} " f"sibling(s) but carries no handoff.seq token; ordering cannot be asserted" ) # Condition 4: trace_id must match across the edge. if child["trace_id"] != parent["trace_id"]: raise CausalityReconstructionError( f"trace_id mutation across handoff: child {child['trace_id']} != " f"parent {parent['trace_id']}" ) def reconstruct_chain(spans: list[dict]) -> list[dict]: """Reconstruct causal chain, validating every declared edge.""" by_id = {s["span_id"]: s for s in spans} children: dict[str, list[dict]] = {} for s in spans: pid = s.get("parent_span_id") if pid: children.setdefault(pid, []).append(s) edges = [] for pid, kids in children.items(): parent = by_id.get(pid) if parent is None: raise CausalityReconstructionError( f"orphaned subtree: parent {pid} not present in trace" ) for kid in kids: validate_parent_edge(kid, parent, kids) edges.append((pid, kid["span_id"])) return edges ```