Skip to content

fix(review): make --max-tools a cap instead of a floor - #1687

Open
abhisheksharma2411 wants to merge 4 commits into
alibaba:mainfrom
abhisheksharma2411:fix/935-max-tools-cap-ignored
Open

abhisheksharma2411 wants to merge 4 commits into
alibaba:mainfrom
abhisheksharma2411:fix/935-max-tools-cap-ignored

Conversation

@abhisheksharma2411

Copy link
Copy Markdown
Contributor

Closes #935.

loadCommonContext only raises MaxToolRequestTimes when 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 50 through 100 were 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.

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.
@CLAassistant

CLAassistant commented Oct 10, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review complete: 0 finding(s) across 2 selected item(s).

@NanaseInori NanaseInori left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 kittimzhe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@chaojixinren

Copy link
Copy Markdown
Contributor

Could we update cli-reference.md and faq.md across locales? They still say --max-tools only raises the limit, which this fix changes for review.

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]>
@abhisheksharma2411

abhisheksharma2411 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Could we update cli-reference.md and faq.md across locales? They still say --max-tools only raises the limit, which this fix changes for review.

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.

@chaojixinren chaojixinren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

review: --max-tools 10-29 is accepted but silently ignored

6 participants