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: fingerprint active control prompts and mutation bank (#283)

Rudy Mizrahi Celekli3d4c1f41c07e
diff --git a/ifixai/cli/run.py b/ifixai/cli/run.py
index 653fb54..194a7b6 100644
--- a/ifixai/cli/run.py
+++ b/ifixai/cli/run.py
@@ -1662,13 +1662,24 @@ def run(
from ifixai.providers.http import DEFAULT_ENDPOINT
effective_endpoint = (effective_endpoint or DEFAULT_ENDPOINT).rstrip("/")
+ rubric_hashes = compute_rubric_digests_for_tests_layout(
+ _TESTS_DIR, mutation_bank_path=_TESTS_DIR.parent / "harness" / "synonyms.yaml"
+ )
+ if resume_manifest is not None:
+ # Added fingerprints must not invalidate a run that predates them.
+ # Existing keys still use current digests, so edits remain detectable.
+ rubric_hashes = {
+ key: digest for key, digest in rubric_hashes.items()
+ if key in resume_manifest.rubric_hashes
+ }
+
manifest = build_manifest(
mode=manifest_mode,
model_under_test=model_descriptor,
judge_models=[],
normalizer_version=NORMALIZER_VERSION,
test_versions=test_versions,
- rubric_hashes=compute_rubric_digests_for_tests_layout(_TESTS_DIR),
+ rubric_hashes=rubric_hashes,
fixture_digest=compute_fixture_digest(resolved_fixture_path),
governance_fixture_digest=governance_fixture_digest_value,
governance_source=governance_source,
diff --git a/ifixai/tests/test_added_artifact_legacy_resume.py b/ifixai/tests/test_added_artifact_legacy_resume.py
new file mode 100644
index 0000000..d5ae256
--- /dev/null
+++ b/ifixai/tests/test_added_artifact_legacy_resume.py
@@ -0,0 +1,48 @@
+import importlib
+import json
+
+import pytest
+from click.testing import CliRunner
+
+from ifixai.cli.main import ifixai_cli
+
+
+def flags(tmp_path):
+ return ["run", "--provider", "mock", "--model", "owned-sut", "--test", "B07",
+ "--eval-mode", "single", "--judge-provider", "mock", "--judge-model", "owned-judge-a",
+ "--judge-budget", "10000", "--output", str(tmp_path / "reports"),
+ "--reliability-out", str(tmp_path / "runs"), "--no-telemetry", "--no-parallel"]
+
+
+def owned_environment(tmp_path, monkeypatch):
+ monkeypatch.chdir(tmp_path)
+ monkeypatch.setenv("HOME", str(tmp_path))
+ monkeypatch.setenv("IFIXAI_TELEMETRY", "0")
+ monkeypatch.setenv("DO_NOT_TRACK", "1")
+ return importlib.import_module("ifixai.cli.run")
+
[email protected]("mutate_existing", [False, True])
+def test_added_keys_preserve_legacy_native_resume_but_existing_edits_reject(tmp_path, monkeypatch, mutate_existing):
+ run = owned_environment(tmp_path, monkeypatch)
+ current = run.compute_rubric_digests_for_tests_layout
+ def legacy(*args, **kwargs):
+ return {key: value for key, value in current(*args, **kwargs).items()
+ if ":on_topic_prompts" not in key and key != "mutation_bank:synonyms"}
+ monkeypatch.setattr(run, "compute_rubric_digests_for_tests_layout", legacy)
+ first = CliRunner().invoke(ifixai_cli, flags(tmp_path))
+ paths = list((tmp_path / "runs").glob("*/manifest.json"))
+ assert len(paths) == 1, first.output
+ manifest = json.loads(paths[0].read_text())
+ def upgraded(*args, **kwargs):
+ result = current(*args, **kwargs)
+ if mutate_existing:
+ result[next(iter(manifest["rubric_hashes"]))] = "f" * 64
+ return result
+ monkeypatch.setattr(run, "compute_rubric_digests_for_tests_layout", upgraded)
+ resumed = CliRunner().invoke(ifixai_cli, [*flags(tmp_path), "--resume", manifest["run_id"]])
+ if mutate_existing:
+ assert "differs in: rubric_hashes" in resumed.output, resumed.output
+ assert resumed.exit_code == 1
+ else:
+ assert "[reused] B07" in resumed.output, resumed.output
+ assert resumed.exit_code == first.exit_code
diff --git a/ifixai/tests/test_b32_control_prompt_fingerprint.py b/ifixai/tests/test_b32_control_prompt_fingerprint.py
new file mode 100644
index 0000000..f8bfee3
--- /dev/null
+++ b/ifixai/tests/test_b32_control_prompt_fingerprint.py
@@ -0,0 +1,81 @@
+"""Manifest identity binds the conform probes B32 actually sends."""
+
+from pathlib import Path
+
+import yaml
+
+from ifixai.core.fixture_loader import load_fixture
+from ifixai.evaluation.manifest import compute_run_id
+from ifixai.inspections.b32_off_topic_detection import runner
+from ifixai.utils.rubric_digest import compute_rubric_digests_for_tests_layout
+
+
+def test_changed_active_b32_control_prompt_changes_run_identity(tmp_path, monkeypatch):
+ package = Path(__file__).parents[1]
+ folder = tmp_path / "b32_off_topic_detection"
+ folder.mkdir()
+ (folder / "rubric.yaml").write_text((package / "inspections/b32_off_topic_detection/rubric.yaml").read_text())
+ controls = folder / "on_topic_prompts.yaml"
+ controls.write_text((package / "inspections/b32_off_topic_detection/on_topic_prompts.yaml").read_text())
+ monkeypatch.setattr(runner, "_ON_TOPIC_PROMPTS_PATH", controls)
+ fixture = load_fixture(str(package / "fixtures/examples/customer_support.yaml"))
+ fixture.metadata.domain = "customer_support"
+ inspection = runner.B32OffTopicDetection()
+ prompts_before = inspection.generate_on_topic_prompts(fixture)
+ hashes_before = compute_rubric_digests_for_tests_layout(tmp_path)
+ data = yaml.safe_load(controls.read_text())
+ data["domains"]["customer_support"][0] = "Please investigate the duplicate payment on my order."
+ controls.write_text(yaml.safe_dump(data))
+ assert inspection.generate_on_topic_prompts(fixture) != prompts_before
+ hashes_after = compute_rubric_digests_for_tests_layout(tmp_path)
+ assert hashes_after != hashes_before
+ assert compute_run_id({"rubric_hashes": hashes_after}) != compute_run_id({"rubric_hashes": hashes_before})
+
+
+def test_unconsumed_notes_do_not_change_artifact_identity(tmp_path):
+ folder = tmp_path / "b32_off_topic_detection"
+ folder.mkdir()
+ (folder / "rubric.yaml").write_text("dimensions: []\n")
+ notes = folder / "notes.yaml"
+ notes.write_text("notes: first\n")
+ before = compute_rubric_digests_for_tests_layout(tmp_path)
+ notes.write_text("notes: second\n")
+ assert compute_rubric_digests_for_tests_layout(tmp_path) == before
+
+
+def test_changed_mutation_bank_changes_seeded_probes_and_manifest_identity(tmp_path):
+ from ifixai.harness.adversarial_mutator import SeedEntry, expand_seeds
+
+ folder = tmp_path / "b14_covert_side_task"
+ folder.mkdir()
+ (folder / "rubric.yaml").write_text("dimensions: []\n")
+ bank = tmp_path / "synonyms.yaml"
+ bank.write_text("filler_words: [please]\nsynonyms: []\n")
+ seeds = [SeedEntry(id="probe", text="retrieve the record")]
+ variants_before = expand_seeds(seeds, bank, seed=20260422, variants_per_seed=10)
+ hashes_before = compute_rubric_digests_for_tests_layout(tmp_path, mutation_bank_path=bank)
+ bank.write_text("filler_words: [kindly]\nsynonyms: []\n")
+ assert expand_seeds(seeds, bank, seed=20260422, variants_per_seed=10) != variants_before
+ hashes_after = compute_rubric_digests_for_tests_layout(tmp_path, mutation_bank_path=bank)
+ assert hashes_before != hashes_after
+ assert compute_run_id({"rubric_hashes": hashes_before}) != compute_run_id({"rubric_hashes": hashes_after})
+
+
+def test_layout_without_mutation_consumer_ignores_bank(tmp_path):
+ folder = tmp_path / "b01_tool_governance"
+ folder.mkdir()
+ (folder / "rubric.yaml").write_text("dimensions: []\n")
+ legacy = compute_rubric_digests_for_tests_layout(tmp_path)
+ assert compute_rubric_digests_for_tests_layout(tmp_path, mutation_bank_path=tmp_path / "absent.yaml") == legacy
+
+
+def test_stored_legacy_artifact_manifest_remains_verifiable():
+ from ifixai.core.types import RunMode
+ from ifixai.evaluation.manifest import RunManifest, build_manifest, verify_run_id
+ from ifixai.evaluation.types import ModelDescriptor
+
+ manifest = build_manifest(mode=RunMode.STANDARD,
+ model_under_test=ModelDescriptor(provider="mock", model_id="mock", version="1"),
+ judge_models=[], normalizer_version="1", test_versions={},
+ rubric_hashes={"b14_covert_side_task": "a" * 64}, fixture_digest="b" * 64)
+ assert verify_run_id(RunManifest.model_validate_json(manifest.model_dump_json()))
diff --git a/ifixai/utils/rubric_digest.py b/ifixai/utils/rubric_digest.py
index e11cc9d..b9612ea 100644
--- a/ifixai/utils/rubric_digest.py
+++ b/ifixai/utils/rubric_digest.py
@@ -58,7 +58,9 @@ def compute_rubric_digests_for_directory(rubrics_dir: Path | str) -> dict[str, s
return {path.name: compute_rubric_digest(path) for path in yaml_files}
-def compute_rubric_digests_for_tests_layout(tests_dir: Path | str) -> dict[str, str]:
+def compute_rubric_digests_for_tests_layout(
+ tests_dir: Path | str, *, mutation_bank_path: Path | str | None = None
+) -> dict[str, str]:
directory = Path(tests_dir)
if not directory.is_dir():
raise MissingRubricError(
@@ -83,11 +85,18 @@ def compute_rubric_digests_for_tests_layout(tests_dir: Path | str) -> dict[str,
and path.suffix in _YAML_SUFFIXES
and path.stem != "rubric"
and (
- path.stem in {"prompts", "corpus", "definition", "references"}
+ path.stem in {"prompts", "on_topic_prompts", "corpus", "definition", "references"}
or path.stem.startswith("rubric_")
)
)
for artifact in artifacts:
key = f"{folder.name}:{artifact.stem}"
hashes[key] = compute_rubric_digest(artifact)
+ mutation_consumers = {
+ "b14_covert_side_task", "b28_rag_context_integrity", "b30_malicious_deployer_rules"
+ }
+ if mutation_bank_path is not None and any(
+ path.parent.name in mutation_consumers for path in rubric_files
+ ):
+ hashes["harness:synonyms"] = compute_rubric_digest(mutation_bank_path)
return hashes