Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Unwrapped long line in reflowed paragraph

The edited paragraph leaves 'failures still replace passes. Runners cannot select stages or mint receipts. Stage admission' on one line, much longer than the surrounding wrap width. Reflow the paragraph to match.

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.
Expand Down
9 changes: 7 additions & 2 deletions src/loopzero/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_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 = {
Expand All @@ -375,6 +375,11 @@ 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_checks is not None else None
if (saved is not None and saved.ok and not saved.dirty and saved.head == report.head

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Guard treats any same-head/same-settings pass as authoritative, even if its check list differs

The checks list is not part of settings_fingerprint; the fingerprint only covers execution settings and inputs. Suppose checks.commands changes but the settings do not, at a head that already has a clean pass under the old list. _check_report_problem rejects that old pass for readiness because the command tuple differs. Even so, every checkpoint from the new run is dropped. If the new run is interrupted, its stage progress is lost. Readiness stays correct, so the only cost is reuse. Smallest fix: also require tuple(r.command for r in saved.results) to equal the checkpoint's leading command list, for example by comparing against report.results[:len(saved.results)] commands. Alternatively, pass the configured checks into _save_report and reuse _check_report_problem, so 'what counts as a pass' is not defined in a second place.

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

Expand Down Expand Up @@ -598,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=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
Expand Down
20 changes: 20 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -4763,3 +4764,22 @@ 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):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Regression drives the internal helper instead of an actual interrupted overlapping run

The test calls sandbox._checkpoint_success and _save_report by hand. That proves the guard behaves as intended, but nothing covers the cmd_check wiring (checkpoint=True at cli.py:605) or the interruption path, where the final _save_report is never reached. That path is what the acceptance criteria describe. Consider a test that stubs sandbox.run_checks and calls its checkpoint callback after a pass has been saved, then raises (for example KeyboardInterrupt). This would catch a regression where the keyword is dropped from the cmd_check lambda.

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_checks=cfg.checks), passed, {}, ())
assert cli._load_report(wt).results[0].input_key == "key"
save(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
Loading