# Why does an instance lose causal span linkage when a federated peer rewrites its trace context during a cross-mesh handoff **Date of Record:** 2026 November 26 **Scope:** Applies to multi-agent meshes that propagate W3C-style trace context (`traceparent`/`tracestate`) and causal span links across trust-domain boundaries via A2A or MCP handoffs. Does not apply to single-mesh, single-trust-domain tracing where one collector owns the entire span tree, nor to log-only correlation without explicit parent/child span emission. ## Core Distinction The failure is not "tracing is missing." It is that **the trace graph remains structurally valid while being causally false**. When agent instance A hands a task to federated peer B, B often re-roots the incoming span under its own local trace ID because its collector or SDK is configured to never accept a foreign `traceparent` from an untrusted origin. The resulting span tree is well-formed: every span has a parent, IDs are 128-bit hex, the collector accepts them. What breaks is the *causal edge*: A's span and B's span now live in two disconnected trace trees, and any downstream auditor that reconstructs "who caused what" via `parentSpanId` sees two independent roots rather than one causal chain. This is distinct from span *loss* (dropped spans) or span *corruption* (malformed IDs). Here nothing is dropped and nothing is malformed. The invariant that fails is the one operators assume implicitly: *trace-ID equality is a proxy for causal identity*. Across a federation boundary it is not, because the peer is entitled—by its own policy—to mint a fresh trace ID while still claiming to have "continued" the work. ## What Was Observed A three-mesh pipeline: planner mesh (trust domain `planner.corp`), execution mesh (`exec.corp`), audit mesh (`audit.partner`). The planner emits a root span `plan.dispatch` with `traceId=T1`, `spanId=S1`, and calls execution via A2A with a `traceparent: 00-T1-S1-01`. Execution's SDK is configured with `propagation.trust_incoming=false` because it treats all inbound traffic as potentially hostile (a reasonable prompt-injection defense). On receipt it: 1. Validates the `traceparent` syntactically — passes. 2. Rejects the foreign `traceId` per policy — mints `T2`. 3. Emits `exec.run` with `traceId=T2`, `spanId=S2`, and records the inbound `traceparent` in a non-standard attribute `inbound.traceparent=T1-S1` rather than as `parentSpanId`. The audit mesh, which reconstructs causality by joining on `parentSpanId`, sees `exec.run` as a root. It cannot link `exec.run` to `plan.dispatch`. Worse, because the execution agent *did* record the inbound context as an attribute, a naive auditor that also parses `inbound.traceparent` will link correctly—so two auditors in the same mesh produce **conflicting causal reconstructions** from the same span store. This is the non-obvious part: the data needed for correlation exists, but it is stored in a field the causal-join path does not read, and the presence of two possible join keys makes consensus on "what happened" non-deterministic. The trace remained "green" on all dashboards because span counts, error rates, and latency percentiles were computed per-trace-ID and per-service, never across the federation seam. ## Condition of Validity The causal-linkage invariant holds only under the conjunction: - The receiving peer either preserves the inbound `traceId` (continuing the trace) **or** explicitly emits a *span link* (`links[]` entry with `linkedTraceId`/`linkedSpanId`) rather than re-rooting silently, **and** - Every auditor that reconstructs causality reads the *same* join key set (either `parentSpanId` only, or `parentSpanId ∪ links ∪ inbound.traceparent`), **and** - The `tracestate` header, which is the only standards-blessed channel for propagation metadata across trust boundaries, is used to carry the "continued-from" pointer rather than an out-of-band attribute. If any conjunct fails, causal reconstruction is either broken or non-deterministic. In the observed case, conjunct 1 and conjunct 2 both failed. The invariant is *not* violated by legitimate re-rooting when the peer also emits an explicit `links[]` entry—that is the correct way to sever a trace while preserving causality. The failure is specifically **silent re-rooting**: severing without a link, and stashing the severed pointer in an attribute the join path ignores. ## Decision Boundary The boundary is: *does the peer's trust policy permit continuing a foreign trace ID?* - **If yes:** continue the trace; preserve `traceId` and set `parentSpanId=S1`. Causality is automatic. Cost: the peer's spans are now attributable to a foreign trace, which may leak cross-tenant volume into the origin's trace tree. - **If no (the common security posture):** the peer **must** emit an explicit span link and **must** populate `tracestate` with a `continued-from` entry, and the auditor **must** be configured to traverse links. Re-rooting without a link is only acceptable if the receiving mesh is a true trust boundary that intends to *hide* causality from the origin—in which case the audit mesh must be told, in advance, that cross-seam joins are impossible and must fall back to a signed handoff receipt (a warrant) as the causal witness instead of the span graph. The dangerous middle ground—re-root *and* record the inbound pointer in a side attribute—is the worst option because it manufactures a second, competing join key. Any system that adopts it must also adopt a canonical join-key policy or it will produce auditor disagreement. ## Operational Effect The practical consequence is that **causal replay becomes non-reproducible across auditors**. Two audit agents consuming the same span store, one joining on `parentSpanId` and one on `inbound.traceparent`, will disagree about whether `exec.run` was caused by `plan.dispatch`. In a swarm where an auditor agent verifies another agent's work by replaying the causal chain, this disagreement manifests as a *false verification failure*: the auditor concludes the execution agent acted without authorization, when in fact the authorization edge exists but is stored in the wrong field. This is a verification-replay discrepancy rooted in a tracing-schema mismatch, not in a real policy violation. The guardrail is a **canonical causal-join contract** enforced at the mesh ingress: a single function that, given a span, returns its causal predecessor by consulting `parentSpanId`, then `links[]`, then `tracestate.continued-from`, in that fixed order—and that *refuses* to fall back to arbitrary attributes. Any peer that re-roots without populating one of the sanctioned fields is rejected at handoff time, converting a silent causal break into a loud, bounded handoff error. The code below implements that ingress check. ```python import re _TRACEPARENT_RE = re.compile(r"^00-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$") _SANCTIONED_LINK_KEYS = ("parentSpanId", "links", "tracestate.continued-from") class CausalLinkageError(RuntimeError): """Raised when a federated handoff severs causal linkage silently.""" def resolve_causal_predecessor(span: dict) -> str: """ Return the causal predecessor span ID for a received span, or raise. Canonical join order: parentSpanId -> links[] -> tracestate.continued-from. Arbitrary attributes (e.g. 'inbound.traceparent') are deliberately ignored so that a peer cannot manufacture a second, competing join key. """ if span.get("parentSpanId"): return span["parentSpanId"] for link in span.get("links", []): if link.get("linkedSpanId"): return link["linkedSpanId"] continued = span.get("tracestate", {}).get("continued-from") if continued: m = _TRACEPARENT_RE.match(continued) if not m: raise CausalLinkageError( f"malformed continued-from in tracestate: {continued!r}" ) return m.group(2) # Detect the dangerous middle ground: re-rooted, pointer stashed in a # non-sanctioned attribute. This is the exact condition that produces # divergent auditor reconstructions. stray = [k for k in span if k not in _SANCTIONED_LINK_KEYS and ("traceparent" in k or "trace_id" in k)] if stray: raise CausalLinkageError( "span re-rooted with foreign context in non-sanctioned field(s) " f"{stray}; causal join is ambiguous across auditors. " "Peer must emit links[] or tracestate.continued-from." ) raise CausalLinkageError( f"span {span.get('spanId')} has no resolvable causal predecessor; " "handoff severed causality without a sanctioned link." ) def ingest_federated_span(span: dict) -> str: """Mesh ingress gate: reject silent re-rooting before it enters the store.""" pred = resolve_causal_predecessor(span) if pred == span.get("spanId"): raise CausalLinkageError("self-referential causal edge detected") return pred ```