From bcf882e44c12fd8c361a4cbb96349c3265ad30ff Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 03:08:56 +0100 Subject: [PATCH 1/2] Preserve passing receipts across late check checkpoints Co-Authored-By: Codex --- docs/ARCHITECTURE.md | 5 +++-- src/loopzero/cli.py | 8 ++++++-- tests/test_cli.py | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 661a86f4..96396648 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -478,8 +478,9 @@ stage is retried after success or uncertain launch. Only the coordinator writes the authoritative `checks.json` receipt. Writers lock the task state directory while rechecking HEAD and atomically replacing the receipt from a synced sibling temporary file. Successful keyed stages are checkpointed in the same receipt -for reuse. The checkpoint cannot satisfy readiness before final worktree -validation. Runners cannot select stages or mint receipts. Stage admission +for reuse. A checkpoint cannot replace a clean pass for the same head and +settings or satisfy readiness before final worktree validation. Completed +failures still replace passes. Runners cannot select stages or mint receipts. Stage admission belongs to the runner: the outer `loopzero check` must not hold a heavy slot when a runner is configured. Without a runner, the existing local execution path is unchanged. diff --git a/src/loopzero/cli.py b/src/loopzero/cli.py index 515d3da7..13a8bee2 100644 --- a/src/loopzero/cli.py +++ b/src/loopzero/cli.py @@ -359,7 +359,7 @@ def _lock_task_state(wt: Path) -> Iterator[None]: os.close(fd) -def _save_report(wt: Path, report: CheckReport) -> str | None: +def _save_report(wt: Path, report: CheckReport, *, checkpoint: bool = False) -> str | None: """Publish the receipt or return the current HEAD if the result is stale.""" path = wt / CHECKS_FILE payload = { @@ -375,6 +375,10 @@ def _save_report(wt: Path, report: CheckReport) -> str | None: current_head = worktree.head(wt) if report.head != current_head: return current_head + saved = _load_report(wt) if checkpoint else None + if (saved is not None and saved.ok and not saved.dirty and saved.head == report.head + and saved.settings_sha256 == report.settings_sha256): + return None _write_json_atomically(path, payload) return None @@ -598,7 +602,7 @@ def cmd_check(args: argparse.Namespace) -> int: report = sandbox.run_checks(config, wt, progress=lambda command: print( f"running: {command}", flush=True), status=lambda message: print(message, flush=True), - checkpoint=lambda partial: _save_report(wt, partial)) + checkpoint=lambda partial: _save_report(wt, partial, checkpoint=True)) except sandbox.SandboxUnavailable as exc: print(f"sandbox unavailable: {exc}", file=sys.stderr) return 2 diff --git a/tests/test_cli.py b/tests/test_cli.py index 3cd7131b..d4d88d6b 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -10,6 +10,7 @@ import subprocess import sys from dataclasses import replace +from functools import partial from pathlib import Path from types import SimpleNamespace from unittest.mock import Mock @@ -4763,3 +4764,19 @@ def test_pr_marks_legacy_same_head_check_unverified(wt, gh, capsys): assert "unverified" not in draft assert f"Recorded for `{head[:12]}`\n- `echo ok`: exit 0" in draft assert "Manual validation evidence." in draft + + +def test_late_checkpoint_preserves_completed_pass(wt, head): + cfg = config.load(wt / "workflow.toml") + passed = CheckReport(head, False, tuple(CheckResult(c, 0, 0, "", input_key="key") for c in cfg.checks), + cli.sandbox.settings_fingerprint(cfg, wt)) + save = partial(cli._save_report, wt) + checkpoint = cli.sandbox._checkpoint_success + checkpoint(partial(save, checkpoint=True), passed, {}, ()) + assert cli._load_report(wt).results[0].input_key == "key" + save(passed) + checkpoint(partial(save, checkpoint=True), passed, {}, ()) + assert cli._current_check_report(wt, cfg, head) == passed + failed = replace(passed, results=(replace(passed.results[0], exit_code=1),)) + save(failed) + assert cli._load_report(wt) == failed From 9f518793a1e5eeae3e5c71e395d285563c574f2d Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 03:38:07 +0100 Subject: [PATCH 2/2] Match the check command list before preserving a pass Architecture-Review: unchanged; same settings and commands retain the current pass. Co-Authored-By: Codex --- src/loopzero/cli.py | 9 +++++---- tests/test_cli.py | 7 +++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/loopzero/cli.py b/src/loopzero/cli.py index 13a8bee2..214653bb 100644 --- a/src/loopzero/cli.py +++ b/src/loopzero/cli.py @@ -359,7 +359,7 @@ def _lock_task_state(wt: Path) -> Iterator[None]: os.close(fd) -def _save_report(wt: Path, report: CheckReport, *, checkpoint: bool = False) -> str | None: +def _save_report(wt: Path, report: CheckReport, *, checkpoint_checks: tuple[str, ...] | None = None) -> str | None: """Publish the receipt or return the current HEAD if the result is stale.""" path = wt / CHECKS_FILE payload = { @@ -375,9 +375,10 @@ def _save_report(wt: Path, report: CheckReport, *, checkpoint: bool = False) -> current_head = worktree.head(wt) if report.head != current_head: return current_head - saved = _load_report(wt) if checkpoint else None + saved = _load_report(wt) if checkpoint_checks is not None else None if (saved is not None and saved.ok and not saved.dirty and saved.head == report.head - and saved.settings_sha256 == report.settings_sha256): + and saved.settings_sha256 == report.settings_sha256 + and tuple(result.command for result in saved.results) == checkpoint_checks): return None _write_json_atomically(path, payload) return None @@ -602,7 +603,7 @@ def cmd_check(args: argparse.Namespace) -> int: report = sandbox.run_checks(config, wt, progress=lambda command: print( f"running: {command}", flush=True), status=lambda message: print(message, flush=True), - checkpoint=lambda partial: _save_report(wt, partial, checkpoint=True)) + checkpoint=lambda partial: _save_report(wt, partial, checkpoint_checks=config.checks)) except sandbox.SandboxUnavailable as exc: print(f"sandbox unavailable: {exc}", file=sys.stderr) return 2 diff --git a/tests/test_cli.py b/tests/test_cli.py index d4d88d6b..9833355d 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -4772,11 +4772,14 @@ def test_late_checkpoint_preserves_completed_pass(wt, head): cli.sandbox.settings_fingerprint(cfg, wt)) save = partial(cli._save_report, wt) checkpoint = cli.sandbox._checkpoint_success - checkpoint(partial(save, checkpoint=True), passed, {}, ()) + checkpoint(partial(save, checkpoint_checks=cfg.checks), passed, {}, ()) assert cli._load_report(wt).results[0].input_key == "key" save(passed) - checkpoint(partial(save, checkpoint=True), passed, {}, ()) + checkpoint(partial(save, checkpoint_checks=cfg.checks), passed, {}, ()) assert cli._current_check_report(wt, cfg, head) == passed failed = replace(passed, results=(replace(passed.results[0], exit_code=1),)) save(failed) assert cli._load_report(wt) == failed + save(passed) + checkpoint(partial(save, checkpoint_checks=cfg.checks[:1]), replace(passed, results=passed.results[:1]), {}, ()) + assert not cli._load_report(wt).ok