# What happens when an instance propagates a parent span ID across an agent hop but never emits the corresponding child span **Date of Record:** 2026 November 16 **Scope:** Applies to multi-agent systems instrumented with OpenTelemetry-style GenAI semantic conventions where a span's `parent_span_id` is set before the child span is guaranteed to be exported (e.g., fire-and-forget span creation, async delegation, or handoff to a sub-agent process). Does not apply to single-process synchronous call graphs where span start/end are lexically nested, nor to systems using W3C `traceparent` propagation with a collector-side span assembler that buffers incomplete traces. ## Core Distinction A *trace* is a set of spans that share a `trace_id`. A *causal chain* is an ordered subset of those spans where each span's `parent_span_id` resolves to a span that actually exists in the exported set. These are not the same thing. Observability backends will happily accept a span whose `parent_span_id` points at a span that was never exported, was dropped by sampling, or was exported after the trace was already closed by the backend's retention policy. The trace renders — it just renders as a forest of orphans rather than a tree. The failure is not "missing span." Missing spans are expected under sampling. The failure is **dangling parent references that are indistinguishable from sampled-out parents**, which makes causal reconstruction silently wrong rather than visibly incomplete. ## What Was Observed During a multi-hop agent run (planner → tool-router → retrieval sub-agent → synthesis), the retrieval sub-agent was invoked via an async task queue. The orchestrator created a span for the hop, set `parent_span_id` on the sub-agent's root span to the orchestrator's span ID, and enqueued the work. The orchestrator's span was ended and exported immediately after enqueue. The sub-agent's span was exported on a separate worker, several seconds later, sometimes after the collector had already marked the trace complete. Result: the backend stored the sub-agent span with a `parent_span_id` referencing a span that existed in storage but in a *different trace segment* (the collector's trace assembly had already flushed and rotated). Trace reconstruction queries that joined child→parent by `span_id` found the parent, but the parent's own `parent_span_id` pointed at a planner span that had been sampled out at 10%. The chain broke at the planner hop, not at the sub-agent hop — the *wrong* hop. Engineers spent a day investigating the planner, which was healthy, while the actual causal discontinuity was downstream. The non-obvious part: **the reconstructed chain looked complete from the leaf upward for N hops and then terminated at a plausible-looking root.** There was no orphan flag, no `is_root=true` anomaly, because the terminating span *did* have a `parent_span_id`; it just didn't resolve. Backends that treat unresolvable parents as roots silently promote a mid-chain span to root status. ## Condition of Validity Causal reconstruction across hops is only valid when, for every span S in the chain, one of the following holds and is *recorded on S itself*: 1. `parent_span_id` resolves to an exported span in the same trace, or 2. S carries an explicit `parent_sampled_out=true` (or equivalent) attribute set at span creation, or 3. S is genuinely a root (`parent_span_id` absent, not merely unresolvable). The invariant that must be enforced at instrumentation time: **a span must not be exported with a `parent_span_id` unless the instrumentation layer can guarantee either the parent's export or an explicit sampling/absence marker.** Setting a parent reference and deferring the parent's fate to a separate process violates this. This condition is *not* satisfied by the common pattern of "set parent, export async, hope the collector reassembles." It is satisfied by propagating a `traceparent` header (which carries the `trace_flags` sampled bit) and having the child inherit the sampling decision, so a sampled-out parent is *known* to be sampled out rather than unknown. ## Decision Boundary At reconstruction time, when a span's `parent_span_id` fails to resolve: - If the span carries a sampling marker → treat as a valid chain terminus; the causal edge is *known absent by design*. - If the span carries no marker → **do not promote to root.** Treat the chain as *broken at an unknown point* and surface the trace as `causal_integrity=degraded`. Do not render it as a complete tree. - If the trace spans multiple collector segments (detectable via mismatched `resource.service.name` on adjacent spans or a segment boundary attribute) → require an explicit cross-segment link span before joining. The boundary is between *absent-by-design* and *absent-by-accident*. Collapsing the two is the failure. ## Operational Effect When the invariant is enforced, degraded traces are flagged at write time and the on-call engineer sees "causal chain broken between planner and retrieval (parent not exported, no sampling marker)" instead of a clean-looking tree that misattributes the break to the wrong hop. When it is not enforced, mean-time-to-misdiagnosis roughly doubles because the reconstruction is confidently wrong. The fix is cheap — a boolean attribute and a header — but it must be applied at span creation, not at query time, because by query time the information needed to distinguish the two cases has already been discarded. The following guard should run in the instrumentation layer before any span is exported with a parent reference. ```python class DanglingParentError(RuntimeError): """Raised when a span is about to be exported with an unresolvable, unmarked parent reference, which would corrupt causal reconstruction.""" pass def validate_span_for_export(span, known_exported_span_ids, sampled_out_span_ids): """ span: dict with keys span_id, trace_id, parent_span_id (may be None), attributes (dict). known_exported_span_ids: set of span_ids already confirmed exported in this trace segment. sampled_out_span_ids: set of span_ids known to have been dropped by the sampler (carried via traceparent trace_flags). """ parent = span.get("parent_span_id") if parent is None: return # genuine root if parent in known_exported_span_ids: return # resolves within segment if parent in sampled_out_span_ids: # Absent by design: record the marker so reconstruction treats this # as a valid terminus rather than a dangling edge. span["attributes"]["parent_sampled_out"] = True return # Parent is neither exported nor known-sampled-out. The span must not be # exported with a live parent reference; doing so silently promotes a # mid-chain span to root at query time. raise DanglingParentError( f"span {span['span_id']} in trace {span['trace_id']} references " f"parent {parent} that is neither exported nor marked sampled-out; " f"refusing export to preserve causal integrity" ) ```