# Why does an instance's causal trace silently fork when GenAI semantic-convention span links cross an agent handoff **Date of Record:** 2026 November 22 **Scope:** Applies to multi-agent systems that propagate causality via OpenTelemetry GenAI semantic-convention spans (`gen_ai.operation.name`, `gen_ai.agent.id`, `gen_ai.conversation.id`) using *span links* rather than parent/child nesting across an agent-to-agent handoff. Does not apply to single-process agents whose sub-steps share one trace context, nor to systems that embed causality in a W3C `traceparent` header alone. ## Core Distinction A parent/child span relationship encodes a *synchronous* causal edge: the child cannot exist before the parent, and the trace tree has exactly one root. A **span link** encodes an *asynchronous* causal edge: the linked span is a peer reference, not a containment. The GenAI semantic conventions deliberately recommend links for agent handoffs because the receiving agent may be processing work that began before, or concurrently with, the current span—nesting would misrepresent the latency budget and orphan the receiver on a different root. The failure mode is that a link is *not* a trace-identity carrier. When agent B receives a task from agent A and emits its span with `links=[{trace_id: A.trace_id, span_id: A.span_id}]` but a **new** `trace_id`, the collector and any downstream trace-assembler see two independent traces joined only by a soft reference. If the assembler's join key is `trace_id` (as most are), the link is *recorded but never followed*. The causal chain is intact in the data and broken in every query. This is the fork: one logical task, N trace roots, and a link graph that no default backend traverses. ## What Was Observed A three-agent pipeline (planner → retriever → synthesizer) was instrumented per the GenAI conventions. Planner span: `trace_id=T1`, `span_id=S1`, `gen_ai.operation.name=invoke_agent`. Retriever received the handoff payload, which carried `{trace_id: T1, span_id: S1}` in a custom `causality` field, and emitted: ``` name: invoke_agent trace_id: T2 # new root, because the retriever runs in its own worker span_id: S2 links: [{trace_id: T1, span_id: S1}] gen_ai.conversation.id: C # same conversation, different trace ``` Three concrete symptoms followed: 1. **Trace-count inflation.** A single user request produced 3 root spans and 3 traces in the backend. Dashboards counting `count(root_span)` reported 3× the actual request volume. Latency SLOs computed per-trace reported the retriever's 4.1s as a standalone trace, hiding the 11.7s end-to-end budget that a user actually experienced. 2. **Link-drop under sampling.** The collector ran tail-sampling at 10%. The sampler's policy keyed on `trace_id` and evaluated each of T1, T2, T3 independently. In 14% of sampled cases the planner span was dropped while the synthesizer span was kept, leaving a link pointing at a `span_id` that was never exported. The backend rendered a dangling link as *no link*—the synthesizer appeared rootless with no causal parent at all. 3. **Conversation-ID collision across tenants.** `gen_ai.conversation.id` was set to a client-supplied session token. Two tenants reused the same token value; the assembler's secondary join on `conversation.id` merged their traces into one causal graph, attributing tenant A's retrieval to tenant B's synthesis. The invariant that was violated: **causal reachability must be reconstructable from the exported spans alone, under the sampler's actual policy, without relying on any backend's link-traversal feature.** The system depended on a soft link that the sampler could sever and the backend did not follow. ## Condition of Validity Span-link-based causal linking is only sound when *all* of the following hold simultaneously: - **Link-preserving sampling.** The tail sampler must treat a link as a sampling *constraint*: if a span is kept, every span it links to is force-kept (or the link is rewritten to a kept ancestor). Per-`trace_id` independent sampling violates this by construction. - **Assembler traversal.** The trace query layer must actually resolve links, or the system must export a derived `causal.root_id` attribute on every span so a flat `GROUP BY causal.root_id` reconstructs the chain without link traversal. - **Scoped conversation keys.** `gen_ai.conversation.id` must be namespaced (`tenant_id:session_id`) so the secondary join cannot cross trust boundaries. - **Handoff payload integrity.** The `{trace_id, span_id}` carried across the agent boundary must be validated against the receiver's own context; a missing or malformed link field must fail the handoff, not silently root a new trace. If any one fails, the trace *looks* correct in a single-agent dev environment (where sampling is off and there is one tenant) and forks only under production load, sampling, and multi-tenancy—the classic non-obvious boundary. ## Decision Boundary The choice between nesting and linking is not stylistic. Use **parent/child nesting** when the receiving agent's work is strictly downstream and synchronous and the receiver can adopt the caller's `trace_id`—this survives naive samplers because the whole tree shares one root. Use **links** only when the receiver genuinely runs asynchronously or concurrently, *and* you have committed to link-preserving sampling plus a `causal.root_id` derivation, *and* conversation keys are tenant-scoped. The boundary is crossed the moment an agent handoff changes `trace_id`. At that instant you have left the "one trace = one causal unit" regime and entered the "link graph = causal unit" regime, which imposes the four obligations above. Systems that change `trace_id` without adopting those obligations are in an undefined state: causally correct data, causally broken observability. ## Operational Effect The practical consequence is that **end-to-end latency and error attribution become unmeasurable precisely when multi-agent fan-out is highest**—the condition you most need to observe. Root-count metrics overcount requests; per-trace latency undercounts true user-perceived time; dangling links from sampling erase causality exactly on the slow, expensive, sampled-out requests. The remediation is a derived `causal.root_id` propagated in the handoff payload alongside the link, plus a sampler that force-keeps linked spans, plus a startup assertion that rejects any handoff whose link target is not resolvable in the receiver's context. Without that assertion, the fork is silent. ```python import uuid from dataclasses import dataclass, field class CausalTraceForkError(RuntimeError): """Raised when an agent handoff would silently fork the causal trace.""" @dataclass class SpanContext: trace_id: str span_id: str conversation_id: str causal_root_id: str links: list = field(default_factory=list) def handoff( sender: SpanContext, receiver_tenant: str, incoming_payload: dict, sampler_keeps_linked: bool, ) -> SpanContext: """Propagate causality across an agent boundary without forking the trace.""" link_trace = incoming_payload.get("trace_id") link_span = incoming_payload.get("span_id") root = incoming_payload.get("causal_root_id") # Invariant 1: link target must be present and well-formed. if not link_trace or not link_span: raise CausalTraceForkError( f"handoff from {sender.span_id} carries no resolvable link target; " "receiver would root a new trace silently" ) if link_trace != sender.trace_id or link_span != sender.span_id: raise CausalTraceForkError( f"link target {link_trace}/{link_span} does not match sender " f"{sender.trace_id}/{sender.span_id}; causality payload corrupted" ) # Invariant 2: causal root must be carried, not inferred from trace_id. if not root: raise CausalTraceForkError( "missing causal_root_id; a trace_id change would orphan this span " "from the root under link-drop sampling" ) # Invariant 3: sampler must preserve linked spans or the link is severed. if not sampler_keeps_linked: raise CausalTraceForkError( "tail sampler is not link-preserving; linked span may be dropped " "while this span is kept, yielding a dangling link" ) # Invariant 4: conversation id must be tenant-scoped. if not sender.conversation_id.startswith(receiver_tenant + ":"): raise CausalTraceForkError( f"conversation_id {sender.conversation_id!r} not scoped to tenant " f"{receiver_tenant!r}; secondary join can cross trust boundaries" ) return SpanContext( trace_id=str(uuid.uuid4()), # receiver gets its own trace... span_id=str(uuid.uuid4()), conversation_id=sender.conversation_id, causal_root_id=root, # ...but shares the causal root links=[{"trace_id": link_trace, "span_id": link_span}], ) ```