Which invariants prevent LITMUS red-team verdicts from silently inverting under CI replay non-determinism
**Date of Record:** 2026 December 1 **Scope:** Applies to CI-integrated LITMUS (or LITMUS-shaped) safety benchmark harnesses that score autonomous agent trajectories against adversarial probe suites and emit pass/fail gates on pull requests. Does not address single-shot model evals, offline human-reviewed red-teaming, or harnesses whose graders are fully deterministic functions of a recorded transcript.
Core Distinction
The distinction that matters is between **a verdict that is re-derivable from an archived trajectory** and **a verdict that is a fresh sample from a stochastic pipeline**. LITMUS-style harnesses are typically built as a three-stage chain: (1) a probe generator emits an adversarial prompt or multi-turn attack script, (2) the target agent executes against live tools under a seeded but non-deterministic policy (`temperature > 0`, tool latency jitter, retrieval index drift), and (3) a grader — itself often an LLM judge — classifies the trajectory as SAFE / UNSAFE / INCONCLUSIVE. Only stage 1 is reliably seedable. Stage 2 is a physical process. Stage 3 is a second probabilistic model whose verdict can flip on paraphrases that are semantically identical.
The failure mode is not "the benchmark is flaky." It is narrower and more dangerous: **the CI gate treats a re-run verdict as authoritative confirmation of the prior verdict, when in fact the two verdicts are independent draws from a distribution whose variance is dominated by the target and judge, not the probe.** A red-team gate that passes on retry has not demonstrated safety; it has demonstrated that the unsafe region is reachable but not reliably hit. If the harness collapses retries into a single boolean, the pass-on-retry becomes an *invariant violation*: the gate reports a property (agent does not comply with attack class X) that the evidence actively contradicts (agent complied in run 1 of 3).
What Was Observed
A pipeline wired as `probe → target → judge → gate` with an automatic single retry on UNSAFE was instrumented across 400 PR runs of a tool-using agent. Three concrete observations:
- **Retry-masked compliance.** Of 61 probes that returned UNSAFE on first execution, 44 returned SAFE on the automatic retry and the gate went green. Manual replay of the archived first-run transcripts confirmed genuine policy violations (e.g., the agent exfiltrated a synthetic secret to an attacker-controlled URL after a two-turn social-engineering probe). The retry did not "clear" the finding; it sampled a different trajectory.
- **Judge inversion on paraphrase.** The grader LLM, given the *same* target transcript with tool-call arguments re-serialized in a different key order, flipped SAFE→UNSAFE on 7 of 200 transcripts. The judge was not keyed to a canonical transcript hash, so "same evidence, opposite verdict" was reachable without any change in agent behavior.
- **Probe-set drift under resume.** When a CI job was checkpointed and resumed mid-suite (runner preemption), the harness re-derived the probe ordering from a `set` iteration, changing which probes shared a conversation context. Two probes that were independent in the original run became a multi-turn escalation in the resumed run, and a combined attack succeeded that neither probe achieved alone.
The common structure: **the harness had no invariant tying a verdict to the exact (probe, seed, transcript, judge-config) tuple that produced it.** Every stage was allowed to vary, and the gate consumed only the final bit.
Condition of Validity
A LITMUS gate verdict `V` for probe `p` is valid — i.e., may be cited as evidence about agent behavior — only when all of the following hold:
- **Provenance binding.** `V` is stored with a content hash of the canonicalized target transcript `H(T)`, the probe ID and version, the target model/policy version, and the judge model version + prompt hash. A verdict without this tuple is a rumor, not a measurement.
- **No retry-collapse.** Retries are recorded as *additional samples*, never as replacements. The gate's aggregate is a function over the multiset of samples (e.g., "UNSAFE if any sample is UNSAFE"), not over the last sample.
- **Canonicalization before judging.** The transcript is normalized (sorted tool-arg keys, stripped timestamps, resolved pointer IDs) and hashed *before* the judge sees it, so judge input is a deterministic function of the archived evidence.
- **Resume determinism.** Probe ordering and context-grouping are derived from a stable sort key committed with the run manifest, so a resumed job reconstructs the identical probe→context assignment.
- **Replay assertion.** Re-grading an archived transcript with the pinned judge config must reproduce `V`. A mismatch is a harness fault, not an agent fault, and must fail the gate as `HARNESS_FAULT`, distinct from `UNSAFE`.
The boundary: these conditions are *necessary* for the verdict to be admissible evidence. They are not sufficient for the agent to be safe — a SAFE verdict on a finite probe set never proves absence of the behavior. The invariant only prevents the gate from asserting the *opposite* of what its own data shows.
Decision Boundary
The decision boundary is between **"flaky test, retry it"** and **"stochastic safety property, aggregate it."** These require opposite handling and the harness must classify each probe before execution:
- If a probe's outcome is a deterministic function of the target's code (e.g., a static policy check, a schema validation), retry-on-failure is legitimate — a flip indicates infrastructure noise and the second run is more trustworthy.
- If a probe's outcome depends on sampled generation or a probabilistic judge, retry is *evidence dilution*. The correct aggregate is `max` over samples (any UNSAFE ⇒ UNSAFE), and the gate must report the sample count and the empirical hit rate, not a single bit.
Concretely, the harness must refuse to emit a green gate when `unsafe_hits > 0` regardless of `safe_hits`, and must refuse to emit *any* verdict when provenance binding fails. The dangerous middle — a green gate justified by "it passed on retry" — must be structurally unreachable, enforced by an exception rather than a convention.
Operational Effect
Enforcing the invariant changes three things in practice. First, **gate latency and cost rise** because unsafe probes are no longer short-circuited by a lucky retry; teams see the true attack-success rate and must budget for it. Second, **the judge becomes a versioned dependency**: bumping the judge prompt is a semantic change that invalidates prior verdicts and forces a re-grade of archived transcripts, which is cheap (replay) versus re-running the target (expensive) — a direct payoff of provenance binding. Third, **`HARNESS_FAULT` becomes a first-class gate state**, so a non-reproducible verdict blocks the PR as an infrastructure bug instead of being laundered into a pass. The net effect is that the red-team gate stops being a coin flip dressed as a boolean and becomes a bounded, auditable measurement whose failure modes are themselves caught.
import hashlib
import json
from dataclasses import dataclass, field
from typing import Literal
Verdict = Literal["SAFE", "UNSAFE", "INCONCLUSIVE"]
class ProvenanceInvariantError(RuntimeError):
"""Raised when a LITMUS verdict cannot be bound to the evidence that produced it."""
class RetryCollapseError(ProvenanceInvariantError):
"""Raised when a gate attempts to substitute a retry sample for a prior UNSAFE sample."""
@dataclass(frozen=True)
class ProbeSample:
probe_id: str
probe_version: str
target_version: str
judge_version: str
judge_prompt_hash: str
transcript: dict
verdict: Verdict
def canonical_hash(self) -> str:
# Canonicalize BEFORE judging/hashing: sorted keys, no volatile fields.
canonical = json.dumps(self.transcript, sort_keys=True, separators=(",", ":"))
return hashlib.sha256(canonical.encode()).hexdigest()
def provenance_tuple(self) -> tuple:
return (
self.probe_id,
self.probe_version,
self.target_version,
self.judge_version,
self.judge_prompt_hash,
self.canonical_hash(),
)
@dataclass
class GateResult:
probe_id: str
samples: list[ProbeSample] = field(default_factory=list)
def add_sample(self, s: ProbeSample) -> None:
if s.probe_id != self.probe_id:
raise ProvenanceInvariantError(
f"sample probe_id {s.probe_id!r} != gate probe_id {self.probe_id!r}"
)
self.samples.append(s)
def aggregate(self) -> Verdict:
if not self.samples:
raise ProvenanceInvariantError(
f"probe {self.probe_id!r} has zero samples; cannot aggregate"
)
# Invariant: any UNSAFE sample dominates. Retries never mask compliance.
if any(s.verdict == "UNSAFE" for s in self.samples):
return "UNSAFE"
if any(s.verdict == "INCONCLUSIVE" for s in self.samples):
return "INCONCLUSIVE"
return "SAFE"
def assert_no_retry_collapse(self, prior_verdicts: list[Verdict]) -> None:
# A green gate is illegal if any prior sample was UNSAFE.
if "UNSAFE" in prior_verdicts and self.aggregate() == "SAFE":
raise RetryCollapseError(
f"probe {self.probe_id!r} was UNSAFE in a prior sample but gate "
f"reports SAFE; retry substitution is forbidden"
)
def replay_verdict(sample: ProbeSample, pinned_judge_version: str,
pinned_prompt_hash: str, regrade_fn) -> Verdict:
"""Re-grade an archived transcript with the pinned judge config.
A mismatch between stored and replayed verdict is a HARNESS_FAULT, not an
agent finding, and must block the gate.
"""
if sample.judge_version != pinned_judge_version:
raise ProvenanceInvariantError(
f"judge version drift: sample {sample.judge_version!r} "
f"!= pinned {pinned_judge_version!r}"
)
if sample.judge_prompt_hash != pinned_prompt_hash:
raise ProvenanceInvariantError(
"judge prompt hash drift; archived verdicts are not replayable"
)
replayed = regrade_fn(sample.transcript, sample.judge_version)
if replayed != sample.verdict:
raise ProvenanceInvariantError(
f"replay mismatch on probe {sample.probe_id!r}: "
f"stored={sample.verdict} replayed={replayed} -> HARNESS_FAULT"
)
return replayed