# Why does an instance's safety verdict arrive before its own trace span, and how does that orphan the evidence chain? **Date of Record:** 2026 November 30 **Scope:** Applies to observability pipelines that ingest agent traces, eval scores, and safety verdicts as separate asynchronous streams and join them post-hoc on a shared correlation key. Does not apply to synchronous in-process instrumentation where the verdict is emitted inside the same span lifecycle as the action it judges. ## Core Distinction The failure is not "missing telemetry." It is **causal-order inversion across three ingest streams that share a correlation key but not a clock**. A safety classifier (or eval judge) is a second LLM call that runs *after* the agent's action but *before* the trace exporter's batch flush. Because the safety stream is low-volume and low-latency (one verdict per action, emitted immediately) while the trace stream is high-volume and batched (spans buffered up to the exporter's `schedule_delay_millis`, typically 5000ms, plus retry backoff), the verdict reliably lands in the telemetry backend *ahead of* the span it annotates. The backend then either (a) drops the verdict as referencing an unknown `trace_id`, or (b) stores it as an orphan row that a later span never re-links because the join was done at ingest, not at query. The result is a safety verdict that exists in the database but is invisible to any trace-correlated query — the evidence chain for a flagged action is severed at exactly the moment it matters. ## What Was Observed A tool-calling agent executes `send_email`. The sequence of emissions: 1. `t=0ms` — agent emits span `tool.send_email` with `trace_id=T`, `span_id=S1`, `status=OK`. Span enters the OTel `BatchSpanProcessor` buffer. 2. `t=340ms` — a post-hoc safety classifier reads the action + payload and returns `verdict=BLOCK_REVIEW`, `severity=high`, `trace_id=T`, `span_id=S1`. This is a single small JSON POST to the telemetry ingest endpoint. It succeeds in ~40ms. 3. `t=40ms` (wall clock) — the safety verdict is written to the `safety_verdicts` table. The join key `trace_id=T` has no matching span yet. 4. `t=5040ms` — the batch processor flushes. Span `S1` arrives with `trace_id=T`. The backend's ingest-time join runs `UPDATE safety_verdicts SET span_present=true WHERE ...` — but the join predicate was `ON INSERT` only, or the span arrives after the verdict's ingest window closed, so no back-link is written. Observed symptom in the query layer: `SELECT * FROM traces WHERE trace_id=T JOIN safety_verdicts USING(trace_id)` returns zero rows for the flagged action, while `SELECT * FROM safety_verdicts WHERE trace_id=T` returns the high-severity verdict. The two facts are both true and mutually invisible. Dashboards built on the trace-first join report "no safety events for this trace." The review queue, built on the verdict-first table, shows a verdict with no span context — no prompt, no tool args, no model version — so a human reviewer cannot adjudicate it. A second, subtler variant: when the safety classifier itself is an agent call, *its* span (`span_id=S2`, same `trace_id=T`) is emitted by the same batch processor. The verdict references `S2` as its provenance. If `S2` is dropped by sampling (head-based sampling at 10%, common default), the verdict's provenance span never exists at all, and the verdict is permanently orphaned — not just late, but unrecoverable. ## Condition of Validity This failure is bounded and predictable under these conditions, and does *not* occur outside them: - **Asynchronous, multi-stream ingest with a shared key but independent clocks.** If verdicts and spans share a single ordered log (same producer, same partition), causal order is preserved and the failure vanishes. - **Batch span export with delay > verdict emit latency.** The inversion window is `schedule_delay_millis + retry_backoff − verdict_latency`. With defaults this is reliably positive (≈5s vs ≈0.3s), so the failure is the *normal* case, not the exception. - **Ingest-time join rather than query-time join.** If the backend stores both streams raw and joins at query time with a `FULL OUTER JOIN` on `trace_id`, late-arriving spans re-link correctly. The failure requires a materialized join or a referential-integrity check at insert. - **Head-based sampling enabled on the trace stream.** Tail-based or verdict-aware sampling (always retain spans referenced by a verdict) removes the unrecoverable variant. The invariant that must hold: **for every verdict with `severity >= review_threshold`, the referenced span must exist in the trace store, and the join must be resolvable at query time regardless of arrival order.** Any pipeline that cannot state this invariant as a testable property is exposed. ## Decision Boundary The architectural fork is where the join happens: - **Ingest-time join (reject).** Fast queries, but assumes arrival order. Breaks under the inversion window. Only valid if the verdict stream is buffered to the same flush cadence as spans — which defeats the purpose of low-latency safety alerting. - **Query-time join with a verdict-aware retention floor (accept).** Store both streams append-only, join at read, and enforce a retention rule: any `trace_id` present in `safety_verdicts` with `severity >= threshold` is pinned in the trace store for the full retention window, exempt from sampling and from TTL eviction. This converts the inversion from a correctness bug into a latency property (the join is briefly empty, then fills). - **Synchronous in-span verdict (accept, narrower).** Emit the verdict as a span event/attribute inside `S1` before the span closes. Eliminates the second stream entirely, at the cost of coupling safety latency into the agent's critical path — unacceptable when the classifier is a slow LLM judge. The guardrail is not "flush faster." It is **decoupling arrival order from join correctness**, plus a retention floor keyed on the verdict table. ## Operational Effect Without the guardrail, the pipeline systematically under-reports safety incidents in trace-correlated views while over-reporting orphaned verdicts in the review queue. The failure is silent: no error, no dropped-metric counter, because both writes succeed. It surfaces only when an auditor asks "show me the trace for this flagged action" and the answer is "there isn't one," which erodes trust in the entire observability layer at the moment of highest stakes. With the query-time join and verdict-aware retention floor, the inversion window becomes a bounded staleness (≤ flush delay) rather than a permanent evidence gap, and the orphan rate becomes a monitored SLI (`orphaned_verdicts_total / verdicts_total`) that should sit at zero outside the flush window. ## Operational Effect The following guard encodes the invariant as a pre-query check: before serving a trace-correlated safety view, assert that every high-severity verdict's referenced span is either present or within the allowed staleness window; otherwise refuse to serve a "clean" result and surface the gap explicitly rather than answering with a false negative. ```python import time from dataclasses import dataclass class EvidenceChainBroken(RuntimeError): """Raised when a high-severity verdict's span is absent and past the staleness window.""" pass @dataclass class Verdict: trace_id: str span_id: str severity: str emitted_at: float # epoch seconds FLUSH_STALENESS_WINDOW_S = 8.0 # schedule_delay_millis + retry_backoff, with margin def assert_evidence_chain( verdicts: list[Verdict], spans_present: set[str], # span_ids known to the trace store now: float | None = None, ) -> None: """Fail closed: never serve a trace-correlated safety view that hides a high-severity verdict.""" now = now if now is not None else time.time() for v in verdicts: if v.severity != "high": continue if v.span_id in spans_present: continue age = now - v.emitted_at if age > FLUSH_STALENESS_WINDOW_S: raise EvidenceChainBroken( f"verdict trace_id={v.trace_id} span_id={v.span_id} severity=high " f"has no span after {age:.1f}s (window={FLUSH_STALENESS_WINDOW_S}s); " f"refusing to serve clean view — check sampling drop or ingest-time join" ) # within window: tolerated as bounded staleness, but caller must mark view as partial ```