All writing

September 22, 2026 · 4 min read

Reviewing a 237k-character PR diff without truncation

A 200k cut-off made an automated review look complete while skipping the last 37,000 characters. Here is the chunking strategy that fixed it — and the failure modes it had to survive.

An automated review that silently skips part of a diff is worse than no review at all. The output looks finished. Nothing in the comment says "I stopped reading at 200,000 characters." The author merges, reasonably believing someone — or something — looked at the change.

That is what happened in my macOS app's CI. The review step capped the diff at 200k characters. On a 237k-character pull request, the last ~37,000 characters were never sent: a view model, a sidebar view and the tests. The review still returned a tidy list of findings.

Why truncation is the wrong failure mode

A size limit is a reasonable guard against runaway cost. The mistake is where the failure is reported. Truncating in the workflow, before the reviewer runs, hides the loss from every layer that could have said something about it.

The rule I took from this: if the system cannot review everything, it must either say so or fail. Silence is not an acceptable outcome.

Chunk on files, not characters

Splitting a diff at an arbitrary character offset breaks its grammar. A file header can land at the end of one chunk, its first hunk at the start of the next, and the model sees fragments with no context. It is also impossible to tell which findings belong to which file.

The replacement splits at diff --git boundaries: each chunk contains whole files, up to about 150k characters. One oversized file becomes a chunk by itself rather than being cut in half. The aim is not perfectly equal chunks; it is never reviewing half a file.

filter noise (docs, Markdown, Xcode project files)
        ↓
split on diff --git boundaries
        ↓
chunk ≤ 150k, whole files only
        ↓
review chunk 1 → findings
review chunk 2 with chunk 1 findings as context
        ↓
combine under "Review part N/M (files: …)"

Passing earlier findings forward matters. Without it, the model re-reports the same issue in every chunk, and the comment becomes noise. With it, the instruction is explicit: add only new findings.

Make the plan inspectable

The most useful addition was not the chunker; it was --dry-run. It prints the chunk plan — count, sizes, file lists — with no API key and no API call. That turns a costly experiment into a local check, and it makes CI behaviour debuggable without reading the source.

The PR exercised the pipeline on itself. Its raw diff was 237,777 characters. A dry run split it into two chunks of 90,324 and 105,130 characters across 13 and 4 files, with 41,787 characters of generated or documentation noise filtered out. All 22 source files were accounted for.

Failure modes worth designing for

  • A chunk fails after earlier ones succeed. Fail the run, but still print the findings that were produced. Partial information beats a blank comment.
  • The diff contains only docs. Print "No reviewable source changes" and exit 0. This is not an error.
  • Filtering or chunking loses a file. Abort loudly. A missing diff --git header is a bug in the tool, not something to work around.
  • The contract changes. Keep the same environment variables, output file, exit codes and error prefixes. A fix to an internal step should not become a migration for everyone who calls it.

The uncomfortable trade-off

Reviewing a large PR now costs more: more API calls, more latency, more tokens. There is no way around that if the goal is full coverage. The alternative is cheaper and less honest.

The test suite for the change is about 325 lines, which is more than the chunker itself. That is the right ratio for infrastructure: the part that decides what gets reviewed should be easier to trust than the review.

The pull request is #22 on GitHub, and the shorter engineering summary is in the open-source write-up.