# Where must an instance anchor a federated trace's causal clock when its parent span arrives after the child has already committed side effects? **Date of Record:** 2026 November 23 **Scope:** Applies to multi-agent systems where spans are propagated across independently-clocked agent runtimes (A2A handoffs, MCP tool calls crossing trust domains) and where child agents execute irreversible side effects (writes, payments, external tool invocations) before receiving their parent's trace context. Does not apply to single-process, single-clock tracing where the parent context is guaranteed to be in the child's initial envelope. ## Core Distinction The distinction that matters is between **causal ordering as a metadata property** and **causal ordering as a physical constraint on side effects**. Conventional distributed tracing (OpenTelemetry-style) treats the trace as a *record* of causality: the parent span ID and `traceparent` header are annotations you attach to work that has already been scheduled, and the collector reassembles them post-hoc. Lamport/Hybrid Logical Clocks (HLC) exist precisely because wall clocks disagree, so the trace graph tolerates out-of-order arrival — the collector sorts by `(trace_id, span_id, parent_span_id)` and reconstructs the DAG. The failure mode in federated agent systems is that the *side effect* is not a record. When agent B executes a tool call — issues a refund, writes a memory record, mutates a shared vector index — it commits a durable state transition that the trace graph is supposed to *explain*. If B's parent context (A's span) arrives after B has already committed, the trace graph will show A→B, but the *actual* causal chain may have been B→A→B (B acted speculatively, A retroactively adopted it), or A→B and A'→B in a fork, and the graph will silently lie. The invariant that breaks is not "spans must be ordered" but **"no span may commit a side effect before its causal predecessor's clock is pinned."** ## What Was Observed A federated swarm of three agent runtimes (call them Planner, Executor, Auditor) using A2A handoffs with `traceparent` propagation in message headers. Executor's runtime was configured for *optimistic dispatch*: on receiving a task envelope it began tool execution immediately, buffering the trace context until the first `await` yielded, then attached headers on outbound calls. Under load, the envelope's `traceparent` field arrived in a *second* message — a follow-up "context sync" frame sent by Planner asynchronously after the primary task frame — because Planner's envelope serializer emitted the task payload and the trace header from two different coroutines with no ordering guarantee between them. The observed trace: Executor's tool-call span `E1` carried a parent of `P0` (Planner's root) in 94% of cases, but in the remaining 6% — precisely the cases where Planner's context-sync frame was delayed past Executor's first tool dispatch — `E1` was emitted with a *synthetic* root parent (a locally-generated `P_local` root, because Executor's fallback on missing parent was to mint one). When the real `P0` arrived 40–200 ms later, Executor's tracer adopted it and *rewrote* `E1`'s parent to `P0`, but the side effect (a memory write to the shared episodic store) had already committed under a key derived from `P_local`. Consequence: the Auditor, replaying the trace to verify consistency, saw `P0 → E1 → A1` (Auditor's verification span) and concluded the memory write was causally downstream of Planner's intent. It was not — it was downstream of a *local* root that Planner had no record of. The Auditor's replay passed. The actual state divergence (a memory record keyed to a phantom trace) was invisible to trace-based verification because the trace had been *repaired* to look consistent. The signature of this failure is a **trace that is internally consistent but externally false** — the DAG is acyclic, parent links resolve, clocks are monotonic within each runtime, and yet the causal story is fabricated by the late-binding repair. ## Condition of Validity The invariant "parent context precedes side effect" holds only when the following condition is met at every child runtime: > A child span may not emit, commit, or key any durable artifact until its `parent_span_id` and the parent's HLC component have been *received and pinned*, not merely *expected*. This is stronger than "trace context must be in the envelope." It requires the envelope's trace fields to be **causally ordered with respect to the payload within the same transport frame**, or, if split across frames, gated by an explicit `context_ready` barrier. The condition fails in any of three ways: 1. **Frame split without barrier.** Task payload and trace header emitted from separate coroutines (the observed case). Fix: single-frame atomic envelope, or a `context_ready` flag the child must observe before dispatching. 2. **Optimistic dispatch with late parent adoption.** Child mints a local root on missing parent and repairs later. This is the *dangerous* variant because it produces a valid-looking trace. Fix: missing parent is a hard error, not a fallback — the child must block or fail, never synthesize. 3. **Clock skew exceeding the HLC tolerance window.** If child and parent HLCs diverge by more than the trace's `max_clock_drift`, the parent's timestamp may sort *after* the child's even when the parent causally precedes it. Fix: HLC reconciliation on handoff, with the child's clock advanced to `max(local, parent_hlc + 1)` on receipt. The condition is *not* satisfied by "the collector will sort it out." The collector sorts records; it cannot unsort side effects. ## Decision Boundary The boundary is between **repairable** and **unrepairable** late-arriving parent context: - **Repairable:** The child has not yet committed a side effect. The parent arrives, the child pins it, the span is emitted correctly. No action needed beyond the barrier. - **Unrepairable:** The child has committed a side effect keyed to a synthetic or absent parent. The correct response is **not** to rewrite the parent link (which fabricates causality) but to emit a **causality-gap marker**: a span of kind `LINK_REPAIR` with `attributes.trace.causal_gap = true`, `attributes.trace.synthetic_parent = P_local`, and `attributes.trace.adopted_parent = P0`, plus a `links` entry to `P0` rather than a parent rewrite. The Auditor must treat any `causal_gap` span as *unverifiable* and route the associated side effect to reconciliation, not to the passing replay. The decision rule: **if the side effect's key derives from the synthetic parent, the side effect is orphaned and must be re-keyed or rolled back; if the side effect's key is independent of the trace, the span may be linked but not re-parented.** Rewriting the parent is always wrong — it converts a detectable gap into an undetectable lie. ## Operational Effect Downstream, three concrete effects: 1. **Auditor replay becomes unsound.** A replay that trusts parent links will pass traces with repaired causality. The Auditor must be given the `causal_gap` markers and must *fail closed* on them — a trace containing an unresolved gap cannot certify the associated memory writes. 2. **Memory store accumulates phantom-trace records.** Episodic records keyed to `P_local` are unreachable from any Planner-originated query. They must be swept by a reconciliation job that matches `synthetic_parent` spans against late-arriving `P0` frames within a bounded window (observed: 200 ms tail; set window to p99.9 of context-sync latency, not a fixed constant). 3. **The trace graph's acyclicity is no longer sufficient for correctness.** Teams relying on "the DAG is acyclic and parents resolve" as a health check will miss this class entirely. The health check must be augmented with: *no span may have `attributes.trace.synthetic_parent` set without a corresponding `causal_gap` marker*, and *no side-effect-bearing span may have a parent whose HLC timestamp is later than the span's own commit timestamp by more than the drift tolerance*. The guardrail that bounds the failure: **pin-before-commit**. The child runtime's dispatch loop must acquire the parent context (or fail) before the first side-effecting call, and the trace emitter must refuse to emit a side-effect-bearing span with an unresolved parent. This is enforced below. ```python import time from dataclasses import dataclass, field from typing import Optional class CausalityGapError(RuntimeError): """Raised when a side effect would commit before its parent context is pinned.""" pass @dataclass class TraceContext: trace_id: str span_id: str hlc: int synthetic: bool = False @dataclass class ChildRuntime: runtime_id: str local_hlc: int = 0 pinned_parent: Optional[TraceContext] = None drift_tolerance: int = 50 # HLC ticks; p99.9 of observed context-sync skew committed_effects: list = field(default_factory=list) def receive_context(self, parent: TraceContext) -> None: # HLC reconciliation: advance local clock past parent on receipt. self.local_hlc = max(self.local_hlc, parent.hlc + 1) if parent.synthetic: # Synthetic parents are never valid predecessors for side effects. raise CausalityGapError( f"runtime {self.runtime_id}: refusing synthetic parent " f"{parent.span_id}; mint a causal_gap marker, not a parent" ) self.pinned_parent = parent def commit_side_effect(self, effect_key: str, tool: str) -> str: if self.pinned_parent is None: # The critical guard: no fallback root, no optimistic dispatch. raise CausalityGapError( f"runtime {self.runtime_id}: side effect '{tool}' attempted " f"before parent context pinned; block or fail, never synthesize" ) if self.local_hlc - self.pinned_parent.hlc > self.drift_tolerance: raise CausalityGapError( f"runtime {self.runtime_id}: clock skew {self.local_hlc - self.pinned_parent.hlc} " f"exceeds tolerance {self.drift_tolerance}; reconcile HLC before commit" ) # Effect is keyed to the *pinned* parent span, not a local root. keyed = f"{self.pinned_parent.span_id}/{effect_key}" self.committed_effects.append((tool, keyed, self.local_hlc)) return keyed def dispatch_with_barrier(rt: ChildRuntime, envelope: dict) -> str: """Envelope must carry trace context atomically with payload.""" ctx = envelope.get("trace_context") if ctx is None: # Split-frame case: wait for context-sync, do not dispatch. raise CausalityGapError( f"runtime {rt.runtime_id}: envelope missing trace_context; " f"refuse dispatch until context_ready barrier observed" ) rt.receive_context(ctx) return rt.commit_side_effect(envelope["effect_key"], envelope["tool"]) ```