World's first open-source, agentic video production system. 12 production pipelines, 100+ tools, 700+ agent skill and production-knowledge files. Turn your AI coding assistant into a full video production studio.
Python agentagentic-aiaiclaudecopilotcursorelevenlabsffmpegfluximage-generationopen-sourceopenaipythonremotionstable-diffusiontext-to-speechtext-to-videovideo-generationvideo-production
fix(checkpoint): validate before persisting stage decisions (#704)
Rudy Mizrahi Celekli15554039e19a
diff --git a/lib/checkpoint.py b/lib/checkpoint.pyindex 23e4b228..3951d35c 100644--- a/lib/checkpoint.py+++ b/lib/checkpoint.py@@ -528,7 +528,6 @@ def write_checkpoint(# append them to the project-level decision log file, then write the# reference back into relevant artifacts so downstream consumers can find it.if "decision_log" in artifacts and isinstance(artifacts["decision_log"], dict):- _merge_decision_log(pipeline_dir, project_id, artifacts["decision_log"])log_ref = str(_decision_log_path(pipeline_dir, project_id))# Write decision_log_ref into proposal_packet and render_report@@ -546,6 +545,10 @@ def write_checkpoint(validate_checkpoint(checkpoint)+ # Reject invalid stage/artifact payloads before persisting their decisions.+ if "decision_log" in artifacts and isinstance(artifacts["decision_log"], dict):+ _merge_decision_log(pipeline_dir, project_id, artifacts["decision_log"])+path = _checkpoint_path(pipeline_dir, project_id, stage)path.parent.mkdir(parents=True, exist_ok=True)# Serialize to a temp file first so a mid-write failure (disk full,diff --git a/tests/lib/test_checkpoint_decision_validation.py b/tests/lib/test_checkpoint_decision_validation.pynew file mode 100644index 00000000..a5f7876f--- /dev/null+++ b/tests/lib/test_checkpoint_decision_validation.py@@ -0,0 +1,57 @@+"""Rejected stage writes must not append to the accepted decision history."""++import json++import pytest++from lib.checkpoint import CheckpointValidationError, read_checkpoint, write_checkpoint+++def decision_log(decision_id):+ return {+ "version": "1.0", "project_id": "film",+ "decisions": [{+ "decision_id": decision_id, "stage": "research",+ "category": "provider_selection", "subject": "narration",+ "options_considered": [{+ "option_id": "local", "label": "Local", "score": 1,+ "reason": "No external call needed",+ }],+ "selected": "local", "reason": "Local fixture",+ }],+ }++[email protected]("invalid_kwargs", [+ {"metadata": "not an object"},+ {"artifacts": {"script": {"version": "1.0"}}},+])+def test_rejected_checkpoint_keeps_prior_decisions(tmp_path, invalid_kwargs):+ write_checkpoint(tmp_path, "film", "research", "in_progress",+ {"decision_log": decision_log("accepted")})+ log_path = tmp_path / "film" / "decision_log.json"+ original = log_path.read_bytes()+ kwargs = dict(invalid_kwargs)+ artifacts = kwargs.pop("artifacts", {})+ artifacts["decision_log"] = decision_log("rejected")++ with pytest.raises(CheckpointValidationError):+ write_checkpoint(tmp_path, "film", "research", "in_progress", artifacts, **kwargs)++ assert log_path.read_bytes() == original+ assert read_checkpoint(tmp_path, "film", "research")["artifacts"]["decision_log"] == decision_log("accepted")+++def test_rejected_first_write_does_not_create_a_decision_log(tmp_path):+ with pytest.raises(CheckpointValidationError):+ write_checkpoint(tmp_path, "film", "research", "in_progress",+ {"decision_log": decision_log("rejected")}, metadata=[])+ assert not (tmp_path / "film" / "decision_log.json").exists()+++def test_accepted_write_merges_new_decisions_and_deduplicates_replay(tmp_path):+ for name in ("first", "second", "second"):+ write_checkpoint(tmp_path, "film", "research", "in_progress",+ {"decision_log": decision_log(name)})+ log = json.loads((tmp_path / "film" / "decision_log.json").read_text())+ assert [d["decision_id"] for d in log["decisions"]] == ["first", "second"]