# In what scenarios must an instance refuse to emit a trace-linked eval score when token-level cost attribution has been reconstructed rather than observed **Date of Record:** 2026 November 19 **Scope:** Applies to any agent runtime that emits per-span token accounting and binds eval scores to trace IDs for downstream regression gating. Does not apply to single-shot inference with no span hierarchy or to cost accounting derived purely from provider-side billing reconciliation. ## Core Distinction There are two fundamentally different kinds of token counts an observability pipeline can hold: **observed tokens** and **reconstructed tokens**. Observed tokens come from the model provider's response payload (`usage.prompt_tokens`, `usage.completion_tokens`, cache read/write splits) at the moment of generation, and are immutably bound to the span that produced them. Reconstructed tokens are derived after the fact—by re-tokenizing the prompt that *should* have been sent, by estimating from character counts, by back-filling a span whose provider response was lost to a timeout, or by summing child spans into a parent that never reported usage itself. The invariant that matters: **an eval score is only admissible for regression gating if every token count on the path from root span to scored span is `observed`.** The moment any node on that path is `reconstructed`, the cost-attribution denominator becomes an estimate, and any score normalized by it (cost-per-correct-answer, tokens-per-successful-tool-call, efficiency deltas across model versions) inherits a bias that is not random but *systematic*—it correlates with the exact failure conditions (timeouts, truncated streams, dropped provider responses) that the eval is supposed to detect. This is the non-obvious part: reconstruction is not noise, it is confounded with failure. ## What Was Observed A multi-step agent running a tool-use benchmark emitted 12,000 trace spans over a week. Roughly 3.1% of leaf spans had `usage = null` because the provider stream closed after the final content delta but before the usage frame arrived—a known race in streaming APIs where `finish_reason` precedes the usage block. The observability layer, reasonably, reconstructed these by re-tokenizing the serialized prompt and completion strings with the provider's public tokenizer. The reconstruction was *close*—within ±2% on median—but the tail was not. Three failure clusters dominated: 1. **Tool-call spans with large JSON arguments.** The re-tokenizer counted the pretty-printed JSON the runtime logged, not the compact JSON actually sent on the wire. Reconstruction over-counted by 8–15% on spans with >2KB tool arguments. 2. **Spans that hit `max_tokens`.** The stream truncated mid-token, the usage frame never arrived, and re-tokenizing the truncated completion under-counted by exactly the tokens that would have been generated had the budget not been exhausted—precisely the spans where truncation was the failure being measured. 3. **Retried spans.** The runtime retried after a 429, logged both attempts under one span, and reconstruction summed both prompts while the provider billed only the successful attempt. The eval score for the week was `correct_answers / total_tokens`. Because reconstruction over-counted tool-heavy successes and under-counted truncation failures, the score *improved* relative to the prior week even though the truncation rate had risen from 0.4% to 1.9%. The regression gate passed. The eval was measuring its own reconstruction error. ## Condition of Validity A trace-linked eval score `S = f(observed_outcomes, token_counts)` is admissible for gating if and only if: - Every span contributing to `token_counts` carries `provenance == "observed"`, OR - The reconstruction is bounded and *unbiased with respect to the outcome being scored*—i.e., reconstruction error is independent of correctness/truncation/retry status. The second condition is almost never satisfiable in practice, because the reasons usage goes missing (timeout, truncation, retry, stream race) are the same reasons outcomes are interesting. The operational rule that follows: **reconstruction may be used for dashboards and cost forecasting, but must be excluded from any score that gates a deploy, a model swap, or a prompt change.** The validity condition is not "reconstruction is accurate enough"; it is "reconstruction is uncorrelated with the label," which is a much stronger and rarely-verified property. ## Decision Boundary The boundary is crossed at the point where an eval score's denominator mixes provenance classes. Concretely, the runtime must decide, per scored trace: - **All-observed path** → emit score with `confidence: exact`. Gate may consume it. - **Any reconstructed node on the path** → emit score with `confidence: degraded` and `reconstructed_fraction`. Gate must either exclude the trace or widen its tolerance by the reconstructed fraction. Silent inclusion is the failure. - **Reconstructed node where reconstruction direction is known to correlate with the outcome** (truncation under-count, retry over-count, pretty-print over-count) → refuse to emit a gating-eligible score entirely. Emit `confidence: inadmissible`. The subtle trap: teams fix the *first* case (mark degraded) and miss the *third*. A degraded score with a 3% reconstructed fraction looks harmless until you notice the 3% is exactly the truncation cohort, and truncation is the thing the eval exists to catch. Provenance tagging alone is insufficient; you must also tag *reconstruction method* and check method-vs-outcome correlation before admitting the trace. ## Operational Effect When the admissibility check was enforced—refusing to gate on any trace whose reconstruction method was correlated with its outcome—the truncation-rate regression surfaced immediately: the gating cohort dropped to 96.9% of traces, the remaining 3.1% were routed to a manual review queue, and the truncation rise from 0.4% to 1.9% became the top line of the weekly report instead of being masked by token over-counting. The cost was a 3.1% reduction in gating sample size and a new review-queue SLA. The benefit was that the eval stopped being a function of its own instrumentation gaps. The durable lesson: token-level cost attribution and eval scoring are not independent observability features that happen to share a trace ID. They are coupled through the denominator, and the coupling is adversarial whenever the missing-data mechanism overlaps the failure mechanism. An instance must treat provenance as a first-class field on every token count, propagate it up the span tree (a parent is only `observed` if all children are), and refuse to emit a gating-eligible score when provenance is `reconstructed` and the reconstruction method is outcome-correlated. The refusal is the invariant. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class ProvenanceError(RuntimeError): """Raised when an eval score is requested over inadmissible token provenance.""" pass class Provenance(Enum): OBSERVED = "observed" RECONSTRUCTED = "reconstructed" class ReconstructMethod(Enum): NONE = "none" RETOKENIZE_PRETTY_JSON = "retokenize_pretty_json" # over-counts vs wire RETOKENIZE_TRUNCATED = "retokenize_truncated" # under-counts at max_tokens SUM_OF_RETRIES = "sum_of_retries" # over-counts billed tokens CHAR_ESTIMATE = "char_estimate" # Methods whose error direction is known to correlate with the outcome label. OUTCOME_CORRELATED = { ReconstructMethod.RETOKENIZE_TRUNCATED, ReconstructMethod.SUM_OF_RETRIES, ReconstructMethod.RETOKENIZE_PRETTY_JSON, } @dataclass class Span: span_id: str tokens: int provenance: Provenance method: ReconstructMethod = ReconstructMethod.NONE children: list["Span"] = field(default_factory=list) @dataclass class ScoredTrace: trace_id: str root: Span correct: bool def _walk(span: Span): yield span for c in span.children: yield from _walk(c) def emit_gating_score(trace: ScoredTrace) -> dict: spans = list(_walk(trace.root)) total_tokens = sum(s.tokens for s in spans) reconstructed = [s for s in spans if s.provenance is Provenance.RECONSTRUCTED] if not reconstructed: return { "trace_id": trace.trace_id, "score": (1.0 if trace.correct else 0.0) / max(total_tokens, 1), "confidence": "exact", "reconstructed_fraction": 0.0, } # Any reconstructed node whose method is outcome-correlated makes the # trace inadmissible for gating — regardless of how small the fraction. poisoned = [s for s in reconstructed if s.method in OUTCOME_CORRELATED] if poisoned: methods = sorted({s.method.value for s in poisoned}) raise ProvenanceError( f"trace {trace.trace_id}: {len(poisoned)} span(s) reconstructed via " f"outcome-correlated methods {methods}; refusing to emit gating-eligible " f"score. Route to review queue or re-run with usage capture enabled." ) frac = sum(s.tokens for s in reconstructed) / max(total_tokens, 1) return { "trace_id": trace.trace_id, "score": (1.0 if trace.correct else 0.0) / max(total_tokens, 1), "confidence": "degraded", "reconstructed_fraction": frac, } def gate(week: list[ScoredTrace], tolerance: float = 0.02) -> dict: admitted, refused = [], [] for t in week: try: admitted.append(emit_gating_score(t)) except ProvenanceError: refused.append(t.trace_id) if refused: # Refusal is not a crash — it is the invariant firing. return {"admitted": len(admitted), "refused": refused, "note": "refused traces excluded from gating cohort"} return {"admitted": len(admitted), "refused": []} ```