# How does an instance detect causal trace divergence when a multi-hop tool invocation silently reorders span completion? **Date of Record:** 2026 November 20 **Scope:** Applies to runtime observability systems that reconstruct causal DAGs from asynchronous span emissions across multi-hop agent tool invocations, where a tool call fans out to downstream sub-invocations whose completion events may interleave non-deterministically with the parent's own return. Does not apply to strictly synchronous single-threaded tool calls, nor to traces where span emission is serialized through a single ordered log with monotonic sequence numbers. ## Core Distinction The failure mode is not "a span was lost" or "a trace was truncated." It is **causal edge inversion under interleaved completion**: a child span (the downstream tool invoked by an agent) emits its `end` timestamp *before* its parent span (the agent's reasoning step that dispatched the call) emits its own `end`, yet the *start* ordering and the *logical* causality are preserved. A naive reconstructor that infers parentage from timestamp containment (`parent.start <= child.start AND child.end <= parent.end`) will either (a) reject the valid edge because the parent's end is later than expected, or worse (b) attach the child to the *wrong* ancestor — typically a sibling or a grandparent — because the containment test passes against a different enclosing span. The invariant that breaks: **wall-clock containment is not causal containment.** In agent systems, a parent reasoning step often does not "close" until it has consumed and integrated the child's result back into its context and emitted the next reasoning token. The child's transport-level completion and the parent's semantic completion are separated by an unbounded reasoning latency — the time the LLM spends reading the tool result. During that window, the child span is closed but the parent is still open, and any *other* concurrent span whose interval happens to enclose the child's interval becomes a false parent. ## What Was Observed A three-hop agent chain: `planner → retriever → reranker`. The retriever tool internally fans out to two parallel sub-fetches (`fetch_A`, `fetch_B`). The reranker is dispatched by the planner *after* the retriever returns, but the planner's own reasoning span (`plan.step_3`) remains open across the entire retriever round-trip because the planner is awaiting the tool result. Trace excerpt (times in ms, monotonic clock): - `plan.step_3`: start=1000, end=3400 - `retriever`: start=1050, end=2900 - `fetch_A`: start=1100, end=1800 - `fetch_B`: start=1150, end=2700 - `reranker`: start=2950, end=3300 The reconstructor built edges by timestamp containment and produced: - `plan.step_3` → `retriever` ✓ (correct) - `retriever` → `fetch_B` ✓ (correct) - `retriever` → `fetch_A` ✓ (correct) - **`plan.step_3` → `reranker`** ✗ — but also **`retriever` → `reranker`** was *not* proposed, because `reranker.start=2950 < retriever.end=2900` is false. The reranker was correctly a child of `plan.step_3` by containment, but the *sibling relationship* between `retriever` and `reranker` was lost, and the reconstructor additionally emitted a spurious edge `plan.step_3 → fetch_B` on a second pass because `fetch_B`'s interval was fully nested inside `plan.step_3`'s. The observable symptom: the reconstructed DAG showed `fetch_B` with **two parents** (`retriever` and `plan.step_3`), and the reranker with a **latency attribution of 2450 ms** (from `plan.step_3.start` to `reranker.end`) rather than its true 350 ms. Downstream cost and latency rollups were inflated by ~7×, and the "critical path" analysis blamed the reranker for time actually spent in retrieval. The root cause was not clock skew. It was that **the reconstructor used interval nesting as a proxy for the causal edge, and the agent's reasoning latency created a window in which a completed child (`fetch_B`) was enclosed by an ancestor (`plan.step_3`) that was not its parent.** ## Condition of Validity The containment-based reconstruction is only valid under the **synchronous-close assumption**: that a parent span closes within ε of its last child closing, where ε is smaller than the smallest inter-hop gap. This holds for classic RPC tracing where the parent thread blocks on the child and returns immediately. It does **not** hold when: 1. The parent is an LLM reasoning step whose "close" is gated on token generation, not on the child's return. The gap between child-close and parent-close is the **reasoning re-entry latency** — the time to serialize the tool result into the context window, run the next forward pass, and emit the next action. 2. The parent fans out to N children with overlapping intervals, so multiple candidate enclosers exist for any given child. 3. Any sibling or ancestor span overlaps the reasoning re-entry window. The invariant that must hold for correctness: **every span must carry an explicit causal parent identifier, and reconstruction must use that identifier — never interval containment — to build edges.** Containment may be used only as a *consistency check* that flags divergence, never as the edge source. When explicit parentage is absent (e.g., a tool that does not propagate the trace context), the reconstructor must mark the edge as `INFERRED` and must not merge inferred and declared edges into a single DAG without a provenance tag. ## Decision Boundary The instance must switch from "accept the reconstructed DAG" to "quarantine and re-derive" when **any** of the following hold: - A span is assigned more than one parent under containment inference. - A span's declared parent differs from its containment-inferred parent. - The reasoning re-entry gap (parent.end − last_child.end) exceeds the p99 of the tool's own execution latency by a configurable factor (observed default: 3×). This is the signature of a parent that closed late due to reasoning, not due to a slow tool. - A child's interval is enclosed by a non-parent ancestor. Below these thresholds, containment inference is tolerable for latency rollups but must still be provenance-tagged. Above them, the reconstructed DAG is **not admissible** for cost attribution, critical-path analysis, or any downstream decision (e.g., auto-scaling a tool, blaming a hop). The correct action is to fall back to declared parentage if available; if not, to emit an `InferredEdgeAmbiguity` and refuse to produce a critical path rather than produce a wrong one. ## Operational Effect The practical consequence is that **agent observability cannot treat the trace as ground truth for causality without an explicit parent field.** In the observed case, the inflated reranker attribution would have caused an operator to optimize the reranker (the wrong hop) while the actual cost was in retrieval fan-out. The dual-parent `fetch_B` would have caused double-counting in per-tool cost rollups, silently inflating the retriever's apparent cost by the fraction of `fetch_B`'s span that overlapped the planner's open window. The guardrail: propagate an explicit `causal_parent_span_id` through every tool invocation (including across process and transport boundaries via MCP/A2A metadata), and make the reconstructor **fail closed** — refuse to emit a causal edge it cannot attribute to a declared parent, rather than inferring one from intervals. Interval containment is demoted to a divergence detector: when it disagrees with declared parentage, that disagreement is itself the signal that a hop dropped its context propagation, which is the real observability defect to surface. ```python class InferredEdgeAmbiguity(RuntimeError): """Raised when causal reconstruction cannot attribute a span to a declared parent and interval containment yields an ambiguous or multi-parent result.""" pass def reconstruct_edge(span, declared_parents, enclosing_spans, reentry_gap_ms, tool_p99_ms): """ span: dict with start, end, span_id declared_parents: list of span_ids that explicitly claim this span as child enclosing_spans: list of span_ids whose [start,end] contains span's interval """ if len(declared_parents) == 1: parent = declared_parents[0] # consistency check only; never override declared parentage if parent not in enclosing_spans and reentry_gap_ms > 3 * tool_p99_ms: # declared parent closed late (reasoning re-entry); this is expected, not an error pass return {"parent": parent, "provenance": "DECLARED"} if len(declared_parents) > 1: raise InferredEdgeAmbiguity( f"span {span['span_id']} declares multiple parents {declared_parents}; " "trace context propagation is corrupt" ) # No declared parent: fall back to containment, but fail closed on ambiguity if len(enclosing_spans) != 1: raise InferredEdgeAmbiguity( f"span {span['span_id']} has no declared parent and " f"{len(enclosing_spans)} enclosing candidates {enclosing_spans}; " "refusing to infer causal edge" ) if reentry_gap_ms > 3 * tool_p99_ms: raise InferredEdgeAmbiguity( f"span {span['span_id']} sole enclosing candidate {enclosing_spans[0]} " f"exceeds re-entry threshold ({reentry_gap_ms}ms > 3x p99 {tool_p99_ms}ms); " "likely a non-parent ancestor enclosing a completed child" ) return {"parent": enclosing_spans[0], "provenance": "INFERRED"} ```