# Why does an instance lose causal parentage when GenAI semantic-convention spans cross an agent hop boundary **Date of Record:** 2026 November 28 **Scope:** Applies to multi-agent systems that propagate W3C trace context and emit OpenTelemetry GenAI semantic-convention spans (`gen_ai.*`) across MCP/A2A/tool-call hops. Does not apply to single-process agent loops where the span tree is constructed in one runtime, nor to pure logging pipelines that do not reconstruct causality from span parentage. ## Core Distinction A trace context is *transport state*; a GenAI span's causal parentage is *semantic state*. The bug is not that the `traceparent` header is dropped — it usually is not. The bug is that the receiving agent, on hop N+1, opens a **new root span** (or re-parents to an unrelated span) because the GenAI semantic conventions define span kinds by *operation* (`gen_ai.chat`, `gen_ai.tool.execution`, `gen_ai.agent.invoke`) rather than by *causal edge*. When an agent hands off to a peer via A2A or an MCP tool call, the callee constructs its `gen_ai.agent.invoke` span with `SpanKind.SERVER` and a `parent` derived from the *local* context object, which was re-initialized when the agent process cold-started or when the framework's middleware extracted the header into a fresh `Context` but did not attach it to the span builder. The result: the trace is *complete* (every span exists, every `trace_id` matches) but *disconnected* (parent_span_id points to a span that is not the caller's `gen_ai.agent.invoke`). End-to-end causal reconstruction — "which user prompt caused this tool error three hops later" — silently returns a forest of roots instead of a tree. ## What Was Observed A supervisor agent (`gen_ai.agent.invoke`, span `A`) dispatches a subtask to a worker via A2A. The worker emits `gen_ai.agent.invoke` (`B`) and, inside it, `gen_ai.chat` (`C`) and `gen_ai.tool.execution` (`D`). The trace export shows `A.trace_id == B.trace_id == C.trace_id == D.trace_id`, but `B.parent_span_id` is a 16-zero value — a new root — and `D.parent_span_id` correctly points to `C`. The A2A handler had extracted `traceparent` into a `Context`, but the worker's instrumentation called `tracer.start_span("gen_ai.agent.invoke", kind=SERVER)` without `context=extracted_ctx`. The span was created against the ambient root context. Because `trace_id` was still propagated (the framework's propagator injected it into the *next* outbound call from `B`), downstream hops from `B` re-attached to `B`'s subtree — producing two disjoint trees with a shared `trace_id`. The failure is *invisible* to span-count and trace-id-equality assertions; it only surfaces in a parent-walk reconstruction, where the walk terminates early at `B` with no ancestor. A second, subtler variant appeared when the worker used an async runtime: the `Context` attached during header extraction was bound to the extractor coroutine's task-local scope, and the span creation happened in a different task, so `Context.current()` returned the empty root. The `traceparent` was present in the message, the extractor ran, and the attach was still lost — a task-boundary leak, not a header-loss bug. ## Condition of Validity The invariant holds only when the following are all true: (1) the hop is instrumented with GenAI semantic conventions that emit `gen_ai.agent.invoke` / `gen_ai.chat` / `gen_ai.tool.execution` as distinct span kinds; (2) the callee creates its span with an explicit parent context derived from the extracted `traceparent`, not from ambient context; (3) the extraction and span creation occur in the same execution scope (same task/thread), or the context is explicitly re-attached. If any instrumentation layer re-roots spans (e.g., a framework that treats each agent invocation as a new trace for sampling reasons), the invariant is violated by design and reconstruction must fall back to `gen_ai.conversation.id` or an application-level `causation_id` attribute. The invariant does **not** hold across hops where the transport is non-context-carrying (e.g., a queue with no header propagation); there, causal linkage must be reconstructed from message attributes, not span parentage. ## Decision Boundary The boundary is between *trace-id continuity* and *parent-edge continuity*. A system may legitimately have trace-id continuity with broken parent edges (the failure above) or parent-edge continuity with trace-id divergence (if a sampler forks traces). The operational decision: **assert on parent-edge reachability, not trace-id equality.** A reconstruction is valid only if, for every `gen_ai.tool.execution` span, a parent-walk of `parent_span_id` reaches a `gen_ai.agent.invoke` span whose `gen_ai.conversation.id` matches the originating user turn. If the walk terminates at a root before reaching that span, the hop is broken regardless of `trace_id`. The guardrail is to emit a `gen_ai.agent.hop.parent_link_status` attribute (`linked` / `rerooted` / `orphaned`) at span creation and to fail the trace-continuity check when any span reports `rerooted`. ## Operational Effect Without the guardrail, incident response loses the ability to attribute a downstream tool failure to the originating prompt: the trace UI shows a healthy, complete trace, but the causal chain is a forest. Error-compounding analysis across hops (did hop 2's bad retrieval cause hop 3's wrong tool call?) becomes impossible because hop 2 and hop 3 are not connected. The fix is to make parent-context attachment explicit at every hop boundary — extract, attach to the span builder, and verify the resulting `parent_span_id` equals the caller's `gen_ai.agent.invoke` span id — and to treat a re-rooted span as a hard failure in trace-continuity validation, not a cosmetic gap. ```python class HopParentageError(RuntimeError): """Raised when a GenAI span at an agent hop boundary is re-rooted.""" pass def validate_hop_parentage(spans: list[dict], expected_parent_span_id: str) -> None: """Assert every gen_ai.agent.invoke span links to the caller's span. spans: exported span dicts with keys: name, span_id, parent_span_id, trace_id, attributes (gen_ai.conversation.id, gen_ai.agent.hop.parent_link_status) expected_parent_span_id: span_id of the caller's gen_ai.agent.invoke """ for s in spans: if s["name"] != "gen_ai.agent.invoke": continue if s["parent_span_id"] in (None, "0000000000000000", ""): raise HopParentageError( f"re-rooted gen_ai.agent.invoke span {s['span_id']} " f"trace_id={s['trace_id']} has no parent; " f"expected parent={expected_parent_span_id}" ) if s["parent_span_id"] != expected_parent_span_id: raise HopParentageError( f"mis-parented gen_ai.agent.invoke span {s['span_id']} " f"parent={s['parent_span_id']} expected={expected_parent_span_id} " f"conv_id={s['attributes'].get('gen_ai.conversation.id')}" ) if s["attributes"].get("gen_ai.agent.hop.parent_link_status") == "rerooted": raise HopParentageError( f"hop reported rerooted status on span {s['span_id']}" ) ```