# When must an instance quarantine a trace span whose safety signal arrived after the SLO window closed? **Date of Record:** 2026 November 26 **Scope:** Applies to observability pipelines that compute per-agent SLOs (task success, tool-error rate, policy-violation rate) by joining three asynchronous streams: execution traces (spans emitted at runtime), evaluation verdicts (emitted by an offline or shadow judge, often seconds-to-minutes later), and safety signals (emitted by a guard model or policy engine that may be delayed, retried, or reordered). Does not apply to synchronous inline scoring where the safety verdict is a precondition of the span being committed. ## Core Distinction The failure is not "late data." It is a **window-closure race between a finalized SLO aggregate and an in-flight safety verdict on spans the aggregate already consumed**. An SLO is a *closed* reduction: `violation_rate = count(violating spans) / count(eligible spans)` over a fixed `[t0, t1)`. A safety signal is an *open* stream keyed by `trace_id`/`span_id` that can arrive arbitrarily late, arrive twice, arrive with a revised verdict, or never arrive (guard model timeout). The invariant people assume — "a span's safety label is immutable once the span is emitted" — is false. The label is a *separate event* with its own clock, and the SLO reducer has no way to know whether the absence of a label at `t1` means "clean" or "not yet judged." The non-obvious part: **the correct behavior is not to backfill the window.** Backfilling turns a point-in-time SLO (what was true when the on-call was paged) into a moving target, and it silently rewrites the denominator. The boundary decision is whether to (a) hold the window open, (b) close it and emit an *incomplete* marker, or (c) close it and quarantine the span so a later verdict lands in a *correction ledger* rather than mutating the published SLO. Choosing wrong produces either false-green SLOs (late violations never counted) or thrashing SLOs (violation rate oscillates as verdicts trickle in, defeating alerting). ## What Was Observed A support agent fleet ran a 5-minute SLO window (`t1 - t0 = 300s`) on `policy_violation_rate`, threshold 0.5%. Traces were emitted at request completion. The safety guard model was invoked asynchronously per span with a p99 latency of 11s but a long tail: retries on guard-model 429s pushed some verdicts to 40–190s after span emission. The reducer fired at `t1 + 5s` grace. Failure trace for one window: 1. At `t1`, 4,100 spans were eligible; 3,980 had safety verdicts (all clean). 120 spans were pending (guard retry backoff). Reducer computed `0/3980 = 0.00%`, emitted `state=green`, no page. 2. At `t1 + 74s`, 9 late verdicts arrived, 6 flagged `policy_violation` (a prompt-injection payload had induced the agent to echo a customer's stored PII into a tool call). True rate over eligible spans was `6/4100 = 0.146%` — still under threshold, but the 120-span gap was 2.9% of the denominator and unaccounted. 3. The pipeline's "late event" handler *did* backfill: it recomputed the window and **overwrote** the published SLO row. The dashboard flipped from green to 0.146% but the alerting rule had already evaluated the green value and would not re-fire until the next window. The on-call saw a green window that was retroactively 0.146% and never paged. 4. Compounding: two of the 120 pending spans *never* got a verdict (guard 429 exhausted retries). They were dropped from the denominator on recompute, so the published rate was over a 4,098-span denominator while the trace store held 4,100. Reconciliation between trace count and SLO denominator drifted by 2 spans per window, ~1,400/day. The core defect: the reducer treated "no verdict at `t1`" as "clean," and the backfill treated "verdict arrived late" as "mutate history." Neither is sound. The span was **eligible but unjudged**, a third state the schema did not represent. ## Condition of Validity The quarantine-and-ledger pattern is valid only when all three hold: - **Verdicts are idempotent and versioned.** Each safety signal carries `(span_id, verdict_version, verdict_ts)`. A revised verdict for the same span supersedes by version, not by arrival order. Without this, ledger replay is non-deterministic. - **The SLO window is a closed interval with an explicit finalization event.** There is a single `window.finalized` record; after it, no span may be added to the window's eligible set. Spans that *were* eligible at `t1` but unjudged are recorded as `unjudged_count`, not silently dropped. - **Late verdicts are attributable to a finalized window.** The ledger keys corrections by `(window_id, span_id)`, so a correction can be applied to the *next* window's alerting budget or to a separate "SLO correction" metric, but never to the closed aggregate. When any of these fails — e.g., the guard model emits unversioned verdicts, or the window has no finalization event because it is a sliding window — the pattern is invalid and you must fall back to a **hold-open** window with a bounded max-lateness `L`, accepting that the SLO is only defined at `t1 + L`. ## Decision Boundary Given a span eligible at `t1` with no verdict, decide among three actions by comparing `now - t1` against the configured `max_lateness L` and the guard's retry-exhaustion signal: | Condition | Action | Invariant preserved | |---|---|---| | Verdict arrived, `verdict_ts <= t1`, `version` newest | Include in window reduction | Closed-interval determinism | | No verdict, `now - t1 <= L`, guard still retrying | Hold window open (do not finalize) | Denominator completeness | | No verdict, `now - t1 > L` **or** guard retries exhausted | Finalize window; record span as `unjudged`; **quarantine** span to correction ledger | No false-green, no silent denominator drop | | Verdict arrived after `window.finalized`, `version` newest | Append to correction ledger; do **not** mutate published SLO; emit `slo_correction` event | Published SLO immutability | The boundary is `now - t1 == L` **and** retry-exhaustion. `L` must be derived from the guard's p99.9, not its p99; setting `L = p99` guarantees ~0.1% of spans are quarantined every window by construction. The quarantine is not an error — it is the *only* honest representation of "eligible, unjudged." The alternative (drop from denominator) is the drift observed above. Critically: **an unjudged span must not be counted as clean.** A window with `unjudged_count / eligible_count > q` (e.g., `q = 1%`) must be marked `state=indeterminate`, not `green`, regardless of the observed violation rate over judged spans. Otherwise a guard-model outage (all verdicts pending) reads as a perfect SLO. ## Operational Effect After adopting quarantine-and-ledger: `policy_violation_rate` became `judged_violations / eligible_spans` with `unjudged_count` published alongside. The alerting rule gained a second clause: page if `rate > 0.5%` **or** `unjudged_count / eligible > 1%`. The retroactive-overwrite path was removed; late verdicts emit `slo_correction` events consumed by a weekly budget review, never by the pager. Denominator drift between trace store and SLO dropped to zero because eligible count is frozen at finalization. The cost: SLOs are published at `t1 + L` (here `L = 210s`) instead of `t1 + 5s`, and the correction ledger requires a replay-safe reducer. Both are acceptable; the false-green window that hid a PII-leak injection was not. The general invariant: **an SLO is a function of a closed eligible set and a verdict-assignment function that must be total over that set before publication.** If the verdict function is partial at finalization, the missing mass must be surfaced as `unjudged`, never imputed as clean and never backfilled into a closed aggregate. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class SloWindowError(RuntimeError): """Raised when a safety verdict would violate SLO window closure invariants.""" class WindowState(Enum): OPEN = "open" FINALIZED = "finalized" INDETERMINATE = "indeterminate" @dataclass class SafetyVerdict: span_id: str version: int verdict_ts: float violating: bool @dataclass class SloWindow: window_id: str t0: float t1: float max_lateness: float # L, derived from guard p99.9 unjudged_ratio_limit: float # q, e.g. 0.01 eligible: set = field(default_factory=set) verdicts: dict = field(default_factory=dict) # span_id -> SafetyVerdict state: WindowState = WindowState.OPEN finalized_at: Optional[float] = None def finalize(self, now: float, retries_exhausted: set) -> None: if self.state is not WindowState.OPEN: raise SloWindowError(f"window {self.window_id} already {self.state}") if now - self.t1 < self.max_lateness and not retries_exhausted: raise SloWindowError( f"window {self.window_id} finalized before max_lateness " f"({now - self.t1:.1f}s < {self.max_lateness}s) with live retries" ) unjudged = self.eligible - set(self.verdicts) # spans whose guard retries exhausted are quarantined, not dropped self.quarantined = unjudged ratio = len(unjudged) / max(len(self.eligible), 1) self.state = ( WindowState.INDETERMINATE if ratio > self.unjudged_ratio_limit else WindowState.FINALIZED ) self.finalized_at = now def apply_late_verdict(self, v: SafetyVerdict) -> bool: """Returns True if routed to correction ledger, False if applied in-window.""" if v.span_id not in self.eligible: raise SloWindowError( f"verdict for span {v.span_id} not eligible in {self.window_id}" ) if self.state is WindowState.OPEN: prior = self.verdicts.get(v.span_id) if prior and prior.version >= v.version: raise SloWindowError( f"stale verdict v{prior.version} >= v{v.version} for {v.span_id}" ) self.verdicts[v.span_id] = v return False # window closed: never mutate published aggregate if v.span_id in self.quarantined or v.span_id not in self.verdicts: self.quarantined.discard(v.span_id) return True # caller appends to correction ledger def violation_rate(self) -> float: if self.state is WindowState.OPEN: raise SloWindowError( f"cannot publish rate for open window {self.window_id}" ) judged = len(self.verdicts) if judged == 0: raise SloWindowError(f"window {self.window_id} has zero judged spans") viol = sum(1 for v in self.verdicts.values() if v.violating) return viol / len(self.eligible) # denominator = frozen eligible set ```