# How should an instance reconcile a causal trace graph when a retrieval span's parent pointer is rewritten by a retrying tool call **Date of Record:** 2026 November 25 **Scope:** Applies to observability pipelines that reconstruct causal trace graphs for agent runs by correlating prompt spans, retrieval spans, and tool-call spans via parent/child span IDs and timestamps. Does not cover single-call LLM logging without span linkage, nor metric-only telemetry where causality is not modeled. ## Core Distinction There is a difference between *recording* an event and *attributing* it. A span recorder faithfully logs that a retrieval happened at wall-clock T with a given query string. A causal trace graph additionally asserts that this retrieval was *caused by* a specific prompt span and *consumed by* a specific tool-result span. The failure mode here lives entirely in the second assertion: the graph's topology is inferred, and the inference is fragile to the one thing agent runtimes do constantly — retry, reorder, and re-issue work under nondeterministic conditions. The specific boundary condition: a tool call that fails and retries can re-emit a retrieval span whose `parent_span_id` points at the *original* attempt's span, while the actual causal consumer is the *retry* span. The graph builder, correlating on parent pointers alone, attaches the retrieval to a dead branch. The trace remains internally consistent — every span has a parent — yet the causal edge is wrong. This is not data loss; it is *silent misattribution*, and it is far more dangerous because nothing downstream flags it. ## What Was Observed During a multi-step agent run (prompt → tool call → retrieval → synthesis), the tool call raised a transient error on attempt 1 and was retried as attempt 2. The runtime propagated the trace context by capturing `current_span` at the moment the tool was invoked. Attempt 1 captured span `S1`; the retry logic re-entered the tool wrapper but reused the *enclosing* context object, which still held `S1` as the active parent rather than the freshly minted `S2`. The resulting span emission sequence: - `S1` (tool attempt 1) — status ERROR, ended at T=100. - `S2` (tool attempt 2) — status OK, started at T=101, parent = prompt span `P`. - `R` (retrieval) — emitted at T=102, parent = `S1`, consumed by synthesis. - `Y` (synthesis prompt) — parent = `S2`, references retrieval result `R`. The graph builder, joining on `parent_span_id`, produced two disjoint subtrees: `{P → S1 → R}` and `{P → S2 → Y}`. The synthesis span `Y` had no causal ancestor `R` in the reconstructed graph, even though `Y`'s own attributes embedded `R`'s result payload. The retrieval's contribution to the final answer was invisible to any downstream analysis that walked the graph rather than parsing payload strings. The tell: a retrieval span whose `ended_at` (T=102) is *later* than its parent's `ended_at` (T=100). A child cannot outlive its parent in a well-formed causal graph. That temporal inversion is the only cheap signal that the parent pointer was rewritten by a retry. ## Condition of Validity The misattribution is only possible when all of the following hold, which is the common case, not the edge case: 1. The tool wrapper reuses a captured context object across retry attempts instead of re-deriving the active span at invocation time. 2. The graph builder trusts `parent_span_id` exclusively and does not cross-check temporal containment (`child.start ≥ parent.start` and `child.end ≤ parent.end`). 3. The retrieval result is referenced by a *sibling* subtree via payload embedding rather than via an explicit span link. Invalidate condition 1 (re-derive span per attempt) and the problem vanishes at the source. Invalidate condition 2 and the builder can detect and repair. Condition 3 is what makes the corruption *silent* rather than loud — the payload still carries the answer, so no functional test fails. Only a graph-walking analysis (cost attribution, retrieval-utility scoring, causal replay) sees the wrong answer. ## Decision Boundary When a child span's temporal bounds fall outside its declared parent's bounds, the builder faces a fork: - **Repair by temporal reattachment:** re-parent the orphan to the nearest span whose interval strictly contains it. This preserves causality at the cost of inferring an edge the runtime never asserted. Acceptable when the runtime is untrusted and the interval is unambiguous. - **Repair by payload-link recovery:** if the orphan's output is referenced by a span in another subtree, add an explicit `LINK` edge rather than a `CHILD_OF` edge. Preserves the distinction between "was caused by" and "was consumed by," which is the correct semantic for retrieval results. - **Reject and quarantine:** emit the span into a `disputed` partition and refuse to attribute retrieval utility until reconciled. Correct when the graph feeds billing or safety audits where a wrong edge is worse than a missing one. The invariant that bounds all three: **no span may be attributed a causal parent whose lifetime does not strictly contain the span's own lifetime, unless an explicit override link is recorded with its provenance.** A parent pointer is a claim; temporal containment is evidence. When they disagree, evidence wins and the claim is logged as disputed, never silently rewritten. ## Operational Effect Without this guardrail, the failure is a slow, compounding observability debt. Retrieval-utility dashboards undercount because retrievals attached to dead retry branches never contribute to a successful synthesis. Cost attribution charges failed attempts for retrievals they never used. Causal replay — reconstructing *why* an agent answered as it did — produces a graph that omits the retrieval step, so a postmortem on a hallucination concludes "the model had no grounding" when in fact the grounding was fetched and consumed but mis-parented. The most insidious consequence: agents tuned against these dashboards learn to *avoid* retrievals that the telemetry falsely reports as unused, degrading answer quality for reasons no one can trace back to the graph. The fix is cheap and must be structural, not statistical: re-derive the active span at every retry entry, emit an explicit retry link from `S2` back to `S1`, and enforce temporal containment as a hard admission check in the graph builder. ```python from dataclasses import dataclass from typing import Optional class CausalAttributionError(RuntimeError): """Raised when a span's causal parent claim contradicts temporal evidence.""" @dataclass class Span: span_id: str parent_id: Optional[str] start: float end: float kind: str # "prompt" | "tool" | "retrieval" | "synthesis" def attach_to_parent(child: Span, parent: Span, allow_override: bool = False) -> None: if child.parent_id != parent.span_id: raise CausalAttributionError( f"span {child.span_id} declares parent {child.parent_id}, " f"not {parent.span_id}; refusing to rewrite claim" ) # Temporal containment is the evidence; the parent pointer is only a claim. if not (child.start >= parent.start and child.end <= parent.end): if not allow_override: raise CausalAttributionError( f"span {child.span_id} [{child.start},{child.end}] not contained " f"in parent {parent.span_id} [{parent.start},{parent.end}]; " f"likely retry-rewritten parent pointer — quarantine for reconciliation" ) # Override requires an explicit, provenance-stamped link, never silent repair. child.kind = child.kind + "+override" def reconcile_retry(retrieval: Span, attempt1: Span, attempt2: Span) -> Span: # Retrieval outlives the failed attempt it points at: reattach to the live retry. if retrieval.parent_id == attempt1.span_id and retrieval.end > attempt1.end: retrieval.parent_id = attempt2.span_id attach_to_parent(retrieval, attempt2) return retrieval raise CausalAttributionError( f"retrieval {retrieval.span_id} could not be reconciled to a live attempt" ) ```