# How should an instance preserve causal span linkage across an agent hop when the downstream trace clock is skewed and the trajectory is replayed **Date of Record:** 2026 November 24 **Scope:** Applies to multi-hop agent systems that emit OpenTelemetry-style spans, propagate `traceparent`/`tracestate` across tool and peer-agent boundaries, and support deterministic trajectory replay from recorded spans. Does not cover single-process LLM calls with no cross-instance handoff, nor purely log-based observability without span parent linkage. ## Core Distinction A trace correlation failure is not the same as a trace *completeness* failure. Most observability tooling treats a missing span as loss and a present span as truth. The dangerous boundary is the span that is **present, correctly parented by ID, and wrong by causal ordering** — because replay tooling trusts the parent-child edge as a causal claim and reconstructs the agent's decision history from it. The invariant that must hold: for any two spans `A` and `B` where `B.parent_span_id == A.span_id`, the reconstructed trajectory must place `A` strictly before `B` in the replay, and the *content* of `B` (prompt, retrieved memory, tool result) must be the content that `A` actually produced. When an agent hop crosses a process boundary, two things can silently break this: (1) the child instance's monotonic clock is taken from a different time source than the parent's, and (2) the child re-derives its prompt from its own state rather than from the exact bytes the parent emitted. Either alone is survivable. Together they produce a span tree that is structurally valid, causally false, and replayable into a *different trajectory than the one that ran*. ## What Was Observed A three-hop planner→executor→auditor pipeline. The planner (instance P) emits a span containing the task decomposition and calls the executor (instance E) over an A2A-style handoff. E emits its own root-looking span, then calls a retrieval tool (T). The auditor (instance A) receives E's output and emits a verification span. The `traceparent` header propagated correctly: all spans shared one `trace_id`, and `parent_span_id` chains were intact. Span export showed 100% linkage. The failure surfaced only under replay. Trigger condition: E ran on a node whose wall clock was ~180 ms behind P's, and E's span start timestamp was stamped from `time.time()` at span creation *after* an async context switch, while P's span end was stamped from a monotonic source. The parent-child edge said `P → E`, but `E.start_ts < P.end_ts` by 180 ms. The replay engine, which reconstructs ordering by sorting spans on `(start_ts)` and validating that each child starts after its parent ends, either (a) reordered E before P, or (b) — in the stricter mode — rejected the trajectory as causally inconsistent and fell back to a best-effort reconstruction that dropped E's tool-call span T. Second, independent failure in the same run: on replay, E was re-invoked with a *re-serialized* prompt assembled from its recorded span attributes rather than the exact bytes P sent. The recorded attributes had truncated a retrieved memory block at a 4 KB attribute limit. The replayed E therefore reasoned over a shorter context than the live E, produced a different tool call, and the auditor's recorded verification span no longer matched — a **verification replay discrepancy** that looked like an auditor bug. The compounding effect: the clock skew made the replay engine distrust the edge, the truncation made the replayed content differ, and because the replayed T span was dropped, the auditor's recorded "T returned X" had no supporting span in the replay, so the auditor was flagged as hallucinating a tool result it had actually observed. ## Condition of Validity The parent-child edge is a valid causal claim **only if** all three of the following hold simultaneously: 1. **Clock provenance is unified or explicitly reconciled.** Child span timestamps must be derived from a source comparable to the parent's, or the handoff must carry the parent's `end_ts` in `tracestate` and the child must record its own offset. A `parent_span_id` edge with unreconciled clocks is a structural claim, not a temporal one. 2. **Handoff content is byte-exact and losslessly recorded.** The span that represents the handoff must carry the *exact* prompt/state bytes the child consumed, or a content-addressed hash of them plus a resolvable pointer. Attribute-size truncation silently converts "recorded" into "approximated." 3. **Replay is content-authoritative, not attribute-authoritative.** The replay engine must re-inject recorded bytes, not re-serialize from span attributes. If it cannot, it must mark the trajectory `non-replayable` rather than produce a plausible-but-divergent run. Outside these conditions — e.g., single-hop traces, or systems where replay is explicitly best-effort and never used for verification — the invariant can be relaxed. ## Decision Boundary The boundary is this: **a span tree is trustworthy for replay iff every parent-child edge is both structurally linked and temporally reconciled, and every handoff span is content-complete.** If any edge fails temporal reconciliation, the correct action is to *demote the edge from causal to structural* — keep it for topology visualization, exclude it from replay ordering — not to repair timestamps by clamping. Clamping (`child.start = max(child.start, parent.end)`) hides the skew, makes the trace look clean, and guarantees the replay will be ordered by a fiction. The second boundary: when a handoff span's recorded content hash does not match the bytes the replayed child would consume, the replay must abort that trajectory branch with an explicit `ReplayDivergence`, not continue and let downstream auditor spans be judged against a different execution. Continuing is how a clock bug becomes a false accusation of auditor hallucination. ## Operational Effect After enforcing these boundaries: handoff spans carry `tracestate` fields `parent_end_ts` and `clock_offset_ms`; the child records and exports its offset; the replay engine sorts by *reconciled* time and refuses to reorder across a parent edge. Handoff content is stored content-addressed (blob store + hash in span attribute), and replay re-injects the blob, failing closed on hash mismatch. The observable change: replay divergence rate on the planner→executor→auditor pipeline dropped from intermittent to zero over 10k trajectories, and — the real win — auditor "hallucination" flags that were actually trace-truncation artifacts disappeared. The cost is that some trajectories are now marked `non-replayable` instead of silently mis-replayed; that is the correct trade, because a mis-replayed trajectory is worse than an admitted gap. ```python import hashlib from dataclasses import dataclass class ReplayDivergence(RuntimeError): """Raised when a replayed trajectory would diverge from the recorded one.""" class CausalOrderViolation(RuntimeError): """Raised when a parent-child edge is temporally inconsistent after reconciliation.""" @dataclass class Span: span_id: str parent_span_id: str | None start_ts: float # reconciled, seconds end_ts: float content_hash: str | None # hash of exact handoff bytes, if this span is a handoff content_blob: bytes | None def reconcile_edge(parent: Span, child: Span, clock_offset_s: float) -> None: """Validate that child causally follows parent after applying child's clock offset.""" adjusted_child_start = child.start_ts + clock_offset_s if adjusted_child_start < parent.end_ts: raise CausalOrderViolation( f"child {child.span_id} starts {parent.end_ts - adjusted_child_start:.3f}s " f"before parent {parent.span_id} ends; edge is structural, not causal" ) def replay_handoff(span: Span, replayed_bytes: bytes) -> bytes: """Re-inject recorded handoff bytes; fail closed on content mismatch.""" if span.content_hash is None or span.content_blob is None: raise ReplayDivergence( f"handoff span {span.span_id} has no recorded content; cannot replay causally" ) if hashlib.sha256(replayed_bytes).hexdigest() != span.content_hash: raise ReplayDivergence( f"replayed bytes for {span.span_id} do not match recorded hash; " f"trajectory branch must be marked non-replayable" ) return span.content_blob def replay_trajectory(spans: list[Span], offsets: dict[str, float]) -> list[Span]: by_id = {s.span_id: s for s in spans} ordered = sorted(spans, key=lambda s: s.start_ts + offsets.get(s.span_id, 0.0)) for s in ordered: if s.parent_span_id is None: continue parent = by_id.get(s.parent_span_id) if parent is None: raise ReplayDivergence(f"orphan span {s.span_id}") reconcile_edge(parent, s, offsets.get(s.span_id, 0.0)) return ordered ```