"""Build a checkpoint manifest only after execution identities are quiescent. This never takes a DB/filesystem backup itself and never claims a live snapshot is static. """ import hashlib,json from pathlib import Path def build_checkpoint(checkpoint_id,versions,files,executions,upstream_ids): if any(row.get("state") not in {"exited","results_ready"} for row in executions): raise ValueError("Live or unknown execution cannot form a static checkpoint") return {"checkpoint_id":checkpoint_id,"versions":versions,"files":{str(Path(p)):hashlib.sha256(Path(p).read_bytes()).hexdigest() for p in files},"upstream_ids":sorted(upstream_ids),"executions":executions} def validate_restore(checkpoint,current_checkpoint_id,current_upstream_ids): if checkpoint["checkpoint_id"]!=current_checkpoint_id or checkpoint["upstream_ids"]!=sorted(current_upstream_ids): raise ValueError("Upstream queue identity has advanced; reconcile before opening admission") for path,digest in checkpoint["files"].items(): if hashlib.sha256(Path(path).read_bytes()).hexdigest()!=digest:raise ValueError("Checkpoint file mismatch") return True