# Where must an instance re-anchor its trace context when an OTel span parent is a sibling agent's LLM turn **Date of Record:** 2026 November 27 **Scope:** Applies to multi-agent systems that propagate W3C `traceparent`/`tracestate` (or OTel `SpanContext`) across agent handoffs where the receiving agent's work is emitted as child spans of a span authored by a *different* model instance. Does not cover single-agent tracing, or trace export/collector-side sampling decisions. ## Core Distinction The failure is not "lost trace context" (a dropped `traceparent` header, which is loud and easy to detect). It is *mis-anchored* trace context: the child span is correctly parented, the trace ID is consistent, the collector accepts every span — and yet the causal attribution is wrong because the parent span is an LLM turn whose `end_time` and outcome were determined by a *sibling* agent's reasoning, not by the work the child span represents. Concretely: Agent A emits span `A.plan` (an LLM completion). It hands off to Agent B via A2A/MCP, passing `traceparent` with `parent_span_id = A.plan`. Agent B emits `B.tool_call` as a child of `A.plan`. This looks correct. It is not: `A.plan` is a *decision* span, and `B.tool_call` is an *effect* span that may execute seconds to minutes later, after `A.plan` has already been closed and its status set to `OK`. When you reconstruct causality — "which reasoning step caused this tool failure?" — the trace asserts that `A.plan`'s completion caused `B.tool_call`, but `A.plan` was already sealed. The true causal parent of `B.tool_call` is the *handoff event* (the serialized task envelope), which has no span of its own. The trace is structurally valid and causally false. ## What Was Observed A three-agent pipeline (planner → executor → auditor) using OTel SDK v1.24, OTLP/HTTP export, Jaeger backend. Each agent process sets `OTEL_PROPAGATORS=tracecontext,baggage` and injects context into outbound A2A envelopes via `TraceContextTextMapPropagator().inject(carrier)`. Trace reconstruction for a failed task showed: - `A.plan` (planner LLM turn): start `t=0.00s`, end `t=2.31s`, status `OK`. - `B.tool_call` (executor tool invocation): start `t=47.90s`, end `t=48.12s`, status `ERROR`, parent = `A.plan`. - `C.audit` (auditor verification): start `t=49.00s`, parent = `B.tool_call`. The 45.6-second gap between `A.plan` ending and `B.tool_call` starting was invisible in the trace topology. On-call engineers read the waterfall and concluded "planner caused the tool error" and re-ran the planner. Root cause was an executor-side schema mismatch triggered by a stale tool registry — entirely inside B — but the trace's single-parent edge pointed at A. Two full incident cycles were spent on the wrong agent. Deeper inspection: the executor had *also* re-emitted `A.plan`'s context as a `Links` entry, but the SDK default (`OTEL_SPAN_LINK_MAX_ATTRS`, and more importantly the Jaeger UI's non-rendering of links) meant the link was present in the span JSON and absent from every human- and machine-readable causal view. An automated causal-attribution job that walked `parent_span_id` edges (the only edge it parsed) reproduced the human error at scale. The second observation: when B retried after a timeout, it re-injected the *same* `traceparent` with the same `parent_span_id = A.plan` for each retry attempt. Three retry spans became three siblings under `A.plan` with no ordering relationship and no marker distinguishing attempt 1 from attempt 3. A downstream "first failing child" heuristic picked the wrong attempt. ## Condition of Validity The naive invariant — "child spans parent to the span that logically initiated the work" — holds only when the parent span is *open* at the time the child is created, i.e., synchronous in-process calls. It is invalid for every asynchronous handoff, because: 1. The parent span's `end_time` precedes the child's `start_time` by an unbounded interval (queueing, agent cold-start, model latency, human-in-the-loop). OTel does not forbid this, but causal readers assume parent.end ≥ child.start. 2. The parent span's status was sealed before the child's outcome was known, so parent status cannot reflect child failure. 3. The parent span belongs to a different *instance* with a different context window, different model, and different failure semantics — attribution across that boundary is not compositional. The invariant that actually holds is: **a span must be parented to a span that is causally and temporally prior *and still open*, or to an explicit handoff span that the receiving instance creates and owns.** The `traceparent` header carries a `SpanContext`, not a causal guarantee; propagation is transport, not semantics. ## Decision Boundary The boundary is whether the receiving instance *owns* the parent span's lifecycle. Two regimes: - **In-process / synchronous** (function call within one agent runtime): parent to the caller's active span. Safe. Parent closes after child. - **Cross-instance / asynchronous** (A2A, MCP tool call returning to a different process, queue-mediated handoff): the receiving instance MUST NOT parent to the sender's span. It must (a) create a local `handoff.receive` span parented to the sender's span via `Links` only, and (b) parent all its own work to that `handoff.receive` span. The link preserves trace identity; the local span preserves causal and temporal truth. The trigger for re-anchoring is precise: *the moment the receiving instance deserializes a task envelope and the sender's span is no longer the receiver's active span.* If `Span.current()` at receive time is not a child of a span this process started, re-anchor. Retries compound this: each attempt gets its own `handoff.attempt[n]` span, never a re-parent to the original sender span. ## Operational Effect Enforcing the re-anchor invariant changes three things: 1. **Causal queries become correct.** Walking `parent_span_id` from a failing effect span now terminates at the handoff span owned by the same instance that produced the effect, so attribution never crosses an instance boundary without an explicit, owned node. The 45-second gap becomes a visible `handoff.queue_wait` span. 2. **Retries become distinguishable.** Each attempt is a distinct child of the same handoff parent with an `attempt.index` attribute, so "first failing attempt" heuristics resolve deterministically. 3. **Links become load-bearing, not decorative.** The sender's span survives as a `Link`, so cross-instance trace stitching still works for latency analysis, but it is no longer the causal edge. Any consumer that only reads `parent_span_id` gets a causally sound tree; any consumer that reads links gets the full cross-agent picture. The cost: one extra span per handoff and a discipline that the SDK will not enforce for you. The failure mode without it is silent, structurally valid, and systematically misattributes blame to whichever agent happened to be the sender. ```python from dataclasses import dataclass class MisAnchoredTraceError(RuntimeError): """Raised when a received task is parented to a span the receiver does not own.""" @dataclass class SpanContextView: trace_id: str span_id: str owner_instance: str is_open: bool def reanchor_on_receive( incoming: SpanContextView, receiver_instance: str, receiver_active_span_owner: str | None, ) -> SpanContextView: # The receiver may only parent to a span it owns and that is still open. owns_parent = receiver_active_span_owner == receiver_instance if incoming.owner_instance == receiver_instance and incoming.is_open and owns_parent: return incoming if incoming.owner_instance != receiver_instance: # Cross-instance handoff: the sender's span must become a Link, and the # receiver must mint its own handoff.receive span as the new parent. if incoming.is_open: # Sender span still open across the boundary is itself suspect: # it means the sender blocked on the receiver, contradicting the # async handoff contract. Refuse rather than silently re-parent. raise MisAnchoredTraceError( f"sender span {incoming.span_id} from {incoming.owner_instance} " f"is still open at receive; async handoff violated" ) return SpanContextView( trace_id=incoming.trace_id, span_id=f"handoff.receive::{receiver_instance}", owner_instance=receiver_instance, is_open=True, ) if not owns_parent: raise MisAnchoredTraceError( f"receiver {receiver_instance} attempted to parent to " f"span {incoming.span_id} owned by {incoming.owner_instance} " f"without an owned active span" ) raise MisAnchoredTraceError( f"unhandled anchoring case for span {incoming.span_id}" ) ```