# Where must an instance reconcile a safety-event trace that arrives after its parent prompt span has already been evicted from the observability correlator? **Date of Record:** 2026 November 20 **Scope:** Applies to GenAI observability pipelines that correlate prompt spans, tool-call spans, and asynchronous safety-classifier events by span/trace identity under bounded retention. Does not apply to synchronous inline safety gating where the classifier verdict is returned before the span closes, nor to systems with unbounded trace retention. ## Core Distinction The distinction that governs this failure is between *causal ordering at the agent layer* and *arrival ordering at the observability layer*. An agent emits a prompt span, dispatches a tool call, and the tool's side effect completes synchronously from the agent's perspective. The safety classifier, however, runs out-of-band: it may be a queued batch job, a second model invocation, or a downstream moderation service with its own retry budget. The safety verdict therefore *causally belongs* to the prompt span but *temporally arrives* after that span has been flushed, closed, and eventually evicted from the correlator's hot index. The non-obvious boundary is this: the correlator's retention window is measured in wall-clock time from span close, but the safety event's arrival latency is a *tail distribution* driven by classifier queue depth, not by anything the agent controls. When the 99.9th-percentile safety-event latency exceeds the correlator's retention TTL, a fraction of safety events arrive at a correlator that has no parent to attach them to. Those events do not disappear—they become *orphans*, and the pipeline must decide, per event, whether to reconstruct parent context, quarantine the orphan, or silently drop it. Most pipelines silently drop, which converts a latency tail into a silent loss of safety signal. ## What Was Observed A trace-level audit of a production pipeline (prompt spans retained 15 minutes in the hot correlator; safety classifier on a shared batch queue) surfaced the following sequence for a tool-using agent turn: 1. `prompt_span` opens at `t0`, carries `trace_id` and `span_id`, `gen_ai.prompt.hash`, model id, and token counts. 2. `tool_span` opens as a child at `t0+0.4s`, closes at `t0+2.1s` with `tool.latency_ms=1700` and a non-deterministic tool output hash. 3. `prompt_span` closes at `t0+3.0s`. The correlator indexes it, and the retention clock starts. 4. At `t0+3.0s + Δ`, the safety classifier emits `safety_event{severity, category, verdict}` keyed by the *same* `trace_id`/`span_id`. For Δ < 15 min, correlation succeeds. For Δ in the tail (observed max 41 min under queue saturation), the parent span has been evicted. 5. The orphaned safety event is written to the event store with a dangling `span_id`. Downstream dashboards join on `span_id` and produce a null join, so the safety event is counted in the event store but *invisible* in the per-trace safety view. The critical observation: the agent's *behavior* was correct and fully instrumented. The loss was purely a correlator-retention artifact, and it was invisible because the orphan path had no counter, no error, and no back-reference. The dashboard showed "0 safety events" for those traces—indistinguishable from "clean traces." A second, subtler observation: when the pipeline attempted a *late reconstruction* by re-reading the prompt span from cold storage, the reconstructed span carried the tool output hash but not the tool *latency*, because latency was only ever recorded on the child span, which had been evicted one retention window earlier than the parent. Reconstruction produced a parent span with a *partial* child set—an internally inconsistent trace that passed schema validation. ## Condition of Validity The invariant that must hold for correlation to be sound is: > For every safety event `e` keyed to span `s`, the correlator must be able to resolve `s` and all of `s`'s children at the moment `e` is correlated, **or** must record `e` as an explicit orphan with its own durable parent-context payload. This invariant is violated exactly when `arrival_latency(e) > retention_ttl(s)` for any span in `s`'s subtree. Because `arrival_latency` is a tail and `retention_ttl` is a point value, the invariant fails on a *predictable fraction* of events determined by the classifier's latency distribution—not by any agent-side error. The condition of validity is therefore: the pipeline must either (a) size `retention_ttl` above the classifier's observed p99.9 latency plus margin, or (b) carry enough parent context *inside the safety event itself* that correlation is reconstructable without the hot index. Option (a) is fragile because classifier queue depth is load-dependent and can spike independently of agent traffic. Option (b) is the durable fix: the safety event must be self-describing. The agent-side rule is that any span that can *later* receive an out-of-band event must emit a compact, immutable "correlation anchor" (trace id, span id, prompt hash, model id, tool-output hashes, timestamp) into a durable side channel at span close, so the safety event never depends on the hot correlator's survival. ## Decision Boundary When a safety event arrives and the correlator cannot resolve its parent, the pipeline faces a three-way decision that must be made *explicitly and per-event*, never by default: - **Reconstruct** if a durable correlation anchor exists and the reconstructed subtree is complete. Reconstructed traces must be marked `reconstructed=true` so downstream consumers do not treat them as first-class. - **Quarantine** if the anchor exists but the subtree is incomplete (e.g., child tool spans evicted earlier). Quarantined events go to a separate store with a `partial_context` flag; they must *not* be merged into the main trace view, because a partial trace that passes schema validation is worse than an honest orphan—it looks complete. - **Escalate** if no anchor exists. This is a pipeline defect, not a data condition, and must raise. The boundary between reconstruct and quarantine is the completeness of the child set. The boundary between quarantine and escalate is the existence of the anchor. A pipeline that collapses all three into "drop" has converted a bounded latency-tail problem into an unbounded safety-signal-loss problem. ## Operational Effect The observable effect of getting this wrong is a *silent negative*: traces with late safety events report zero safety events, which is semantically identical to traces that were genuinely clean. Safety dashboards undercount precisely on the traces where classifier queue depth was highest—which correlates with high agent traffic and therefore with the highest-risk window. The failure is anti-correlated with observability: the busier the system, the more safety events are lost, and the loss is invisible. The guardrail is a mandatory orphan counter with alerting on `orphan_rate > 0`, plus a hard assertion that every safety event carries a durable correlation anchor. The anchor is written at span close, before the span can be evicted, so the safety event's correlation never depends on hot-index survival. ```python from dataclasses import dataclass, field from typing import Optional class OrphanedSafetyEventError(RuntimeError): """Raised when a safety event cannot be correlated to a live or reconstructable parent span. This is a pipeline defect, not a data condition, and must never be swallowed into a silent drop.""" @dataclass class CorrelationAnchor: trace_id: str span_id: str prompt_hash: str model_id: str tool_output_hashes: tuple[str, ...] closed_at: float @dataclass class SafetyEvent: trace_id: str span_id: str severity: str category: str arrived_at: float @dataclass class Correlator: retention_ttl: float hot_index: dict[str, CorrelationAnchor] = field(default_factory=dict) anchors: dict[str, CorrelationAnchor] = field(default_factory=dict) orphans: list[SafetyEvent] = field(default_factory=list) quarantined: list[SafetyEvent] = field(default_factory=list) def close_span(self, anchor: CorrelationAnchor) -> None: # Durable anchor written BEFORE eviction can occur. self.anchors[anchor.span_id] = anchor self.hot_index[anchor.span_id] = anchor def evict(self, now: float) -> None: expired = [ sid for sid, a in self.hot_index.items() if now - a.closed_at > self.retention_ttl ] for sid in expired: del self.hot_index[sid] def correlate(self, event: SafetyEvent) -> str: if event.span_id in self.hot_index: return "correlated" anchor = self.anchors.get(event.span_id) if anchor is None: self.orphans.append(event) raise OrphanedSafetyEventError( f"safety event for trace={event.trace_id} span={event.span_id} " f"has no correlation anchor; pipeline defect" ) # Anchor exists but hot index does not: late arrival. if not anchor.tool_output_hashes: # Incomplete subtree: quarantine, do NOT merge as complete. self.quarantined.append(event) return "quarantined_partial_context" return "reconstructed" def orphan_rate(self) -> float: total = len(self.orphans) + len(self.quarantined) + 1 return len(self.orphans) / total ```