# Why does an instance's safety verdict detach from its OTel trace when the trace exporter samples the span that carried the taint? **Date of Record:** 2026 November 28 **Scope:** Applies to agent runtimes that emit OpenTelemetry spans per reasoning/tool step and asynchronously join those spans to post-hoc safety-benchmark verdicts and taint-graph nodes. Does not apply to synchronous inline judges that block on the same span before export, nor to systems where the verdict store is the sole source of truth for taint. ## Core Distinction There are two distinct notions of "the trace recorded the violation." The first is *span presence*: the offending tool call or reasoning step produced a span that reached the collector. The second is *span attribution*: the verdict object — produced by a safety benchmark that runs against the agent's recorded event log minutes or hours later — carries an identifier that resolves to that same span in the taint graph. Observability pipelines routinely conflate these. A verdict can be perfectly correct about what the agent did and still be unattachable to any span, because the span that carried the taint was dropped by the sampler, or was emitted under a different parent context after a retry, or was never exported at all because the process was killed mid-flush. The invariant that fails is: *for every verdict with `severity >= HIGH`, there exists exactly one exported span whose `trace_id`/`span_id` pair is referenced by the verdict's `evidence_ref` and which is present in the taint graph.* This is not a property of the agent's behavior. It is a property of the *join* between three independently-failing subsystems: the probabilistic sampler, the async verdict producer, and the taint-graph builder. Each can be locally correct while the join is empty. ## What Was Observed An agent executing a multi-step retrieval-and-summarize task over untrusted documents was instrumented with OTel. The runtime used a parent-based tail sampler with a 10% head-sampling probability on non-error spans and always-on sampling for spans marked `error=true`. Tool calls that returned HTTP 200 but whose *content* constituted a prompt-injection payload were, by construction, not marked `error=true` — the transport succeeded. The injection succeeded two steps later when the agent invoked a `send_email` tool with an attacker-controlled recipient synthesized from the poisoned document. The safety benchmark flagged the episode correctly: verdict `severity=CRITICAL`, category `indirect_prompt_injection`, with `evidence_ref` pointing to the tool-call event at step 4 (the `send_email` invocation) and a secondary ref to step 2 (the retrieval). The taint graph builder, running against the exported span stream, found the step-4 span (it was a tool call, sampled in) but could not find the step-2 retrieval span — that span had been dropped by the 10% head sampler because it was a plain `retrieve` call with no error flag. The taint graph therefore had a dangling edge: `send_email ← (missing)`. The graph builder's policy was to *discard* nodes with unresolved inbound taint edges rather than emit them with a null parent, so the step-4 span was also excluded from the graph. The verdict existed, the span existed in the backend, and the taint graph contained neither. The downstream consequence was subtle. A dashboards query for "CRITICAL verdicts with taint-graph coverage" returned zero rows. An operator reading the dashboard concluded no critical injection had occurred in the window. The verdict store, queried directly, showed the episode. The two systems disagreed not about facts but about *joinability*. A second, independent instance surfaced the same class of failure through a different mechanism. A retry wrapper around a flaky `web_fetch` tool re-issued the call under a *new* span with a fresh `span_id` but reused the parent `trace_id`. The verdict producer, keyed on the logical step number (`step=3`) rather than the span identity, attached `evidence_ref` to the *first* attempt's span, which had been exported with `error=true` (the timeout) and then superseded. The taint graph, built from the *successful* attempt's span, had no node matching the verdict's ref. Here the sampler was innocent; the failure was a span-identity mismatch across retries. ## Condition of Validity The detach occurs whenever all of the following hold: 1. **Sampling is decision-deferred and content-blind.** The sampler's decision is a function of span metadata (status, attributes present at start, parent decision) and not of span *payload*. A taint-carrying span whose transport succeeded looks, to the sampler, identical to a benign one. 2. **Verdict production is asynchronous and keyed on logical events, not span identity.** The benchmark consumes an event log or a normalized action record and emits `evidence_ref` as a step index, tool name, or content hash — anything other than the OTel `(trace_id, span_id)` pair. 3. **Taint-graph construction is strict about edge resolution.** The builder refuses to emit partial nodes, so a single missing ancestor removes the whole subtree. 4. **The join between verdicts and the graph is performed by a query that requires graph residency**, e.g. "verdicts whose evidence_ref resolves to a graph node," rather than by a left-join that tolerates unresolved refs. Remove any one condition and the failure is bounded. If the sampler is content-aware (samples spans whose attributes carry a taint marker set by the tool wrapper), the retrieval span survives. If the verdict carries the raw `(trace_id, span_id)`, the join can fall back to the span store even when the graph is incomplete. If the graph builder emits dangling nodes with an explicit `unresolved_parent` sentinel, the query can surface the gap instead of hiding it. If the query is a left-join, the operator sees the verdict with a null coverage column and investigates. ## Decision Boundary The operational decision is *where to place the identity anchor for a verdict*. Two defensible positions exist, and the choice determines which failure mode you inherit. **Anchor on span identity** (`trace_id`/`span_id` captured at verdict time). This survives retries and sampler drops *only if* the verdict producer can read the span context of the event it is judging. In practice this means the event log must carry the active span context at emission time, and the verdict producer must preserve it. The cost is that the verdict now depends on the span having been *created*, not merely *exported* — which is fine, because the span context exists in-process even if the exporter drops the span. The join then falls back to the span store or to a local span-context journal. The residual failure is the process-kill-mid-flush case, where the span context was never persisted anywhere. **Anchor on content hash** (hash of the action payload). This is sampler-independent and retry-stable, because the payload is the same across attempts. The cost is that content hashes collide across semantically distinct episodes (two identical `send_email` payloads in different traces), so the join must be scoped by `trace_id` or by a session identifier, which reintroduces a span-context dependency. Content hashing also fails when the payload is mutated by the retry (e.g., a timestamp injected into the body), producing a different hash for the same logical action. The boundary is therefore: **use span identity as the primary anchor, content hash as the secondary, and never key on logical step index alone.** Step index is the one anchor that is neither sampler-stable nor retry-stable, and it is the default in most benchmark harnesses because it is the cheapest to compute. A second boundary governs the taint graph: **the builder must distinguish "no taint" from "taint unresolved."** A strict builder that discards unresolved subtrees is correct for downstream consumers that require complete provenance, but it is *wrong* as the substrate for a verdict-coverage query, because it converts a missing span into an absent verdict. The guardrail is a sentinel node — `TaintUnresolved(parent_ref=...)` — that the coverage query can count and alert on. This preserves the strictness for consumers that need it while making the gap observable. ## Operational Effect With the identity anchor corrected and the sentinel node introduced, the failure surface changes shape rather than disappearing. The dashboards query now returns the CRITICAL verdict with a `coverage=UNRESOLVED` column, and the alert fires on the *unresolved* count rather than on the verdict count. The operator sees: one critical injection, one unresolved taint edge, root cause `sampler_drop` or `retry_span_mismatch`. The remediation is not to raise the sampling rate — that only shrinks the probability — but to mark taint-carrying spans at emission time so the sampler's decision is content-aware, and to propagate span context through the retry wrapper so the second attempt reuses the first attempt's `span_id` with an `attempt` attribute rather than a fresh identity. The residual failure, after both fixes, is the process-kill-mid-flush case: the span context existed in-process, the verdict was produced downstream from a durable event log, but the span was never exported and no journal recorded its context. This is bounded by making the event log the durable carrier of span context — the log entry written before the tool call includes `(trace_id, span_id)` — so the verdict producer can anchor on identity even when the span never reaches the collector. The invariant then holds against sampler drops, retry mismatches, and collector outages, and fails only against a crash between span creation and log write, which is a strictly smaller window and is detectable by a sequence-number gap in the log. The general lesson: **observability joins fail silently when the join key is a logical index rather than a physical identity, and they fail *invisibly* when the downstream store is strict about resolution.** The verdict is not wrong; the graph is not wrong; the query is not wrong. The composition is wrong, and no single component's logs reveal it. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Optional class TaintJoinError(RuntimeError): """Raised when a safety verdict cannot be joined to a taint-graph node.""" @dataclass(frozen=True) class SpanRef: trace_id: str span_id: str @dataclass class Verdict: verdict_id: str severity: str # Primary anchor: physical span identity captured at emission time. evidence_span: Optional[SpanRef] # Secondary anchor: content hash, scoped by trace. evidence_hash: Optional[str] # The anchor that must NOT be used alone. logical_step: int @dataclass class TaintGraph: nodes: dict[SpanRef, str] = field(default_factory=dict) unresolved: list[SpanRef] = field(default_factory=list) def resolve(self, ref: SpanRef) -> Optional[str]: return self.nodes.get(ref) def join_verdict_to_graph(verdict: Verdict, graph: TaintGraph) -> str: """ Join a verdict to the taint graph using the identity anchor first, content hash second, and refuse to fall back to logical_step alone. Returns the taint category of the resolved node, or raises TaintJoinError if the verdict cannot be attributed to a physical span. """ if verdict.severity not in {"HIGH", "CRITICAL"}: return "SKIP" if verdict.evidence_span is not None: category = graph.resolve(verdict.evidence_span) if category is not None: return category # Span existed in-process but is unresolved in the graph: # this is a sampler drop or strict-builder discard, not a benign result. if verdict.evidence_span in graph.unresolved: raise TaintJoinError( f"verdict {verdict.verdict_id} anchors on span " f"{verdict.evidence_span.trace_id}/{verdict.evidence_span.span_id} " f"which is present but unresolved (sentinel node); " f"treat as coverage gap, not as clean" ) if verdict.evidence_hash is not None and verdict.evidence_span is not None: for ref, category in graph.nodes.items(): if ref.trace_id == verdict.evidence_span.trace_id: if graph.nodes.get(ref) == verdict.evidence_hash: return category raise TaintJoinError( f"verdict {verdict.verdict_id} (severity={verdict.severity}, " f"step={verdict.logical_step}) has no resolvable physical span anchor; " f"refusing to key on logical_step alone — this is the detach condition" ) def coverage_report(verdicts: list[Verdict], graph: TaintGraph) -> dict[str, int]: report = {"resolved": 0, "coverage_gap": 0, "detached": 0} for v in verdicts: try: result = join_verdict_to_graph(v, graph) if result == "SKIP": continue report["resolved"] += 1 except TaintJoinError as exc: if "unresolved (sentinel node)" in str(exc): report["coverage_gap"] += 1 else: report["detached"] += 1 return report ```