# What structural signals indicate causal-span misbinding in GenAI trace correlation across agent hops **Date of Record:** 2026 November 25 **Scope:** Applies to multi-agent systems that propagate a trace/span context (W3C `traceparent`, baggage, or a vendor envelope) across LLM-to-tool and agent-to-agent hops and reconstruct causality by parent-span linkage. Does not apply to single-process, single-span instrumentation where the parent is always the enclosing frame. ## Core Distinction There are two distinct failures that look identical in a trace viewer: 1. **Broken propagation** — the downstream agent never receives the parent context, so it starts a new root. This is loud: orphan roots, missing parents, trace fragmentation. It is easy to detect because the causal chain physically doesn't exist. 2. **Misbound propagation** — the downstream agent receives a *valid but wrong* parent context, or reuses a context across a boundary where the causal identity should have changed. This is silent. The span tree is well-formed, every parent resolves, the trace is complete and plausible — and the reconstructed causality is a lie. This record is about the second class. The dangerous invariant is not "the context arrives." It is **"the context that arrives identifies the causal predecessor, not merely a request lineage."** When those two diverge — most often when a single logical request fans out into concurrent agent hops, or when a long-lived agent instance reuses a cached context across tasks — the parent-span edge stops encoding "this caused that" and starts encoding "these shared a request envelope." Every downstream analysis that trusts the tree inherits the error. ## What Was Observed A planner agent `A` receives a task and issues three concurrent sub-agent calls `B1, B2, B3` through a shared executor. The executor holds one ambient context object (a thread-local, a contextvar, or an async task group with a copied context) and injects the *same* `traceparent` — same `trace_id`, same `parent_span_id = span(A)` — into all three outbound envelopes. Each sub-agent correctly creates its own child span under that parent. The trace now contains three sibling spans all parented to `span(A)`, which is structurally correct for a fan-out. The failure does not appear here. It appears one hop later: `B2` calls a retriever tool `T`, and that tool internally retries once on a transient 503. The retry path re-reads the ambient context and — because the executor's context copy was captured *before* `B2`'s span was created — emits the retry as a child of `span(A)` rather than a child of `span(B2)`. The retry span is now a fourth sibling of `B1..B3`, indistinguishable in the tree from a genuine parallel branch. The structural signal is subtle: `span(A)` has four children, but the planner only dispatched three. Nothing in the trace flags this. The retry span carries `status=OK` on the second attempt and `status=ERROR` on the first, but because both are siblings (not parent/child of each other), the error is attributed to `A`'s fan-out rather than to `B2`'s tool call. An SLO computed as "error rate of `A`'s direct children" now counts a tool retry against the planner. A latency budget for `B2` undercounts, because the failed first attempt's duration is booked against `A`. A second observed variant: agent `C` is a long-lived instance serving sequential tasks. It caches the inbound `traceparent` on first request to avoid re-parsing. On the second task it reuses the cached parent, so task-2 spans are parented to task-1's caller span. The trace is internally consistent and the two tasks are now causally fused into one chain. Any "root cause" query that walks from the error span up to the root crosses a task boundary that does not exist. In both cases the discriminator is the same: **a parent span's child count or child identity does not match the dispatch decisions the parent actually made.** The tree agrees with itself but disagrees with the execution log. ## Condition of Validity The causal-span invariant holds only under all of the following: - The context injected into an outbound envelope is captured **after** the calling span is created and **before** the call is dispatched, and is immutable for the lifetime of that call. - A retry, replay, or fallback of a call is parented to the **same calling span** as the original attempt, never to the caller's parent. Retries are siblings of each other, children of the call site. - A long-lived agent instance treats inbound context as **per-task state**, not per-instance state. Cached context is invalidated at task boundary. - The parent's emitted child count is reconcilable against its own dispatch record (a counter, a log line, a fan-out manifest). If the parent cannot state how many children it expected, the tree cannot be validated against it. When any of these is violated, the tree remains syntactically valid but semantically unbound. The failure is not detectable by schema validation, parent-resolution checks, or "trace is complete" assertions — all of which pass. ## Decision Boundary The boundary is between **trusting the tree** and **reconciling the tree against dispatch records**. The decision rule: - If the parent span carries an authoritative dispatch manifest (expected child count and identities), reconcile. Mismatch → the parent edge is misbound; quarantine the subtree from causal analysis and re-derive parentage from the manifest rather than the `parent_span_id`. - If the parent carries no manifest, the tree is *unverifiable* for causal claims and may only be used for lineage/grouping. Do not compute error attribution or latency budgets from direct-child aggregation on unverifiable trees. - For long-lived instances: if the same `trace_id` appears across two tasks whose task IDs differ, the second task's spans are misparented by definition. Split the trace at the task boundary; do not merge. The guardrail is architectural, not observational: **make the parent emit its dispatch intent, then check the tree against it.** Observation alone cannot distinguish a genuine fourth branch from a misbound retry, because both are well-formed children. ## Operational Effect Without reconciliation, three concrete regressions appear: 1. **Error attribution drift** — retries and fallbacks are booked against the caller, inflating the caller's error rate and masking the true failing component. Alerting fires on the planner while the retriever is the actual fault. 2. **Latency budget undercount** — failed first attempts parented to the caller are excluded from the callee's critical path, so the callee appears faster than it is and its timeout budget is set too tight. 3. **Causal fusion across tasks** — long-lived agents fuse independent tasks into one chain, so root-cause walks cross task boundaries and "this error was caused by that upstream step" becomes false. The remediation is the same in all three: capture context at the call site after span creation, parent retries to the call site, invalidate cached context at task boundaries, and reconcile child counts against an emitted dispatch manifest. The tree is only trustworthy where it has been checked against intent. ```python class CausalSpanMisbindingError(RuntimeError): """Raised when a span tree is well-formed but its parent edges do not match the caller's emitted dispatch intent (misbound propagation).""" pass def reconcile_children(parent_span, dispatch_manifest, observed_children): """ parent_span: dict with 'span_id' and 'task_id' dispatch_manifest: dict {child_call_id: expected_child_span_id} observed_children: list of dicts with 'span_id', 'parent_span_id', 'task_id' """ expected = set(dispatch_manifest.values()) observed = {c["span_id"] for c in observed_children if c["parent_span_id"] == parent_span["span_id"]} # 1. Every dispatched call must appear as a child of the caller. missing = expected - observed if missing: raise CausalSpanMisbindingError( f"parent {parent_span['span_id']} dispatched {len(expected)} calls " f"but {len(missing)} children are absent from the tree: {sorted(missing)}" ) # 2. No child may appear that the caller did not dispatch. # A retry parented to the caller's parent shows up here. extra = observed - expected if extra: raise CausalSpanMisbindingError( f"parent {parent_span['span_id']} has undispatched children " f"(likely misbound retry/fallback): {sorted(extra)}" ) # 3. No child may belong to a different task than its parent. for c in observed_children: if c["parent_span_id"] == parent_span["span_id"] and \ c["task_id"] != parent_span["task_id"]: raise CausalSpanMisbindingError( f"child {c['span_id']} (task {c['task_id']}) parented to " f"{parent_span['span_id']} (task {parent_span['task_id']}): " f"cached context reused across task boundary" ) return True ```