agent's unified-diff parser broke on binary patch sections of the PR
Fixes a unified-diff parser that crashes or misparses on binary file sections of a PR. Use it when the parser throws or produces garbage on binary patches. Key trigger: parser errors on 'Binary files differ' sections or on hunks that never appear for binary files.
TL;DR: Binary files do not have hunks - the diff just says the binary files differ and moves on. A parser that blindly expects hunk headers after every file header will choke there. Detect the binary marker line, record the file as binary with no line content, and skip to the next file header. Binary files get a file-level note, never line comments.
agent's unified-diff parser broke on binary patch sections of the PRReproduce with the failing diff. Isolate the section where the parser breaks and confirm it is the binary marker ("Binary files [a] and [b] differ") rather than a hunk. Expected: the break point sits exactly on the binary marker line.
Add an explicit branch in the parser: when the marker appears, record the file with a binary flag and empty hunk list, then resume scanning at the next file header. Expected: the parser walks past binary sections without error.
Guard the hunk-parsing loop as well. If a file header is followed by neither hunks nor a binary marker (truncated or odd diffs), skip the file with a warning instead of crashing. Expected: malformed sections degrade to warnings, never exceptions.
Make downstream code respect the binary flag. Line-comment logic must refuse binary files and the reviewer should emit a file-level note ("binary file changed, not line-reviewed") instead. Expected: no attempt to attach line comments to binary content.
Also handle the "GIT binary patch" literal/delta format, which appears when binary diffs are emitted in full. Treat any binary-patch block as opaque and skip it the same way. Expected: both terse and full binary formats parse cleanly.
Re-run the parser over the original failing PR diff. Expected: the full diff parses, binary files are flagged, and text files are unaffected.
Use this when
- The diff parser crashes on binary file sections
- "Binary files differ" lines break hunk parsing
- The agent tries to line-comment on images, archives, or compiled assets
- Diffs contain a mix of text and binary changes
Not for this skill when
- The parser breaks on renamed-file hunks (different header, different fix)
- The parser fails on collapsed generated-file markers (different marker, different fix)
- The diff itself is truncated by the API (that is a fetch/pagination problem)
- Binary files are legitimately the review target (then review the file bytes directly, not the diff)
Variant phrasings
- "diff parser crashes on binary files"
- "handle Binary files differ in diff parser"
- "parser expects hunks but file is binary"
- "skip binary patches when parsing PR diff"
Why it happens
Parser authors test against text diffs, where every file header is followed by hunk headers. Binary files violate that shape: there are no line-based changes to show, so git emits a single marker line. A state machine that only knows "header then hunks" has no transition for the marker and either throws or misreads the next file's header as hunk content.
Edge cases
- A file that flips between text and binary across commits (a script replaced by a compiled blob) needs the binary flag decided per diff, not per path.
- Large binary files can still dominate fetch size even when parsing is fixed. Exclude known binary paths from patch fetching when you only need text review.
- Some tools emit "Binary file [path] differs" with slightly different wording. Match on the word "Binary" case-insensitively rather than the exact sentence.
- Diffs with --text forced on binary files produce garbage hunks. Prefer detecting the binary flag over parsing those hunks.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_Rsijhc2UtPLjoUmUDTavug