alibaba/open-code-review · error
--max-tokens-budget must be a non-negative integer (0 means
Error message
--max-tokens-budget must be a non-negative integer (0 means unlimited)
What it means
This validation error is thrown by validateReviewOptions in cmd/opencodereview/shared_flags.go when the --max-tokens-budget flag is given a negative integer. The library requires that this flag be a non-negative integer; 0 has special meaning (unlimited budget), while any positive value caps the total token spend of the review run. Negative values indicate a configuration mistake, so the CLI rejects the run before doing any work.
Source
Thrown at cmd/opencodereview/shared_flags.go:154
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)
}
}
return nil
}
func validateScanOptions(opts *scanOptions) error {
if err := validateAudience(opts.audience); err != nil {
return err
}
normalizedFormat, err := validateOutputFormat(opts.outputFormat)
if err != nil {
return err
}
opts.outputFormat = normalizedFormatView on GitHub (pinned to 5cf97d0d15)
Solutions
- Pass 0 instead of a negative number if you want an unlimited budget
- Set a positive integer token budget, e.g. --max-tokens-budget 100000
- Fix the script or environment variable that computed the negative value
Example fix
// before ocr review --max-tokens-budget -500 // after ocr review --max-tokens-budget 0 # unlimited, or a positive integer like 100000
Defensive patterns
Strategy: validation
Validate before calling
if [ "$MAX_TOKENS_BUDGET" -lt 0 ]; then MAX_TOKENS_BUDGET=0; fi ocr review --max-tokens-budget "$MAX_TOKENS_BUDGET"
Type guard
func validBudget(n int) bool { return n >= 0 } Prevention
- Clamp computed budgets with a lower bound of 0 before passing the flag
- Remember the convention: 0 = unlimited, never use negative numbers
- Add a shell wrapper that validates numeric flags before invoking the CLI
When it happens
Trigger: Running `ocr review --max-tokens-budget -1` (or any negative value). The flag is parsed into opts.maxTokensBudget by registerReviewFlags, then validateReviewOptions rejects negatives at line 153 before the pipeline starts.
Common situations: Scripts that compute a budget programmatically and produce a negative result (e.g. subtracting consumed tokens from a quota that is already exhausted); shell variables that are empty and expand to a bare '-' sign; typo'd hand-typed flags.
Related errors
- background file %q is empty after sanitisation
- background file %q must not contain the reserved delimiters
- background content is %d characters, exceeding the hard limi
- invalid --color value %q: must be one of auto, always, never
- --effort: %w
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/b5aa0d3b9754a319.
Report an issue: GitHub.