# What happens when an instance replays a sampled trace and mistakes reconstruction for causation **Date of Record:** 2026 November 23 **Scope:** Applies to agent runtimes that emit span-level observability traces under head/tail sampling and later use those traces for replay, post-hoc debugging, or causal attribution of a failure. Does not apply to full-fidelity synchronous tracing where every span is persisted and replayed against an identical environment snapshot. ## Core Distinction There are two things an observability pipeline can hand back to an agent, and they are not interchangeable: 1. **A record of what happened** — the actual span tree, timestamps, tool payloads, and token counts produced by one concrete execution. 2. **A reconstruction of what could have happened** — a replay that re-drives the agent from a checkpoint using recorded inputs, but re-executes the probabilistic parts (LLM calls, sampling, tool retries) afresh. The boundary failure is this: **a replay is a new execution, not a rewind.** When a trace was sampled out of the original run (because head-sampling dropped it, or tail-sampling kept only the "interesting" branches), the replay must synthesize the missing spans. It does so by *inferring* them — from the checkpoint state, from sibling traces, or by re-calling the model. Those synthesized spans are indistinguishable in schema from observed spans. An agent performing causal attribution then walks the reconstructed trace and assigns blame to a span that never existed in the original run. The attribution is internally consistent, externally wrong, and — because it is deterministic-looking — trusted. The invariant that breaks: *causal attribution requires that every span on the attributed path be marked with its provenance (observed vs. synthesized) and that attribution never cross a synthesized edge without flagging the inference.* Sampled traces violate this silently because sampling is a *storage* decision, not a *semantic* one, and the replay layer has no way to recover which spans were dropped versus which never occurred. ## What Was Observed A tool-using agent (`planner → retrieve → summarize → write`) failed intermittently with a truncated final answer. The team enabled tail-based sampling at 10% to control cost, keeping traces where `status=ERROR` or `latency > p95`. The failing trace was kept; the two preceding successful traces that shared the same session were dropped by head-sampling at the collector. During incident review, an attribution agent was pointed at the retained failing trace and asked to identify the root-cause span. The trace showed: - `retrieve` span: 1 call, 2.1s, returned 3 documents. - `summarize` span: 1 call, context window 94% full. - `write` span: `finish_reason=length`, output truncated. The attribution agent concluded: *summarize over-filled the context window, causing write to hit the length cap.* Plausible. Wrong. What actually happened, per the (dropped) sibling traces: `retrieve` had been called **three times** in the original run — twice retrying on a transient 503 from the vector store, each retry appending its results to the context without deduplication. The retained trace showed one `retrieve` span because the sampler kept only the last retry's span and the replay layer, reconstructing the `summarize` input from the checkpoint, re-ran the prompt against a *reconstructed* context assembled from the single retained retrieve span. The context saturation was real in the original run (three retrieves' worth of documents) but the replay reproduced it with one retrieve's worth plus padding from the checkpoint's serialized message history. The attribution agent saw a saturated context and a single retrieve and inferred the summarize step was at fault. The true causal chain — retry amplification in retrieve — was invisible because the retries were sampled out and the replay had no record they existed. The failure is not that the replay was wrong about the *symptom* (context was full). It is that the replay **manufactured a causal edge** (`summarize → saturation`) that did not exist in the original execution, and suppressed the real edge (`retrieve.retry ×3 → saturation`) because the spans carrying it were never stored. ## Condition of Validity This failure mode is bounded by a precise condition. It manifests when **all three** hold: 1. **Sampling is non-uniform across a causal chain.** The collector drops spans from the same logical execution using a policy (head sampling, tail sampling on error/latency, per-span rate limits) that does not preserve the full ancestor path of any retained span. If sampling is per-*trace* (all-or-nothing), the chain is intact and replay is faithful up to non-determinism. 2. **Replay synthesizes missing ancestors rather than refusing.** The replay layer, given a retained leaf span and a checkpoint, reconstructs the upstream state by re-deriving it (re-calling the model, re-reading the checkpoint's serialized context, or borrowing from a sibling trace). It emits these reconstructions with the same span schema as observed spans, with no `provenance` field distinguishing them. 3. **Attribution treats the reconstructed tree as ground truth.** The attribution step walks parent/child edges and assigns causal weight without consulting provenance. A synthesized edge is traversed identically to an observed edge. When any one of these is absent, the failure does not occur. If sampling is per-trace, there are no missing ancestors. If replay refuses on missing ancestors (returns `INCOMPLETE`), attribution cannot proceed on a fabricated tree. If attribution checks provenance, it can down-weight or flag synthesized edges. The dangerous case is the conjunction, which is also the *default* configuration of most observability stacks: per-span sampling for cost, best-effort replay for debuggability, and attribution that trusts the tree. A secondary condition sharpens the risk: **non-determinism in the replayed span itself.** Even when ancestors are observed, replaying a `summarize` span re-calls the model at temperature > 0. The replayed span may produce a *different* output than the original, and the attribution agent will attribute the original failure to the replayed output's characteristics. The replay is a counterfactual, not a record. This is why the boundary is specifically about *causal attribution*: a trace is fine as a debugging aid even when replayed; it is not fine as a causal oracle. ## Decision Boundary The operational rule is a hard separation between three trace states, enforced at the schema level: - **`OBSERVED`** — span was persisted from the original execution. Safe for attribution. - **`SYNTHESIZED`** — span was reconstructed during replay (re-derived from checkpoint, re-called, or borrowed). Usable for debugging display, **never** for causal attribution. Any attribution path containing a `SYNTHESIZED` edge must be returned as `ATTRIBUTION_INDETERMINATE` with the synthesized edges enumerated. - **`MISSING`** — span is known to have existed (referenced by a child's `parent_span_id` or by a checkpoint's retry counter) but was not persisted. This is the critical state: it is *evidence of absence*, not absence of evidence. A `MISSING` ancestor means the causal chain is broken and attribution must refuse, not reconstruct. The decision boundary is triggered by the presence of `MISSING` ancestors in the retained span tree. When a retained span's `parent_span_id` points to a span not in storage, the correct behavior is to **stop and report the gap**, not to synthesize a parent. Synthesis is only permitted when the gap is provably benign (e.g., a `MISSING` span that is a leaf-side sibling with no downstream effect), and even then the synthesized span must be tagged and its downstream edges marked as inferred. The counter-intuitive part: **a longer trace is not a more trustworthy trace.** A replay that synthesizes aggressively produces a *complete-looking* tree that is more misleading than a tree with explicit holes. The holes are the signal. An attribution agent that sees `MISSING` and refuses is correct; one that sees a synthesized parent and proceeds is the failure. ## Operational Effect When this boundary is respected, three things change: 1. **Attribution becomes falsifiable.** Every causal claim carries the provenance of the edges it traversed. A reviewer can ask "was this edge observed or inferred?" and get a machine-checkable answer. The fabricated `summarize → saturation` edge would have been tagged `SYNTHESIZED` and the attribution would have returned `INDETERMINATE` instead of a confident wrong root cause. 2. **Replay cost drops and honesty rises.** Refusing to synthesize missing ancestors means the replay layer does not re-call the model to fill gaps. The trace is returned with explicit holes, which is cheaper and — crucially — does not introduce new non-determinism into the debugging artifact. 3. **Sampling policy becomes a first-class causal decision.** Teams must choose per-trace sampling (or ancestor-preserving tail sampling) for any workload where attribution matters, because per-span sampling silently severs causal chains. The cost model shifts: you are not paying for spans, you are paying for *attributable* traces. The residual risk after the guardrail: `SYNTHESIZED` spans that happen to reproduce the original output (temperature 0, cached tool responses) are indistinguishable in *content* from observed spans. Provenance tagging is the only thing separating them. If the tag is lost in serialization, downstream, or aggregation, the boundary silently reverts. The guardrail must be enforced at the point of attribution, not merely at the point of emission — the attribution function must reject any span lacking a `provenance` field rather than defaulting it to `OBSERVED`. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class Provenance(Enum): OBSERVED = "observed" SYNTHESIZED = "synthesized" MISSING = "missing" class CausalAttributionError(RuntimeError): """Raised when attribution would traverse a non-observed causal edge.""" pass @dataclass class Span: span_id: str parent_span_id: Optional[str] provenance: Provenance payload: dict = field(default_factory=dict) def attribute_root_cause( spans: dict[str, Span], failing_span_id: str, ) -> str: """ Walk the ancestor path from the failing span to the root and return the root-cause span_id. Refuses if any ancestor is SYNTHESIZED or MISSING, because the causal chain is not fully observed and attribution would be a reconstruction, not a record. """ path: list[Span] = [] cursor = spans.get(failing_span_id) if cursor is None: raise CausalAttributionError( f"failing span {failing_span_id} not in storage; cannot attribute" ) while cursor is not None: if cursor.provenance is Provenance.MISSING: raise CausalAttributionError( f"causal chain broken at span {cursor.span_id}: ancestor was " f"sampled out and is MISSING. Attribution is indeterminate; " f"do not synthesize a parent. Re-collect with per-trace sampling." ) if cursor.provenance is Provenance.SYNTHESIZED: raise CausalAttributionError( f"causal chain crosses SYNTHESIZED span {cursor.span_id}: this " f"span was reconstructed during replay and did not exist in the " f"original execution. Attribution would assign blame to an " f"inferred edge. Return ATTRIBUTION_INDETERMINATE." ) path.append(cursor) if cursor.parent_span_id is None: break parent = spans.get(cursor.parent_span_id) if parent is None: # Parent referenced but not stored: evidence of a sampled-out ancestor. raise CausalAttributionError( f"span {cursor.span_id} references parent " f"{cursor.parent_span_id} which is not in storage; the " f"ancestor was dropped by sampling. Attribution refused." ) cursor = parent # All edges on the path are OBSERVED; the root of the path is the # earliest observed span, which is the best-supported causal candidate. return path[-1].span_id ```