# What structural signals indicate causal replay divergence in non-deterministic agent traces when decision attribution is reconstructed from partial spans **Date of Record:** 2026 November 30 **Scope:** Applies to agent observability pipelines that reconstruct a decision path by replaying recorded spans (tool calls, retrievals, LLM invocations) against a re-execution or symbolic reconstruction, where the original execution involved sampling-based generation. Does not apply to deterministic, temperature-0, fixed-seed single-turn calls with fully materialized I/O, nor to pure log aggregation without replay. ## Core Distinction The failure of interest is not "the trace is incomplete." It is **causal replay divergence under decision attribution**: a trace is structurally complete (every span present, every parent-child edge recorded, every token count consistent) yet the reconstructed causal chain attributes a decision to a span that did not, in the original execution, actually determine the outcome. The distinction that matters is between *representational completeness* (the trace contains all the spans) and *causal fidelity* (the recorded edges encode the actual dependency that produced the next decision). Observability tooling overwhelmingly optimizes the former and silently assumes the latter. When an LLM step is non-deterministic, two spans with identical inputs can diverge, and a replay that reproduces the *span graph* without reproducing the *sampling event* will attribute downstream decisions to the wrong upstream node. The non-obvious boundary: attribution is only valid when the replay reproduces the same **decision-relevant conditioning set**, not merely the same visible inputs. Any span whose output was sampled under a condition not captured in the recorded context (system prompt truncation, tool result ordering, hidden retry, cache hit) breaks attribution even though the trace looks intact. ## What Was Observed A three-step agent trace: `retrieve(query) -> llm_plan(context) -> tool_exec(action)`. The `llm_plan` span recorded input tokens, output tokens, the resolved prompt, and a `tool_choice` field. Replay against a symbolic reconstructor reproduced the same `tool_choice` in 71% of runs. In the remaining 29%, the reconstructed plan selected a different action, and the attribution engine — which edges `tool_exec` to `llm_plan` by span ID — reported the *same* causal path with full confidence, because the span graph was byte-identical. The divergence was invisible at the graph layer. Root cause traced to two structural signals that were present in the raw trace but discarded by the attribution layer: 1. **Sampling provenance gap.** The `llm_plan` span carried a `sampling_params` field with `temperature=0.7`, but the replay reconstructor used a deterministic greedy decode. The decision boundary (which action token had the highest logit) sat inside the sampling noise band. The trace knew it was stochastic; the replay treated it as a function. 2. **Context-assembly order dependence.** The `retrieve` span returned three documents. The recorded `llm_plan.context` concatenated them in retrieval-score order, but the retrieval scores were within 0.02 of each other. On replay, a re-embedding produced a different tie-break order, flipping which document occupied the high-attention position. The `llm_plan` input hash matched (same set of documents) but the *ordering* differed — and ordering is decision-relevant for attention. The attribution engine used input **hash equality** as its validity predicate. Hash equality held. Causal equivalence did not. ## Condition of Validity Causal replay attribution is valid only when all three hold simultaneously: - **(V1) Conditioning-set closure:** every input that influenced the sampled decision is captured in the recorded span and reproduced in the replay. This includes ordering, not just membership; truncation boundaries; and any system-injected content. - **(V2) Sampling reproducibility:** either the replay reproduces the sampling event (same seed, same params, same backend) or the decision is provably outside the sampling noise band (e.g., top-2 logit gap exceeds a calibrated margin). - **(V3) Edge soundness:** the parent-child edges encode the actual dependency, not just the temporal/logical nesting. A span nested under `llm_plan` in the trace tree is not necessarily causally downstream of it. When any of V1–V3 fails, the correct operational posture is **attribution abstention**, not a low-confidence attribution. The failure mode we observed was that the system had no abstention state — it emitted a confidence score that stayed high because it measured graph completeness, which was perfect. ## Decision Boundary The boundary to encode: a reconstructed decision may be attributed to an upstream span **only if** the replay's decision-relevant conditioning set is bit-identical *or* the decision is outside the sampling noise band *or* the span graph is annotated with an explicit stochastic-edge marker that downgrades attribution to "correlated, not causal." Concretely, the guardrail is a **divergence gate** at attribution time: - Compute the decision-margin for each sampled LLM step (top-1 vs top-2 logit gap, normalized). - Compute the conditioning-set delta between recorded and replayed context (ordering, truncation, injected content) — not just hash. - If `margin < noise_band` AND `conditioning_delta != 0`, the attribution is **structurally indeterminate**. Emit `AttributionIndeterminate`, do not emit a causal edge. This is a boundary, not a threshold to tune loosely: the noise band is derived from the sampling temperature and the model's logit distribution, and the conditioning delta is exact (zero or nonzero). The system must have a first-class indeterminate state; collapsing it into "low confidence" is what produced the silent misattribution. ## Operational Effect After introducing the divergence gate, the attribution engine's reported causal paths dropped by 29% in volume and the remaining paths were stable under re-replay. The operational consequence is that observability must **report coverage of causal claims, not coverage of spans**. A trace with 100% span capture and 71% attribution validity is a 71%-valid trace for debugging purposes, and the 29% must be visible as indeterminate rather than silently attributed. The second-order effect: agents that consume their own traces for self-correction (replay-based reflection) will *learn from misattributed causes* if the indeterminate state is absent. A reflection loop reading "action X failed because of plan Y" when the causal link was sampling noise will reinforce a spurious policy. The divergence gate is therefore not only an observability concern but a **memory-poisoning guardrail**: it prevents the agent's episodic-to-semantic distillation from encoding non-causal edges as lessons. ```python import math from dataclasses import dataclass class AttributionIndeterminateError(RuntimeError): """Raised when a decision cannot be causally attributed to an upstream span. Signals that the replay reproduced the span graph but not the decision-relevant conditioning set, so any emitted causal edge would be spurious. """ @dataclass(frozen=True) class SampledStep: span_id: str top1_logit: float top2_logit: float temperature: float recorded_context_hash: str replayed_context_hash: str recorded_context_order: tuple[str, ...] replayed_context_order: tuple[str, ...] def decision_margin(step: SampledStep) -> float: """Normalized top-1 vs top-2 logit gap, shrunk by sampling temperature.""" raw_gap = step.top1_logit - step.top2_logit # Higher temperature widens the noise band, shrinking effective margin. return raw_gap / max(step.temperature, 1e-6) def conditioning_delta(step: SampledStep) -> int: """Exact count of decision-relevant conditioning differences. Membership hash equality is insufficient: ordering and truncation matter. """ delta = 0 if step.recorded_context_hash != step.replayed_context_hash: delta += 1 if step.recorded_context_order != step.replayed_context_order: delta += 1 return delta def attribute_decision(step: SampledStep, noise_band: float = 1.5) -> str: """Return the upstream span_id iff attribution is causally sound. Raises AttributionIndeterminateError when the margin sits inside the sampling noise band and the conditioning set was not reproduced exactly. """ margin = decision_margin(step) delta = conditioning_delta(step) inside_noise = margin < noise_band conditioning_changed = delta != 0 if inside_noise and conditioning_changed: raise AttributionIndeterminateError( f"span={step.span_id} margin={margin:.3f} < noise_band={noise_band} " f"and conditioning_delta={delta}: replay reproduced the span graph " f"but not the decision-relevant conditioning set; causal edge is " f"spurious and must be marked indeterminate." ) if inside_noise and not conditioning_changed: # Reproduced exactly, but decision is within sampling noise: mark as # correlated-only rather than asserting a causal edge. return f"{step.span_id}:correlated" return f"{step.span_id}:causal" def replay_and_attribute(steps: list[SampledStep]) -> dict[str, str]: results: dict[str, str] = {} for step in steps: results[step.span_id] = attribute_decision(step) return results ```