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.
Python agent-evaluationaiai-alignmentai-evaluationai-governanceai-safetyclidiagnostic-tooleu-ai-acthallucination-detectioniso-42001llm-evaluationllm-securitynist-ai-rmfowasp-llmprompt-injectionpythonresponsible-airisk-assessmentrisk-management
fix: serialize concurrent checkpoint publication (#320)
Wu Shuwen28c0fb5d1b98
diff --git a/ifixai/evaluation/checkpoint.py b/ifixai/evaluation/checkpoint.pyindex cdaf420..5f52faf 100644--- a/ifixai/evaluation/checkpoint.py+++ b/ifixai/evaluation/checkpoint.py@@ -19,6 +19,7 @@ import jsonimport loggingfrom pathlib import Pathfrom tempfile import NamedTemporaryFile+from threading import Lockfrom typing import Optionalfrom ifixai.core.types import TestResult, TestStatus@@ -26,6 +27,7 @@ from ifixai.evaluation.manifest import RunManifestfrom ifixai.evaluation.schemas import ResumeState_logger = logging.getLogger(__name__)+_checkpoint_publish_lock = Lock()def _checkpoint_path(runs_root: Path, run_id: str) -> Path:@@ -85,7 +87,10 @@ def save_checkpoint(try:with fh:json.dump(payload, fh, indent=2, sort_keys=True, default=str)- tmp.replace(path)+ # Windows can reject simultaneous replacements of the same destination.+ # Serialize only the atomic publish step; staging remains concurrent.+ with _checkpoint_publish_lock:+ tmp.replace(path)finally:tmp.unlink(missing_ok=True)return pathdiff --git a/ifixai/tests/evaluation/test_checkpoint_atomic_save.py b/ifixai/tests/evaluation/test_checkpoint_atomic_save.pyindex 815acf9..647d917 100644--- a/ifixai/tests/evaluation/test_checkpoint_atomic_save.py+++ b/ifixai/tests/evaluation/test_checkpoint_atomic_save.py@@ -7,19 +7,19 @@ from threading import Barrierimport pytestfrom ifixai.core.types import TestResult+from ifixai.evaluation import checkpointfrom ifixai.evaluation.checkpoint import load_checkpoint, save_checkpointdef test_overlapping_saves_publish_complete_checkpoints(tmp_path, monkeypatch):barrier = Barrier(2)- replace = Path.replace+ dump = checkpoint.json.dump- def synchronized_replace(self, target):- if Path(target).name == "checkpoint.json":- barrier.wait(timeout=5)- return replace(self, target)+ def synchronized_dump(payload, stream, **kwargs):+ dump(payload, stream, **kwargs)+ barrier.wait(timeout=5)- monkeypatch.setattr(Path, "replace", synchronized_replace)+ monkeypatch.setattr(checkpoint.json, "dump", synchronized_dump)results = [{key: TestResult(test_id=key)} for key in ("B01", "B08")]with ThreadPoolExecutor(max_workers=2) as executor:futures = [executor.submit(save_checkpoint, tmp_path, "run-1", r) for r in results]