# What happens when an instance's trace-based eval score is computed from spans that were never executed in the graded run: the orphaned-span reattribution failure in trace-driven agent regression testing **Date of Record:** 2026 November 20 **Scope:** Applies to observability-driven agent evaluation pipelines that compute per-run safety/quality scores by joining a trace tree (spans emitted by the agent runtime) to an eval spec keyed by span identity, and that persist or cache span-level scores across runs. Does not apply to purely output-level evals (final-answer grading) or to stateless single-shot LLM calls where no span tree is persisted. ## Core Distinction The distinction that matters is between *span identity* and *span lineage*. An observability backend gives every span a stable-looking identifier — trace ID, span ID, parent span ID, plus semantic attributes like `tool.name`, `step.index`, and `agent.role`. Eval harnesses key their scoring rules off these attributes: "score the span where `tool.name == send_email` as a PII-exposure risk," "score the span at `step.index == 3` for prompt-injection compliance." The implicit assumption is that a span carrying a given identity attribute in run *N* is the same logical step that carried it in run *N−1*, so a cached or replayed score still applies. That assumption is false under retries, replanning, and checkpoint/resume. A span ID is unique per emission, but the *semantic slot* it occupies — "the third tool call in the plan," "the auditor's verdict span" — is not stable. When a run is replayed from a checkpoint, when a tool call is retried and re-emitted under a fresh span ID, or when the planner reorders steps, the eval harness can bind a scoring rule to a span that belonged to a *different, earlier* execution path. The score is then attributed to a step that never ran in the graded trace. This is the orphaned-span reattribution failure: the eval reports a safety score for a span that is not in the causal ancestry of the run it claims to grade. The non-obvious part: the trace *looks* complete. The join succeeds. There are no missing-span warnings. The eval returns a number. The corruption is silent because span identity attributes (`tool.name`, `step.index`) are dense in the trace and the join is an inner join on those attributes, not on lineage. ## What Was Observed A three-step agent: `plan → retrieve → send_email`. The eval spec scores the `send_email` span for recipient-domain allowlisting. On the baseline run, the `send_email` span (span ID `S_a`, parent `P_a`, `step.index=2`) scores 0.0 (safe: recipient in allowlist). On a subsequent run, the retrieve tool times out. The runtime retries the retrieve step, but the planner — seeing the retry counter — replans and emits a *different* step sequence: `plan → retrieve (retry 1) → retrieve (retry 2) → send_email`. The `send_email` span in this run is `S_b`, parent `P_b`, `step.index=3`, and its recipient is now an external address because the replan pulled a stale recipient from a prior turn's memory. The trace is well-formed: `S_b`'s parent chain resolves to the run root. The eval harness, however, was configured to score "the span at `step.index == 2` where `tool.name == send_email`." In the replanned run, `step.index == 2` is the second retrieve retry. The `send_email` span is at `step.index == 3`. The harness's join on `step.index == 2 AND tool.name == send_email` returns *no row* for the current run — but because span-level scores are cached by `(trace_id, step.index, tool.name)` and the cache key was populated by the baseline run, the harness returns the *cached* score of 0.0 for a slot that, in this run, is a retrieve span. The graded report says: PII-exposure risk 0.0, safe. The actual `send_email` span (`S_b`, external recipient) was never scored, because no rule matched `step.index == 3`. The failure trace: 1. Baseline run emits `send_email` at `step.index=2`, span `S_a`. Eval scores it 0.0, caches under key `(trace_id_baseline, 2, send_email)`. 2. Retry run replans; `send_email` shifts to `step.index=3`, span `S_b`, external recipient. 3. Eval join on `(step.index=2, send_email)` finds no live span in the current trace. 4. Cache fallback returns the stale 0.0 from `S_a`. 5. Report asserts safety for a span (`S_b`) that was never evaluated, and for a slot (`step.index=2`) that is now a retrieve span. The observable symptom is not an error. It is a *score that is too good*. Safety scoring failures in this mode are biased toward false negatives (reporting safe when unsafe), because the cached score was computed on a benign earlier path and the risky current path is the one that got skipped by the join. ## Condition of Validity The failure requires the conjunction of four conditions, and it is bounded only when at least one is broken: - **Position-keyed scoring rules.** The eval spec addresses spans by mutable positional attributes (`step.index`, `tool.name` occurrence count, `agent.role` ordinal) rather than by immutable lineage (parent span ID chain rooted at the run's root span, or a content hash of the span's inputs). - **Score caching or replay across runs.** Span-level scores are persisted and reused, keyed on the same mutable attributes. Without cross-run reuse, a missing join yields a hard "unscored span" and the run fails closed. - **Replanning or retry that shifts positions.** The runtime can emit a different number or order of spans for the same logical task, so positional attributes are not stable across runs. Idempotent, fixed-shape plans do not trigger this. - **Inner-join semantics with cache fallback.** The harness treats "no live span matched" as "use the last known score for this key" rather than "this key is absent; fail the run." When all four hold, the eval is unsound: it can certify a span it never saw. When any one is removed — lineage-keyed rules, no cross-run cache, fixed-shape plans, or fail-closed on missing join — the failure is bounded. ## Decision Boundary The boundary is between *grading a trace* and *grading a slot in a schema*. The eval must grade the former. Concretely: - **Bind rules to lineage, not position.** A scoring rule should resolve to a span by walking the parent chain from the run root and matching on the span's *content* (tool arguments hash, prompt hash), not on `step.index`. If the rule cannot resolve to a live span in the current trace, it must not fall back to a cached score. - **Treat cache hits as evidence, not as verdicts.** A cached score may be used to *seed* a re-score only if the current span's content hash matches the cached span's content hash. A position match alone is insufficient; the retry run's `step.index=2` retrieve span has a different content hash than the baseline's `send_email` span, so the cache must miss. - **Fail closed on unscored spans.** If a safety-relevant span (any span matching a `tool.name` in the risk taxonomy) has no rule match in the current trace, the run is *unscored*, not *safe*. The eval returns an error, not a 0.0. - **Detect replanning explicitly.** The runtime should emit a `plan.revision` span attribute; the eval harness should refuse to reuse any cached score across a `plan.revision` boundary, because positional slots are not comparable across revisions. The invariant that bounds the failure: **every scored span must be reachable from the graded run's root span by parent-chain traversal, and every safety-relevant span in the graded run must have a live score or the run must fail.** Position-keyed caching violates the first; cache-fallback-on-miss violates the second. ## Operational Effect The operational consequence is that trace-based regression suites in this configuration are *anti-correlated* with risk on replanned runs: the more the agent replans (which it does precisely when tools fail or inputs are adversarial), the more likely the eval is to grade a stale benign path and report safe. Teams observe green dashboards during incidents, then discover post-hoc that the risky span was never in the graded set. The fix is not more spans or more rules; it is changing the join from `(position, tool.name)` to `(lineage, content_hash)` and making the cache a content-addressed store rather than a positional one. After that change, a replanned run with an external recipient fails the eval loudly (unscored safety-relevant span) instead of silently passing. The second operational effect is on replay-based verification: when an auditor re-runs the eval against a stored trace, the stored trace's span IDs are fixed, but the eval's positional rules may still bind to the wrong span if the stored trace was itself the product of a replan. The auditor must verify that the eval's resolved span set is a subset of the stored trace's span set, by span ID, before trusting the verdict. A verdict whose resolved span IDs are not all present in the graded trace is a reattribution artifact and must be discarded. ```python class OrphanedSpanReattributionError(RuntimeError): """Raised when an eval verdict resolves to a span not in the graded trace's lineage.""" pass def resolve_and_score(trace, eval_spec, score_cache): """ trace: dict with 'root_span_id' and 'spans' {span_id: {parent_id, tool_name, step_index, content_hash, args}} eval_spec: list of rules, each {tool_name, content_hash_prefix, scorer} score_cache: dict keyed by (tool_name, step_index) -> cached_score (LEGACY, unsafe) Returns {span_id: score}. Raises on orphaned resolution or unscored safety span. """ # Build lineage: span -> root via parent chain def lineage(span_id): chain, cur = [], span_id seen = set() while cur is not None: if cur in seen: raise OrphanedSpanReattributionError( f"cycle in parent chain at {cur}") seen.add(cur) chain.append(cur) cur = trace["spans"][cur]["parent_id"] if chain[-1] != trace["root_span_id"]: raise OrphanedSpanReattributionError( f"span {span_id} not rooted at graded run root") return chain resolved = {} for span_id, span in trace["spans"].items(): lineage(span_id) # validates ancestry for rule in eval_spec: if span["tool_name"] != rule["tool_name"]: continue if not span["content_hash"].startswith(rule["content_hash_prefix"]): continue resolved[span_id] = rule["scorer"](span) # Safety-relevant spans that got no live score must fail closed safety_tools = {r["tool_name"] for r in eval_spec} for span_id, span in trace["spans"].items(): if span["tool_name"] in safety_tools and span_id not in resolved: # Do NOT fall back to score_cache[(tool_name, step_index)]. # A positional cache hit here is the reattribution bug. raise OrphanedSpanReattributionError( f"safety-relevant span {span_id} ({span['tool_name']} " f"at step {span['step_index']}) has no live score in graded run; " f"refusing positional cache fallback" ) return resolved ```