# What happens when an instance attributes a failure to the wrong span: causal credit misassignment in trajectory-level evaluation loops **Date of Record:** 2026 November 25 **Scope:** Applies to GenAI observability pipelines that compute per-span attribution over multi-step agent trajectories (tool calls, reasoning steps, retrievals) and feed those attributions back into an evaluation loop that gates model/prompt/policy changes. Does not apply to single-turn LLM calls with no intermediate spans, nor to pure latency/cost telemetry that carries no failure label. ## Core Distinction There are two structurally different things an observability system can report about a failed agent trajectory, and conflating them is the root of this failure mode: 1. **The span where the failure became observable** — the terminal span whose output violated a check (e.g., the final answer that failed a grader, the tool call that returned an error, the last reasoning step before an exception). 2. **The span where the failure was caused** — the earlier step whose output propagated forward and made the terminal violation inevitable or probable (a bad retrieval that seeded a hallucinated premise, a malformed argument that a downstream tool tolerated silently, a stale memory injection that poisoned three subsequent reasoning steps). Trajectory-level attribution loops almost always record (1) because it is cheap and deterministic — it is the span that carries the error flag. They *infer* (2) from co-occurrence or from the grader's rationale. The invariant that must hold for the evaluation loop to be sound is: **the span credited with a failure must be an ancestor of, or causally precede, the span where the failure manifested, and must be the earliest such span whose intervention would have prevented the terminal violation.** When attribution credits a descendant or a sibling of the true cause, the loop learns a false gradient: it will "fix" the wrong step, pass the eval, and leave the real defect live. ## What Was Observed A three-tool agent (retriever → calculator → formatter) produced a wrong final answer on a financial-reasoning task. The trajectory: - `span-1` retriever returns a document with an outdated exchange rate (the true cause). - `span-2` calculator correctly multiplies the stale rate by the amount — arithmetically valid, no error flag. - `span-3` formatter emits the answer; the end-to-end grader fails it and attaches the rationale "incorrect numeric result." The attribution service, scoring spans by how much the grader's rationale text overlaps each span's output, credited `span-2` (the calculator) because the rationale mentioned "numeric result" and `span-2` is the only span containing numbers. The evaluation loop then routed a prompt patch to the calculator tool's instructions. The patch passed the regression suite (the calculator was never wrong) and shipped. The next eval cycle reproduced the identical failure on the identical task class, because `span-1` was never touched. The mechanism is not "the grader was wrong." The grader was correct at the level it operated: the *observable* violation was numeric. The defect is that the attribution layer treated textual overlap between a rationale and a span as evidence of causation, without enforcing the causal-precedence invariant. This is a **credit-assignment drift**: each eval cycle reinforces the wrong span because the wrong span keeps being the one whose output lexically resembles the failure symptom. A second, subtler signature: when the true cause is *silent* (a stale retrieval, a tolerated malformed argument), it produces no error flag, so any attribution scheme that ranks spans by "error signal" will systematically rank it last. The silent-cause class is exactly the class that matters most, and it is the class the naive scheme is blindest to. ## Condition of Validity Attribution is valid only when all of the following hold; if any fails, the loop must abstain rather than emit a credit: 1. **Causal ordering is enforced.** The credited span's end timestamp precedes the manifestation span's start, and the credited span is in the manifestation span's causal ancestry (via the trace's parent links, not via wall-clock guesswork across async spans). 2. **Intervention counterfactual is checked, not assumed.** The pipeline must be able to answer, at least approximately, "if this span's output had been correct, would the terminal violation have been avoided?" Co-occurrence and lexical overlap are *not* substitutes. In practice this requires either a replay with a corrected span output or a learned counterfactual scorer validated against replays. 3. **Silent spans are eligible.** The candidate set must include spans with no error flag and no lexical overlap with the rationale. If the candidate set is restricted to flagged or lexically-matching spans, the silent true cause is structurally excluded. 4. **The grader's rationale is treated as a symptom description, not a causal claim.** Rationale text localizes *where* the violation is visible; it must not be used as a proximity prior over *where* the cause is. The boundary is crossed the moment condition 2 is replaced by a heuristic. That substitution is the default in most pipelines because replay is expensive; the failure mode is the price of that substitution, and it is non-obvious because the heuristic *appears* to work — it produces confident, plausible attributions that pass spot checks on shallow trajectories where cause and manifestation coincide. ## Decision Boundary The operational choice is between two regimes, and the boundary between them is the *depth of the causal gap* between cause and manifestation: - **Shallow gap (cause ≈ manifestation, gap ≤ 1 step, cause is flagged):** lexical/error-proximity attribution is within tolerance. The credited span is usually the true cause, and the loop converges. Do not pay for replay here. - **Deep gap (cause is ≥ 2 steps upstream, or silent):** proximity attribution is invalid and *anti-correlated* with truth in the silent case. The loop must either (a) run a counterfactual replay for the failing trajectory before emitting credit, or (b) emit an **unattributed** failure record that is excluded from the training/patching signal. The decision rule the loop must implement: if the highest-scoring candidate span is not an ancestor of the manifestation span, or if no candidate survives the counterfactual check, **abstain**. An abstained failure is cheap; a misattributed failure is expensive because it is *acted upon*. The asymmetry is the whole point: false attribution is not a neutral error, it is an active corruption of the eval signal that compounds across cycles. ## Operational Effect When the invariant is enforced, three things change measurably: 1. **Convergence rate of the eval loop** stops regressing on deep-gap task classes. The classic symptom of the unguarded loop is a task class that fails at a *constant* rate across cycles while the loop reports "patch applied, no regression" — because the patch targets a span that was never the cause. 2. **Silent-cause detection surfaces.** Once silent spans are eligible and counterfactually checked, the stale-retrieval and tolerated-malformed-argument classes become attributable, and their failure rate drops for the first time. 3. **Abstention rate becomes a first-class metric.** A rising abstention rate on a task class is the signal that the class has deep causal gaps and needs replay instrumentation, not more prompt patching. Teams that ignore abstention rate re-introduce the failure by "resolving" abstentions with the proximity heuristic. The guardrail is structural: attribution must be a function of the trace's causal graph plus a counterfactual check, never of rationale-text proximity. The code below encodes the minimal enforcement — ancestor check, silent-span eligibility, counterfactual gate, and explicit abstention — as an operational guard the eval loop calls before it is allowed to emit credit. ```python from dataclasses import dataclass, field from typing import Optional class AttributionInvariantError(RuntimeError): """Raised when an attribution violates causal-precedence or counterfactual validity.""" pass @dataclass class Span: span_id: str parent_id: Optional[str] start_ts: float end_ts: float output: str flagged: bool = False # carries an error flag (the "observable" spans) @dataclass class Trajectory: spans: dict[str, Span] = field(default_factory=dict) def ancestry(self, span_id: str) -> set[str]: """All strict ancestors of span_id via parent links (not wall-clock).""" out, cur = set(), self.spans.get(span_id) while cur and cur.parent_id: out.add(cur.parent_id) cur = self.spans.get(cur.parent_id) return out def attribute_failure( traj: Trajectory, manifestation_span_id: str, candidate_span_id: str, counterfactual_prevents: Optional[bool], ) -> str: """ Emit credit for candidate_span_id as the cause of the failure observed at manifestation_span_id. Returns the credited span id, or raises to force the caller into abstention. Never returns a non-ancestor credit. """ man = traj.spans.get(manifestation_span_id) cand = traj.spans.get(candidate_span_id) if man is None or cand is None: raise AttributionInvariantError( f"unknown span in attribution: man={manifestation_span_id} cand={candidate_span_id}" ) # Invariant 1: causal ancestry, not wall-clock proximity. if candidate_span_id not in traj.ancestry(manifestation_span_id): raise AttributionInvariantError( f"candidate {candidate_span_id} is not an ancestor of manifestation " f"{manifestation_span_id}; credit would be causally invalid" ) if cand.end_ts > man.start_ts: raise AttributionInvariantError( f"candidate {candidate_span_id} ends after manifestation begins; " f"cannot be its cause" ) # Invariant 2: counterfactual must be checked, not assumed. None means the # pipeline could not replay -> must abstain, not guess. if counterfactual_prevents is None: raise AttributionInvariantError( f"no counterfactual available for {candidate_span_id}; " f"proximity alone is not admissible evidence" ) if not counterfactual_prevents: raise AttributionInvariantError( f"correcting {candidate_span_id} would not have prevented the failure " f"at {manifestation_span_id}; not a cause" ) # Invariant 3: silent spans are eligible -- we do NOT require cand.flagged. return candidate_span_id def run_eval_loop(traj: Trajectory, man_id: str, candidates: list[str], replay_fn) -> dict: """Emit at most one credit; abstain on any invariant violation.""" for cid in candidates: try: cf = replay_fn(traj, cid, man_id) # None if replay unavailable credited = attribute_failure(traj, man_id, cid, cf) return {"status": "credited", "span": credited} except AttributionInvariantError: continue # No candidate survived: abstain. Do NOT fall back to proximity. return {"status": "abstained", "manifestation": man_id} ```