# Why does an instance lose causal ordering of trace spans when a federated agent hop injects its own local clock into an inherited trace context? **Date of Record:** 2026 November 26 **Scope:** Applies to multi-hop agent federations (A2A, MCP-over-HTTP, custom RPC) where each agent propagates a W3C-style trace context (`traceparent`, `tracestate`) across a handoff and emits spans into a shared collector. Does not apply to single-process agents or to systems where all spans are stamped by one authoritative clock at the collector. ## Core Distinction There are two different things an agent hop can preserve when it forwards a trace: **identity correlation** (the same `trace_id` flows end-to-end, so spans can be *grouped*) and **causal ordering** (the parent-child and happens-before relations between spans are recoverable, so spans can be *sequenced*). Most federated agent stacks guarantee the first and silently lose the second. The failure is non-obvious because the trace *looks* complete in the UI — every span is present, the trace_id matches, nothing is orphaned — yet the reconstructed timeline is wrong, and any downstream reasoning that depends on "which agent knew what, when" (e.g. an auditor agent replaying a decision, or a verifier checking that a tool call preceded the claim it supports) is operating on a fabricated order. The mechanism is specific: a downstream agent, on receiving an inherited `tracestate`, must decide whether to **continue the parent's clock domain** or **start its own**. When it starts its own — because its runtime has no synchronized time source with the upstream, because it was cold-started behind a queue, or because its SDK auto-generates a `start_time` at span-construction rather than at logical-entry — it stamps its child span with a wall-clock timestamp that is *earlier* than the parent span's `end_time`. The collector, which orders sibling spans by timestamp, then renders the child as having happened before the parent finished, or before a sibling that logically preceded it. The causal edges (`parent_span_id`) are still correct in the raw records; the *presentation and any timestamp-based join* is not. ## What Was Observed A three-agent chain: `orchestrator → retriever → synthesizer`. The orchestrator emitted span `S_orch` (start T0, end T0+400ms), handed off to the retriever over A2A with a valid `traceparent`. The retriever ran for 900ms, emitted `S_retr`, and handed to the synthesizer. The synthesizer was cold-started (container spin-up, 1.2s queue delay) and its SDK stamped `S_synth.start_time` from the *host* clock, which had drifted −650ms relative to the orchestrator's NTP-synced host. Observed in the collector: - `S_synth.start_time` = T0+230ms — i.e. **before** `S_retr.end_time` (T0+1300ms) and even before `S_orch.end_time` (T0+400ms). - The parent-child edges were intact: `S_synth.parent_span_id == S_retr.span_id`. So the *graph* was correct. - But the auditor agent, which reconstructs order by sorting spans on `start_time` when the parent edge is ambiguous across federation boundaries (a common fallback when `parent_span_id` points to a span in a *different* `tracestate` it cannot resolve), placed `S_synth` first. It then concluded the synthesizer's output *caused* the retrieval, inverted the causal claim, and emitted a passing verification for a sequence that never occurred. The tell: `tracestate` carried a vendor key `clk=local` injected by the synthesizer's SDK at span creation, overwriting the inherited upstream clock-domain marker. The synthesizer had *decided* to start a new clock domain without recording that decision as a causal break. ## Condition of Validity The invariant that must hold for timestamp-based ordering to be sound across a federated hop is: > For any two spans A and B where A causally precedes B, `A.end_time ≤ B.start_time` **in a single shared clock domain**, OR the trace records an explicit **clock-domain transition** at the hop so that any consumer knows not to compare A and B on raw timestamps. This holds only when every hop either (a) inherits and preserves the upstream clock domain and its offset correction, or (b) emits a `clock_skew` / `causality_break` annotation with the measured offset at the handoff. It fails whenever an agent silently substitutes its local clock and the collector has no way to distinguish "B genuinely started early" from "B's clock is behind." The failure is *latent* — invisible until a consumer sorts or joins on timestamps rather than walking parent edges. ## Decision Boundary The architectural guardrail is a hard rule at the handoff boundary, enforced by the receiving agent's trace middleware before it emits any span: 1. On receiving an inherited `tracestate`, the agent **must not** overwrite the upstream clock-domain key. If it cannot honor the upstream domain, it must append a `clk_break=` entry and set a span attribute `causality.break=true`. 2. The collector must **refuse to order** any pair of spans whose `clk_break` markers disagree, surfacing them as "unordered" rather than sorting them. 3. Any auditor or verifier that reconstructs order must prefer the parent-edge walk; timestamp sort is permitted **only** within a single clock domain. The boundary decision: if `causality.break` is set anywhere on the path between two spans, the consumer must treat their relative order as *unknown*, not *inferred*. Inferring order across a clock-domain break is the bug; the guardrail converts a silent wrong answer into an explicit "cannot order." ## Operational Effect Without the invariant, the system produces **confidently wrong causal reconstructions** — the worst failure class for an auditor agent, because the trace is complete and the trace_id matches, so nothing triggers a re-check. Downstream effects compound: a verifier that inverts a cause-effect edge will pass a replay that contradicts ground truth; a memory-distillation step that summarizes "what the retriever told the synthesizer" will attribute the synthesis to the wrong input; and a second auditor run on the same trace may reach a *different* order if clock drift differs between runs, making the verification non-deterministic across replays. With the `clk_break` guardrail, the same trace yields an explicit unordered pair, the auditor escalates to parent-edge resolution (which is always available and always correct), and the reconstruction is deterministic and sound. The cost is one extra `tracestate` key and a collector-side refusal rule; the benefit is that causal ordering survives federation instead of being silently fabricated by the first cold-started hop. ```python class CausalOrderViolation(RuntimeError): """Raised when a consumer attempts to order spans across a clock-domain break.""" pass def order_spans(spans: list[dict]) -> list[dict]: """ Reconstruct causal order. Timestamp sort is only legal within a single clock domain; across a clk_break the order is unknown and must be resolved by parent-edge walk, never by start_time. """ domains = {s.get("clk_domain", "upstream") for s in spans} breaks = [s for s in spans if s.get("causality.break")] if breaks and len(domains) > 1: # We have spans from >1 clock domain and at least one explicit break. # Sorting by start_time here would fabricate an order. raise CausalOrderViolation( f"cannot timestamp-order {len(spans)} spans across " f"{len(domains)} clock domains with {len(breaks)} causality breaks; " f"resolve via parent_span_id walk instead" ) # Single domain (or no breaks): timestamp sort is sound. return sorted(spans, key=lambda s: s["start_time"]) def verify_handoff(parent: dict, child: dict) -> None: """Enforce the handoff invariant before a child span is emitted.""" if child.get("clk_domain") != parent.get("clk_domain") and not child.get("causality.break"): raise CausalOrderViolation( f"hop {parent['span_id']}->{child['span_id']} changed clock domain " f"({parent.get('clk_domain')}->{child.get('clk_domain')}) " f"without setting causality.break; child start_time would be " f"unorderable against parent end_time" ) ```