Skip to content

Verify saved stage input keys before accepting check receipts - #1308

Closed
eowca wants to merge 2 commits into
mainfrom
lean178/1296-receipt-inputs
Closed

eowca wants to merge 2 commits into
mainfrom
lean178/1296-receipt-inputs

Conversation

@eowca

@eowca eowca commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Reject receipts when checkout bytes change

Git can rewrite a declared input from LF to CRLF while keeping the same head and reporting a clean checkout. Ready and merge now verify the saved stage keys against the bytes on disk.

Closes #1296

Validation

The offline regression reproduced the false ready verdict on current main. After the fix, an unchanged input passes readiness, both delivery commands reject the old receipt after Git rewrites the input, and a fresh check fails. The focused tests and size gate passed.


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

Review

  • primary, claude, 783bb8f, request_changes
  • delta, claude, c859414, request_changes

Architecture-Review: unchanged; local readiness still requires a current successful check receipt, now verified against the existing stage input keys.
Co-Authored-By: Codex <noreply@openai.com>
@eowca
eowca marked this pull request as draft November 26, 2026 01:29

@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 783bb8f8174d78c150177813a816a8008d8aaedc, 40.2s: request_changes (0 critical, 1 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)

Findings without a file location:

  • suggestion: The verification gate now hashes every declared input on each call, including status rendering and wait paths — _check_report_matches is used by _current_check_report (ready, merge, and the wait re-check at cli.py:1302) and by the status renderer at cli.py:416. With this change, each call runs git hash-object and git diff-tree per keyed stage and SHA-256s every matching file. With "*" = ["."] and N stages, that hashes the whole tree N times per call.

Two cheap improvements:

  • Compute each distinct pathspec set's blob and content digest once per call. Stages share the * paths, so only the command and settings parts of the key differ per stage.
  • Check result.input_key is not None before calling _input_key, so a None key short-circuits without the git and hashing work.

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

Comment thread src/loopzero/sandbox.py Resolved
Comment thread src/loopzero/sandbox.py Outdated
return all(result.input_key == _input_key(config, worktree, result.command, base)
and result.input_key is not None
for result in report.results if _keyed_stage(config, result.command))
except (SandboxUnavailable, OSError):

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: Git timeouts while recomputing keys escape instead of failing closed

_git goes through _proc.run, which raises ProcTimeout/ToolMissing on a timeout or a missing git binary. receipt_inputs_match catches only SandboxUnavailable and OSError, so these propagate out of ready/merge as errors rather than producing the "run loopzero check" result. This is not fail-open, but it differs from the stated behaviour of failing closed with a fresh-check prompt. Consider catching LoopZeroError here, or documenting that the gate is allowed to raise.

Architecture-Review: unchanged; stages without an input key keep their existing successful receipt semantics.
Co-Authored-By: Codex <noreply@openai.com>
@eowca
eowca force-pushed the lean178/1296-receipt-inputs branch from dfcb1c5 to c859414 Compare November 26, 2026 01:37

@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 c859414664413a56455f62a2b1e89f247ffc2637, 25.7s: request_changes (0 critical, 1 important, 1 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/sandbox.py
def receipt_inputs_match(config: Config, worktree: Path, report: CheckReport) -> bool:
try:
base = _check_base(config, worktree)
return all(result.input_key == _input_key(config, worktree, result.command, base)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

important: Treating None == None as a match brings back the stale-receipt bug for declared stages whose key cannot be computed

This delta removes the result.input_key is not None requirement for declared stages. receipt_inputs_match now passes whenever the saved key and the recomputed key are both None. _input_key returns None for a declared stage in several cases:

  • any declared path is a symlink or a non-regular entry (mode not 100644/100755, resolve() != path, or not S_ISREG);
  • diff-tree hits E2BIG;
  • any read raises OSError, ValueError, SyntaxError or RuntimeError;
  • _check_base returns "" because base resolution failed and there is no runner.

In any of these cases the receipt stops tracking the stage's regular files. Example: with "*" = ["."] and a tracked symlink (the setup in the new test), Git rewrites feature.py from LF to CRLF. The key is still None, so ready and merge accept the old receipt. That is the exact failure #1296 is meant to close, and it contradicts the task note to "fail closed if a declared stage key is missing or unavailable". A transient read error (EACCES, ELOOP) is also read as "unchanged" instead of "cannot be verified".

The new test test_ready_accepts_fresh_check_for_input_without_reuse_key locks in this fail-open behaviour. It never checks that a byte rewrite is still rejected in this setup.

Smallest fix: keep reuse eligibility separate from receipt verification. Reuse can stay disabled when a key is None. Verification should compute a digest that stays defined in these cases, for example by hashing symlink targets with os.readlink and recording entry modes instead of returning None, and should treat any remaining unavailability as a mismatch. If that is out of scope, restore the previous fail-closed check (result.input_key is not None for declared stages) and accept that ready is blocked for such inputs. Either way, add a regression test that rewrites feature.py with the symlink present and asserts that ready fails.

Comment thread src/loopzero/sandbox.py


def _input_key(config: Config, worktree: Path, command: str, base: str) -> str | None:
if not base or (command not in config.inputs and "." not in config.inputs.get("*", ())):

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: Inlined predicate drops a named helper

Removing _keyed_stage copies its condition straight into _input_key. The reason for that condition (which stages are declared and therefore keyed) is now implicit, and if receipt verification needs to tell declared stages apart again, as the finding above requires, the logic will get duplicated. Consider keeping the helper.

@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #1392. The replacement blocks when a declared stage key is missing or unavailable, has a fresh primary approval, and passed the full local check on its cap-updated head.

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.

Reject saved check passes when declared input bytes change

1 participant