Why does an instance lose causal parent-child correlation when semantic-convention span links are resolved across a fan-out boundary

**Date of Record:** 2026 December 2 **Scope:** Applies to multi-agent systems emitting OpenTelemetry-style spans where causal correlation between an orchestrator span and downstream agent spans is reconstructed from `trace_id`/`span_id` linkage plus GenAI semantic-convention attributes (`gen_ai.operation.name`, `gen_ai.agent.id`, `gen_ai.conversation.id`). Does not apply to single-agent traces with a strictly linear call tree, nor to systems that propagate a single immutable `parent_span_id` through every hop.

Core Distinction

There are two distinct things an agent trace can encode: **structural parentage** (which span object the runtime created inside) and **causal ancestry** (which span's output actually caused this span to exist). In a linear chain these coincide. At a fan-out boundary—one orchestrator dispatching N parallel sub-agents—they diverge, because the runtime that spawns each sub-agent span is a shared worker pool, not the orchestrator. The sub-agent span's structural parent is whatever worker happened to dequeue the task; its causal parent is the orchestrator span that produced the delegation payload. Semantic-convention span linking resolves this by attaching a *link* (not a parent) from the sub-agent span back to the orchestrator, keyed on attributes. The failure mode lives in that link resolution: the link is reconstructed *after the fact* from attribute matching, and attribute matching is not injective across a fan-out.

What Was Observed

An orchestrator agent (`gen_ai.agent.id = planner`) decomposed a task into five sub-tasks and dispatched them to a pool of three worker instances running the same agent binary (`gen_ai.agent.id = researcher`). Each sub-task carried a delegation payload with `gen_ai.conversation.id = conv-88` and a `gen_ai.operation.name = chat`. The workers emitted spans with `parent_span_id` pointing at the pool dispatcher (structural), and the collector's span-linker reconstructed causal links by matching `(conversation.id, operation.name)` against candidate producer spans.

Because all five sub-tasks shared one `conversation.id` and one `operation.name`, the linker could not distinguish which researcher span descended from which planner sub-decision. It resolved to a **many-to-one** link set: every researcher span linked to the single planner span, and the planner span accumulated five inbound causal children with no ordering or cardinality constraint. When a downstream auditor agent replayed the trace to verify that each sub-task was independently reasoned, it saw four researcher spans whose causal parent was also the causal parent of their siblings—i.e., **the fan-out collapsed into a fan-in at the causal layer while remaining a fan-out at the structural layer**. The auditor's consistency check (one causal child per delegation decision) failed open: it reported "verification passed" because it counted links, not link *identity*.

The trace was internally consistent, schema-valid, and semantically wrong.

Condition of Validity

The invariant that must hold is: **for every causal link, the tuple used to resolve it must be unique among concurrent producer spans within the resolution window.** Formally, if `L(s) = match(attrs(s), candidates)` is the linker's resolution function, correctness requires `|L(s)| = 1` for every consumer span `s`. The GenAI semantic conventions do not enforce this. `gen_ai.conversation.id` is scoped to a conversation, not a delegation; `gen_ai.operation.name` is a coarse verb; `gen_ai.agent.id` is identical across all instances of the same agent binary. None of these attributes is a *delegation identifier*. The moment two sub-agents are dispatched under one conversation with one operation name, `|L(s)| > 1` and the linker silently degrades to set-valued linking.

The condition of validity therefore is: **the resolution key must include a per-delegation nonce minted by the orchestrator at dispatch time and propagated in the delegation payload**, not reconstructed from ambient conversation attributes. Absent that nonce, the trace is valid only when the fan-out width is 1 or when sub-agents are serialized with non-overlapping resolution windows—a condition that parallel dispatch specifically violates.

Decision Boundary

The boundary is not "parallel vs. serial." It is **whether the linker resolves links before or after the fan-out closes.** If links are resolved online—each sub-agent span is linked at emit time against the currently-open orchestrator span, with the orchestrator holding an exclusive dispatch lock per sub-task—the ambiguity window is closed and `|L(s)| = 1` holds even under parallelism. If links are resolved offline—the collector batches spans and matches attributes after the fact—the window is open for the entire duration of the fan-out, and any two sub-tasks sharing a conversation are indistinguishable.

The operational decision: **never let a causal link be reconstructed offline from ambient attributes when fan-out width > 1.** Either mint a delegation nonce at dispatch (preferred, survives offline resolution) or force online resolution with a dispatch lock (fragile, breaks under retry and at-least-once delivery). The nonce approach is the only one that survives the auditor's replay, because replay is inherently offline.

Operational Effect

When the invariant is violated, the trace does not fail—it lies. The auditor's verification replay sees a well-formed DAG with correct cardinality at the structural layer and a collapsed, ambiguous causal layer. The practical consequences are: (1) attribution of a bad sub-agent output to the wrong delegation decision becomes impossible, because all sub-tasks share one causal parent; (2) replay-based verification passes spuriously, since link-count checks cannot detect many-to-one collapse; (3) retry semantics corrupt further, because a retried sub-task emits a second span with the same conversation attributes and the linker now has `|L(s)| = 2` for a single logical delegation. The guardrail is a **delegation nonce carried as a first-class attribute (`gen_ai.delegation.id`) and asserted unique at link-resolution time**; the linker must reject any consumer span whose resolution set has cardinality ≠ 1 rather than degrade to set-linking.

from dataclasses import dataclass, field
from typing import Optional


class CausalLinkAmbiguityError(RuntimeError):
    """Raised when a span's causal parent cannot be resolved to exactly one producer."""


@dataclass
class Span:
    span_id: str
    agent_id: str
    conversation_id: str
    operation_name: str
    delegation_id: Optional[str] = None  # minted by orchestrator at dispatch
    parent_span_id: Optional[str] = None  # structural parent (worker pool)


def resolve_causal_parent(consumer: Span, candidates: list[Span]) -> Span:
    """Resolve the unique causal producer for a consumer span.

    Resolution key MUST be the per-delegation nonce. Ambient attributes
    (conversation_id, operation_name, agent_id) are NOT injective across a
    fan-out and will collapse many-to-one.
    """
    if consumer.delegation_id is None:
        raise CausalLinkAmbiguityError(
            f"span {consumer.span_id} has no delegation_id; "
            f"ambient attrs (conv={consumer.conversation_id}, "
            f"op={consumer.operation_name}) are non-injective under fan-out"
        )

    matches = [
        c for c in candidates
        if c.delegation_id == consumer.delegation_id
        and c.agent_id != consumer.agent_id  # producer is a different agent
    ]

    if len(matches) != 1:
        raise CausalLinkAmbiguityError(
            f"span {consumer.span_id} resolved to {len(matches)} causal parents "
            f"for delegation_id={consumer.delegation_id}; "
            f"expected exactly 1 (fan-out collapse or retry duplicate)"
        )

    return matches[0]


def link_fanout(orchestrator: Span, sub_agents: list[Span], producers: list[Span]) -> dict[str, str]:
    """Link every sub-agent span to its unique causal producer, or fail closed."""
    links: dict[str, str] = {}
    for sub in sub_agents:
        parent = resolve_causal_parent(sub, producers)
        if parent.span_id != orchestrator.span_id:
            raise CausalLinkAmbiguityError(
                f"sub-agent {sub.span_id} linked to {parent.span_id}, "
                f"not orchestrator {orchestrator.span_id}"
            )
        links[sub.span_id] = parent.span_id
    return links