Skip to content

Keep PR content from hiding changed code from the reviewer - #1366

Closed
eowca wants to merge 7 commits into
mainfrom
lean178/1101-reviewer-diff-integrity-2
Closed

eowca wants to merge 7 commits into
mainfrom
lean178/1101-reviewer-diff-integrity-2

Conversation

@eowca

@eowca eowca commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Keep PR content from hiding changed code from the reviewer

Context and goal

  • Goal: The reviewer always receives the changed lines of every text file in a PR, or an explicit line naming any file it is not shown; a PR can no longer make changed code disappear from review.
  • Problem: The reviewer's diff honoured the PR's own .gitattributes and git's "contains a NUL byte" binary guess, so a changed text file could arrive only as "Binary files … differ". When a large diff was reviewed in chunks, a modified file whose added lines contained the text git uses for deleted files was replaced by ": deleted, N lines". In both cases an approval could cover code the model never saw.
  • Context: diff_since builds the review material with git diff in the task worktree. split_diff cuts diffs that exceed the reviewer's size budget into chunks and shortens deleted files to a one-line summary.

Closes #1101

Acceptance

  • A PR that adds .gitattributes marking changed text files -diff or binary still gives the reviewer those files' hunks.
  • A changed UTF-8 text file containing a NUL byte is shown as text. A file whose content at HEAD (at the base when deleted) is not UTF-8, such as a real binary, keeps Git's header line and gets "content not shown: not UTF-8 text, N bytes", never as a bare "Binary files differ".
  • In split_diff, a modified file whose added lines include the deletion header text keeps its hunks; only files git's header reports as deleted are summarized.
  • Tests in tests/test_worktree.py cover all three cases with a real temporary git repository.

Notes

  • Replaces PR Keep PR content from hiding changed code from the reviewer #1206: its repair commits after the second (delta) review need review coverage, and the contract puts a head that needs another review in a new PR. This PR carries the same change plus those repairs, merged with current main; Keep PR content from hiding changed code from the reviewer #1206's review threads record the earlier findings and their dispositions.
  • Design pass (trust boundary): the reviewed head and, for delta reviews, the earlier reviewed head are PR-controlled; their .gitattributes and file bytes are untrusted. Invariant: every changed path appears in the material, with its changed lines when the content is UTF-8 text. Chosen approach: git diff --text --no-ext-diff --no-textconv (verified locally: --text overrides -diff/binary attributes and NUL detection), read losslessly as Latin-1 and decoded strictly per file block; deletion judged only from the header before the first hunk. Attributes are not taken from the base because a delta's base is itself a PR head.
  • Regression proof: both new tests in tests/test_worktree.py fail on pre-fix source and pass after.
  • Earlier review round one (Codex on Keep PR content from hiding changed code from the reviewer #1206): files are now classified from their own content, not from the patch, so UTF-8 additions survive a non-UTF-8 old side and a non-UTF-8 byte outside the diff context still yields the notice; Git output is read as bytes, so a bare carriage return in a file cannot fake a file boundary; output is no longer trimmed; notices and deletion summaries keep Git's own (quoted) header line instead of re-parsing paths; deletion needs a whole deleted file mode header line. Regression tests fail at the reviewed head.
  • Earlier review round two (Codex delta on Keep PR content from hiding changed code from the reviewer #1206): classification uses full object IDs (--full-index), so an abbreviated ID cannot resolve as a ref name; the batch reader consumes every payload, so a submodule commit cannot shift later results (test fails at the delta-reviewed head); object IDs are deduplicated and blobs are validated in 64 KiB chunks instead of buffered whole. Not taken: notices for rename-only or mode-only changes, which change no content and are fully shown by Git's rename/mode lines. This was the last review round under the budget.
  • Review round one on this PR (Codex): submodule pointers are diffed even when .gitmodules says ignore = all; the batch reader fails closed on EOF, a truncated payload or a 120 s stall (only a missing object, such as an unfetched submodule commit, is skipped); SHA-256 object IDs are matched at full length. Not taken: classifying before materializing patches for very large binaries, since review material is already bounded by the PR's own size, as for text diffs, and the restructure adds Git calls and code.
  • Trade-off: a binary file that happens to be valid UTF-8 is shown as text (harmless); split_diff already bounds oversized material.

Base

main @ b69efec
Base: b69efec

Validation

Recorded for 70e478b77be9

  • 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 0

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

Review

  • primary, codex, 03267ea, request_changes
  • delta, codex, 70e478b, request_changes

eowca and others added 6 commits November 26, 2026 01:03
The reviewer diff now treats every file as text and ignores attributes
and diff drivers the PR could set, so a PR-added -diff/binary attribute
or a NUL byte no longer reduces a changed text file to "Binary files
differ". A file block that is not UTF-8 is replaced by its path and size.
Chunked review summarizes a file as deleted only when git's header says
so, not when its added lines contain the header text.

Closes #1101

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
diff_since now reads Git's output as bytes, so a bare carriage return
cannot fake a file boundary, keeps it untrimmed, and decides whether to
show a file from its HEAD (or deleted base) blob rather than the patch.
Notices and deletion summaries keep Git's own header line, and only a
whole "deleted file mode" header line marks a deletion.

Refs #1101

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reviewer diff now carries full object IDs, so classification cannot
resolve an abbreviated ID as a ref name. The single cat-file batch reads
each object once, consumes every payload (submodule commits included)
and validates UTF-8 in bounded chunks instead of buffering whole files.

Refs #1101

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-diff-integrity

# Conflicts:
#	tests/test_cli.py
…-diff-integrity-2

# Conflicts:
#	src/loopzero/runners.py
#	tests/test_cli.py
Folds the submodule case into the main diff test and tightens fixtures so
the test suite stays under its line cap after merging main.

Refs #1101

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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 codex on 03267eac62741a9ef20177ccfbe5765a3bcbd42a, 58.4s: request_changes (0 critical, 3 important, 1 suggestion)

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

  • Call 1: requested model gpt-6.2-astra (effort medium); CLI-reported model gpt-6.2-astra (effort medium); configured model gpt-6.2-astra (effort medium)
Raw reviewer output
Native Codex transcript retained in the restricted local review receipt; public evidence is publisher-derived, not backend attestation. Exact raw SHA256: 61980486554599f7e0e7cf6e93b16efa8b99b9affc2989ac0dfba993687d4c5a

Comment thread src/loopzero/worktree.py Resolved
Comment thread src/loopzero/worktree.py Resolved
Comment thread src/loopzero/worktree.py Resolved
Comment thread src/loopzero/worktree.py Outdated

def _content_side(block: bytes) -> tuple[str, str] | None:
# Full object IDs: an abbreviated one could resolve as a ref name instead.
index = re.search(rb"(?m)^index ([0-9a-f]{40}|[0-9a-f]{64})\.\.([0-9a-f]{40}|[0-9a-f]{64})",

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: Match the entire destination object ID in SHA-256 repositories

The second alternation accepts 40 hex characters without checking what follows, so it truncates every 64-character destination ID. This reintroduces abbreviated lookup for precisely the side used to classify additions and modifications. Require a space or end of line after the ID and assert that _content_side preserves both full lengths.

The reviewer diff now ignores .gitmodules ignore settings, the blob
classifier fails as a Git error on EOF, truncated payloads or a stalled
reader, and SHA-256 object IDs are matched at full length.

Refs #1101

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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 codex on 70e478b77be9b420ae457fadcd61c9193332de1b, 13.2s: request_changes (0 critical, 1 important, 0 suggestion)

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

  • Call 1: requested model gpt-6.2-astra (effort medium); CLI-reported model gpt-6.2-astra (effort medium); configured model gpt-6.2-astra (effort medium)
Raw reviewer output
Native Codex transcript retained in the restricted local review receipt; public evidence is publisher-derived, not backend attestation. Exact raw SHA256: 8f605b22c77100973003a2386f1f241d6aaa8d911dfc61216dea7b7eab8a4fbf

Comment thread tests/test_worktree.py Resolved
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Parked at 70e478b (delta-reviewed; every finding fixed or answered). Blocked only by the size gate: merged with current main, tests are 13,538 lines against the 13,500 cap (this PR adds 55; main is at 13,483). Next: once the test cap is raised, rerun loopzero check in this worktree (the local receipt's settings fingerprint is stale after main's trusted settings moved), then loopzero ready --wait and loopzero merge --wait. The delta finding on the EOF test is to be fixed in a test-only follow-up PR after this merges.

@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #1511: this PR's reviewed head merged with current main, with the conflict against #1353 (exact byte patches, escaped non-UTF-8) resolved on top of main's version. The non-UTF-8 notices and their batch reader were dropped because main already shows that content escaped, so the planned EOF-test follow-up is no longer needed. Findings and dispositions stay recorded in this PR's threads.

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.

security: Keep PR-controlled content from hiding changed code from the reviewer

1 participant