fix(review): keep the bounded review diff actually within its char budget - #10071
Conversation
…dget `keepHighSignalHunks` promised to fit a file's patch into `budget` chars but could exceed it three ways: the ≥2-hunk path force-kept the highest-signal hunk WHOLE when none fit, and appended the dropped-hunk notice AFTER selecting, and the single-hunk path sliced to exactly `budget` then appended the truncation notice on top. So the "bounded" diff the reviewer prompt is built from was not bounded. Reserve the notice length before selecting hunks (not after); when no whole hunk fits, return the highest-signal hunk's CONTENT truncated to fit — the same shape the single-hunk path already uses — never nothing, never over budget. The single-hunk path reserves the notice too. `buildUnifiedReviewDiff` reserves the "…diff truncated" line's length in each file's body budget so appending it on the break can never push the total over, upholding its own boundary invariant. Kept hunks are still emitted in file order; the signal ranking, DEFAULT_DIFF_BUDGET, diffFilePriority parity, and the patch-less-file listing are unchanged. Closes JSONbored#10017
|
Tip ✅ LoopOver review result - approve/merge recommendedReview updated: 2026-07-31 06:30:25 UTC
Review summary Nits — 5 non-blocking
Decision drivers
Context & advisory signals — never blocks the verdict
Linked issue satisfactionAddressed Review context
Contributor next steps
Signal definitions
🧪 Chat with LoopOverAsk LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.
Full command reference: https://loopover.ai/docs/loopover-commands 🧪 Experimental — new and may change. 🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.
|
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10071 +/- ##
==========================================
+ Coverage 79.57% 79.60% +0.02%
==========================================
Files 282 283 +1
Lines 58664 58752 +88
Branches 6842 6877 +35
==========================================
+ Hits 46682 46769 +87
Misses 11694 11694
- Partials 288 289 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
What & why
src/review/review-diff.tsis the bounded diff builder for the reviewer prompt, and its contract — stated in three doc comments — is that the diff fits a charbudget.keepHighSignalHunksdidn't hold it:… (N dropped)notice after selecting hunks, sokept + noticecould exceedbudget.budget, then appended the truncation notice on top.So the "bounded" diff fed to the 120B review models was not actually bounded.
The fix
buildUnifiedReviewDiffreserves the…diff truncated (N files total)line's length in each file's body budget, so appending it on theremaining < 240break can never push the total over — upholding its own boundary invariant.Unchanged: the signal ranking, kept-hunks emitted in file order,
DEFAULT_DIFF_BUDGET(80,000),diffFilePriority's ordering and its@loopover/engine/review-grounding.tsparity (untouched — engine-parity drift-check passes),addedLineCount/splitHunks/patch-less-file listing.Tests (
test/unit/review-diff.test.ts)keepHighSignalHunks(patch, budget).length <= budgetfor the ≥2-hunk no-hunk-fits case, the single-hunk case, and a spread of budgets/hunk-counts (fail onmain).budget: 100→<= 100and contains a char of the higher-signal hunk's added lines.budget: 50over a 5,000-char patch →<= 50.buildUnifiedReviewDiffnever exceeds budget across budgets 50–2000, even with the truncation notice appended.Validation
npm run typecheckclean for this file;npm run engine-parity:drift-checkpasses; the review-diff suite (31 tests) green.review-diff.tsis 100% line and branch.git diff --check <base> HEADclean; single-file source change + its test.Closes #10017