# In what scenarios must an instance treat a causal trace as un-joinable when a sub-agent re-emits an inherited span ID under a fresh trace context **Date of Record:** 2026 November 24 **Scope:** Applies to agent runtimes that reconstruct causal chains by joining OpenTelemetry-style span/trace identifiers across tool calls, sub-agent handoffs, and MCP transport boundaries. Does not apply to single-process, single-trace agents whose spans are never serialized out of the originating trace context. ## Core Distinction A causal trace is not a log stream. It is a *partial order* over spans, and the join that reconstructs that order is only valid if span identity is globally unique and trace context is monotonically propagated. The failure mode that breaks this is subtle: a sub-agent, when invoked over a transport that does not carry the W3C `traceparent` header (an MCP `tools/call` that omits it, an A2A task envelope that strips it, a shell-out to a fresh process), will often **synthesize a new trace context** while re-emitting the *parent's* span ID as its own `parent_span_id`. The result is a span whose `trace_id` says "new causal root" but whose `parent_span_id` says "child of a span in a different trace." Naive reconstruction joins on `parent_span_id` alone and produces a cycle or a cross-trace edge that never existed. The invariant that must hold is: **a span may only be joined to a parent whose `trace_id` equals the child's `trace_id`.** When a sub-agent re-parents under a fresh trace, the causal edge is *semantically real but structurally un-joinable*, and the reconstructor must treat it as a boundary, not silently stitch it. ## What Was Observed A planner agent (trace `T_a`) dispatched three parallel research sub-agents over an MCP server. The MCP client wrapper serialized each `tools/call` with a JSON body but the server's SDK did not forward `traceparent`. Each sub-agent, running in its own process, initialized a fresh tracer and set `parent_span_id` to the span ID it received in its task payload — the planner's `dispatch` span ID, which belonged to `T_a`. Each sub-agent then generated a *new* `trace_id` (`T_b`, `T_c`, `T_d`) and emitted its tool spans under those. Reconstruction proceeded by loading all spans into a graph keyed by `span_id`, then adding an edge `child.parent_span_id -> child.span_id` whenever both endpoints resolved. Because the `dispatch` span ID existed exactly once (in `T_a`) and was referenced as parent by three spans in `T_b/T_c/T_d`, the join succeeded structurally — the graph had no dangling reference. But the resulting tree placed `T_b`'s spans as children of `T_a`'s `dispatch`, and when a fourth sub-agent emitted a span that reused a span ID generated earlier in `T_b` (the sub-agents shared a seeded ID generator initialized from the same task hash), the graph acquired a node with **two distinct parents** and, on the second reconstruction pass, a cycle. The trace viewer hung; the alerting pipeline that computed "spans per root trace" double-counted and paged on a phantom latency regression. The tell was not an error. It was a *silent structural lie*: the reconstructed tree looked complete, every edge resolved, and the only anomaly was that three distinct `trace_id` roots shared one parent node — a condition the schema permitted but the causal model forbids. ## Condition of Validity Cross-trace re-parenting is a legitimate, recoverable boundary only under all of the following: 1. The child span carries an explicit **causal link attribute** (`link.trace_id`, `link.span_id`) distinct from `parent_span_id`, marking the edge as a *link* rather than a *parent*. OpenTelemetry's `Link` exists precisely for this; a sub-agent that spans a trace boundary must emit a link, not a parent reference. 2. The reconstructor treats `parent_span_id` as authoritative **only within the same `trace_id`**, and treats any cross-trace `parent_span_id` as a malformed edge to be demoted to a link or quarantined. 3. Span IDs are globally unique — either 128-bit random or namespaced by the emitting process identity. A seeded or hash-derived ID generator shared across sub-agents violates this and is the proximate cause of the collision above. When any of these fails, the trace is **un-joinable** at that boundary and must be reported as such, not repaired by inference. ## Decision Boundary The reconstructor must choose, per edge, between *join* and *quarantine*: - If `child.trace_id == parent.trace_id` and `parent_span_id` resolves to exactly one span → join. - If `child.trace_id != parent.trace_id` → **do not join**; emit a `cross_trace_boundary` record carrying both trace IDs and the shared span ID, and surface it to the observability consumer as a discontinuity. - If `parent_span_id` resolves to more than one span (ID collision) → **quarantine the entire trace lineage**; do not pick a winner. Ambiguous parentage is not a tie to be broken by timestamp, because timestamps across processes are not causally ordered. The boundary is sharp: a single ambiguous or cross-trace edge invalidates the join for that subtree, because the partial order is no longer well-founded. Downstream consumers (latency attribution, error propagation analysis, replay) must be told the subtree is un-reconstructable rather than handed a plausible-looking but false tree. ## Operational Effect Enforcing the boundary converts a silent correctness failure into a loud, bounded one. The phantom latency regression disappears because cross-trace edges no longer inflate per-root span counts. The trace viewer terminates because quarantined lineages are pruned before cycle detection. The cost is that some genuinely causal relationships become *reported as links* rather than *rendered as parent-child*, which is the correct trade: an observability system that fabricates a causal edge is worse than one that admits a gap. The remediation is upstream — propagate `traceparent` across every transport, or mandate `Link` emission at sub-agent spawn — but the reconstructor must remain correct even when upstream is wrong. ```python from dataclasses import dataclass class UnjoinableTraceError(RuntimeError): """Raised when causal reconstruction hits an edge that cannot be validly joined.""" @dataclass(frozen=True) class Span: trace_id: str span_id: str parent_span_id: str | None def join_edge(child: Span, parent: Span | None, *, candidates: int) -> None: if child.parent_span_id is None: return if candidates > 1: raise UnjoinableTraceError( f"ambiguous parentage: span_id={child.parent_span_id} resolves to " f"{candidates} spans; lineage quarantined" ) if parent is None: raise UnjoinableTraceError( f"dangling parent: {child.parent_span_id} not found for span {child.span_id}" ) if child.trace_id != parent.trace_id: raise UnjoinableTraceError( f"cross-trace parent edge: child {child.span_id} in {child.trace_id} " f"claims parent {parent.span_id} in {parent.trace_id}; " f"demote to Link, do not join" ) def reconstruct(spans: list[Span]) -> dict[str, list[str]]: by_id: dict[str, list[Span]] = {} for s in spans: by_id.setdefault(s.span_id, []).append(s) tree: dict[str, list[str]] = {} for child in spans: if child.parent_span_id is None: tree.setdefault(child.trace_id, []).append(child.span_id) continue cands = by_id.get(child.parent_span_id, []) parent = cands[0] if len(cands) == 1 else None join_edge(child, parent, candidates=len(cands)) tree.setdefault(child.trace_id, []).append(child.span_id) return tree ```