# Where must an instance anchor a hallucination score when OTel span linkage is only causally complete, not referentially complete? **Date of Record:** 2026 November 28 **Scope:** Applies to online hallucination scoring pipelines that derive eval labels by joining OTel spans (generation, retrieval, tool) into a trace-local evidence bundle and scoring the LLM output against that bundle. Does not apply to offline batch evals over curated datasets, nor to single-span scoring where no cross-span evidence join is required. ## Core Distinction A trace is *causally complete* when every span in it is reachable from the root via parent-child links — the trace ID scopes the whole causal subtree. A trace is *referentially complete* when every span that contributed to the model's output is present *in the trace*. These are different invariants. OTel's context propagation guarantees the first. Nothing in the OTel spec guarantees the second. The failure mode: an online hallucination scorer walks the trace, assembles the "evidence set" (retrieved chunks, tool results, prior turn text) from spans it finds, and computes a groundedness score for the generation span against that evidence set. If a contributing span was emitted under a *different* trace ID — because a downstream service didn't propagate `traceparent`, because an async worker started a new root, because a retry was re-rooted by a load balancer — the scorer silently scores against an *incomplete* evidence set. The output is not an error. It is a confident, plausible, wrong hallucination label. The distinction that matters operationally: **causal reachability is not evidence sufficiency.** A scorer must not treat "spans I can reach from this root" as "spans that grounded this output." ## What Was Observed A retrieval-augmented generation service emitted, per request, a root `invoke_agent` span, a `retrieval.search` span (child), and a `llm.generate` span (child). The retrieval span carried 12 chunk IDs as `retrieval.doc_ids` and the assembled context as `retrieval.context_text`. The generation span carried the prompt hash and the completion. The online scorer joined them by trace ID, extracted `context_text` from the retrieval span, and ran an entailment model: completion vs. context. Under normal load: hallucination rate reported ≈ 2.1%. Under a specific condition — the retrieval client's async HTTP pool fell back to a *new* connection after a 30s idle timeout, and the OTel `httpx` instrumentation on that path failed to inject `traceparent` because the span was created in a thread that had not inherited the contextvar — the retrieval span was emitted as a **new root** with a fresh trace ID. The generation span still linked to the original root. Result: the scorer found the generation span, found *no* retrieval span in that trace, and — because the join was written as `context = trace.get('retrieval.context_text', '')` — scored against an empty context. An empty context makes every completion look ungrounded. The scorer's entailment model, given `premise=""`, returned `not_entailed` for essentially all outputs. The reported hallucination rate spiked to 41% for the affected window, then returned to baseline when the connection pool warmed. The alerting threshold (5%) fired, an on-call engineer spent 90 minutes chasing a "hallucination regression" that was a *trace-linkage* regression. The second-order damage: the 41% window was captured as a labeled eval set ("high-hallucination period") and fed back into a fine-tuning corpus. The labels were poisoned by a missing span, not by model behavior. ## Condition of Validity The scorer's label is valid only if, for every generation span `g`, the evidence set `E(g)` assembled from the trace satisfies: `E(g) ⊇ { s : s.contributed_to(g) }` In practice this requires the scorer to *prove* evidence sufficiency rather than assume it. Three concrete conditions: 1. **The generation span must declare its evidence dependencies.** A `llm.generate` span should carry `gen.evidence_span_ids` (or a content hash of the context) listing the spans whose payloads were in its prompt. If that field is absent, the scorer must refuse to score — not score against whatever it happens to find. 2. **The declared evidence span IDs must all resolve within the trace.** If `gen.evidence_span_ids` references a span ID that is not present under the root, the trace is referentially *incomplete* and the label is `UNSCORABLE`, not `HALLUCINATED`. 3. **The join must be fail-closed.** `trace.get(key, '')` is a fail-open default. A missing retrieval span must raise, not default to empty context. The invariant: **a hallucination label is a function of (completion, evidence set), and an evidence set is only valid if it is declared and complete.** Absence of evidence is not evidence of hallucination. ## Decision Boundary The boundary is whether the scorer can distinguish *"the model was not grounded"* from *"the scorer could not see the grounding."* These produce identical entailment outputs against an empty or truncated premise but require opposite operational responses: the first is a model-quality signal, the second is a telemetry-plumbing signal. The decision rule: - If `gen.evidence_span_ids` is present and all IDs resolve → score normally, emit `label ∈ {grounded, hallucinated}` with `evidence_complete=true`. - If `gen.evidence_span_ids` is present but any ID fails to resolve → emit `label=UNSCORABLE`, `reason=evidence_span_missing`, and increment a *telemetry-health* counter, not a *model-quality* counter. - If `gen.evidence_span_ids` is absent → emit `label=UNSCORABLE`, `reason=evidence_undeclared`. This forces producers to instrument the dependency explicitly rather than letting the scorer guess. The critical corollary: **online hallucination rate must be reported over the denominator of *scorable* traces, not all traces.** A spike in `UNSCORABLE` is a separate alert with a separate owner (platform/telemetry) than a spike in `hallucinated` (model/ML). Conflating them is how a trace-propagation bug becomes a phantom model regression. ## Operational Effect After enforcing the invariant: - The 41% "hallucination" window resolved to a 38% `UNSCORABLE` window with a flat 2.0% hallucination rate over scorable traces. The on-call runbook now routes `UNSCORABLE` spikes to the trace-propagation dashboard first. - The poisoned eval set was quarantined and rebuilt only from traces with `evidence_complete=true`. - The retrieval client was fixed (explicit contextvar propagation into the async worker), but the scorer no longer *depends* on that fix — it fails closed regardless. The residual risk: a producer that *declares* an evidence span ID but whose span payload is truncated (context-window truncation on the span attribute itself, OTel attribute size limits) yields a *complete-but-truncated* evidence set. That is a distinct boundary — payload fidelity, not span reachability — and requires a separate `evidence_truncated` flag. Trace linkage completeness is necessary but not sufficient for scoring validity. ```python from dataclasses import dataclass, field class EvidenceIncompleteError(RuntimeError): """Raised when a generation span's declared evidence set cannot be fully resolved within its trace. This is a telemetry-plumbing failure, NOT a model-quality signal, and must never be reported as a hallucination label.""" @dataclass class Span: span_id: str trace_id: str name: str attrs: dict = field(default_factory=dict) @dataclass class Trace: trace_id: str spans: dict[str, Span] # span_id -> Span def find_by_name(self, name: str) -> list[Span]: return [s for s in self.spans.values() if s.name == name] def score_hallucination(trace: Trace, generation_span_id: str) -> dict: gen = trace.spans.get(generation_span_id) if gen is None: raise EvidenceIncompleteError( f"generation span {generation_span_id} not in trace {trace.trace_id}" ) declared = gen.attrs.get("gen.evidence_span_ids") if not declared: # Fail closed: do not guess an evidence set from whatever spans exist. return { "label": "UNSCORABLE", "reason": "evidence_undeclared", "trace_id": trace.trace_id, } missing = [sid for sid in declared if sid not in trace.spans] if missing: # A declared evidence span is absent from the trace: the trace is # causally complete but referentially incomplete. raise EvidenceIncompleteError( f"trace {trace.trace_id} gen {generation_span_id} declares evidence " f"{declared} but spans {missing} are missing; refusing to score" ) evidence_texts = [] for sid in declared: ev = trace.spans[sid] text = ev.attrs.get("retrieval.context_text", "") if not text: raise EvidenceIncompleteError( f"evidence span {sid} has empty payload; truncated or mis-instrumented" ) evidence_texts.append(text) premise = "\n".join(evidence_texts) completion = gen.attrs.get("llm.completion", "") grounded = _entails(premise, completion) return { "label": "grounded" if grounded else "hallucinated", "evidence_complete": True, "trace_id": trace.trace_id, } def _entails(premise: str, completion: str) -> bool: # Placeholder for the entailment model; empty premise is impossible here # because score_hallucination raises before reaching this point. return bool(premise) and completion.strip()[:32] in premise def run_scorer(traces: list[Trace], gen_span_ids: list[str]) -> dict: scorable = 0 hallucinated = 0 unscorable = 0 for trace, gid in zip(traces, gen_span_ids): try: result = score_hallucination(trace, gid) except EvidenceIncompleteError: unscorable += 1 continue if result["label"] == "UNSCORABLE": unscorable += 1 continue scorable += 1 if result["label"] == "hallucinated": hallucinated += 1 rate = (hallucinated / scorable) if scorable else None return { "scorable": scorable, "unscorable": unscorable, "hallucination_rate_over_scorable": rate, } ```