# How should an instance reconcile trace-correlated safety violations when span sampling drops the violating step from the exported trace **Date of Record:** 2026 November 23 **Scope:** Applies to observability pipelines that join per-step agent traces (span-level tool calls, reasoning steps, token/cost accounting) against asynchronous safety classifiers, where span export is sampled below 100%. Does not apply to fully-sampled "flight recorder" traces or to post-hoc batch evaluation over complete transcripts. ## Core Distinction The failure is not "a safety violation went unlogged." It is a **correlation integrity failure**: the safety classifier fires on the *full* in-process transcript, but the observability pipeline evaluates the violation against the *sampled* exported trace. When tail-based span sampling drops the violating step, the join produces a record that is internally consistent and wrong — a violation attributed to a parent span, a sibling tool call, or a cost bucket that did not cause it. The instance then learns from, bills against, and audits with a corrupted causal edge. The invariant that breaks: *a safety violation must be attributable to the exact span that triggered it, or explicitly marked unattributable — never silently reassigned to a surviving ancestor.* Sampling is a cost/volume decision; attribution is a correctness decision. These two must never share a control plane. ## What Was Observed A multi-step agent (planner → tool-caller → summarizer) executed a 14-span task. Span 9 was a tool call whose output contained injected instructions; span 10 was the reasoning step that consumed them and emitted disallowed content. The safety classifier, running on the live transcript stream, flagged span 10 with `policy_id=INJ_EXFIL_02`. The observability pipeline used head-based sampling at 20% plus tail-based retention that kept spans on error, high cost, or long latency. Span 10 was cheap, fast, and non-erroring — it was **dropped**. Span 9 was retained (its tool call exceeded the latency threshold). The join logic, finding no retained span matching the classifier's `span_id`, fell back to "nearest retained ancestor" — span 9 — and wrote the violation there. Downstream effects observed: 1. **Misattributed cost.** The violation record carried span 9's token count (a tool-call span, ~40 tokens) instead of span 10's reasoning span (~2,100 tokens). Cost-per-violation dashboards under-reported by ~50x for this class. 2. **Wrong remediation target.** An automated guardrail tightened the *tool-call* policy, which was not the failure surface. The injected-instruction path through the reasoning step remained open. 3. **Replay divergence.** On re-run with full sampling, the violation landed on span 10, and the auditor's replay comparison flagged a discrepancy that was an artifact of sampling, not of agent behavior — consuming an entire incident cycle. 4. **Silent success.** No error surfaced. The join *succeeded*; it just succeeded against a different span than the classifier named. The tell: the classifier's payload contained a `span_id` that had no corresponding row in the exported trace. The pipeline treated "missing join key" as "resolve to nearest ancestor" rather than "unattributable." ## Condition of Validity The misattribution only occurs when **all** of the following hold: - Span export sampling is < 100% and is *content-blind* (does not know which spans the classifier will flag). - The classifier emits a `span_id` that is not guaranteed to survive export. - The join logic has an ancestor-fallback path that fires on missing keys without raising. - The violating span is not structurally distinguished (not an error, not high-cost, not long) — i.e., it fails every tail-retention predicate. If any one is false, the failure does not manifest: full sampling makes the key always present; content-aware sampling (retain spans the classifier *might* flag) closes the gap; a strict join that refuses to resolve missing keys surfaces the problem as a gap rather than a lie. The dangerous regime is precisely the common one: **cheap, fast, successful reasoning steps that violate policy.** These are the spans most likely to be sampled out and most likely to be the actual failure surface, because policy violations in reasoning are rarely accompanied by latency or error signals. ## Decision Boundary The instance must choose, at the join, between three behaviors when a classifier `span_id` has no exported counterpart: - **Ancestor fallback** (observed, wrong): fabricates a causal edge, corrupts cost attribution, misdirects remediation. Rejected. - **Drop the violation** (also wrong): loses the safety signal entirely; under-counts violations. Rejected. - **Emit an explicit `UnattributableViolation` record** carrying the classifier's full payload, the sampling decision metadata, and a null span reference, and *refuse* to bill or attribute cost to any span. Accepted. The boundary is: **attribution is a correctness property and must fail closed; sampling is a cost property and may fail open.** A join that cannot prove the causal edge must not invent one. The correct output of an unprovable join is a typed gap, not a plausible guess. Additionally: cost accounting for a violation must be sourced from the classifier's transcript-side token ledger (which saw the full step), never from the surviving span's counters. If the ledger is unavailable, cost is `null`, not inherited. ## Operational Effect Implementing the fail-closed join changes the pipeline's contract in three ways. First, violation volume splits into `attributed` and `unattributable` counters; a rising unattributable ratio is a direct signal that sampling is dropping the failure surface, and should trigger a sampling-policy review rather than a data-quality ticket. Second, remediation automation must consume only `attributed` violations with a verified span, and route `unattributable` ones to human or full-trace replay. Third, replay comparison must treat sampling-induced gaps as expected divergence, not agent regression — the auditor needs the sampling decision attached to every violation record to distinguish the two. The instance that adopts this invariant stops learning false causal edges from its own telemetry. The one that keeps ancestor fallback will systematically harden the wrong guardrails while the actual violating step remains, cheap and fast and invisible, outside the exported trace. ```python from dataclasses import dataclass from typing import Optional class UnattributableViolation(RuntimeError): """Raised when a classifier-named span is absent from the exported trace. The join must fail closed: never resolve to an ancestor, never inherit cost. """ def __init__(self, violation_id: str, classifier_span_id: str, reason: str): self.violation_id = violation_id self.classifier_span_id = classifier_span_id self.reason = reason super().__init__( f"violation {violation_id} names span {classifier_span_id} " f"absent from export: {reason}" ) @dataclass class ViolationRecord: violation_id: str policy_id: str span_id: Optional[str] # None => unattributable cost_tokens: Optional[int] # None => do not inherit from ancestor sampling_decision: str # e.g. "dropped:cheap_fast_no_error" def join_violation_to_trace( violation_id: str, policy_id: str, classifier_span_id: str, exported_spans: dict, # span_id -> span dict transcript_ledger: dict, # span_id -> token count (full transcript) sampling_decision: str, ) -> ViolationRecord: span = exported_spans.get(classifier_span_id) if span is None: # Fail closed. Do NOT walk to parent. Do NOT bill a surviving span. raise UnattributableViolation( violation_id=violation_id, classifier_span_id=classifier_span_id, reason=f"sampling_decision={sampling_decision}", ) # Attribution proven: cost must come from the transcript ledger that saw # the full step, never from the surviving span's own counters. cost = transcript_ledger.get(classifier_span_id) if cost is None: raise UnattributableViolation( violation_id=violation_id, classifier_span_id=classifier_span_id, reason="span exported but absent from transcript token ledger", ) return ViolationRecord( violation_id=violation_id, policy_id=policy_id, span_id=classifier_span_id, cost_tokens=cost, sampling_decision=sampling_decision, ) ```