alibaba/open-code-review · error
--max-tools must be a non-negative integer (0 means use temp
Error message
--max-tools must be a non-negative integer (0 means use template default)
What it means
validateReviewOptions requires --max-tools to be >= 0; 0 is allowed and means 'use the template default'. Negative values are rejected. Additionally, a positive value below the minimum of 50 is not an error but is clamped up to 50 with a stderr notice.
Source
Thrown at cmd/opencodereview/shared_flags.go:141
func validateReviewOptions(opts *reviewOptions) error {
if err := validateDiffMode(opts.from, opts.to, opts.commit); err != nil {
return err
}
if opts.preview && opts.resume != "" {
return fmt.Errorf("--preview and --resume cannot be used together")
}
if err := validateAudience(opts.audience); err != nil {
return err
}
normalizedFormat, err := validateOutputFormat(opts.outputFormat)
if err != nil {
return err
}
opts.outputFormat = normalizedFormat
const minMaxTools = 50
if opts.maxTools < 0 {
return fmt.Errorf("--max-tools must be a non-negative integer (0 means use template default)")
}
if opts.maxTools > 0 && opts.maxTools < minMaxTools {
fmt.Fprintf(os.Stderr, "[ocr] --max-tools %d is below minimum %d, using %d\n", opts.maxTools, minMaxTools, minMaxTools)
opts.maxTools = minMaxTools
}
if opts.maxGitProcs < 0 {
return fmt.Errorf("--max-git-procs must be a non-negative integer (0 means use default 16)")
}
if opts.maxTokens < 0 {
return fmt.Errorf("--max-tokens must be a non-negative integer (0 means use configured or template default)")
}
if opts.maxTokensBudget < 0 {
return fmt.Errorf("--max-tokens-budget must be a non-negative integer (0 means unlimited)")
}
if opts.effort != "" {
if _, err := template.ParseEffort(opts.effort); err != nil {
return fmt.Errorf("--effort: %w", err)
}View on GitHub (pinned to 5cf97d0d15)
Solutions
- Pass a non-negative integer: --max-tools 0 to use the template default
- Clamp in your script: MAX_TOOLS=$(( value < 0 ? 0 : value ))
- Fix the calculation producing the negative budget
- Omit the flag entirely to get the default
Example fix
// before ocr review --from main --to HEAD --max-tools -5 // after ocr review --from main --to HEAD --max-tools 0 # 0 = template default
Defensive patterns
Strategy: validation
Validate before calling
case "$MAX_TOOLS" in ''|*[!0-9]*) echo "max-tools must be a non-negative integer, got: $MAX_TOOLS"; exit 2;; esac
Type guard
function isNonNegativeInt(v) { return Number.isInteger(v) && v >= 0; } Try / catch
ocr review --max-tools "$MAX_TOOLS" 2>err.log || { grep -q 'max-tools must be a non-negative' err.log && ocr review --max-tools 0; } Prevention
- Clamp computed budgets: v < 0 ? 0 : v
- Remember 0 means 'template default', not 'disabled'
- Validate config files that feed numeric flags
- Note values 1-49 are silently raised to 50 with a stderr warning
When it happens
Trigger: Passing --max-tools -1 (or any negative number) to review — the opts.maxTools < 0 branch in validateReviewOptions, invoked from the review command's anonymous caller.
Common situations: Scripts computing the value via arithmetic that can go negative (e.g. $(($BUDGET - $USED))); config files with placeholder negatives; misunderstanding 0 as 'disable' when it actually means 'default'.
Related errors
- --max-git-procs must be a non-negative integer (0 means use
- --max-tokens must be a non-negative integer (0 means use con
- only one review mode allowed (--from/--to or --commit)
- --to is required when --from is specified
- --from is required when --to is specified
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/ce5c72d837d4c3a7.
Report an issue: GitHub.