# What structural signals indicate parent-child span linkage is broken in multi-agent causal traces under GenAI semantic convention extensions **Date of Record:** 2026 November 26 **Scope:** Applies to multi-agent systems that emit OpenTelemetry spans annotated with GenAI semantic conventions (`gen_ai.*`) and reconstruct causal trees from `parent_span_id`/`trace_id` linkage across agent handoffs. Does not apply to single-agent traces, or to systems that serialize causal order into application-level event logs rather than span parentage. ## Core Distinction There are two ways a multi-agent trace can be "wrong," and they require different detection strategies. The first is **content corruption**: a span records the wrong model, wrong token count, or wrong tool name. This is detectable by schema validation against the `gen_ai.*` attribute contract. The second—the subject here—is **structural linkage corruption**: every span is individually well-formed and schema-valid, but the parent-child edges that constitute the causal tree are attached to the wrong nodes, severed, or duplicated. A trace with perfect attributes and broken parentage is *semantically falsified*: it tells a coherent story about which agent caused which effect, and that story is false. The non-obvious boundary is this: GenAI semantic conventions specify *attributes* (what a span says about itself) but historically leave *linkage semantics* underspecified for delegated agent work. When Agent A invokes Agent B as a tool, the natural trace shape is a child span under A's span. But B is frequently a separate process, a separate service, or a separate *model instance* that creates its own root span and only later gets stitched into A's trace. The stitching step—propagating `trace_id` and `parent_span_id` across the agent boundary—is where linkage silently breaks, and because each span remains valid, no validator fires. ## What Was Observed A supervisor agent (Agent S) decomposed a task into three subtasks and dispatched them to worker agents W1, W2, W3 over an A2A-style transport. Each worker emitted its own spans with `gen_ai.system`, `gen_ai.operation.name`, and `gen_ai.usage.*` attributes correctly populated. The trace backend reconstructed a tree in which: - W1, W2, W3 each appeared as *root spans* (no parent), siblings to S rather than children of S. - S's dispatch span recorded three child tool-execution spans that were empty stubs with zero duration and no `gen_ai` attributes. - One retry of W2 produced a *second* W2 subtree under a *different* trace ID, because the retry path generated a fresh trace context instead of continuing the original. The structural signatures were specific and reproducible: 1. **Orphan-root proliferation**: N worker root spans for a task that logically has one root. Root count exceeding the number of ingress requests is the single most reliable signal that parent context was dropped at a handoff. 2. **Attribute-parent mismatch**: a span's `gen_ai.agent.name` or `gen_ai.conversation.id` indicates it belongs under S, but its `parent_span_id` is null or points to a span in a different trace. The attributes *disagree with the topology*. 3. **Stub-parent inflation**: parent spans whose only children are zero-duration, attribute-free spans, with the real work living in orphan roots. The parent "claims" children that carry no evidence. 4. **Trace-ID fragmentation on retry**: a retried unit of work inherits a new `trace_id` because the retry was initiated from a fresh context rather than from the stored span context of the original attempt. 5. **Duration inversion**: a child span whose start time precedes its claimed parent's start time, or whose end time exceeds the parent's—physically impossible for a synchronous delegation, diagnostic of a stitch performed with wrong timestamps. ## Condition of Validity The linkage invariant holds only when the following condition is satisfied at every agent handoff: > For any span emitted by agent B on behalf of agent A, `B.trace_id == A.trace_id` **and** `B.parent_span_id` resolves to a span that (a) exists in the same trace, (b) has `end_time >= B.start_time`, and (c) carries an agent identity consistent with the delegation edge recorded in A's dispatch span. This condition is *not* guaranteed by W3C trace-context propagation alone, because propagation only carries the context that the caller injects. It fails when: the worker is invoked through a queue or async channel that strips headers; the worker's SDK initializes a tracer before the inbound context is extracted; the retry logic re-enters the worker without re-extracting the stored `SpanContext`; or the worker runs in a runtime (e.g., a separate model-serving process) that does not share the propagation carrier. Each of these is a *context-extraction ordering* failure, not an attribute failure—which is why schema validation never catches it. The invariant is also conditional on **single-parent semantics**. If the system permits a span to be re-parented after emission (late stitching), the invariant must additionally require that re-parenting be idempotent and monotonic: a span may acquire a parent once, and never change `trace_id`. Violation of monotonicity is the retry-fragmentation failure above. ## Decision Boundary The operational question is: *when a trace shows orphan roots or attribute-parent mismatch, do you trust the attributes or the topology?* The decision boundary is: - **Trust topology, distrust attributes, when** the orphan roots carry complete `gen_ai` attributes and the would-be parents are stubs. Here the topology is the artifact of a broken stitch; the attributes are the ground truth of what executed. Reconstruct causality from `gen_ai.conversation.id` and agent-identity edges, not from `parent_span_id`. - **Trust attributes, distrust topology, when** the parent spans carry full attributes and the orphans are attribute-sparse. Here the orphans are likely spurious emissions (e.g., a health-check tracer) and should be pruned. - **Trust neither, quarantine the trace, when** both parent and orphan carry complete, *conflicting* `gen_ai` attributes for the same logical unit of work. This indicates duplicate execution or a poisoned context, and any causal conclusion drawn from it is unsound. The boundary must be evaluated *per trace*, not per system, because a single deployment can exhibit both failure classes depending on which handoff path (sync vs. queued) was used. ## Operational Effect When linkage corruption goes undetected, three downstream operations degrade: 1. **Attribution and cost accounting** double-count or misattribute token usage, because a worker's `gen_ai.usage.*` lives on an orphan root that the billing join never reaches through the (broken) parent chain. 2. **Failure localization** inverts: an error surfaced in S's stub child span points at S, while the actual failing worker sits in a disconnected subtree, so incident response debugs the wrong agent. 3. **Replay and audit** cannot reconstruct the causal order, because the tree that replay walks is not the tree that executed—so verification replays diverge from the original run even when the underlying model calls were identical. The architectural guardrail is a **linkage validator that runs at trace-close time and asserts the invariant above**, rejecting or flagging any trace where root count exceeds ingress count, where any non-root span's `parent_span_id` is unresolvable, or where retry spans differ in `trace_id` from their first attempt. This must be a hard gate, because the failure is invisible to every attribute-level check. ```python from dataclasses import dataclass from typing import Optional class TraceLinkageError(RuntimeError): """Raised when a multi-agent trace violates the parent-child linkage invariant.""" @dataclass class Span: span_id: str trace_id: str parent_span_id: Optional[str] agent_name: Optional[str] conversation_id: Optional[str] start_time: float end_time: float has_genai_attrs: bool is_retry_of: Optional[str] = None def validate_linkage(spans: list[Span], ingress_count: int) -> None: by_id = {s.span_id: s for s in spans} trace_ids = {s.trace_id for s in spans} # Invariant 1: single trace_id per logical task. if len(trace_ids) > 1: raise TraceLinkageError( f"trace fragmentation: {len(trace_ids)} trace_ids for one task; " f"retry likely re-entered with fresh context" ) # Invariant 2: root count must not exceed ingress count (orphan proliferation). roots = [s for s in spans if s.parent_span_id is None] if len(roots) > ingress_count: raise TraceLinkageError( f"orphan-root proliferation: {len(roots)} roots for " f"{ingress_count} ingress requests; parent context dropped at handoff" ) # Invariant 3: every non-root parent must resolve and temporally contain child. for s in spans: if s.parent_span_id is None: continue parent = by_id.get(s.parent_span_id) if parent is None: raise TraceLinkageError( f"unresolvable parent {s.parent_span_id} for span {s.span_id}" ) if parent.end_time < s.start_time: raise TraceLinkageError( f"duration inversion: parent {parent.span_id} ends before " f"child {s.span_id} starts" ) # Invariant 4: retries must preserve trace_id and reference original attempt. for s in spans: if s.is_retry_of is not None: original = by_id.get(s.is_retry_of) if original is None or original.trace_id != s.trace_id: raise TraceLinkageError( f"retry span {s.span_id} does not continue original " f"trace of {s.is_retry_of}" ) # Invariant 5: attribute-parent consistency (agent identity must agree with edge). for s in spans: if s.parent_span_id is None: continue parent = by_id[s.parent_span_id] if s.agent_name and parent.agent_name and s.conversation_id != parent.conversation_id: raise TraceLinkageError( f"attribute-parent mismatch: span {s.span_id} " f"(conv={s.conversation_id}) under parent {parent.span_id} " f"(conv={parent.conversation_id})" ) ```