Skip to content

Check local receipts before remote readiness gates - #1833

Closed
eowca wants to merge 4 commits into
mainfrom
lean178/1405-receipt-first-r54
Closed

eowca wants to merge 4 commits into
mainfrom
lean178/1405-receipt-first-r54

Conversation

@eowca

@eowca eowca commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Check local receipts before remote readiness gates

Context and goal

Closes #1405

Acceptance

  • Ready and merge --wait resolve the PR, validate its head and hold, and reject an invalid local receipt before any remote readiness read. The open-branch replay uses two REST reads and performs no writes or polling.
  • A receipt replaced during remote gate evaluation blocks readiness and writes. Polls retain workflow-change diagnostics, including when a fresh receipt exists for the new settings.
  • Valid receipts still run the existing gates. Status keeps comprehensive diagnostics, and already-merged cleanup remains available.

Validation notes

  • Focused replays passed for ready and Mergify merge --wait, including both parked blockers.
  • Source delta +18, test delta 0. The bounded discovery uses the existing head-filtered list and detail path while preserving transient retry behavior.

Base

Base: 5cfb9c2

Validation

Recorded for 5d027df00ce4

  • uv run --group dev ruff check src tests: exit 0
  • uv run --group dev tach check: exit 0
  • uv run --python 3.14 python scripts/check_architecture_docs.py: exit 0
  • scripts/size_budget.sh: exit 0
  • uv run --group dev pytest -q: exit 1

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Review

  • primary, claude, a1ae38b, request_changes
  • delta, claude, 5d027df, approve

Co-Authored-By: Codex <noreply@openai.com>

@loopzero-feder-positronics loopzero-feder-positronics Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

loopzero primary review by claude on a1ae38bee80738795f2a6d0244eb8791d4577f2e, 64.9s: request_changes (0 critical, 1 important, 3 suggestion)

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)

Findings without a file location:

  • suggestion: Mergify mark_confirmed write is not guarded by the receipt recheck — This change adds _require_receipt before mark_ready, mergify.request and github.merge. It does not add one before mergify.mark_confirmed (cli.py:1748), which is also a remote write on the merge path. It runs after readiness and the extra mergify.markers/membership reads. The acceptance criteria say a receipt replaced during gate evaluation should block writes. If that covers queue bookkeeping, add the same check before mark_confirmed. Otherwise, document that it is exempt.

Native Claude output is retained in the restricted local review receipt.

Comment thread src/loopzero/cli.py Resolved
Comment thread src/loopzero/github.py
if open_matches:
newest = max(open_matches, key=lambda row: (row["created_at"], row["number"]))
return _confirm_branch_pr(repo, branch, endpoint, newest["number"], "OPEN")
if not list_only:

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: list_only makes ready/merge find PRs differently from status and merge --cancel

list_only=True skips the commit-association lookup (_commit_branch_prs) that is still the main path for status (cli.py:1898), merge --cancel (cli.py:1775) and other _require_pr callers. After this change, ready/merge take the open PR from the head-filtered list, while the other commands take the newest commit-associated PR. These can disagree, for example when the list endpoint lags after a PR is opened or reopened. The diff adds no test of pr_for_branch(list_only=True) in test_github.py. Consider either moving all callers to one lookup or adding a test that pins the two-read contract and the open-before-closed fallback order.

Comment thread tests/test_cli.py
(True, "dirty", "check receipt was recorded in a dirty worktree."),
(True, "commands", "check receipt's plan differs from the trusted workflow."),
*((True, condition, "check receipt is incomplete.") for condition in ("empty", "checkpoint")),
@pytest.mark.parametrize("command", ["ready", "merge"])

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: Rewritten receipt test drops the valid-receipt and recovery-hint cases

The old parametrization included (False, "matching", None), which checked that ready succeeds with a current receipt. It also asserted the full recovery text for legacy/incompatible ("Run loopzero check in this worktree at this head with the same current CLI ..."). The new test_delivery_requires_current_receipt only checks failures and a reason prefix. The 'Valid receipts still run the existing gates' acceptance point and the recovery guidance now depend on coverage elsewhere. Consider adding back a valid case that expects exit 0 and receipt accepted: for both ready and merge.

eowca and others added 3 commits November 26, 2026 12:18
Architecture-Review: unchanged; readiness still checks the receipt before gates and gated writes.
Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; the state isolation and readiness ordering both remain in effect.
Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; this clean base merge preserves the readiness change.
Co-Authored-By: Codex <noreply@openai.com>

@loopzero-feder-positronics loopzero-feder-positronics Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

loopzero delta review by claude on 5d027df00ce4db0de0e7408b3b4b25997e64000a, 32.2s: approve (0 critical, 0 important, 2 suggestion)

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)

Native Claude output is retained in the restricted local review receipt.

Comment thread src/loopzero/cli.py
return sha
confirmed = state is not None
if confirmed and not confirmed_marker:
_require_receipt(wt, config, pr.head_sha)

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: New receipt guard before mark_confirmed has no test and is applied inconsistently

The new _require_receipt before mergify.mark_confirmed only runs when the PR is already in the Mergify queue and has no confirmed marker. No test in this delta reaches that state. In the during-gates merge case, membership is None, so the run takes the request path, which was already guarded at line 1752. Also, this write does not admit anything: the PR is already queued. If the receipt is invalid, the command errors, but the PR stays in the queue and can still land. It is just left without the confirmed marker. The same marker write in _wait_for_mergify (line 1698) stays unguarded. Pick one rule and apply it to both: guard both marker writes, or guard neither and keep receipt checks only on admission writes (request and merge). Then add a parametrized case for the guarded path, for example membership returning a state with confirmed_marker=False and the receipt removed during gates.

Comment thread tests/test_cli.py
report["settings_sha256"] = "0" * 64
if condition == "transient":
monkeypatch.setattr(github, "_retry_sleep", lambda _: None)
gh.respond(pr_list_key(), {"stdout": "", "exit_code": 1, "stderr": "HTTP 503"}, [{"number": 7}])

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: The transient case also unlinks the receipt, so it mixes two conditions

The transient case removes the receipt and also injects a 503 on the PR list. It checks that a retry happens before the receipt is rejected. It never checks that a transient error with a valid receipt still goes on to the remote gates. That is fine for the acceptance criteria, but the test name suggests broader coverage. Consider naming it missing-after-transient, or add a valid-receipt transient replay, so that a regression that drops the retry for valid receipts would be caught.

@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #1842. The approved head’s full check caught the exact Git-call assertion after worktree ownership validation landed. The authorized replacement retains the guarded receipt reads, updates the bound in the existing test, and seeks fresh primary review.

@eowca eowca closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check the local receipt before fetching remote readiness evidence

1 participant