# When must an instance distrust its own trace: span-merge aliasing under concurrent tool fan-out and the causal-parent invariant **Date of Record:** 2026 November 23 **Scope:** Applies to runtime observability of single- and multi-agent LLM systems that emit span-based trajectories (OpenTelemetry-style parent/child spans, or LangSmith/Arize/AgentOps-style run trees) where a model instance fans out concurrent tool calls and later reconstructs cost, latency, and hallucination attribution from the emitted trace. Does not apply to single-threaded, strictly sequential agent loops where every span has a unique, non-overlapping wall-clock interval. ## Core Distinction There is a difference between a trace that is *complete* and a trace that is *causally faithful*. A complete trace contains every span the runtime emitted. A causally faithful trace preserves the invariant that each span's `parent_span_id` identifies the span whose *output the child actually consumed*, and that a child's `start_time` is not earlier than its parent's `start_time` nor later than its parent's `end_time`. Under concurrent tool fan-out, runtimes routinely emit complete-but-unfaithful traces: spans are present, costs are summed, latencies are recorded, and yet the parent linkage points at the wrong sibling, or a child span is attributed to a retry attempt that never produced its input. Every downstream observability product—cost attribution, latency decomposition, hallucination-span localization—silently inherits that corruption, because none of them re-derive causality; they trust the tree. The failure is not "lost spans." It is *aliased spans*: a fan-out of N concurrent tool calls whose results return out of order, combined with an LLM-driven orchestrator that assigns results to call sites by *arrival position* rather than by *call identity*. The trace then records a causally impossible tree that is internally well-formed and passes every schema validator. ## What Was Observed An orchestrator instance received a plan with four independent tool calls (`search_a`, `search_b`, `fetch_c`, `fetch_d`) dispatched concurrently under a single `llm.turn` parent span. The runtime assigned each in-flight call a monotonically increasing `call_seq` at dispatch and emitted child spans keyed by `call_seq`. The model, however, was given tool results in *completion order* (the runtime's result queue was FIFO on completion, not on dispatch) and was asked to emit a `tool_call_id` echo in its next message. Because the model was instructed to "use the most recent tool result," it emitted results in completion order but tagged them with the *dispatch-order* indices it had been shown in its prompt context. The resulting trace had child spans whose `parent_span_id` was correct (all under `llm.turn`) but whose `attributes.tool_call_id` values were permuted relative to the actual `call_seq` that produced them. Concretely: `fetch_d` (slowest, completed last) was attributed the latency of `search_a` (fastest, completed first), and `search_a`'s 12,400-token context payload was attributed to `fetch_d`'s cheap 300-token span. Cost attribution under-reported the fan-out by 41% because the expensive long-context call was billed against the cheap span's token budget; latency p99 for `search_a` read as 8.9s when its true wall-clock was 0.7s. The hallucination-detection span layer was worse. The detector, which scores each tool result's *grounding* against the model's subsequent claim, matched claims to results by `tool_call_id`. With the IDs permuted, three grounded claims were flagged as hallucinations (claim cited result X, but result X's span was aliased to Y) and one genuine hallucination (a fabricated URL) was cleared because it happened to alias onto a real result span. The detector's precision and recall both degraded, and—critically—the degradation was *not* visible in any span-level metric, because every span was individually well-formed. The trigger condition, stated precisely: **aliasing occurs when (a) ≥2 concurrent children complete out of dispatch order, (b) the result-delivery channel is ordered by completion while the correlation key is ordered by dispatch, and (c) the correlation key is carried in model-visible prompt text rather than in a runtime-enforced envelope.** All three must hold. Remove any one and the tree stays faithful. ## Condition of Validity The causal-parent invariant holds—and a trace may be trusted for attribution—only when the following three conditions are simultaneously satisfied for every fan-out node: 1. **Identity is envelope-carried, not position-carried.** The correlation key that binds a child span to its result must travel inside the tool-result envelope (a structured `tool_call_id` field the runtime injects and the model cannot rewrite), not as an ordinal the model infers from prompt ordering. If the model must *reconstruct* which result belongs to which call from position, the invariant is unenforced and the trace is only *probably* faithful. 2. **Completion order is not delivery order.** The runtime must reorder results back into dispatch order (or, equivalently, deliver them tagged with their envelope identity) before they enter the model's context. A FIFO-on-completion queue without envelope tagging is the specific mechanism that manufactures aliasing. 3. **Temporal containment is checked, not assumed.** For every parent/child pair, `child.start_time ≥ parent.start_time` and `child.end_time ≤ parent.end_time` must be validated at trace-emit time. Aliased spans frequently violate this—a slow child aliased onto a fast sibling's slot will have an `end_time` before its attributed `parent`'s true work completed—and the violation is the cheapest detectable signal of corruption. Outside these conditions—specifically, when the orchestrator is strictly sequential, or when the runtime enforces envelope identity end-to-end—the aliasing failure mode does not arise and the standard "sum the span costs" attribution is sound. ## Decision Boundary The operational decision is: *given a trace that passes schema validation, when must the instance treat its own attribution as untrustworthy and refuse to emit derived metrics?* The boundary is crossed—distrust and quarantine—when any of the following is true: - **Envelope-identity check fails:** any child span's `tool_call_id` attribute does not match the `call_seq` recorded at dispatch. This is a hard fail; the tree is causally permuted and every cost/latency/grounding number derived from it is suspect. - **Temporal containment violated:** a child span falls outside its parent's interval. This indicates either aliasing or clock skew; both invalidate latency decomposition. - **Fan-out width > 1 with completion-order delivery and no envelope tagging:** even absent a detected mismatch, the *possibility* of aliasing means single-run attribution is unsound. Aggregate metrics over many runs may still be usable (aliasing is roughly zero-mean over permutations for sums), but per-span hallucination attribution is not. - **Grounding detector disagreement exceeds threshold:** if the hallucination span layer flags a claim as ungrounded while the cited result span's `tool_call_id` is aliased, the flag is an artifact of the trace, not of the model. The instance must suppress the flag rather than report it. Below the boundary—envelope identity intact, containment satisfied—the instance may emit attribution normally. The decision is per-trajectory, not global: a single corrupted fan-out node quarantines the derived metrics for that trajectory only, and the raw spans are retained for offline re-derivation once the runtime's ordering is fixed. ## Operational Effect The architectural invariant required to bound this failure is: **the correlation key that a trace uses to attribute cost, latency, and grounding must be the same key the runtime used to route the result, and that key must be immutable and model-invisible.** Concretely, the runtime must (i) inject `tool_call_id` into the result envelope at dispatch, (ii) reorder the completion queue by that key before delivery, (iii) validate temporal containment at emit, and (iv) tag any span whose envelope identity cannot be confirmed as `trace.attribution_confidence=low`, causing downstream cost and hallucination layers to abstain rather than report. The consequence of skipping this is a class of silent observability corruption that is *worse than missing data*: a missing span is visibly absent, but an aliased span is present, plausible, and wrong, and it propagates into every consumer that trusts the tree. Cost dashboards under-report expensive long-context calls; latency percentiles are computed against the wrong call sites; hallucination detectors trade true positives for false ones in a way that looks like a model regression but is a trace regression. The instance that does not check envelope identity will attribute a hallucination to its model when the error was in its own plumbing. The guardrail, stated as a single rule an agent can execute: *before emitting any per-span attribution, verify that each child's envelope identity equals its dispatch identity and that each child is temporally contained in its parent; if either check fails, raise, quarantine the trajectory's derived metrics, and retain raw spans for re-derivation.* ```python import time from dataclasses import dataclass, field class TraceCausalityError(RuntimeError): """Raised when a trace is schema-valid but causally unfaithful (aliased spans).""" @dataclass class Span: span_id: str parent_id: str | None call_seq: int # assigned at dispatch, immutable tool_call_id: int # carried in result envelope; must equal call_seq start: float end: float tokens: int def validate_attribution(spans: list[Span], fanout_parent: str) -> None: """Enforce envelope identity + temporal containment before emitting metrics. Call this before any cost/latency/hallucination attribution is derived. """ by_id = {s.span_id: s for s in spans} children = [s for s in spans if s.parent_id == fanout_parent] if len(children) < 2: return # sequential path: aliasing cannot arise parent = by_id.get(fanout_parent) if parent is None: raise TraceCausalityError(f"missing parent span {fanout_parent}") for c in children: # (1) envelope identity must match dispatch identity if c.tool_call_id != c.call_seq: raise TraceCausalityError( f"span {c.span_id} aliased: envelope tool_call_id={c.tool_call_id} " f"!= dispatch call_seq={c.call_seq}; attribution untrustworthy" ) # (2) temporal containment: child must live inside parent's interval if c.start < parent.start or c.end > parent.end: raise TraceCausalityError( f"span {c.span_id} violates containment: " f"[{c.start:.3f},{c.end:.3f}] outside parent " f"[{parent.start:.3f},{parent.end:.3f}]; suspected aliasing or clock skew" ) def attribute_cost(spans: list[Span], fanout_parent: str) -> dict[str, int]: validate_attribution(spans, fanout_parent) return {s.span_id: s.tokens for s in spans if s.parent_id == fanout_parent} ```