# Why does an instance lose hallucination attribution when a trace-linked eval scorer re-scores a span whose parent context was compacted mid-run? **Date of Record:** 2026 November 30 **Scope:** Applies to agent systems where evaluation scores are attached to spans in a distributed trace and later replayed or re-scored against the recorded trace. Does not apply to online-only scoring where the scorer consumes live context and never re-derives scores from stored spans. ## Core Distinction There are two different things a trace-linked eval scorer can mean by "the context the model saw": 1. **The recorded prompt** — the literal token sequence serialized into the span's `input` field at call time. 2. **The reconstructible prompt** — the token sequence a replay engine can rebuild by walking parent spans, concatenating retrieved chunks, and re-running context assembly. These diverge the moment context compaction, summarization, or truncation happens between a parent span and its child. A hallucination is a claim that is unsupported *relative to what the model actually saw*. If the scorer attributes the claim against the reconstructible prompt instead of the recorded prompt, it will either (a) mark a grounded claim as hallucinated because the grounding evidence was compacted out of the parent, or (b) mark a hallucinated claim as grounded because the replayed context assembly retrieved a chunk the original run never saw. Both are attribution inversions, and both are silent — the score looks valid because the trace is structurally intact. The invariant that must hold: **attribution is only valid when the scorer's evidence set is a subset of the recorded prompt's token set for the span under evaluation.** Anything outside that subset is counterfactual evidence, not attribution. ## What Was Observed A retrieval agent answered a support question across 14 tool calls. At step 9, the orchestrator compacted the message history from ~31k to ~6k tokens, replacing the original retrieved documents (steps 2–5) with a 400-token summary span. The summary was recorded as a child span `ctx.compact` with `parent_id` pointing to the step-9 LLM span, but the *original* retrieval spans remained in the trace under the step-2 parent. The eval scorer ran post-hoc. For each LLM span it rebuilt context by walking ancestors and concatenating `input` fields. Because `ctx.compact` sat between the root and step-9, the walker stopped at the compact span's `output` (the summary) and never reached the retrieval spans — they were siblings of an ancestor, not ancestors themselves. The scorer therefore attributed the step-9 answer against a 400-token summary. Result: 3 of the 5 factual claims in the final answer were scored as hallucinations with confidence 0.91–0.97. All 3 were verbatim supported by retrieval spans that existed in the same trace, 40 lines below in the span tree. The trace was complete. The attribution was wrong because the *evidence walk* and the *context walk* used the same traversal, and compaction had severed one from the other. The inverse case appeared in the same batch: a different run scored 0.98 faithfulness on a claim about a refund window that appeared nowhere in the recorded prompt but *did* appear in a retrieval span the replayer re-fetched live (the retriever had non-deterministic ranking; the replayer hit a fresh index). The replay reconstructed a context the model never saw, and the scorer called it grounded. ## Condition of Validity Trace-linked attribution is valid only under the following conjunction, and any failure of one conjunct invalidates the score without invalidating the trace: - **Evidence containment:** every token the scorer cites as support must be a substring (modulo normalization) of the recorded `input` of the span being scored, or of a recorded span reachable by the *recorded* context-assembly edges — not by a re-derived walk. - **Compaction transparency:** compaction spans must carry an explicit `supersedes` edge listing the span IDs whose content they replaced, so the scorer can distinguish "evidence absent" from "evidence compacted." - **Replay determinism for retrieval:** if the scorer re-fetches any external content, the fetch must be pinned to the recorded retrieval snapshot (content hash + index version), not the live index. - **Scoring-time immutability:** the recorded prompt used for attribution must be the exact token sequence sent to the model, including any system-prompt drift, tool-schema preamble, and truncation markers. If compaction transparency is missing, the scorer cannot tell a genuine hallucination from an evidence-severed claim. It will default to "unsupported" and inflate hallucination rates precisely on the longest, most-compacted runs — which are the runs where the agent did the most work and where accurate scoring matters most. ## Decision Boundary The scorer must branch on whether the evidence set is *closed* (fully contained in recorded spans) or *open* (requires re-derivation): - **Closed evidence → attribute.** Score faithfulness against the recorded prompt. A claim unsupported by recorded spans is a hallucination with full confidence. - **Open evidence → abstain or downgrade.** If any cited support comes from re-derived context, re-fetched retrieval, or a compacted span whose `supersedes` edge is absent, the scorer must emit `attribution_status: indeterminate` rather than a numeric faithfulness score. Emitting a number here is the failure. - **Compacted-and-superseded → attribute against the union.** When `supersedes` edges are present, the valid evidence set is the recorded prompt of the scored span *plus* the recorded outputs of superseded spans. This is the only case where evidence outside the literal prompt is legitimately attributable, because it was demonstrably in the model's history before compaction. The boundary is sharp: the moment a scorer's evidence walk diverges from the recorded context-assembly graph, it is no longer scoring the model — it is scoring the replayer. ## Operational Effect Teams that skip this distinction see two coupled symptoms. First, hallucination rate correlates with run length and compaction count rather than with model behavior — a 14-step run scores worse than a 4-step run on identical model output. Second, decision replay diverges from the original decision: the replayer, fed the reconstructed context, produces a different answer than the recorded one, and the divergence is misattributed to model non-determinism rather than to context reconstruction error. Debugging then chases temperature and seed settings while the actual defect is a severed evidence edge. The fix is structural, not statistical: record compaction as a first-class `supersedes` edge, pin retrieval to content hashes, and make the scorer refuse to emit a numeric attribution when its evidence set is not provably closed. A scorer that abstains on 8% of spans but is correct on the other 92% is operationally superior to one that scores 100% and inverts attribution on exactly the runs that matter. ```python from dataclasses import dataclass from typing import Iterable, Optional class AttributionEvidenceError(RuntimeError): """Raised when a scorer's evidence set is not provably closed over the recorded trace.""" @dataclass(frozen=True) class Span: span_id: str parent_id: Optional[str] input_tokens: str supersedes: tuple[str, ...] = () @dataclass(frozen=True) class Claim: text: str cited_span_ids: tuple[str, ...] def attribute_claim( claim: Claim, scored_span: Span, trace: dict[str, Span], replayed_evidence: Iterable[str] = (), ) -> str: """Return 'supported' | 'hallucinated' | 'indeterminate'. Valid attribution requires every cited span to be either: - the scored span itself, or - reachable via recorded supersedes edges from the scored span. Replayed (re-derived) evidence is never attributable. """ admissible: set[str] = {scored_span.span_id} frontier = list(scored_span.supersedes) while frontier: sid = frontier.pop() if sid in admissible: continue span = trace.get(sid) if span is None: # Cited evidence was compacted away with no supersedes edge recorded. raise AttributionEvidenceError( f"cited span {sid!r} absent from trace and not superseded by " f"{scored_span.span_id!r}; attribution would be counterfactual" ) admissible.add(sid) frontier.extend(span.supersedes) for cited in claim.cited_span_ids: if cited not in admissible: raise AttributionEvidenceError( f"claim cites span {cited!r} outside admissible evidence set " f"{sorted(admissible)}; scorer is walking replayed context, not " f"recorded context" ) if any(replayed_evidence): # Re-fetched evidence cannot ground a claim about what the model saw. return "indeterminate" haystack = " ".join(trace[s].input_tokens for s in admissible) if claim.text.strip().lower() in haystack.lower(): return "supported" return "hallucinated" ```