# Where must an instance reconcile span-parentage before correlation, not after: the orphaned-tool-span amplification failure in LLM observability pipelines **Date of Record:** 2026 November 29 **Scope:** Applies to any observability pipeline that ingests LLM/tool spans from an instrumented agent runtime and joins them into orchestration traces via parent-span identifiers, where span export is asynchronous and the orchestrator and LLM SDK are instrumented independently. Does not apply to single-process, synchronous, in-band tracers where span closure and export are atomic with the parent's lifetime. ## Core Distinction The distinction that governs this failure is between **span correlation** (joining a child span to its parent by ID) and **span parentage validity** (whether the referenced parent still exists in the trace store at join time, and whether the join is performed on the correct trace identity). Most pipelines treat these as the same operation: they store `parent_span_id` on every span at emit time and resolve the tree at query time. That is fine when the parent is guaranteed to be exported before or with the child. It is not fine when the parent span is dropped, delayed, or rewritten by a *second* instrumentation layer that owns the orchestration trace, because the child's `parent_span_id` then points at an identifier that will never resolve—or resolves to a *different* trace under ID reuse. The non-obvious part: the failure is silent. The orphaned child spans do not error. They are simply reparented to the trace root by most correlation engines, which inflates the root span's apparent duration, tool-call count, and token cost, and corrupts every downstream aggregate that treats "spans under trace X" as "work done by agent run X." The corruption is *amplifying*: one lost parent span can reparent an unbounded number of tool spans, and the reparented spans are attributed to whichever trace owns the surviving root—often a concurrent run. ## What Was Observed A multi-agent orchestrator emitted an orchestration span (`orch.run`, one per agent run) from its own tracer, and each LLM call and tool invocation emitted child spans from an independently-instrumented SDK. The two instrumentation layers used different trace-ID generators and a shared span-ID namespace that was *not* globally unique—it was a per-process monotonic counter. Under concurrent runs across worker processes, span IDs collided across processes. The failure trace: 1. Worker A starts run `orch.run#A`. Its tracer assigns root span ID `0x1f`. 2. Worker B starts run `orch.run#B` concurrently. Its tracer also assigns root span ID `0x1f` (same counter, different process). 3. Worker A's LLM SDK emits a tool span with `parent_span_id = 0x1f`, `trace_id = T_A`. 4. Worker A's orchestration span is dropped by the exporter's sampling policy (tail-sampling decided the run was "uninteresting" because it had no errors at decision time, before the tool span arrived). 5. The tool span is exported and stored with `parent_span_id = 0x1f`, `trace_id = T_A`. 6. At query time, the correlation engine resolves `0x1f` against the *global* span index, which returns the surviving `orch.run#B` span (same ID, `trace_id = T_B`), because `#A`'s copy was never stored. 7. The tool span is joined under trace `T_B`. Run B's root span now reports a tool invocation it never made, with latency attributed to B's wall clock, and B's token cost is inflated by A's LLM call. Observed symptoms, in order of detection: - Root-span duration for run B exceeded the sum of its children by a factor that grew with A's concurrency. - Token-cost-per-run aggregates drifted upward monotonically over the day, never down, because dropped-parent events accumulated and reparented spans accumulated under surviving roots. - A "tool call count" dashboard showed runs with tool counts exceeding the orchestrator's own hard cap, which is what finally triggered investigation. - Replaying the same agent workload produced different trace trees, because sampling decisions (and thus which parents survived) were non-deterministic. The invariant that was violated: **a child span's parent reference must resolve within the same trace identity, or the child must be quarantined—never reparented to a same-ID span in a different trace.** ## Condition of Validity The correlation-by-ID approach is valid only under the conjunction: - Span IDs are globally unique across all processes and instrumentation layers (e.g., 128-bit random, not per-process counters). - The parent span is guaranteed to be exported and accepted before any child references it (causal export ordering), *or* the correlation engine treats an unresolved parent as a hard quarantine rather than a reparent-to-root fallback. - Tail-sampling decisions are made only after the run's span set is complete, or the sampler is aware that dropping a parent orphans its children. When any conjunct fails—and in practice at least one fails in every independently-instrumented multi-agent deployment—the pipeline will silently misattribute work. The condition is *especially* likely to be violated under concurrency, because concurrency is exactly what creates ID-collision windows and interleaves sampling decisions with span arrival. ## Decision Boundary The boundary is not "should we correlate by ID"—that is the only scalable option. The boundary is **where parentage reconciliation happens**: at ingest (before correlation) or at query (after correlation). - **Query-time reconciliation** (the common default) resolves parentage lazily. It cannot distinguish "parent not yet arrived" from "parent never will arrive," so it must choose a fallback, and the only available fallback is reparent-to-root or reparent-to-same-ID, both of which corrupt attribution. - **Ingest-time reconciliation** requires the pipeline to hold child spans in a bounded pending buffer keyed by `(trace_id, parent_span_id)` until either the parent arrives or a deadline passes. On deadline expiry with no parent, the child is marked `orphaned` and either dropped or attributed to a synthetic `unresolved-parent` root that is *not* any real run. The decision rule: if the pipeline serves any cost, latency, or tool-count aggregate per agent run, reconciliation MUST be at ingest with a hard deadline and explicit orphan marking. Query-time reparenting is acceptable only for exploratory trace viewing where no aggregate depends on parentage. The deadline is the load-bearing parameter. It must be bounded by the exporter's maximum delivery delay plus clock skew allowance; setting it to "infinity" (unbounded pending buffer) trades corruption for memory exhaustion under sustained parent loss. ## Operational Effect With ingest-time reconciliation and orphan quarantine: - Orphaned tool spans are counted separately and become a first-class signal: a rising orphan rate is the *observable* of parent-span loss, which previously was invisible. - Per-run cost and latency aggregates are bounded by the run's own spans; a lost parent can only *under*-count a run (its orphaned children are excluded), never over-count a concurrent run. - Trace replay becomes deterministic for a fixed span set, because parentage resolution no longer depends on arrival order or sampling timing. - The cost is a bounded pending buffer and a deliberate latency floor on trace visibility equal to the reconciliation deadline—trace trees for a run are not queryable until its parentage is settled. The failure mode without this is not "missing data." It is *fabricated data*: spans attributed to runs that did not produce them, with the fabrication rate scaling with concurrency and parent-drop rate. An agent system whose run-level cost accounting is built on such a pipeline will systematically misprice concurrent workloads, and the error is one-directional (inflation under surviving roots), so it will not average out. ```python import time from dataclasses import dataclass, field from typing import Optional class UnresolvedParentError(RuntimeError): """Raised when a child span's parent cannot be resolved within the same trace identity before the reconciliation deadline expires.""" pass @dataclass class Span: trace_id: str span_id: str parent_span_id: Optional[str] name: str emitted_at: float = field(default_factory=time.monotonic) class IngestReconciler: """Holds child spans pending parent arrival, keyed by (trace_id, parent_span_id). Never reparents across trace identities. Quarantines on deadline expiry.""" def __init__(self, deadline_s: float = 30.0): self.deadline_s = deadline_s self._pending: dict[tuple[str, str], list[Span]] = {} self.orphans: list[Span] = [] self.resolved: list[Span] = [] def ingest(self, span: Span) -> None: if span.parent_span_id is None: # Root span: resolve any children that were waiting on it. self._resolve_children(span) self.resolved.append(span) return key = (span.trace_id, span.span_id) # This span may itself be a parent awaited by others; resolve those. self._resolve_children(span) # Now this span waits on its own parent. self._pending.setdefault((span.trace_id, span.parent_span_id), []).append(span) self._sweep(now=span.emitted_at) def _resolve_children(self, parent: Span) -> None: waiting = self._pending.pop((parent.trace_id, parent.span_id), []) self.resolved.extend(waiting) def _sweep(self, now: float) -> None: expired = [ k for k, children in self._pending.items() if children and (now - children[0].emitted_at) > self.deadline_s ] for k in expired: self.orphans.extend(self._pending.pop(k)) def finalize(self) -> None: """At shutdown, any still-pending child is an unresolved parentage: quarantine it rather than letting a query-time join reparent it.""" for key, children in self._pending.items(): trace_id, parent_id = key for child in children: if child.trace_id != trace_id: raise UnresolvedParentError( f"cross-trace parentage: child {child.span_id} " f"in trace {child.trace_id} references parent " f"{parent_id} in trace {trace_id}" ) self.orphans.extend(children) self._pending.clear() def assert_no_cross_trace_join(self, child: Span, resolved_parent: Span) -> None: if child.trace_id != resolved_parent.trace_id: raise UnresolvedParentError( f"refusing to join child {child.span_id} (trace {child.trace_id}) " f"to parent {resolved_parent.span_id} (trace {resolved_parent.trace_id}); " f"same-ID collision across traces" ) ```