diff --git a/SETUP.md b/SETUP.md index 557f4782..0cc199fb 100644 --- a/SETUP.md +++ b/SETUP.md @@ -74,6 +74,14 @@ symlinked skill directory and resolve its relative links from the real files, so the contract and references stay reachable. Do not also keep copies of these skills in a repository: both would load. +Before resuming automated PR check refreshes or explicit PR resyncs after an +upgrade, advance every PR-body writer to the selected CLI revision. For +unverified receipt warnings, use a revision containing +[3ff80bd9 (#1160)](https://github.com/feder-positronics/loop-zero/commit/3ff80bd91c92f12d557cead31776df40d4328097). +Once the writers are updated, run `loopzero check` for the current head to +replace old receipts. If you roll back across that fix, pause those writes before +switching the CLI and resume them once the writers support the warning again. + If you roll back across [#732](https://github.com/feder-positronics/loop-zero/pull/732) after GitHub may have accepted a Claude review, run `loopzero review --repost` with the publishing CLI revision or a newer compatible revision. The rollback @@ -339,6 +347,29 @@ access to the configured GitHub repository even before a PR exists. See the [workflow diagram](docs/WORKFLOW.md#1-from-idea-to-merged) and [Blockers](core/CONTRACT.md#blockers) for the rest of the workflow. +### Check receipts with remote execution + +Run the current `loopzero check` coordinator from the task worktree with +the same effective settings used by `loopzero ready`. To execute stages +remotely, configure an operator-trusted `[checks].runner` that implements the +[stage protocol](docs/ARCHITECTURE.md#check-stage-runners). The local coordinator +writes the receipt. + +Without a stage adapter, run the whole check locally. Use a local slot if the +host requires one. On miki, run this from the task worktree. + +```sh +HEAVY_SLOT_REMOTE_HOSTS="$HOME/.cache/intelflo-scratch/locks/no-remote-hosts.json" "$HOME/.cache/intelflo-scratch/locks/heavy-slot.sh" loopzero check +``` + +A whole-job remote worker writes its own receipt. Ready can use it only if it +passes the existing checks for a clean, passing receipt at the exact head, +with the current ordered commands and matching settings fingerprint. An older +worker can omit the fingerprint. A current worker can produce a different +fingerprint, for example when its inherited `PATH` differs. GitHub required +CI supplies separate evidence. The [owner queue route](core/CONTRACT.md#blockers) +applies only under its documented conditions. + ## Removing an abandoned task worktree For a merged PR, retry cleanup from a durable directory with diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index bfe286f2..560b2481 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -504,4 +504,11 @@ Receipts that use saved stage results bind the current head and check settings. For delegated checks, both the receipt and the stage key bind the runner's launch path, resolved executable path and executable bytes. Unavailable runner identity prevents receipt reuse. + +A worker running the entire check is itself the coordinator and writes a +receipt with its own effective settings. Transferring it preserves the +fingerprint, if present. Local readiness applies the same receipt predicate +as for any other coordinator. See [check receipts with remote execution](../SETUP.md#check-receipts-with-remote-execution) +for the operator route. + CI and merge-queue candidates run fresh without a local worktree receipt. diff --git a/src/loopzero/cli.py b/src/loopzero/cli.py index b1393e13..df90da9c 100644 --- a/src/loopzero/cli.py +++ b/src/loopzero/cli.py @@ -628,6 +628,11 @@ def cmd_check(args: argparse.Namespace) -> int: print(f"check result discarded: checked HEAD {report.head}, current HEAD {current_head}", file=sys.stderr) return 1 + if report.ok and report.settings_sha256 is None: + print("check stages passed but the receipt is unverified; rerun loopzero check from the task " + "worktree with a stable, readable configured runner before running ready", file=sys.stderr) + _refresh_pr_checks(wt, config) + return 1 if report.ok and not report.dirty: _print_receipt(wt, report, "produced") _refresh_pr_checks(wt, config) diff --git a/tests/test_cli.py b/tests/test_cli.py index 51f3b12a..9d44b146 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -3063,6 +3063,43 @@ def change_policy(_seconds): assert run(capsys, *args, "check")[0] == 1 +def test_check_refuses_unverified_receipt_after_runner_retarget(wt, gh, capsys, head, tmp_path): + runner = tmp_path / "runner" + original = tmp_path / "runner-a" + replacement = tmp_path / "runner-b" + stage = ( + f"#!{sys.executable}\n" + "import json, sys\n" + "frame = json.load(sys.stdin)\n" + "del frame['env']\n" + "frame.update(exit_code=0, duration_s=0, not_started=False, tail='')\n" + ) + for target, extra in ( + (original, f"from pathlib import Path\np = Path({str(runner)!r})\n" + f"p.unlink()\np.symlink_to({str(replacement)!r})\n"), + (replacement, ""), + ): + target.write_text(stage + extra + "print(json.dumps(frame))\n") + target.chmod(0o755) + runner.symlink_to(original) + publish_workflow(wt, WORKFLOW.replace("[checks]", f"[checks]\nrunner = {json.dumps([str(runner)])}")) + arm_approved_ready_pr(gh, head, wt, readiness={"local_exit": None}, isDraft=False) + + code, out, err = run(capsys, "check") + assert code == 1 + assert "receipt produced:" not in out and "PASS" not in out + assert "stages passed but the receipt is unverified" in err + assert "rerun loopzero check from the task worktree with a stable, readable configured runner" in err + report = cli._load_report(wt) + assert report.head == head and not report.dirty and report.ok + assert report.settings_sha256 is None + assert run(capsys, "ready")[0] == 1 + + code, out, _ = run(capsys, "check") + assert code == 0 and "receipt produced:" in out + assert run(capsys, "ready")[0] == 0 + + @pytest.mark.parametrize("base_sensitive", [False, True]) def test_wait_snapshot_handles_trusted_base_advance(wt, repo, base_sensitive): if base_sensitive: @@ -3104,6 +3141,28 @@ def test_ready_matches_effective_inherited_check_environment( assert code == 1 and "not ready: check receipt has an incompatible settings fingerprint." in out +@pytest.mark.parametrize("worker", ["legacy", "different-path", "matching"]) +def test_ready_checks_transferred_whole_job_receipt(wt, gh, capsys, head, tmp_path, monkeypatch, worker): + arm_approved_ready_pr(gh, head, wt, readiness={"local_exit": None}, isDraft=False) + with monkeypatch.context() as worker_env: + if worker == "different-path": + worker_env.setenv("PATH", str(tmp_path / "worker-bin"), prepend=":") + assert run(capsys, "check")[0] == 0 + + receipt = wt / ".loopzero/checks.json" + payload = json.loads(receipt.read_bytes()) + if worker == "legacy": + # Older producers serialize these results without a settings fingerprint. + del payload["settings_sha256"] + # Whole-job transport preserves the producer's fields. + receipt.write_text(json.dumps(payload)) + assert run(capsys, "ready")[0] == (0 if worker == "matching" else 1) + + if worker != "matching": + assert run(capsys, "check")[0] == 0 + assert run(capsys, "ready")[0] == 0 + + def test_ready_ignores_forged_markers(wt: Path, gh: FakeGh, capsys, head) -> None: arm_approved_pr_with_check_result(gh, head, wt, "success", reviews=[rev(head, "primary", login="stranger"), rev(head, "primary", commit="1" * 40)]) code, out, _ = run(capsys, "ready") @@ -4795,19 +4854,28 @@ def test_generated_pr_body_limit(wt, gh, capsys, monkeypatch, create, extra): assert json.loads(writes[0]["--input"])["body"] == prose + suffix -def test_pr_marks_legacy_same_head_check_unverified(wt, gh, capsys): +@pytest.mark.parametrize("refresh", ["resync", "automatic"]) +def test_pr_marks_legacy_same_head_check_unverified(wt, gh, capsys, refresh): head = head_of(wt) - live = "# PR\n\n## Validation\nManual validation evidence.\n" + config = cli._load_config(SimpleNamespace(command="check", config=None), wt, pin_checks=True) + live = ("# PR\n\n## Validation\nManual validation evidence.\n\n" + "\n" + f"Recorded for `{head[:12]}`\n- `echo ok`: exit 0\n" + "\n") gh.respond_pr_list([pr_json(headRefOid=head, body=live)]) gh.respond(f"api repos/{REPO}/pulls/7 --method PATCH", {}) - cli._save_report(wt, CheckReport(head, False, (CheckResult("echo ok", 0, 0.0, ""),))) + stages = tuple(CheckResult(command, 0, 0.0, "") for command in config.checks) + cli._save_report(wt, CheckReport(head, False, stages)) + git(wt, "push", "-q", "-u", "origin", "lz/t1") - assert run(capsys, "pr")[0] == 0 + if refresh == "resync": + assert run(capsys, "pr")[0] == 0 + else: + cli._refresh_pr_checks(wt, config) draft = json.loads(gh.calls[-1]["--input"])["body"] assert "unverified" in draft and "run `loopzero check`" in draft assert "Manual validation evidence." in draft - git(wt, "push", "-q", "-u", "origin", "lz/t1") gh.respond_pr_list([pr_json(headRefOid=head, body=draft)]) assert run(capsys, "check")[0] == 0 draft = json.loads(gh.calls[-1]["--input"])["body"]