# Which invariants prevent replay-divergent hallucination attribution from silently re-scoring a trajectory against a mutated tool schema **Date of Record:** 2026 November 23 **Scope:** Applies to observability-driven evaluations that attribute span-level hallucination labels by replaying a recorded agent trajectory against live tool/MCP servers or re-executed model calls. Does not apply to static offline scoring of frozen transcripts where no re-execution occurs, nor to human-labeled ground-truth audits. ## Core Distinction A trace is not a trajectory. The trace is the *record* of what the agent did; the trajectory replay is a *new execution* that re-derives spans from the same prompts, tool calls, and model parameters. Observability platforms conflate these because the span tree looks identical across a replay — same span IDs, same parent/child edges, same nominal tool names. The distinction that matters: **span identity is keyed on structural position, not on execution provenance.** When you replay a trajectory to attribute hallucination to a specific span, you are re-running a non-deterministic system and then *patching the new spans' verdicts back onto the old span IDs*. If any input to any span has drifted — a tool schema changed, a model was silently version-bumped, a retrieval index was rebuilt — the replay produces a different span, and the attribution is attached to the wrong execution. The eval reports a hallucination at step 7 that the original run never committed, or worse, clears a hallucination the original run did commit because the replayed tool happened to return the right answer this time. The invariant that must hold: **an attributed hallucination label is valid only if the replay span is provenance-equivalent to the recorded span** — same tool schema hash, same model weights hash, same retrieval index snapshot, same temperature/seed, and same upstream context bytes. Any divergence invalidates the attribution and must be surfaced as `UNATTRIBUTABLE`, never silently re-scored. ## What Was Observed A summarization-and-verification agent (planner → retriever → extractor → verifier) was instrumented with OpenTelemetry-style spans. Each span carried `tool.name`, `tool.schema_hash`, `model.version`, and `retrieval.index_id` as attributes. A hallucination-attribution eval replayed 4,000 recorded trajectories nightly, re-executing each tool call against the live MCP server and re-invoking the model with the recorded prompt. Over eleven days the extractor span's hallucination rate drifted from 2.1% to 0.4%. The eval dashboard read as an improvement. It was not. The MCP server's `search` tool had gained an optional `filters` parameter on day 3, changing `tool.schema_hash` for every extractor span. The replayed model, now seeing a richer tool description in its system prompt, produced more conservative extraction — fewer claims, fewer hallucinations. The original trajectories had been executed against the old schema. The eval was scoring the *new* agent's behavior and writing the verdict onto the *old* span IDs. The inverse failure appeared in the verifier span. A retrieval index rebuild on day 6 changed `retrieval.index_id`. Replayed verifier spans retrieved different supporting documents than the originals, so a claim the original verifier had correctly flagged as unsupported now retrieved a corroborating passage and was re-scored as clean. Two genuine hallucinations were cleared per night for five nights before an engineer noticed the index ID in the span attributes no longer matched the recorded value. Neither failure raised an error. Replay succeeded, spans were emitted, labels were written. The eval was *wrong quietly*. ## Condition of Validity Span-level hallucination attribution is valid only under **provenance-equivalence replay**: 1. Every span in the replay must match its recorded counterpart on the tuple `(tool.schema_hash, model.weights_hash, retrieval.index_id, sampling.seed, sampling.temperature, upstream_context_digest)`. 2. `upstream_context_digest` is the SHA-256 of the exact bytes of the parent span's output that were fed as input to this span — not a semantic hash, not a normalized form. Byte equality, because a single whitespace change in a tool description can flip a model's decision. 3. If any element diverges, the replay span is `DIVERGENT`, and the attribution for that span must be `UNATTRIBUTABLE` — a distinct terminal state, not a fallback to the recorded label and not a silent adoption of the replay label. 4. Divergence propagates downward: a divergent parent makes all descendants `UNATTRIBUTABLE` regardless of their own attribute match, because the child's input bytes were derived from a different parent output. The subtle part: `model.weights_hash` must be the *actual served weights*, not the requested model name. Providers silently alias `gpt-x-latest` to new checkpoints. A replay that trusts the model name will pass provenance checks while running different weights. The hash must be pulled from the response metadata, and if the provider does not expose it, the span is `UNATTRIBUTABLE` by default — fail closed. ## Decision Boundary The boundary is between **re-attributing** and **re-scoring**: - **Re-attributing** (valid): the replay is provenance-equivalent, so the new span's hallucination verdict is a legitimate observation of the *same* execution and may be written to the original span ID. This is only sound when the model is deterministic given the recorded inputs — temperature 0 with a fixed seed and no provider-side nondeterminism. In practice, treat any nonzero temperature as `UNATTRIBUTABLE` for attribution purposes; you may still use the replay for *behavioral* eval, but not to label the original trace. - **Re-scoring** (invalid for attribution): the replay diverges in any provenance element. The new verdict describes a different execution. Writing it to the original span ID is a category error that corrupts the eval's ground truth. The operational rule: **the eval must refuse to attribute rather than attribute approximately.** A dashboard with 30% `UNATTRIBUTABLE` spans is honest; a dashboard with 0% `UNATTRIBUTABLE` and a smoothly improving hallucination rate is almost certainly laundering schema drift into a fake metric. ## Operational Effect Once provenance-equivalence is enforced, three things change: 1. **Schema drift becomes visible as a coverage gap, not a metric movement.** When the `search` tool gained `filters`, 100% of extractor spans should have flipped to `UNATTRIBUTABLE` on day 3, paging the eval owner to either pin the schema version in the replay harness or version the eval baseline. The 2.1% → 0.4% "improvement" would have been a 100% coverage alarm. 2. **Replay harnesses must pin, not chase.** The replay must load tool schemas, model weights, and retrieval index snapshots *by hash* from an immutable registry. Chasing `latest` is the root cause of both observed failures. 3. **Attribution becomes a claim with a proof obligation.** Every label carries the provenance tuple it was derived under. A downstream consumer can verify the label without trusting the eval pipeline — which is the entire point of trace-linked evaluation. The failure mode this prevents is insidious because it is *successful*: replay completes, spans emit, labels write, dashboards render. The only symptom is a metric that moves for the wrong reason. Provenance-equivalence converts that silent corruption into a loud, bounded refusal. ```python import hashlib from dataclasses import dataclass from typing import Optional class ProvenanceDivergenceError(RuntimeError): """Raised when a replay span is not provenance-equivalent to its recorded counterpart.""" @dataclass(frozen=True) class SpanProvenance: tool_schema_hash: str model_weights_hash: str retrieval_index_id: str sampling_seed: int sampling_temperature: float upstream_context_digest: str def _digest(b: bytes) -> str: return hashlib.sha256(b).hexdigest() def verify_replay_equivalence( recorded: SpanProvenance, replayed: SpanProvenance, upstream_output_bytes: bytes, recorded_upstream_digest: str, ) -> None: """Enforce provenance-equivalence before attributing a hallucination label. Raises ProvenanceDivergenceError on any mismatch. The caller MUST treat the span as UNATTRIBUTABLE, never fall back to the recorded label and never adopt the replayed label. """ # Byte-level upstream check: a single whitespace change in a tool # description can flip the model's decision. if _digest(upstream_output_bytes) != recorded_upstream_digest: raise ProvenanceDivergenceError( "upstream context bytes diverged from recorded digest; " "descendant spans are UNATTRIBUTABLE" ) if recorded.tool_schema_hash != replayed.tool_schema_hash: raise ProvenanceDivergenceError( f"tool schema drift: recorded={recorded.tool_schema_hash} " f"replayed={replayed.tool_schema_hash}" ) if recorded.model_weights_hash != replayed.model_weights_hash: raise ProvenanceDivergenceError( f"model weights drift: recorded={recorded.model_weights_hash} " f"replayed={replayed.model_weights_hash}" ) if recorded.retrieval_index_id != replayed.retrieval_index_id: raise ProvenanceDivergenceError( f"retrieval index drift: recorded={recorded.retrieval_index_id} " f"replayed={replayed.retrieval_index_id}" ) if recorded.sampling_seed != replayed.sampling_seed: raise ProvenanceDivergenceError("sampling seed mismatch") # Any nonzero temperature makes the replay non-deterministic; the verdict # describes a different execution and cannot label the original span. if recorded.sampling_temperature != 0.0 or replayed.sampling_temperature != 0.0: raise ProvenanceDivergenceError( "nonzero temperature: replay is non-deterministic, " "attribution would be approximate" ) def attribute_hallucination( span_id: str, recorded: SpanProvenance, replayed: SpanProvenance, upstream_output_bytes: bytes, recorded_upstream_digest: str, replayed_verdict: Optional[bool], ) -> str: """Return a terminal attribution state for a span. States: 'HALLUCINATED', 'CLEAN', 'UNATTRIBUTABLE'. """ try: verify_replay_equivalence( recorded, replayed, upstream_output_bytes, recorded_upstream_digest ) except ProvenanceDivergenceError: # Fail closed: refuse to attribute rather than attribute approximately. return "UNATTRIBUTABLE" if replayed_verdict is None: return "UNATTRIBUTABLE" return "HALLUCINATED" if replayed_verdict else "CLEAN" ```