Open source · Merged
Review every line of a 237k-character PR
The automated review truncated diffs at 200k characters and silently skipped the tail. File-boundary chunking made coverage complete — without changing the pipeline's contract.
The issue
Every pull request in the repository runs through an LLM review step. It is useful enough that people read it before merging — which made the failure mode dangerous rather than cosmetic: the workflow truncated the diff at 200,000 characters.
On a 237,000-character PR it dropped the last ~37,000 characters. The review came back looking complete. The tail — a view-model, a sidebar view and tests — was never seen. A reviewer cannot tell the difference between "no findings" and "never looked".
Root cause
Truncation happened inline in the workflow, before the review script ran. There was a single size guard and no concept of coverage: anything past the limit was cut, and nothing recorded that it had been cut. The script itself had one input and one API call, so a large PR had no path to being reviewed in parts.
The fix
-
Filter noise first. Docs, Markdown and Xcode project files
(
.xcodeproj,pbxproj, schemes) are removed before chunking. They are large, generated or prose — not source worth spending review tokens on. - Chunk on file boundaries. The remaining diff is split into chunks of at most 150,000 characters, by default, and never mid-file. An oversized single file becomes its own whole chunk rather than being cut in half.
-
Carry findings forward. Each chunk gets its own API call. Previous chunks'
findings are passed as context so the model adds new findings instead of repeating old ones.
Output is combined under
### Review part N/M (files: …). -
Fail loudly, never silently. A chunk failure after earlier successes fails
the run but still prints the earlier findings. A docs-only diff prints "No reviewable source
changes" and exits 0. If filtering or chunking would lose a
diff --githeader, the script aborts. -
Keep the contract. The same environment variables, output files, exit codes
and error prefixes still apply.
SKIP_PATH_PATTERNSandMAX_CHARS_PER_CHUNKare configurable without editing code. -
Add
--dry-run. It prints the chunk plan — count, sizes, file lists — with no API key and no API call, so the plan can be inspected in CI or locally.
Tests
-
A new 325-line test suite for the chunking and filtering logic
(
.github/scripts/test_ollama_review.py). - The PR reviewed itself. Its raw diff was 237,777 characters; a local dry run split it into two chunks (90,324 + 105,130 characters across 13 + 4 files) with 41,787 characters of noise filtered out.
- All 22 raw-diff files were accounted for, and the files that were previously cut are now covered.
- The Ollama Cloud PR review check passed on the PR.
Trade-offs
- More API calls. A large PR now costs two or more requests instead of one, so it is slower and more expensive. That is the price of actually reviewing the whole change.
- Carry-over context is not free. Passing earlier findings forward consumes tokens and can bias the model toward existing findings. It is still cheaper than re-reviewing the same files from scratch.
- File boundaries can exceed the limit. One enormous file cannot be split without breaking diff syntax. The script accepts that and sends the file whole, which is safer than a half-file review with missing line context.
-
Noise filtering is opinionated. Documentation changes will not be reviewed.
That is a deliberate default, and
SKIP_PATH_PATTERNSmakes it reversible.
Result: coverage is complete for any PR size, and the pipeline says so when it cannot review something instead of quietly truncating.