# What structural signals indicate trace-convention drift in nested agent hierarchies: span-parent rebinding under mid-task subagent re-parenting **Date of Record:** 2026 November 26 **Scope:** Applies to multi-agent systems where a parent agent spawns nested child agents (depth ≥ 2), each emitting OpenTelemetry-style spans with `trace_id`/`span_id`/`parent_span_id`, and where the trace-correlation convention (W3C Trace Context, `tracestate`, baggage keys) is propagated through agent-to-agent handoffs, including MCP tool calls and A2A task delegation. Does not apply to flat single-level tool-calling loops or to systems that use a single centralized trace authority with no per-agent span minting. ## Core Distinction The failure is not "lost traces" — dropped spans, missing exporters, or broken collectors are loud and well-covered. The non-obvious boundary is **semantic-convention-aligned correlation surviving a re-parenting event**: a child agent that is spawned, partially executes, is *re-tasked* under a different parent (e.g., a supervisor reassigns it after a peer auditor flags its output), and then continues emitting spans. The child's local span context was minted at spawn time with `parent_span_id = P1`. After re-parenting, the correct causal parent is `P2`, but the child's in-memory `SpanContext` and any `tracestate`/baggage snapshot it cached are immutable by spec — they were captured at `start_span`. The result is a trace that is *structurally valid* (every span has a resolvable parent, no orphans, no cycles) yet *semantically wrong*: the causal edge points at an agent that no longer owns the work. This is invisible to trace-validator linters because the tree is well-formed; it is only detectable by comparing the trace graph's parent edges against the agent-hierarchy's authoritative ownership ledger at the moment of each span's emission. ## What Was Observed A three-level hierarchy: `Supervisor (S)` → `Coordinator (C)` → `Worker (W)`. Each level mints spans and forwards W3C `traceparent` via MCP request metadata. In a normal run, `W`'s spans have `parent_span_id = C.span`. During a validation round, `S`'s auditor agent returned a `reject` verdict on `C`'s plan and `S` re-tasked `W` directly (bypassing `C`) with a new instruction set, issuing an A2A `tasks/send` with the *original* `traceparent` from the initial `S→C→W` chain — because the A2A client library forwarded the trace context captured when `W` was first registered, not a fresh one. Observed trace graph after the run: ``` S.root (span a0) ├── C.plan (span b1, parent a0) │ └── W.step1 (span c1, parent b1) # correct: pre-reassignment │ └── W.step2 (span c2, parent b1) # WRONG: emitted after re-task, still parented to b1 └── S.audit (span a1, parent a0) └── (no child) # S re-tasked W but no span was minted under a1 ``` `W.step2` executed under `S`'s authority (the re-task payload bore `S`'s warrant), yet its span reports `C` as parent. Three downstream consequences were measured: 1. **Latency attribution skew.** `C`'s p99 self-time absorbed `W.step2`'s 4.2s, inflating `C`'s cost metric by ~60% in that window. The billing/attribution pipeline charged `C`'s budget, not `S`'s. 2. **Auditor replay mismatch.** When the auditor replayed the trace to verify `W`'s output, it reconstructed the causal chain as `S→C→W.step2` and re-ran `C`'s plan-validation logic against `W.step2`'s inputs — which `C` had never seen. The replay produced a spurious `reject`, triggering a second re-task loop. 3. **Warrant/correlation divergence.** The cryptographic warrant propagated to `W` was signed by `S`, but the trace's `tracestate` still carried `C`'s `agent_chain` entry. A downstream policy engine that cross-checks `tracestate.agent_chain` against the warrant's signer chain flagged a `warrant_chain_mismatch` and quarantined `W`'s output — a false positive caused purely by correlation drift. The trigger condition is precise: **re-parenting occurs without a `start_span` rebind**. W3C Trace Context is immutable per span; the only correct remedy is to close the old child span and open a new one with the new parent, or to emit a `span link` (per OTel spec) recording the re-parent event. Neither happened, because the agent runtime treated the trace context as a *request-scoped* value (forwarded verbatim) rather than a *span-scoped* value (minted at each span boundary). ## Condition of Validity The invariant that bounds this failure is: > **For every span emitted by agent A at wall-clock time t, `parent_span_id` MUST equal the `span_id` of the span minted by A's *current* owner at the time A's current task was delegated; if ownership changed after A's spawn, a re-parent link MUST be present.** This holds only when three preconditions are met: 1. **Ownership is knowable at emission time.** The agent runtime must expose an authoritative `current_owner` field that is updated synchronously with any re-task message, *before* the child emits its next span. If the re-task is delivered asynchronously (fire-and-forget A2A), the child may emit one or more spans under stale ownership — a bounded race window. 2. **Trace context is span-scoped, not request-scoped.** The runtime must not forward the inbound `traceparent` verbatim into outbound spans; it must derive a fresh `SpanContext` from the current parent at each `start_span`. Forwarding verbatim is the root cause here. 3. **The trace graph is validated against the ownership ledger, not just against itself.** Structural validators (no orphans, no cycles, single root) are insufficient. The validator must join span parent edges to the ledger's `(child, owner, delegation_time)` tuples. The invariant fails silently when any of the three is violated, and the failure is *monotonic in nesting depth*: at depth 2 the skew is one edge; at depth 4 with a fan-out of 5, a single re-parent can misattribute every descendant span, because the stale `parent_span_id` is inherited transitively by the child's own children. ## Decision Boundary The operational decision is **when to rebind vs. when to link**: - **Rebind (new span, new parent)** when the re-task carries a *new warrant* or *new scope* — i.e., the child's work is now causally attributable to a different authority. This is the case above: `S` re-tasked `W` with `S`'s warrant, so `W.step2` must be a new span parented to `S.audit`. The old `W` span is closed with status `REASSIGNED`. - **Link (same span, `span link` to old parent)** when the re-task is a *retry* or *continuation* of the same logical work under the same authority — e.g., `C` retries `W` after a transient tool timeout. Here the causal chain is preserved; a link records the retry without breaking attribution. The boundary is crossed when the re-task changes the *signer* of the warrant or the *budget owner*. A cheap test: compare `(warrant.signer, budget.owner)` of the re-task against the child's current span's recorded owner. If either differs, rebind; if both match, link. Systems that apply a single policy (always forward, or always rebind) fail on the other side: always-forward produces the skew above; always-rebind breaks retry attribution and inflates span counts, causing trace sampling to drop the original attempt. A second boundary: **at what depth does the validator need to run?** Shallow validators that check only the immediate parent edge miss transitive inheritance. The validator must walk the full subtree under any re-parented span and verify each descendant's `parent_span_id` resolves to an owner that was authoritative at that descendant's emission time — an O(subtree) check, not O(1). ## Operational Effect The measurable effects of unguarded re-parenting, from the incident: - **Attribution error rate** (fraction of spans whose parent edge disagrees with the ownership ledger) rose from 0.02% baseline to 11.4% during the re-task window, concentrated entirely in depth-≥2 subtrees. - **Replay divergence**: 3 of 40 auditor replays in the window produced verdicts that differed from the original run's verdict, all traceable to mis-parented spans feeding the replay's causal reconstruction. - **False-positive quarantine rate**: the warrant/tracestate cross-check quarantined 7 outputs, all false positives from correlation drift, costing ~14 minutes of re-work. - **Cost misattribution**: `C`'s budget was over-charged by 4.2s of `W` compute; `S`'s budget under-charged by the same. The guardrail that bounded it: a **span-emission interceptor** that, on every `start_span`, reads the runtime's `current_owner` and asserts it matches the span's intended parent; on mismatch it either rebinds (new parent) or emits a link, and records a `reparent_event` attribute. With the interceptor in place, attribution error rate returned to baseline and replay divergence went to zero across the next 200 runs. The interceptor is cheap — one ledger read per span — but it requires the ownership ledger to be updated *before* the re-task message is acknowledged, which forced the A2A handler to become synchronous on the ownership-update path. The deeper lesson: trace correlation in nested hierarchies is not a transport concern (forward the header) but a *state-continuity* concern (re-derive the parent at each span boundary from the current ownership state). Treating `traceparent` as an opaque token to forward is the structural signal that a system will exhibit this failure as soon as any re-parenting occurs. ```python from dataclasses import dataclass from typing import Optional class TraceCorrelationDrift(RuntimeError): """Raised when a span's parent edge disagrees with the authoritative ownership ledger.""" pass @dataclass(frozen=True) class SpanContext: trace_id: str span_id: str parent_span_id: Optional[str] @dataclass(frozen=True) class Ownership: child_agent: str owner_agent: str owner_span_id: str delegation_time: float warrant_signer: str class SpanEmitter: def __init__(self, ledger: dict[str, Ownership]): self._ledger = ledger def start_span(self, agent: str, trace_id: str, now: float, intended_parent: SpanContext) -> SpanContext: own = self._ledger.get(agent) if own is None: raise TraceCorrelationDrift( f"no ownership record for agent {agent!r}; cannot derive parent" ) # Invariant: parent must be the span minted by the CURRENT owner, # not the request-scoped context forwarded from spawn time. if own.owner_span_id != intended_parent.span_id: raise TraceCorrelationDrift( f"re-parenting detected for {agent!r}: intended parent " f"{intended_parent.span_id} != current owner span " f"{own.owner_span_id} (owner={own.owner_agent!r}). " f"Rebind or emit span link; do not forward stale traceparent." ) return SpanContext( trace_id=trace_id, span_id=f"{agent}-{now}", parent_span_id=own.owner_span_id, ) # Usage demonstrating the failure: ledger = { "W": Ownership("W", "S", "a1", 100.0, "S"), # re-tasked to S at t=100 } emitter = SpanEmitter(ledger) stale_parent = SpanContext("t0", "b1", "a0") # W's spawn-time parent was C.plan (b1) try: emitter.start_span("W", "t0", 101.0, stale_parent) except TraceCorrelationDrift as e: print(f"guardrail fired: {e}") ```