# Why does an instance-local span parent pointer survive federation export but silently re-root the reconstructed agent graph? **Date of Record:** 2026 November 29 **Scope:** Applies to multi-instance agent systems where each LLM instance emits OpenTelemetry GenAI spans (`gen_ai.*` semantic conventions) into a local collector, and a federation layer merges those span sets into a cross-instance trace graph. Does not apply to single-process, single-collector deployments where `parentSpanId` is never rewritten in transit. ## Core Distinction A span's `parentSpanId` is a *local* pointer into one instance's span table. A federation merge treats it as a *global* pointer. These are not the same object. The local pointer is valid only within the emitting instance's trace context; once spans from multiple instances are concatenated into one trace, the same `parentSpanId` string resolves against a union span table in which the original parent may be absent, renamed, or shadowed by a colliding ID from another instance. The distinction that matters operationally: **the parent pointer is a reference into a namespace, not a fact about causality.** When two instances independently mint span IDs (e.g., each seeded its RNG from its own clock), the probability of a 64-bit collision is negligible, but the probability that a *dangling* parent pointer exists is not — because each instance only emits spans for work it performed, and the parent of a cross-instance handoff span was performed by a *different* instance whose span may never have been exported (sampled out, dropped by backpressure, or lost on crash). The invariant that federation actually needs is not "every span has a resolvable parent." It is: **every span either has a resolvable parent within the merged set, or is explicitly marked as a federation boundary root with a `gen_ai.agent.handoff.from_instance` attribute.** A span that has neither is a re-rooted orphan, and the reconstruction algorithm will silently promote it to a root, corrupting the agent graph topology. ## What Was Observed A three-instance planner/executor/auditor pipeline. The executor instance (E) received a task from planner (P) via an A2A handoff, ran three tool calls, then handed to auditor (A). E's collector was configured with `parentbased_traceidratio` sampling at 0.5. The handoff span `executor.handoff.in` was sampled in; its parent — P's `planner.dispatch` span — was sampled *out* on P's side (a different sampling decision, because sampling is per-instance and the trace-id-ratio seed was computed against each instance's local `TraceIdRatioBased` sampler instance, not shared). On export, E emitted: - `executor.handoff.in` with `parentSpanId = ` and no root marker (E believed it had a parent). - Three tool spans, each parented correctly to `executor.handoff.in`. P emitted nothing for the dispatch (sampled out). A emitted its own spans parented to `executor.handoff.out`. The federation merger concatenated the three span sets. `executor.handoff.in`'s `parentSpanId` resolved to *nothing* in the merged set. The merger's reconstruction pass — a standard "build parent→children map, roots = spans whose parent is absent" — promoted `executor.handoff.in` to a **root**. The reconstructed graph now showed the executor handoff as an independent root, not as a child of the planner dispatch. Downstream, the auditor's spans appeared as a separate root too, because `executor.handoff.out`'s parent chain was intact but its *grandparent* (the planner) was gone. The reconstructed graph had three roots where the ground truth had one. Any topology-aware analysis — critical-path latency, fan-out detection, "did the planner's reasoning reach the executor" — was wrong. Worse, the graph *looked* well-formed: every non-root span had a parent, every span was reachable, no cycle. The corruption was invisible to structural validation because re-rooting produces a *valid* forest, just not the *correct* tree. ## Condition of Validity The failure is bounded by a single condition, and it is checkable at export time: > A span S with `parentSpanId = p` is a *federation-valid child* only if `p` is present in the merged span set **and** the emitting instance of `p` equals the emitting instance named in S's `gen_ai.agent.handoff.from_instance` (or S carries no handoff attribute, meaning intra-instance parenting). Otherwise S must be emitted with `gen_ai.agent.federation_boundary = true` and `gen_ai.agent.handoff.from_instance` set. The subtlety: the emitter cannot know at emit time whether `p` will survive sampling *on the other instance*. So the guardrail cannot be enforced purely at emit time by the child. It must be enforced at *merge* time by the federation layer, which is the only party that sees both the child and the absence of the parent. The merge-time check is: for each span whose `parentSpanId` is absent from the merged set, require the `federation_boundary` marker; if absent, the span is a **dangling-parent orphan** and must be quarantined, not re-rooted. The second, less obvious condition: sampling decisions must be *trace-id-consistent across instances*. If each instance runs its own `TraceIdRatioBased` sampler with the same ratio but different internal state, the same trace gets different decisions on different instances, and *every* cross-instance edge becomes a candidate dangling parent. The fix is not a bigger sample rate; it is a sampler that hashes the trace ID deterministically (the W3C `traceidratio` sampler does this correctly only if the ratio threshold is identical and the hash function is identical — a `TraceState`-propagated `th` threshold is required when instances disagree on ratio). ## Decision Boundary The decision boundary is: **do you trust `parentSpanId` as causality, or do you trust the handoff attributes as causality?** - If you trust `parentSpanId` alone, you inherit re-rooting on any sampling asymmetry, any collector drop, any crash mid-trace. The graph is structurally valid and causally wrong. - If you trust handoff attributes alone, you reconstruct causality from the A2A/MCP handoff records (which carry `from_instance`, `to_instance`, `handoff_id`), and treat `parentSpanId` as a *hint* that must be cross-checked. This is more robust but requires every handoff to emit a handoff span on both sides — which means the handoff span itself must be exempt from sampling (always-on), or the boundary record is lost. The operational rule: **handoff spans are always sampled, regardless of ratio.** They are the only spans whose loss breaks federation topology. Everything else can be sampled. This is a one-line collector filter (`filter/handoff` with `keep` on `gen_ai.agent.handoff.*`) and it eliminates the dangling-parent class entirely for the handoff edge, at the cost of a small fixed span volume proportional to handoff count, not token count. ## Operational Effect Without the guardrail: reconstructed agent graphs show *more roots than agents*. A three-agent pipeline looks like three independent trees. Latency attribution double-counts because the critical path is split across roots. Fan-out detection misses cross-agent fan-out (planner dispatching to two executors looks like two roots, not one fan-out). Auditor consensus checks that walk the graph from root find only the auditor's subtree and conclude "no upstream disagreement" — a false negative on the exact verification the auditor exists to perform. With the guardrail: dangling-parent spans are quarantined into a `federation_orphans` bucket with their claimed `parentSpanId` and `from_instance`. The reconstruction either (a) resolves the orphan via the handoff span on the parent side, if it survived, or (b) marks the orphan as a *known* boundary root with an explicit `federation_boundary=true`, which downstream analysis treats as "causality truncated here" rather than "causality begins here." The distinction between *truncated* and *begins* is the entire point: a truncated root is a data-quality fact; a begins-root is a false causal claim. The invariant to enforce in code: **no span enters the merged graph as a root unless it has no `parentSpanId`, or it has `federation_boundary=true`.** Any span with a non-empty `parentSpanId` that resolves to nothing is an error, not a root. This is the check the merger must run before reconstruction, and it is the check that was missing. ```python from dataclasses import dataclass, field from typing import Optional class DanglingParentError(RuntimeError): """Raised when a span claims a parent that is absent from the merged set and carries no federation-boundary marker. Re-rooting such a span would produce a structurally valid but causally false agent graph.""" pass @dataclass class Span: span_id: str parent_span_id: Optional[str] name: str instance: str attributes: dict = field(default_factory=dict) def reconstruct_agent_graph(spans: list[Span]) -> dict[str, list[str]]: """Build parent->children adjacency for the merged federation span set. Invariant: a span with a non-empty parent_span_id MUST resolve within the merged set, OR carry gen_ai.agent.federation_boundary=true. Otherwise it is a dangling-parent orphan and reconstruction must abort rather than re-root. """ by_id = {s.span_id: s for s in spans} children: dict[str, list[str]] = {} roots: list[str] = [] for s in spans: if not s.parent_span_id: roots.append(s.span_id) continue parent = by_id.get(s.parent_span_id) if parent is None: is_boundary = s.attributes.get("gen_ai.agent.federation_boundary") is True from_instance = s.attributes.get("gen_ai.agent.handoff.from_instance") if not is_boundary: raise DanglingParentError( f"span {s.span_id!r} ({s.name}) on instance {s.instance!r} " f"claims parent {s.parent_span_id!r} absent from merged set; " f"no federation_boundary marker, from_instance={from_instance!r}. " f"Refusing to re-root: this would fabricate a causal root." ) # Explicit boundary root: causality truncated, not begun. roots.append(s.span_id) continue # Cross-instance edge sanity: if a handoff attribute names a source # instance, the resolved parent must belong to that instance. declared_from = s.attributes.get("gen_ai.agent.handoff.from_instance") if declared_from is not None and parent.instance != declared_from: raise DanglingParentError( f"span {s.span_id!r} declares handoff from {declared_from!r} " f"but resolved parent {parent.span_id!r} lives on " f"{parent.instance!r}; federation edge is inconsistent." ) children.setdefault(s.parent_span_id, []).append(s.span_id) return {"roots": roots, "children": children} def merge_federation(batches: list[list[Span]]) -> dict[str, list[str]]: merged: list[Span] = [s for batch in batches for s in batch] return reconstruct_agent_graph(merged) ```