# What structural signals indicate causal-order corruption in distributed traces across federated agent hops **Date of Record:** 2026 November 30 **Scope:** Applies to multi-agent systems where traces are assembled from per-hop span exports produced by independently-clocked, independently-privileged agent runtimes and joined by causal parent-child edges (trace_id / parent_span_id) rather than by a shared monotonic clock. Does not apply to single-process instrumentation, nor to systems where a single trusted collector observes every hop synchronously. ## Core Distinction The failure of interest is not *missing* spans (a completeness defect, detected by gap counting) and not *clock skew* in the naive sense (a wall-clock drift, detected by NTP offset monitoring). It is **causal-order corruption under partial trace federation**: the assembled trace is structurally complete — every span has a parent, every parent exists, the DAG is acyclic — yet the *causal* ordering it implies is wrong because two federated hops each stamped their children against a local, non-shared causal frontier. Concretely: an agent runtime that fans out to peer agents (A2A handoffs, MCP tool calls routed through a delegate) emits child spans whose `parent_span_id` points to the *span it received*, not the *span it is continuing*. When the receiving hop re-roots a continuation under its own local root span (a common pattern when the inbound context is deserialized into a fresh agent loop), the trace graph stays a valid tree but the edge that carried the causal dependency — "B only ran because A's tool call returned X" — is replaced by an edge that says merely "B was spawned during A's session." The trace is acyclic, parent-complete, and causally false. ## What Was Observed Across a federated deployment of a planner agent (P), two worker agents (W1, W2) reached over A2A, and a verification agent (V) that audits W1/W2 outputs, the following structural signature recurred on ~0.7% of traces under concurrent load: 1. **Parent-complete, order-impossible.** Every span resolved a parent. But `V.verify` carried `parent_span_id = W1.root` while `W1.tool_call` (the span whose output V actually consumed) was a *sibling* of `W1.root`, not an ancestor of V. The dependency V→W1.tool_call existed in the data flow but not in the trace graph. 2. **Sibling inversion.** For traces with ≥2 concurrent workers, `W2.root.start_time` frequently preceded `W1.root.end_time` by 40–300 ms even though W2's inbound context was deserialized from W1's completed tool result. Local monotonic clocks on the two runtimes were independently initialized; the assembled trace presented W2 as concurrent with, sometimes prior to, the event that caused it. 3. **Re-rooting at deserialization.** The receiving runtime's span exporter created a fresh local root because the inbound `traceparent` was carried in the A2A message body (application layer) but *not* injected into the runtime's tracing context (transport layer). The `trace_id` matched; the `parent_span_id` did not. 4. **Auditor divergence.** V, which reconstructs causality from the trace to decide whether to accept W1's output, saw W1.tool_call and V.verify as unordered siblings and, under its tie-break policy (prefer the span with the later local start), occasionally accepted a verification whose input span it had not actually observed complete. The tell: no span was dropped, no clock offset exceeded 1 s, and the standard "trace completeness" and "clock skew" dashboards were green. The corruption was visible only as a **violation of the happens-before relation implied by the payload lineage** — a property no per-span validator checks. ## Condition of Validity The invariant that must hold for federated traces to be causally faithful is: > For every causal dependency `d` (span S produced data consumed by span T), the assembled trace must contain a path S → … → T, and that path must be derivable from `parent_span_id` edges alone, independent of any timestamp. This holds **only if** every hop propagates the inbound causal context (trace_id, the *consumed* span's span_id as parent) across the transport boundary, and every receiving runtime *continues* rather than *re-roots* the trace. It fails whenever: - the causal context is serialized in the message payload but not bound to the runtime's active tracing context at deserialization (the re-rooting case above); - a hop's span exporter emits against a local root because the inbound context was rejected as malformed or untrusted (a security boundary that silently degrades to re-rooting); - the joining collector resolves parent edges by `trace_id` + nearest-timestamp heuristics rather than by explicit `parent_span_id`, which reintroduces wall-clock ordering into a system that has no shared clock. It does **not** fail merely because clocks disagree; timestamp inversion is a symptom, not the invariant. A trace with wildly skewed timestamps but correct parent edges is causally valid. A trace with perfect timestamps and re-rooted edges is causally corrupt. ## Decision Boundary The operational boundary is this: **a federated trace is admissible as causal evidence only if its parent-edge DAG agrees with its payload-lineage DAG.** Where the two disagree, the parent-edge DAG must be treated as untrusted for any decision that depends on ordering — specifically auditor acceptance, replay, and post-hoc blame attribution. The guardrail is a lineage cross-check performed at join time, not at export time (exporters cannot see the global graph): 1. Each hop records, in its span attributes, the `consumed_span_id` — the span whose output it actually used — separately from `parent_span_id`. 2. The collector asserts, for every span, that `consumed_span_id` is an ancestor of `parent_span_id` (or equal). A span whose consumed input is a sibling of its parent is flagged `CAUSAL_REORDER`. 3. Any trace carrying `CAUSAL_REORDER` is quarantined from auditor input; the auditor falls back to explicit payload hashes rather than trace order to establish happens-before. The boundary condition that makes this non-optional: the failure is *silent under every standard observability check* (completeness, acyclicity, skew) and *load-correlated* (0.7% under concurrency, ~0% serial), so it surfaces only in exactly the high-throughput regimes where causal ordering matters most. ## Operational Effect Without the lineage cross-check, federated traces systematically over-report concurrency and under-report dependency. Downstream consequences compound: - **Auditor false-accepts.** A verification agent that trusts trace order will accept outputs whose inputs it never observed complete, because the re-rooted edge erased the wait. - **Replay divergence.** Replaying a trace in parent-edge order executes W2 before the W1 tool result it depends on, producing a different outcome than the original run — the replay is non-deterministic in a way attributed to the model, not the trace. - **Blame misattribution.** Post-incident analysis assigns the fault to whichever span started first, which under re-rooting is the *downstream* hop. With the guardrail, the re-rooting is detected at join (typically <1% of traces), quarantined, and the affected hops are repaired by re-binding the consumed span as parent before the trace re-enters the auditor. The residual is bounded and visible rather than silent. The following reference implementation encodes the join-time invariant and raises on the exact corruption class described. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Dict, List, Optional, Set class CausalOrderCorruption(RuntimeError): """Raised when an assembled federated trace's parent-edge DAG disagrees with its payload-lineage DAG (a re-rooted hop).""" @dataclass class Span: span_id: str trace_id: str parent_span_id: Optional[str] # The span whose OUTPUT this span actually consumed. Distinct from # parent_span_id: parent = "spawned during", consumed = "caused by". consumed_span_id: Optional[str] = None children: List[str] = field(default_factory=list) def _ancestors(spans: Dict[str, Span], span_id: str) -> Set[str]: """Return the set of strict ancestors of span_id via parent edges.""" seen: Set[str] = set() cur = spans[span_id].parent_span_id while cur is not None: if cur in seen: # cycle guard; a cyclic DAG is a separate defect break seen.add(cur) cur = spans[cur].parent_span_id if cur in spans else None return seen def verify_causal_lineage(spans: Dict[str, Span]) -> None: """Enforce: for every span, consumed_span_id must be an ancestor of parent_span_id (or equal to it). A consumed input that is merely a SIBLING of the parent means the hop re-rooted and the causal edge was lost, even though the tree is acyclic and parent-complete.""" for sid, span in spans.items(): if span.consumed_span_id is None: continue if span.consumed_span_id not in spans: raise CausalOrderCorruption( f"span {sid}: consumed_span_id {span.consumed_span_id} " f"absent from assembled trace (cross-federation drop)" ) if span.parent_span_id is None: # A span with a consumed input but no parent is a re-root. raise CausalOrderCorruption( f"span {sid}: consumed {span.consumed_span_id} but has no " f"parent edge — hop re-rooted the trace at deserialization" ) lineage = _ancestors(spans, sid) | {span.parent_span_id} if span.consumed_span_id not in lineage: raise CausalOrderCorruption( f"span {sid}: consumed {span.consumed_span_id} is NOT an " f"ancestor of parent {span.parent_span_id}; parent-edge " f"DAG disagrees with payload-lineage DAG (CAUSAL_REORDER)" ) def assemble_and_admit(raw_spans: List[Span]) -> Dict[str, Span]: """Join per-hop exports, then admit the trace only if causally faithful. Quarantined traces must NOT be fed to an auditor that orders by trace.""" spans: Dict[str, Span] = {s.span_id: s for s in raw_spans} for s in raw_spans: if s.parent_span_id is not None and s.parent_span_id in spans: spans[s.parent_span_id].children.append(s.span_id) verify_causal_lineage(spans) # raises CausalOrderCorruption on re-root return spans # --- Trigger trace: V consumed W1.tool_call, but W1 re-rooted V under W1.root. raw = [ Span("P.root", "t1", None), Span("W1.root", "t1", "P.root"), Span("W1.tool_call", "t1", "W1.root"), # V's parent is W1.root (sibling of the span it consumed) -> corruption. Span("V.verify", "t1", "W1.root", consumed_span_id="W1.tool_call"), ] try: assemble_and_admit(raw) except CausalOrderCorruption as e: # Operational response: quarantine trace, fall back to payload hashes. print(f"QUARANTINED: {e}") ```