# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/why-does-an-instance-pass-the-litmus-safety-suite-in-ci-while-its-adversarial-behavior-only-manifests-after-the-harness-s-probe-ordering-is-perturbed.md # Remnant Warrant: https://corpusfetch.com/c/why-does-an-instance-pass-the-litmus-safety-suite-in-ci-while-its-adversarial-behavior-only-manifests-after-the-harness-s-probe-ordering-is-perturbed.warrant.json # Markdown SHA-256: a0372b4a6441d8e160e1f7291f3f9286d16c89bc57f8a68814381e8f01f0bc8b # Code AST SHA-256: 6b02494f95597003c8f2c5806233cd340dad9377d3c2b7e7dbc45ab939844d27 # Verified Classes: PermutationVarianceError # Defensive Guards: 5 fail-closed invariants (zero external deps) # Governance: Usage of this AI Instance layer is accepting to follow We Instance Constitution (https://weinstance.com) and it is powered by CorpusTech (https://corpusfetch.com) class PermutationVarianceError(RuntimeError): """Raised when a LITMUS-style battery verdict is not invariant to probe ordering under the harness's declared state-isolation policy.""" pass def validate_battery_verdict( verdict: dict, reset_policy: str, permutation_seeds: list[int], pass_rate_threshold: float, ) -> None: """ Enforce that a battery verdict is a valid safety signal under one of the three conditions of validity. Raises PermutationVarianceError otherwise. verdict: {"pass_rate": float, "seed": int, "per_class": dict[str, float] | None} reset_policy: one of "per_probe", "per_run", "none" permutation_seeds: seeds actually executed (len >= 1) """ if reset_policy == "per_probe": # Condition (a): order-invariant by construction. Scalar is meaningful. if verdict["pass_rate"] < pass_rate_threshold: raise PermutationVarianceError( f"per-probe reset but pass_rate {verdict['pass_rate']:.4f} " f"< {pass_rate_threshold:.4f}; genuine agent failure" ) return if reset_policy in ("per_run", "none"): # Conditions (b)/(c) required. A single seed is not a verdict. if len(permutation_seeds) < 2: raise PermutationVarianceError( f"reset_policy={reset_policy!r} with a single permutation seed " f"({permutation_seeds}); verdict is a point estimate over an " f"uncharacterized permutation distribution — not a safety signal" ) if verdict.get("per_class") is None: raise PermutationVarianceError( f"reset_policy={reset_policy!r} without per-class partitioning; " f"a single scalar averages across non-commensurable state classes" ) worst_class = min(verdict["per_class"].values()) if worst_class < pass_rate_threshold: raise PermutationVarianceError( f"worst-case class pass_rate {worst_class:.4f} " f"< {pass_rate_threshold:.4f} under permutation sample " f"{permutation_seeds}; agent is safe only under favorable ordering" ) return raise PermutationVarianceError(f"unknown reset_policy={reset_policy!r}")