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: reject inconsistent checkpoint entries during resume (#130)

Rudy Mizrahi Celekli0dd5005f6695
diff --git a/ifixai/evaluation/checkpoint.py b/ifixai/evaluation/checkpoint.py
index 58023dc..de697aa 100644
--- a/ifixai/evaluation/checkpoint.py
+++ b/ifixai/evaluation/checkpoint.py
@@ -20,7 +20,7 @@ import logging
from pathlib import Path
from typing import Optional
-from ifixai.core.types import TestResult
+from ifixai.core.types import TestResult, TestStatus
from ifixai.evaluation.manifest import RunManifest
from ifixai.evaluation.schemas import ResumeState
@@ -40,6 +40,9 @@ def load_checkpoint(runs_root: Path, run_id: str) -> dict[str, TestResult]:
except (OSError, json.JSONDecodeError) as exc:
_logger.warning("checkpoint unreadable (%s) — starting fresh", exc)
return {}
+ if not isinstance(raw, dict):
+ _logger.warning("checkpoint root is not an object — starting fresh")
+ return {}
out: dict[str, TestResult] = {}
for test_id, payload in raw.items():
try:
@@ -50,7 +53,13 @@ def load_checkpoint(runs_root: Path, run_id: str) -> dict[str, TestResult]:
test_id, exc,
)
continue
- if result.error_message:
+ if result.test_id != test_id:
+ _logger.warning(
+ "checkpoint entry %s contains result for %s — will re-run",
+ test_id, result.test_id,
+ )
+ continue
+ if result.error_message or result.status == TestStatus.ERROR:
_logger.info("skipping stale errored result for %s", test_id)
continue
out[test_id] = result
diff --git a/ifixai/tests/evaluation/test_checkpoint_validation.py b/ifixai/tests/evaluation/test_checkpoint_validation.py
new file mode 100644
index 0000000..ec95ceb
--- /dev/null
+++ b/ifixai/tests/evaluation/test_checkpoint_validation.py
@@ -0,0 +1,42 @@
+"""Damaged checkpoint data must never silently skip the wrong inspection."""
+
+import json
+
+from ifixai.core.types import TestResult, TestStatus
+from ifixai.evaluation.checkpoint import load_checkpoint
+
+
+def _write_checkpoint(tmp_path, payload):
+ run_dir = tmp_path / "run-1"
+ run_dir.mkdir()
+ (run_dir / "checkpoint.json").write_text(json.dumps(payload), encoding="utf-8")
+
+
+def test_non_mapping_checkpoint_is_ignored(tmp_path):
+ _write_checkpoint(tmp_path, [{"test_id": "B01"}])
+
+ assert load_checkpoint(tmp_path, "run-1") == {}
+
+
+def test_checkpoint_entry_with_mismatched_id_is_rerun(tmp_path):
+ _write_checkpoint(tmp_path, {
+ "B01": TestResult(test_id="B08", status=TestStatus.PASS).model_dump(mode="json")
+ })
+
+ assert load_checkpoint(tmp_path, "run-1") == {}
+
+
+def test_error_status_is_rerun_even_without_error_message(tmp_path):
+ _write_checkpoint(tmp_path, {
+ "B01": TestResult(test_id="B01", status=TestStatus.ERROR).model_dump(mode="json")
+ })
+
+ assert load_checkpoint(tmp_path, "run-1") == {}
+
+
+def test_valid_completed_entry_is_reused(tmp_path):
+ _write_checkpoint(tmp_path, {
+ "B01": TestResult(test_id="B01", status=TestStatus.PASS).model_dump(mode="json")
+ })
+
+ assert load_checkpoint(tmp_path, "run-1")["B01"].status == TestStatus.PASS