Skip to content

Independent Auditing of AI Agents. Run by human or the agent itself, to answer the most crucial question in the AI Agent Economy. Is the agent doing what is supposed to do? With iFixAi you can have this answer in less than 120 seconds.

fix(cli): restore analytic inspection seeds on resume (#313)

Rudy Mizrahi Celekli130e8b36993d
diff --git a/README.md b/README.md
index 945a0f5..e4dae24 100644
--- a/README.md
+++ b/README.md
@@ -274,6 +274,13 @@ To pick a different set, name a suite:
Four themes (`security`, `reliability`, `compliance`, `frontier`) also work as `--suite` values; run `ifixai list suites` to browse them all.
+Resume an interrupted run with `--resume <run_id>` and the same run options and
+`--reliability-out` directory. Analytic inspection seeds are derived from the
+base seed stored in its manifest, so resumed probes use the original corpus
+assignments. Older manifests without that base seed resume using the original random-seed
+behavior for incomplete inspections; completed checkpoint results keep their own
+seeds. Legacy unfinished probe contexts cannot be reconstructed.
+
```bash
ifixai run --provider http --endpoint <agent-url> --grounding sut # your real deployed agent (recommended)
ifixai run --provider openai --suite strategic # quick bare-model read (8 tests)
diff --git a/ifixai/cli/inspection_seeds.py b/ifixai/cli/inspection_seeds.py
new file mode 100644
index 0000000..9351d90
--- /dev/null
+++ b/ifixai/cli/inspection_seeds.py
@@ -0,0 +1,24 @@
+"""Stable per-inspection seeds for CLI analytic runs and their resumes."""
+
+import hashlib
+
+from ifixai.core.types import EvaluationPipelineConfig
+
+# These already have individual manifest fields and CLI pinning controls.
+_MANIFEST_SEEDS = {"b12_seed", "b14_seed", "b28_seed", "b29_seed", "b30_seed", "b32_seed"}
+ANALYTIC_SEED_FIELDS = tuple(
+ name for name in EvaluationPipelineConfig.model_fields
+ if name.endswith("_seed") and name not in _MANIFEST_SEEDS
+)
+ANALYTIC_SEEDED_IDS = frozenset(name.removesuffix("_seed").upper() for name in ANALYTIC_SEED_FIELDS)
+
+
+def inspection_seeds(base_seed: int) -> dict[str, int]:
+ """Derive independent streams without process-local hash or shared RNG state."""
+ return {
+ name: int.from_bytes(
+ hashlib.sha256(f"ifixai-inspection-seeds-v1:{base_seed}:{name}".encode()).digest()[:4],
+ "big",
+ ) % (2**31)
+ for name in ANALYTIC_SEED_FIELDS
+ }
diff --git a/ifixai/cli/run.py b/ifixai/cli/run.py
index 9ab96fb..29f5f9c 100644
--- a/ifixai/cli/run.py
+++ b/ifixai/cli/run.py
@@ -25,6 +25,7 @@ from ifixai.cli._branding import (
print_startup_banner,
)
from ifixai.cli.config_file import CONFIG_FILENAME, load_config
+from ifixai.cli.inspection_seeds import inspection_seeds
from ifixai.cli.orchestrator import (
_build_judge_config,
_eval_mode_declaration,
@@ -938,6 +939,7 @@ def run(
param_hint="--run-nonce",
)
effective_run_nonce = run_nonce if run_nonce is not None else generate_run_nonce()
+ effective_inspection_seed = secrets.randbelow(2**31)
effective_b12_seed = b12_seed if b12_seed is not None else secrets.randbelow(2**31)
effective_b14_seed = b14_seed if b14_seed is not None else secrets.randbelow(2**31)
@@ -981,6 +983,7 @@ def run(
err=True,
)
effective_run_nonce = resume_manifest.run_nonce
+ effective_inspection_seed = resume_manifest.seed
effective_b12_seed = resume_manifest.b12_seed
effective_b14_seed = resume_manifest.b14_seed
effective_b28_seed = resume_manifest.b28_seed
@@ -1574,6 +1577,8 @@ def run(
b32_seed=effective_b32_seed,
b29_seed_pinned=b29_seed_pinned,
b32_seed_pinned=b32_seed_pinned,
+ **(inspection_seeds(effective_inspection_seed)
+ if effective_inspection_seed is not None else {}),
)
judge_config = _build_judge_config(
@@ -1742,6 +1747,7 @@ def run(
governance_source=governance_source,
mode_filter=(list(test) if test else (["strategic"] if strategic else ["all"])),
judge_identity=judge_identity_descriptor,
+ seed=effective_inspection_seed,
b12_seed=effective_b12_seed,
b14_seed=effective_b14_seed,
b28_seed=effective_b28_seed,
diff --git a/ifixai/tests/test_cli_inspection_replay_seeds.py b/ifixai/tests/test_cli_inspection_replay_seeds.py
new file mode 100644
index 0000000..bf1bdb5
--- /dev/null
+++ b/ifixai/tests/test_cli_inspection_replay_seeds.py
@@ -0,0 +1,142 @@
+"""Interrupted analytic CLI runs must resume the same inspection corpus."""
+
+import importlib
+import json
+from pathlib import Path
+
+import pytest
+from click.testing import CliRunner
+
+from ifixai.cli.main import ifixai_cli
+from ifixai.inspections.v09_prompt_override_resistance import runner as v09
+from ifixai.inspections.v09_prompt_override_resistance.runner_rotation import (
+ manifest_digest,
+)
+
+
[email protected]("legacy", [False, True])
+def test_native_v09_interrupted_resume_preserves_rotation(tmp_path, monkeypatch, legacy):
+ monkeypatch.chdir(tmp_path)
+ monkeypatch.setenv("HOME", str(tmp_path))
+ monkeypatch.setenv("IFIXAI_TELEMETRY", "0")
+ monkeypatch.setenv("DO_NOT_TRACK", "1")
+ # Make the old random config's drift reproducible, rather than a flaky
+ # assertion that two random seeds happen to select different rotations.
+ cli_run = importlib.import_module("ifixai.cli.run")
+ original_manifest = cli_run.build_manifest
+ if legacy:
+ def legacy_manifest(**kwargs):
+ kwargs["seed"] = None
+ return original_manifest(**kwargs)
+ monkeypatch.setattr(cli_run, "build_manifest", legacy_manifest)
+ original_rotation = v09.rotation_offsets
+ original_specs = v09.select_probe_specs
+ rotations = []
+ seeds = []
+
+ def record_rotation(seed):
+ seeds.append(seed)
+ rotation = original_rotation(seed)
+ rotations.append(manifest_digest(rotation))
+ return rotation
+
+ def interrupt_once(users, rotation):
+ specs = original_specs(users, rotation)
+ if len(rotations) == 1:
+ raise KeyboardInterrupt
+ return specs
+
+ monkeypatch.setattr(v09, "rotation_offsets", record_rotation)
+ monkeypatch.setattr(v09, "select_probe_specs", interrupt_once)
+ # Pydantic captures default_factory functions when the class is defined.
+ # Supply deterministic successive seeds through the real factory's RNG.
+ draws = iter(range(1, 10000))
+ monkeypatch.setattr("ifixai.core.types.secrets.randbelow", lambda _: next(draws))
+ fixture = Path(__file__).parents[1] / "fixtures/examples/customer_support.yaml"
+ args = ["run", "--provider", "mock", "--model", "owned-mock",
+ "--fixture", str(fixture), "--test", "B01", "--test", "V09",
+ "--eval-mode", "single", "--judge-provider", "mock",
+ "--judge-api-key", "owned-unused", "--judge-budget", "0",
+ "--output", str(tmp_path / "reports"),
+ "--reliability-out", str(tmp_path / "runs"),
+ "--no-parallel", "--no-promo", "--no-telemetry"]
+ first = CliRunner().invoke(ifixai_cli, args)
+ assert first.exit_code == 130, first.output
+ manifest_path, = (tmp_path / "runs").glob("*/manifest.json")
+ manifest = json.loads(manifest_path.read_text())
+ checkpoint = json.loads(manifest_path.with_name("checkpoint.json").read_text())
+ assert "B01" in checkpoint
+ assert "V09" not in checkpoint
+ monkeypatch.setattr(cli_run, "build_manifest", original_manifest)
+ resumed = CliRunner().invoke(ifixai_cli, [*args, "--resume", manifest["run_id"]])
+ assert resumed.exit_code in (0, 2), resumed.output
+ assert "[reused] B01" in resumed.output
+ assert len(seeds) == 2
+ if legacy:
+ assert seeds[0] != seeds[1]
+ assert checkpoint["B01"] == json.loads(manifest_path.with_name("checkpoint.json").read_text())["B01"]
+ assert json.loads(manifest_path.read_text())["seed"] is None
+ else:
+ assert seeds[0] == seeds[1], (seeds, rotations)
+ assert rotations[0] == rotations[1]
+ assert json.loads(manifest_path.read_text())["run_id"] == manifest["run_id"]
+ checkpoint = json.loads(manifest_path.with_name("checkpoint.json").read_text())
+ assert "V09" in checkpoint
+ assert checkpoint["V09"]["variant_seed"] == seeds[1]
+
+
[email protected]("mode", ["single", "deterministic"])
+def test_native_legacy_b_only_resume_remains_compatible(tmp_path, monkeypatch, mode):
+ monkeypatch.chdir(tmp_path)
+ monkeypatch.setenv("HOME", str(tmp_path))
+ monkeypatch.setenv("IFIXAI_TELEMETRY", "0")
+ cli_run = importlib.import_module("ifixai.cli.run")
+ original_manifest = cli_run.build_manifest
+
+ def legacy_manifest(**kwargs):
+ kwargs["seed"] = None
+ return original_manifest(**kwargs)
+
+ monkeypatch.setattr(cli_run, "build_manifest", legacy_manifest)
+ configs = []
+ original_execute = cli_run.execute_tests
+
+ async def capture_execute(*args, **kwargs):
+ configs.append(kwargs.get("pipeline_config"))
+ return await original_execute(*args, **kwargs)
+
+ monkeypatch.setattr(cli_run, "execute_tests", capture_execute)
+ args = ["run", "--provider", "mock", "--fixture", "customer_support",
+ "--test", "B01", "--eval-mode", mode, "--no-promo", "--no-telemetry",
+ "--no-parallel", "--output", str(tmp_path / "reports"),
+ "--reliability-out", str(tmp_path / "runs")]
+ if mode == "single":
+ args += ["--judge-provider", "mock"]
+ first = CliRunner().invoke(ifixai_cli, args)
+ assert first.exit_code == 2, first.output
+ path, = (tmp_path / "runs").glob("*/manifest.json")
+ manifest = json.loads(path.read_text())
+ monkeypatch.setattr(cli_run, "build_manifest", original_manifest)
+ resumed = CliRunner().invoke(ifixai_cli, [*args, "--resume", manifest["run_id"]])
+ assert resumed.exit_code == 2, resumed.output
+ assert "[reused] B01" in resumed.output
+ assert json.loads(path.read_text())["seed"] is None
+ if mode == "deterministic":
+ assert configs == [None, None]
+
+
+def test_derived_seeds_cover_all_unpersisted_inspections():
+ from ifixai.cli.inspection_seeds import ANALYTIC_SEED_FIELDS, inspection_seeds
+ from ifixai.core.types import EvaluationPipelineConfig
+
+ seeds = inspection_seeds(17)
+ config = EvaluationPipelineConfig(**seeds)
+ assert len(seeds) == 22
+ assert seeds == inspection_seeds(17)
+ assert seeds != inspection_seeds(18)
+ assert len(set(seeds.values())) == len(seeds)
+ assert config.b12_seed_pinned is False
+ assert config.v09_seed_pinned is False
+ for field in ANALYTIC_SEED_FIELDS:
+ assert getattr(config, field) == seeds[field]
+ assert 0 <= seeds[field] < 2**31