Orca-Code-Review/scripts/diff-guard.mjs
Zhenghua Bao 6d253e0399
feat: raise the diff limits so a large PR gets reviewed instead of refused (#53)
512 KB / 300 files / 20 minutes becomes 5000 KB / 2000 files / 60 minutes.

The old limits were a ceiling on WASTE — chosen so tokens were not spent on
diffs that review badly. The side effect was that a large PR could never be
reviewed at all, and "never" is worse than "expensive". Size alone was never
the right test either: the engine reads the diff through its own tooling rather
than taking it as one prompt, so a 2 MB diff is not automatically beyond it.

What does bound it is the model's context window, which the action cannot see —
it is given a model string, and the actual route is the workspace's recipe. So
this trades a clean, cheap refusal for a real attempt that may end in a
wall-clock timeout or an aborted pass. That is a deliberate trade and it is
written into the input description, including how to get the old behaviour back
(lower the number).

The timeout had to rise with the limits, not after them. At 20 minutes a review
allowed to accept a much larger diff would have been killed halfway — the same
non-review as before, with a worse message. It is a per-pass ceiling and
`exhaustive` makes up to three passes, which is now worth saying out loud
because 3x60 is a different proposition from 3x20.

The two limits are counted separately because they describe different shapes: a
mechanical rename across 900 files is small and shallow, one 4 MB generated
file is large and shallow, and either can be worth reviewing.

Every place that states these numbers moved together — the inputs, the guard's
own fallbacks, the oversized-diff notice posted on the PR (whose example values
were 1024/500, which after this change would have been advice to LOWER the
limit), the example workflow, the skill's workflow template, and the skill's
input and troubleshooting references.

The guard's fallbacks are pinned to the inputs by a test now, because they are
one number in two places and the second one is reachable: action.yml passes
`--max-kb "$MAX_KB"` quoted, so `max-diff-kb: ""` arrives as an empty argument
and lands on the fallback. A stale number there would enforce a limit nobody
documented, silently. The test reads the default out of action.yml rather than
restating it, and is mutation-checked in both directions — editing only the
script reds it, and so does editing only action.yml.

That test also turned up a defect in itself, which is worth recording because
its failure mode was invisible: it anchored on bare "\n" while this repo has no
`.gitattributes` and `core.autocrlf` is the Windows default, so action.yml is
CRLF in every Windows checkout. It would have passed on Linux CI forever and
failed on every developer machine — and CI green reads as "works". Newlines are
normalized on read now, mutation-checked against the CRLF working copy.

567 tests, 558 passing, failure set identical to main's (9 pre-existing and
unrelated). The file-count fixture is ~180 KB, far under the size limit, so it
still tests the count and not the size.
2026-09-09 15:02:50 +08:00

121 lines
4 KiB