From a42ca7733a193326f3427cd30e5c1185b9404e6b Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 04:23:51 +0100 Subject: [PATCH 1/5] Explain why a check receipt is unusable Architecture-Review: unchanged; receipt predicates and their precedence are preserved. Co-Authored-By: Codex --- src/loopzero/cli.py | 17 +++++++++++++++-- tests/test_cli.py | 26 +++++++++++++------------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/loopzero/cli.py b/src/loopzero/cli.py index 48a64159..e4a6656e 100644 --- a/src/loopzero/cli.py +++ b/src/loopzero/cli.py @@ -317,9 +317,22 @@ def _readiness( def _check_report_problem( report: CheckReport | None, wt: Path, config: Config, head: str, *, require_pass: bool = True, ) -> str | None: - if (report is None or report.head != head or report.dirty or (require_pass and not report.ok) - or tuple(result.command for result in report.results) != config.checks): + if report is None: return "run loopzero check at this head" + if report.head != head: + return f"check receipt is for {report.head[:12]}. Run `loopzero check` at {head[:12]}." + if report.dirty: + return ("check receipt was recorded in a dirty worktree. Run `git status --short`, " + "settle the changes, then run `loopzero check`.") + if require_pass and report.results and not report.ok: + return ("check receipt records a failed stage. Fix the failure, then run `loopzero check`. " + "Retry unchanged only if the failure was transient.") + commands = tuple(result.command for result in report.results) + if commands != config.checks or (require_pass and not report.ok): + if config.checks[:len(commands)] == commands: + return "check receipt is incomplete. Run `loopzero check` to resume with the current workflow." + return ("check receipt's plan differs from the trusted workflow. " + "Run `loopzero check` with the current workflow.") recovery = ("Run loopzero check in this worktree at this head with the same current CLI and effective " "settings as ready, using a local coordinator for delegated stages.") if report.settings_sha256 is None: diff --git a/tests/test_cli.py b/tests/test_cli.py index b5536583..0f34de50 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -3037,7 +3037,7 @@ def test_ready_requires_clean_successful_local_report_at_head( assert ("Run loopzero check in this worktree at this head with the same current CLI and effective " "settings as ready, using a local coordinator for delegated stages." in out) elif condition != "matching": - assert out.endswith("not ready: run loopzero check at this head\n") + assert ("not ready: run loopzero check at this head" if condition == "missing" else "not ready: check receipt") in out @pytest.mark.parametrize("wait_for", [None, "ready", "merge"]) @@ -3765,7 +3765,7 @@ def test_status_silently_ignores_legacy_report_without_dirty( assert code == 0 and err == "" assert "ready: no" in out - assert " - run loopzero check at this head" in out + assert " - check receipt was recorded in a dirty worktree." in out def test_gh_errors_are_one_line_on_stderr(wt: Path, gh: FakeGh, capsys) -> None: @@ -4595,22 +4595,22 @@ def broken(*args, **kwargs): assert run(capsys, command)[0] == 0 -@pytest.mark.parametrize("invalid", ["stale", "red", "dirty", "commands"]) -def test_invalid_receipt_is_not_announced(wt, gh, capsys, head, invalid): +@pytest.mark.parametrize("field,value,reason", [ + ("head", "a" * 40, "check receipt is for aaaaaaaaaaaa."), + ("exit_code", 1, "check receipt records a failed stage."), + ("dirty", True, "check receipt was recorded in a dirty worktree."), + ("command", "changed", "check receipt's plan differs from the trusted workflow."), + ("results", [], "check receipt is incomplete."), +]) +def test_invalid_receipt_is_not_announced(wt, gh, capsys, head, field, value, reason): arm_approved_ready_pr(gh, head, wt) path = wt / ".loopzero/checks.json" data = json.loads(path.read_text()) - if invalid == "stale": - data["head"] = "a" * 40 - elif invalid == "dirty": - data["dirty"] = True - elif invalid == "red": - data["results"][0]["exit_code"] = 1 - else: - data["results"][0]["command"] = "changed" + target = data["results"][0] if field in {"exit_code", "command"} else data + target[field] = value path.write_text(json.dumps(data)) code, out, _ = run(capsys, "ready") - assert code == 1 and "run loopzero check at this head" in out + assert code == 1 and f"not ready: {reason}" in out assert "receipt accepted:" not in out From 84277f2c276f873313f1a00bea9c1e00a38b17e9 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 04:30:54 +0100 Subject: [PATCH 2/5] Distinguish interrupted checkpoints from changed check plans Architecture-Review: unchanged; the existing checkpoint marker and check receipt validation are preserved. Co-Authored-By: Codex --- src/loopzero/cli.py | 10 +++++----- src/loopzero/sandbox.py | 5 ++++- tests/test_cli.py | 9 +++++++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/loopzero/cli.py b/src/loopzero/cli.py index e4a6656e..46dc9402 100644 --- a/src/loopzero/cli.py +++ b/src/loopzero/cli.py @@ -324,13 +324,13 @@ def _check_report_problem( if report.dirty: return ("check receipt was recorded in a dirty worktree. Run `git status --short`, " "settle the changes, then run `loopzero check`.") - if require_pass and report.results and not report.ok: - return ("check receipt records a failed stage. Fix the failure, then run `loopzero check`. " - "Retry unchanged only if the failure was transient.") commands = tuple(result.command for result in report.results) - if commands != config.checks or (require_pass and not report.ok): - if config.checks[:len(commands)] == commands: + if (require_pass and not report.ok) or commands != config.checks: + if not commands or commands[-1] == sandbox.INCOMPLETE_CHECK_COMMAND: return "check receipt is incomplete. Run `loopzero check` to resume with the current workflow." + if require_pass and not report.ok: + return ("check receipt records a failed stage. Fix the failure, then run `loopzero check`. " + "Retry unchanged only if the failure was transient.") return ("check receipt's plan differs from the trusted workflow. " "Run `loopzero check` with the current workflow.") recovery = ("Run loopzero check in this worktree at this head with the same current CLI and effective " diff --git a/src/loopzero/sandbox.py b/src/loopzero/sandbox.py index 7409f050..0441d1f6 100644 --- a/src/loopzero/sandbox.py +++ b/src/loopzero/sandbox.py @@ -169,13 +169,16 @@ def run_checks(config: Config, worktree: Path, *, timeout: float = DEFAULT_TIMEO return CheckReport(head=head, dirty=dirty, results=tuple(results), settings_sha256=settings_sha256) +INCOMPLETE_CHECK_COMMAND = "" + + def _checkpoint_success(checkpoint: Callable[[CheckReport], None] | None, report: CheckReport, previous: dict[str, CheckResult], remaining: tuple[str, ...]) -> None: stage = report.results[-1] if checkpoint is not None and stage.input_key and stage.exit_code == 0: # Even the last stage leaves a nonpassing receipt until final validation. - incomplete = CheckResult("", 1, 0.0, "") + incomplete = CheckResult(INCOMPLETE_CHECK_COMMAND, 1, 0.0, "") unvisited = tuple(previous[command] for command in remaining if command in previous) checkpoint(replace(report, results=(*report.results, *unvisited, incomplete))) diff --git a/tests/test_cli.py b/tests/test_cli.py index 0f34de50..4e7d49cd 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -12,7 +12,7 @@ import subprocess import sys from contextlib import suppress -from dataclasses import replace +from dataclasses import asdict, replace from pathlib import Path from select import select from types import SimpleNamespace @@ -3022,7 +3022,7 @@ def test_ready_requires_clean_successful_local_report_at_head( if condition == "wrong-head": report["head"] = "0" * 40 elif condition == "wrong-commands": - report["results"][0]["command"] = "true" + report["results"].pop() elif condition == "legacy": del report["settings_sha256"] else: @@ -3036,6 +3036,8 @@ def test_ready_requires_clean_successful_local_report_at_head( assert f"not ready: {reason}." in out assert ("Run loopzero check in this worktree at this head with the same current CLI and effective " "settings as ready, using a local coordinator for delegated stages." in out) + elif condition == "wrong-commands": + assert "not ready: check receipt's plan differs from the trusted workflow." in out elif condition != "matching": assert ("not ready: run loopzero check at this head" if condition == "missing" else "not ready: check receipt") in out @@ -4601,12 +4603,15 @@ def broken(*args, **kwargs): ("dirty", True, "check receipt was recorded in a dirty worktree."), ("command", "changed", "check receipt's plan differs from the trusted workflow."), ("results", [], "check receipt is incomplete."), + ("results", "checkpoint", "check receipt is incomplete."), ]) def test_invalid_receipt_is_not_announced(wt, gh, capsys, head, field, value, reason): arm_approved_ready_pr(gh, head, wt) path = wt / ".loopzero/checks.json" data = json.loads(path.read_text()) target = data["results"][0] if field in {"exit_code", "command"} else data + if value == "checkpoint": + value = [data["results"][0], asdict(CheckResult("", 1, 0.0, ""))] target[field] = value path.write_text(json.dumps(data)) code, out, _ = run(capsys, "ready") From 57212083f17a845ad3d14d64cc906b3b1aa29a82 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 07:53:02 +0100 Subject: [PATCH 3/5] Document zero-second waits and queue cancellation Architecture-Review: unchanged; the documented behavior matches the current CLI without changing the delivery interface. Co-Authored-By: Codex --- core/CONTRACT.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/CONTRACT.md b/core/CONTRACT.md index 01f99ca4..110515b0 100644 --- a/core/CONTRACT.md +++ b/core/CONTRACT.md @@ -23,9 +23,10 @@ own delivery state; `.loopzero/` holds task text and local receipts. 5. `loopzero ready --wait` marks ready PRs ready for review. It also activates drafts blocked only by missing/skipped checks to trigger CI, even with mergeability pending. Without waiting, activation exits 3. - Both waiters observe the unchanged head while all blockers can settle, - with `--wait[=SECONDS]` (default 1800). Pending mergeability can block with - green checks and gets its own timeout message (exit 3). + Both waiters use `--wait[=SECONDS]` (default 1800) on the unchanged head. + Zero seconds can still activate or enqueue a PR. Pending mergeability can + time out (exit 3) with green checks. `loopzero merge --cancel` requests + Mergify removal without `--wait`. Green can precede CI scheduling. After two minutes with only missing checks and none pending, inspect scheduling, triggers and permissions, then retry. 6. After step 5 exits 0, run from a durable directory such as `/tmp` From a6871b96790c2ddf60adfaf1292e9273a07b29de Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 07:53:02 +0100 Subject: [PATCH 4/5] Clarify trusted and delegated check execution Architecture-Review: unchanged; the documented behavior matches the current CLI without changing the delivery interface. Co-Authored-By: Codex --- README.md | 2 +- docs/ARCHITECTURE.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4a50355e..cc1cfd90 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ ownership and the contributor routine that keeps documentation current. | Command | What it does | | --- | --- | | `loopzero start ` | Create a worktree and branch from base; write the Context/Problem/Goal task template. | -| `loopzero check` | Run `workflow.toml` checks in a bwrap sandbox; exit code is the verdict. | +| `loopzero check` | Run trusted-base checks with local bwrap or the configured runner. | | `loopzero pr` | Push and open a draft PR from the task file, with its Validation section rendered. | | `loopzero review` | Run one Claude or Codex review on the exact head; post it and append its summary under Review. Exits 0 on approval, 5 on changes requested. | | `loopzero ready [--wait[=SECONDS]]` | Verify head, findings and CI; optionally wait for required checks on that head. | diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 1d67cb81..e45b53ee 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -157,7 +157,7 @@ For a Codex executable installed inside protected native state, the implicit runtime mount exposes only the resolved executable and its existing sibling `codex-code-mode-host`, read-only. Neighboring history and configuration remain hidden; helper aliases into protected state and explicit state mounts fail closed. -Check, review, ready, merge, and status use the workflow at one remote-tracking +Check, pr, review, ready, merge, and status use the workflow at one remote-tracking delivery revision selected by the workflow at Git's local `origin/HEAD`. Missing trusted refs or workflows block these commands. An explicit `--config` supplies validated policy for bootstrap or operator overrides. @@ -497,8 +497,8 @@ command, version, sandbox configuration and the resolved base SHA. A stage runs fresh when a matched path cannot be identified as a readable regular file. The receipt fingerprint also binds the base SHA when reuse is configured, so advancing the base invalidates a pass at the same task head. -If the remote ref is absent, checks use the task's recorded base. Without -either base, local stages run fresh. +With explicit `--config`, reuse can fall back to the recorded task base if the +remote ref is absent. Without either base, local stages run fresh. The `"*"` entry adds shared inputs to listed commands. Unlisted commands reuse only when `"*"` includes `"."` (the whole tree); a partial or empty `"*"` leaves them unkeyed. Consumers own complete input declarations. From b96148b03f587a24d88563a8fd121473fe288832 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 07:53:03 +0100 Subject: [PATCH 5/5] Correct saved review path and repost options Architecture-Review: unchanged; the documented behavior matches the current CLI without changing the delivery interface. Co-Authored-By: Codex --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4a50355e..bc91acaa 100644 --- a/README.md +++ b/README.md @@ -48,8 +48,8 @@ GitHub; keep acceptance changes in both task.md and the PR by rerunning `pr`. Review publication records duration and distinguishes requested model/effort from CLI-reported claims, which are not backend attestation; saved artifacts preserve -them for `--repost`. The full transcript stays in `.loopzero/review--.json`; -`loopzero review --repost` uses it without rerunning the model. +them in `.loopzero/review--.json`. `loopzero review --repost` uses +the saved review without a model call and rejects `--model` and `--effort`. Waits observe immediately, then use 30/60/120-second intervals with up to 10% earlier jitter, bounded by the timeout. Each readiness observation rechecks