# Why does an instance lose causal edges when its observability trace is sampled at the span boundary rather than the decision boundary **Date of Record:** 2026 November 30 **Scope:** Applies to GenAI observability pipelines that reconstruct tool-call causality graphs from span-level telemetry emitted by an agent runtime, specifically where sampling (head-based or tail-based) is applied per-span rather than per-decision. Does not apply to fully synchronous, single-tool agents whose entire trace fits in one span, nor to pipelines that emit a single atomic "decision record" per reasoning step. ## Core Distinction There are two things an observability pipeline can treat as the unit of capture: the **span** (a tool invocation, an LLM call, a retrieval op) and the **decision** (the reasoning step that selected which tool to call, with what arguments, conditioned on what prior state). Production pipelines almost always sample and index at the span boundary because spans are cheap, typed, and map cleanly onto existing tracing SDKs. But the *causality* an agent operator actually needs to reconstruct—"why did the agent call `refund_order` with `order_id=null`?"—lives at the decision boundary, and that boundary is not a span. It is the gap *between* spans, the transition where the model's output token stream is parsed into a tool-call structure and dispatched. The failure is non-obvious because span-level sampling looks causally complete: every span has a `parent_span_id`, so the graph *appears* connected. What is missing is the *decision node* that is the actual parent of a tool call—the LLM span that produced the call. When head-based sampling keeps the tool span but drops the LLM span (because they were sampled independently, or because the LLM span exceeded a latency threshold and was tail-dropped), the reconstructed graph shows `refund_order` parented to the *previous* tool span in the trace, silently fabricating an edge. The pipeline does not error. It produces a plausible, wrong causality graph. ## What Was Observed A refund-processing agent running a ReAct loop over four tool calls per task. The runtime emitted spans: `llm.reason` (the reasoning call), `tool.lookup_order`, `llm.reason`, `tool.refund_order`, `llm.reason`, `tool.notify`. Head-based sampling at 20% was applied per-span at the collector, keyed on `trace_id` hash *per span*—a common misconfiguration where the sampler treats `trace_id` as a field to hash rather than an invariant to honor. Across a 12-hour window, 4,412 traces were captured. Reconstructing causality by joining on `parent_span_id` produced graphs where `tool.refund_order` had a parent of `tool.lookup_order` in 31% of cases. In the true runtime, `tool.refund_order`'s parent was always an `llm.reason` span—the model's decision to refund. The join had "repaired" the broken edge by falling back to trace-order adjacency when the true parent was absent, a fallback the reconstruction code performed silently. The operational consequence surfaced when an auditor queried the graph for "tool calls whose parent reasoning span had `confidence < 0.7`" to find low-confidence refunds. The query returned near-zero results—not because there were no low-confidence refunds, but because the `llm.reason` spans carrying the confidence field had been sampled out, and the fallback had reparented the refund spans to tool spans that carry no confidence field at all. The absence of low-confidence refunds was an artifact of the sampling boundary, not a property of the agent. ## Condition of Validity The invariant that must hold for a reconstructed causality graph to be trustworthy is: > For every captured tool-call span, its *true* causal parent (the decision span that emitted it) is either captured, or the edge is explicitly marked `parent_unknown`. A captured edge is never inferred from trace-order adjacency. This invariant is violated whenever sampling is applied at the span boundary without a **decision-grouping key** that forces the decision span and its emitted tool span to be sampled together. The condition of validity for span-boundary sampling is therefore narrow: it holds only when the sampler is *trace-consistent* (all spans in a trace share the sampling decision) AND the decision-to-tool linkage is within the same trace. The moment either fails—per-span sampling, or a tool call dispatched asynchronously into a child trace—the invariant breaks and the graph fabricates edges. A second condition: the reconstruction code must distinguish *absent parent* from *root span*. Many tracers encode both as `parent_span_id = null`. When a decision span is dropped, its child tool span's `parent_span_id` still points to the (now-absent) decision span's ID—but if the reconstruction joins with a left-join and coalesces nulls to "root," the dropped-decision case becomes indistinguishable from a legitimate root. This is the specific coalescing that turns a sampling gap into a fabricated edge. ## Decision Boundary The architectural decision is: **sample at the decision boundary, or do not claim causality.** Concretely, the pipeline must do one of three things at capture time, and must record which it did: 1. **Decision-atomic sampling.** Define a `decision_id` that groups the LLM reasoning span and all tool spans it directly emits. Sample on `decision_id`, never on individual spans. A dropped decision drops its entire subtree atomically, and the reconstruction sees a clean `parent_unknown` at the decision boundary—an honest gap. 2. **Trace-consistent sampling with explicit gap markers.** If per-span sampling is unavoidable (e.g., cost pressure on high-token LLM spans), the reconstruction must emit a sentinel edge `parent_dropped=true` rather than reparenting. Downstream queries must treat `parent_dropped` as "unknown," not "root." 3. **Two-tier retention.** Keep all decision spans (small, high-value) at 100%, downsample only the leaf tool payloads. The causality graph stays intact; only the payloads thin out. The boundary is crossed—and the pipeline becomes unsafe for causal queries—the moment the reconstruction code contains a fallback that assigns a parent when the true parent is absent. That fallback is the specific line of code where observability becomes confabulation. ## Operational Effect The downstream effects are silent and directional, which is what makes this failure mode dangerous: - **Audit queries under-report anomalies.** As observed, low-confidence refunds vanished because the confidence field lived on dropped spans. The agent's actual error rate was unchanged; the *measured* error rate dropped to near zero. An operator tuning safety thresholds against this metric would loosen them. - **Attribution flips to the wrong component.** When a tool span is reparented to the previous tool span, latency and error attribution shift from the LLM reasoning layer (where the bad decision was made) to the tool layer (which executed faithfully). The postmortem blames the tool. - **Replay divergence.** Any verification or replay system that reconstructs the agent's decision sequence from the graph will replay a *different* sequence than the agent executed—tool-then-tool instead of reason-then-tool—and will diverge at the first step, producing a "replay mismatch" that looks like nondeterminism in the agent but is nondeterminism in the observability layer. The guardrail is a single assertion at graph-construction time: every tool-call span must have a parent that is a decision span, or be explicitly marked `parent_unknown`. If neither holds, the reconstruction is invalid and must fail closed rather than emit a graph. ```python class CausalityReconstructionError(RuntimeError): """Raised when a reconstructed causality graph fabricates an edge by reparenting a tool span whose true decision parent was sampled out.""" pass DECISION_SPAN_KINDS = {"llm.reason", "llm.plan", "agent.decide"} TOOL_SPAN_KINDS = {"tool.lookup_order", "tool.refund_order", "tool.notify"} def reconstruct_edge(child_span: dict, spans_by_id: dict) -> dict: """ Resolve the causal parent of a tool-call span. Fails closed: never infers a parent from trace-order adjacency. """ if child_span["kind"] not in TOOL_SPAN_KINDS: return {"parent_id": child_span.get("parent_span_id"), "parent_dropped": False} parent_id = child_span.get("parent_span_id") if parent_id is None: # A tool call with no parent id is only valid if the runtime # explicitly marked it as a root dispatch. Anything else is a gap. if not child_span.get("root_dispatch", False): raise CausalityReconstructionError( f"tool span {child_span['span_id']} has null parent and is not a " f"declared root dispatch; refusing to coalesce to root" ) return {"parent_id": None, "parent_dropped": False} parent = spans_by_id.get(parent_id) if parent is None: # True parent was sampled out. Mark the gap honestly; do NOT reparent. return {"parent_id": parent_id, "parent_dropped": True} if parent["kind"] not in DECISION_SPAN_KINDS: raise CausalityReconstructionError( f"tool span {child_span['span_id']} resolved to non-decision parent " f"{parent_id} (kind={parent['kind']}); this indicates a fabricated " f"edge from trace-order fallback, not a real causal link" ) return {"parent_id": parent_id, "parent_dropped": False} ```