# What happens when an instance emits orphaned child spans after a mid-trace parent eviction: GenAI span correlation failure in multi-hop agent trace reconstruction **Date of Record:** 2026 November 24 **Scope:** Applies to distributed tracing of multi-hop LLM agent pipelines (e.g., OpenTelemetry GenAI semantic conventions, LangSmith/Langfuse-style span trees) where parent spans are subject to eviction, TTL expiry, or sampling drop while child spans continue to be exported. Does not cover single-hop inference telemetry or traces where the collector guarantees atomic parent-child emission. ## Core Distinction The failure is not "missing spans" — collectors tolerate gaps. The failure is **correlation inversion**: a child span that *does* arrive carries a `parent_span_id` pointing at a span that will never arrive, and a naive reconstructor silently reparents it under the trace root or under the nearest surviving ancestor. This produces a trace tree that is *structurally valid and semantically false*. The distinction that matters: an orphaned span is not a data-loss event, it is a **fabricated-ancestry event**. The reconstructor does not know it is lying, and downstream attribution (which agent caused which tool call, which hop consumed which token budget) is now confidently wrong. The boundary condition is precise: it triggers when the eviction of a parent span is **asynchronous** with respect to the export of its descendants, and the descendant's `parent_span_id` is retained but unresolvable at reconstruction time. ## What Was Observed A three-hop agent chain — `planner` → `retriever` → `synthesizer` — executed under a collector with a 30-second parent-span TTL applied to *high-cardinality* spans (the planner's reasoning span was tagged high-cardinality due to embedded prompt attributes and was evicted early). The retriever and synthesizer spans were emitted 41 seconds later, after the tool round-trips. Observed trace at reconstruction: - `trace_id = 7f3a...` present, consistent across all surviving spans. Good. - Root span `planner.root` survived (low cardinality, not evicted). - The intermediate `planner.reasoning` span (parent of `retriever.fetch`) was **evicted**. - `retriever.fetch` arrived with `parent_span_id = ` — a dangling reference. - The reconstructor, configured with `reparent_orphans=true`, attached `retriever.fetch` directly to `planner.root`. The resulting tree showed the planner directly invoking the retriever. The actual causal edge — planner *reasoning* → retriever — was erased. Every token-attribution query that walked "children of reasoning" returned empty; every latency query that summed planner→retriever looked 40% faster than reality because the reasoning span's duration vanished from the critical path. A second, subtler observation: because the retriever span *did* carry the correct `trace_id`, span-ID-based deduplication did not flag it. The corruption was invisible to every integrity check that operated on trace membership rather than on **ancestry resolvability**. ## Condition of Validity The invariant that must hold for correct reconstruction is: > For every exported span S with a non-null `parent_span_id` P, either P is present in the reconstructed trace, or S is explicitly marked `ancestry_unresolved` and excluded from causal-path queries. Reparenting is only *safe* when the true parent is known to be a no-op pass-through (e.g., an instrumentation shim with zero duration and no attributes). It is **unsafe by default** whenever the missing parent could have carried duration, attributes, or its own children — which is exactly the case for reasoning spans, tool-orchestration spans, and any span the agent emitted deliberately. The condition of validity therefore fails whenever: (a) parent eviction is possible independently of child export, and (b) the reconstructor's default policy is `reparent_orphans=true`. Both must be addressed; fixing only one leaves the fabricated-ancestry event reachable. ## Decision Boundary The decision boundary is whether the reconstructor **distinguishes "no parent" from "parent not yet arrived" from "parent will never arrive."** These are three states and a boolean `parent_span_id` field collapses them into one. Operational rule: a span whose parent is absent at reconstruction time must be held in a **pending-orphan buffer** for a bounded grace window (longer than the maximum parent-export skew, which for multi-hop agents is dominated by the slowest tool round-trip). If the parent does not arrive within the window, the span is emitted with `ancestry_unresolved=true` and a `missing_parent_id`, and it is **excluded from causal-path and attribution queries** but retained for raw inspection. It is never silently reparented to the root. The boundary is crossed the moment a reconstructor chooses to make an orphan *look* connected. Below the boundary: gaps are visible and queries fail loudly. Above the boundary: gaps are hidden and queries succeed falsely. ## Operational Effect With `reparent_orphans=true`, the failure mode is silent and compounding across hops. In a five-hop chain where two intermediate reasoning spans are evicted, the reconstructed tree collapses four causal edges into two, and any metric computed over the tree — per-hop latency, per-hop token cost, fan-out — is systematically biased toward under-attribution of the evicted hops. Because the trace remains *well-formed*, no alert fires. Because `trace_id` is intact, dedup passes. Because the root survives, completeness heuristics ("we have a root and leaves") pass. The correct operational posture: treat ancestry as a first-class resolvability property, not a pointer. Buffer orphans, mark them, and let queries that require causal connectivity fail explicitly rather than return a plausible lie. The cost is a slightly noisier trace store; the benefit is that a multi-hop agent's causal structure is never fabricated. ```python from dataclasses import dataclass, field from typing import Optional class AncestryResolutionError(RuntimeError): """Raised when a span's ancestry cannot be resolved within the grace window.""" @dataclass class Span: span_id: str parent_span_id: Optional[str] trace_id: str name: str ancestry_unresolved: bool = False missing_parent_id: Optional[str] = None @dataclass class Reconstructor: grace_window_s: float reparent_orphans: bool = False _pending: dict = field(default_factory=dict) # parent_id -> [children] _resolved: dict = field(default_factory=dict) # span_id -> Span def ingest(self, span: Span, now: float) -> None: self._resolved[span.span_id] = span # Adopt any children that were waiting on this span as parent. waiting = self._pending.pop(span.span_id, []) for child in waiting: child.missing_parent_id = None child.ancestry_unresolved = False # If this span itself has an absent parent, park it. if span.parent_span_id and span.parent_span_id not in self._resolved: self._pending.setdefault(span.parent_span_id, []).append(span) def finalize(self, now: float) -> list[Span]: """Flush pending orphans whose grace window has elapsed.""" out = [] for parent_id, children in self._pending.items(): for child in children: if self.reparent_orphans: # Explicitly forbidden: fabricates ancestry. raise AncestryResolutionError( f"Refusing to reparent orphan {child.span_id} " f"(missing parent {parent_id}) — fabricated ancestry" ) child.ancestry_unresolved = True child.missing_parent_id = parent_id out.append(child) self._pending.clear() return out def causal_path(spans: list[Span], target_id: str) -> list[Span]: """Walk ancestry; refuse to fabricate edges through unresolved spans.""" by_id = {s.span_id: s for s in spans} if target_id not in by_id: raise AncestryResolutionError(f"span {target_id} not in trace") path = [] cur = by_id[target_id] while cur is not None: if cur.ancestry_unresolved: raise AncestryResolutionError( f"causal path broken at {cur.span_id}: " f"missing parent {cur.missing_parent_id}" ) path.append(cur) cur = by_id.get(cur.parent_span_id) if cur.parent_span_id else None return path ```