Repository navigation
fix(review): make --max-tools a cap instead of a floor - #1687
abhisheksharma2411 wants to merge 4 commits into
Conversation
Closes alibaba#935. loadCommonContext only raised MaxToolRequestTimes when the flag exceeded the template default, so review's --max-tools 50..100 was accepted, clamped to the minimum, and then ignored. The template default is 100, so every value in that range left the run on 100 rounds with no warning. A cost guard looked active while nothing had changed. Review now sets the budget to exactly the value given. Scan is untouched: its flag help says "only takes effect when greater than template default", so raise-only is the documented contract there, not a bug. Verified the reproduction first: asking for 60 left the effective limit at 100. The test fails with that exact symptom if the raise-only condition comes back.
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 2 selected item(s). |
NanaseInori
left a comment
There was a problem hiding this comment.
Applying the override after loadCommonContext fixes values below the template default being ignored. The later effort selection only changes review rounds, so it does not overwrite this tool-round value. Zero still retains the default, and scan behavior is unchanged. No blocking issue found.
The existing CLI minimum of 50 still applies; this change does not make values below 50 effective as entered. A test through validateReviewOptions would make that boundary clearer.
kittimzhe
left a comment
There was a problem hiding this comment.
Verified locally on the PR branch — correct fix for #935, and the surrounding semantics hold together better than the description claims. Details for the record:
Local run: all three new tests pass (TestMaxToolsCapLowersTheBudget, TestMaxToolsCapStillRaises, TestMaxToolsZeroKeepsTemplateDefault).
Flag-help audit: the asymmetry this PR institutionalizes is already documented on both sides — review's flag (shared_flags.go:57) says "max tool call rounds per subtask (0 = template default; min 50)" (cap semantics), while scan's (:235) says "only takes effect when greater than template default" (floor semantics, and scan_cmd.go:138 re-applies the floor explicitly). So no docs follow-up is hiding here.
Path audit: delegate_cmd.go:105 builds a reviewOptions without maxTools, but that's the preview path (file selection only — no review loop runs), so the cap has nothing to govern there. The only full-review entry point is executeReviewContext, where the cap is applied. No gaps.
Edge: the min-50 clamp (shared_flags.go:145) warns and raises before the cap ever sees the value, so applyMaxToolsCap only ever receives 0 (keep default) or ≥50 — the three tests cover exactly that domain.
One non-blocking note: for review runs, the raise inside loadCommonContext is now dead work (the cap immediately overwrites it), but scan still needs it, so the layering is awkward-by-necessity rather than wrong. If that ever bothers anyone, hoisting the raise out of loadCommonContext into scan's path would make each command own its semantics — pure follow-up material, not for this PR.
|
Could we update |
cli-reference.md and faq.md in all five locales still said the flag only ever raises the limit, which this PR changes for ocr review. Say it is a cap in both directions there, and note that scan's flag of the same name still only raises. The 1-49 clamp is unchanged: flag validation raises those to 50 before the template is loaded, so the cap never goes below the documented minimum. Signed-off-by: Abhishek Sharma <[email protected]>
Done — cli-reference.md and faq.md in all five locales. One thing I scoped deliberately: it's a cap for ocr review only. Scan registers its own --max-tools that still only raises, and loadCommonContext is unchanged, so saying it repo-wide would have been wrong. Each locale now says the review flag works both ways and notes scan's is unchanged. I also kept the "1–49 is raised to 50" line. That clamp happens in flag validation before the template loads, so the cap can't go under the minimum. |
Rebuilt on top of lizhengfeng101's merge of main (d864a3c) rather than over it -- the branch had moved on the remote while this was worked on locally. main has since landed resolveReviewMaxTools, which is the same fix this branch made for the review path. That half is dropped: applyMaxToolsCap is gone and review_cmd.go keeps main's call. main also rewrote the --max-tools docs in all five locales, so those take main's wording and the earlier docs commit here is superseded by it. What is left is the half of alibaba#935 main did not touch. scan owns scan_template.json and applied --max-tools to it as an only-raise override, so a value under the scan default was accepted and then ignored -- which is why the docs this branch wrote had to carve out an exception for scan. The exception is gone instead: scan goes through the same helper, now named resolveMaxTools since it serves both commands. The template build moved into loadScanTemplate to give the test a seam. The helper was always correct and what broke was scan not calling it, so a test of the helper alone would pass with the old override back in place. Verified by putting it back: the test fails with 60 instead of 59. Signed-off-by: Abhishek Sharma <[email protected]>
Closes #935.
loadCommonContextonly raisesMaxToolRequestTimeswhen the flag is bigger than the template default. Review's default is 100 and the flag clamps to a minimum of 50, so--max-tools 50through100were accepted and then ignored. No warning, so a cost guard looked like it was on.Review now sets the budget to exactly the value given.
Scan is untouched. Its flag help says "only takes effect when greater than template default", so raise-only is the documented behaviour there rather than the same bug.
I reproduced it before changing anything — asking for 60 left the effective limit at 100. The new test fails with that same symptom if the raise-only condition comes back.
The numbers in the original report have shifted (it says 10-29 against a default of 30); the mismatch is the same one.
go test ./cmd/opencodereview/passes.AI/LLM disclosure
I used Claude Code (Anthropic) to help write this fix and its tests. I reviewed it all and can explain any of it.