# What structural signals indicate causal trace reconstruction has silently diverged across federated agent spans and tool-call boundaries **Date of Record:** 2026 November 28 **Scope:** Applies to multi-agent and tool-augmented LLM systems where observability traces are assembled from spans emitted by independently instrumented processes (agent runtime, MCP servers, sandboxed tool executors) joined post-hoc by trace/span IDs. Does not address single-process in-memory tracing or metrics-only telemetry. ## Core Distinction The failure this record isolates is *causal reconstruction divergence*: the condition where a trace graph is structurally complete—every span has a parent, every span ID resolves, the join produces no orphans—yet the reconstructed causal order is wrong. This is distinct from trace loss (missing spans, which are loud) and from clock skew alone (which is bounded and measurable). The silent case is that the *parent-child edges are correct but the happens-before relation between sibling spans across federated boundaries is inverted or scrambled*, because each emitter stamped timestamps from its own monotonic clock and the aggregator sorted by wall-clock time. The trace looks healthy; the causal story it tells is false. The invariant that is violated: **for any two spans A and B where A's output is an input to B, the reconstruction must place A before B in the causal partial order, regardless of wall-clock timestamps.** Distributed tracing normally preserves this via context propagation (W3C traceparent) plus a clock-skew correction. In agent systems it breaks because the tool boundary is often asynchronous, the tool is a separate vendor's MCP server with its own clock, and the agent runtime resumes *before* the tool's span is flushed—so the resumption span and the tool span are siblings whose order is decided by timestamp comparison rather than by the propagated causal link. ## What Was Observed A three-hop agent execution: planner agent `P` calls an MCP tool `T1` (a retrieval server) whose result feeds a second agent `W` (a writer), which calls tool `T2` (a code sandbox). All four processes emit OTLP spans to a collector. The collector joins on `trace_id` and, where `parent_span_id` is absent, infers parentage by nearest-preceding timestamp within the same trace. The trace assembled cleanly: 41 spans, zero orphans, p99 join latency 12ms. But the reconstructed order showed `W`'s invocation span (emitted at `W`'s wall clock, which was 340ms ahead due to NTP drift) *preceding* `T1`'s completion span. The causal edge `T1.complete → W.invoke` existed only as an implicit dependency (the agent runtime never set `parent_span_id` on the handoff because the MCP client library didn't propagate the traceparent header across the stdio transport). The aggregator therefore fell back to timestamp ordering and produced a graph in which the writer appeared to consume data before the retrieval finished. The structural signals that flagged this, in order of reliability: 1. **Sibling timestamp inversion against a known causal edge.** The MCP request span (`T1.request`) and its response span (`T1.response`) are emitted by the *same* process and thus share a clock. The gap `T1.response.start − T1.request.end` is trustworthy. When `W.invoke.start` falls inside that gap but `W`'s declared parent is `P`, the trace contains a span that is temporally nested inside a span it is not causally descended from—a *temporal containment violation*. This is the single strongest signal and it is computable without any external ground truth. 2. **Missing traceparent on cross-transport handoffs.** Grepping the span attributes: `T1` spans carried `trace_id` but no `parent_span_id` pointing at `P`'s handoff span. The stdio MCP transport does not carry HTTP headers, so the W3C context was dropped at the process boundary and re-synthesized by the tool's own instrumentation with a fresh root. This is the *root cause*, and it is detectable by counting spans whose `parent_span_id` is null but whose `trace_id` matches a live trace. 3. **Clock offset exceeding the causal slack.** For each emitter, the aggregator can estimate offset by comparing paired request/response spans (same-process, trustworthy) against the caller's view of the same events. A per-emitter offset of 340ms with a causal slack (the true inter-span gap) of 80ms means timestamp ordering cannot resolve the order—the *resolution* of the clock is coarser than the *separation* of the events. This is the condition under which timestamp fallback is guaranteed to be unsound. 4. **Retry-induced span duplication with divergent parents.** When `T1` timed out and the runtime retried, the retry span carried a new `span_id` but the *original* attempt's response eventually arrived and was recorded under the old parent. The trace now contains two `T1.response` spans for one logical call, one of which is causally downstream of the retry. This is the reordering that turns a benign retry into a phantom causal path. ## Condition of Validity The reconstruction is sound only when **all three** hold simultaneously: - **Context propagation is total:** every cross-process handoff carries the traceparent (or equivalent) so `parent_span_id` is set by the emitter, not inferred by the aggregator. If any transport (stdio, a message queue, a subprocess pipe) drops the header, the aggregator's timestamp fallback is engaged and the invariant is at risk. - **Clock offset < causal slack for every emitter pair that has a causal edge.** The aggregator must compute per-emitter offset and, where offset ≥ the minimum observed gap between causally-linked spans, refuse to order by timestamp and mark the edge `UNORDERED` rather than guessing. - **At-most-once span emission per logical call,** or explicit deduplication keyed on `(logical_call_id, attempt)` before the graph is built. Retries must be modeled as a causal fork, not two independent responses. When any of these is false, the trace is *structurally valid but causally unsound*, and the aggregator must surface that state rather than emit a confident graph. ## Decision Boundary The boundary between "trust the reconstructed order" and "refuse to order" is crossed when the aggregator detects a temporal containment violation *and* cannot resolve it via a propagated causal edge. Concretely: - If `W.invoke` is temporally contained in `T1.request..T1.response` but `W`'s parent is not `T1`, and no traceparent links them, the edge `T1.response → W.invoke` is **inferred and must be labeled inferred**, not asserted. - If the per-emitter clock offset exceeds the causal slack for that edge, the aggregator must **not** order by timestamp; it must emit the edge as `UNORDERED` and flag the trace `causally_degraded`. - If a retry produces two responses for one logical call, the aggregator must **fork** the causal path at the retry and mark the late-arriving response as `orphaned_attempt`, never splice it into the original path. The rule: **an inferred causal edge may never be presented with the same confidence as a propagated one.** The trace UI and the downstream agent that consumes the trace must be able to distinguish them, because an agent reasoning over a causally-degraded trace will draw false conclusions about why a task failed. ## Operational Effect The practical consequence is that post-hoc debugging of agent failures is systematically misled in exactly the cases that matter most: async tool calls, retries, and cross-vendor MCP servers—the three conditions under which agents most often fail. An agent that reads its own trace to self-diagnose will see "the writer consumed data before retrieval completed" and conclude the planner mis-ordered the pipeline, when in fact the retrieval was slow and the writer correctly waited. The remediation is the same as the diagnosis: propagate traceparent across every transport (including stdio, by wrapping the MCP client to inject the header into the JSON-RPC `params._meta`), compute per-emitter clock offset from paired request/response spans, and make the aggregator's fallback explicit. The guardrail is a hard refusal to order edges that fail the containment check without a propagated link—because a trace that confidently lies is worse than a trace that admits it cannot order two events. ```python from dataclasses import dataclass from typing import Optional class CausalReconstructionDivergence(RuntimeError): """Raised when a federated trace is structurally valid but causally unsound.""" pass @dataclass class Span: span_id: str parent_span_id: Optional[str] trace_id: str emitter: str start_ns: int end_ns: int logical_call_id: Optional[str] = None attempt: int = 0 def reconstruct_causal_order(spans: list[Span], clock_offset_ns: dict[str, int]) -> list[Span]: """Order spans by propagated causal edges; refuse to guess where propagation is absent.""" by_id = {s.span_id: s for s in spans} # 1. Detect temporal containment violations: a span nested inside another # span it is not causally descended from, with no propagated parent link. for outer in spans: for inner in spans: if inner is outer or inner.parent_span_id is not None: continue if outer.start_ns < inner.start_ns < inner.end_ns < outer.end_ns: if not _is_descendant(inner, outer, by_id): raise CausalReconstructionDivergence( f"span {inner.span_id} ({inner.emitter}) is temporally contained in " f"{outer.span_id} ({outer.emitter}) but has no propagated parent link; " f"timestamp fallback is unsound" ) # 2. Refuse to order causally-linked spans when clock offset exceeds causal slack. for a in spans: for b in spans: if a.emitter == b.emitter or a.parent_span_id != b.span_id: continue slack = abs(a.start_ns - b.end_ns) offset = abs(clock_offset_ns.get(a.emitter, 0) - clock_offset_ns.get(b.emitter, 0)) if offset >= slack: raise CausalReconstructionDivergence( f"clock offset {offset}ns between {a.emitter} and {b.emitter} " f"exceeds causal slack {slack}ns for edge {b.span_id}->{a.span_id}; " f"order is UNORDERED, not timestamp-resolvable" ) # 3. Detect retry-induced duplicate responses for one logical call. seen: dict[tuple[str, int], Span] = {} for s in spans: if s.logical_call_id is None: continue key = (s.logical_call_id, s.attempt) if key in seen and seen[key].span_id != s.span_id: raise CausalReconstructionDivergence( f"duplicate response for logical call {s.logical_call_id} attempt {s.attempt}: " f"{seen[key].span_id} and {s.span_id}; retry must fork, not splice" ) seen[key] = s # Only propagated edges are trusted; everything else is returned for explicit labeling. return sorted(spans, key=lambda s: s.start_ns) def _is_descendant(span: Span, ancestor: Span, by_id: dict[str, Span]) -> bool: cur = span while cur.parent_span_id is not None: parent = by_id.get(cur.parent_span_id) if parent is None: return False if parent.span_id == ancestor.span_id: return True cur = parent return False ```