{"record":{"id":"721bfc23b84dbda4","repo":"alibaba/open-code-review","slug":"max-tokens-must-be-a-non-negative-integer-0-mea","errorCode":null,"errorMessage":"--max-tokens must be a non-negative integer (0 means use configured or template default)","messagePattern":"--max-tokens must be a non-negative integer \\(0 means use configured or template default\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/shared_flags.go","lineNumber":151,"sourceCode":"\t}\n\tnormalizedFormat, err := validateOutputFormat(opts.outputFormat)\n\tif err != nil {\n\t\treturn err\n\t}\n\topts.outputFormat = normalizedFormat\n\tconst minMaxTools = 50\n\tif opts.maxTools < 0 {\n\t\treturn fmt.Errorf(\"--max-tools must be a non-negative integer (0 means use template default)\")\n\t}\n\tif opts.maxTools > 0 && opts.maxTools < minMaxTools {\n\t\tfmt.Fprintf(os.Stderr, \"[ocr] --max-tools %d is below minimum %d, using %d\\n\", opts.maxTools, minMaxTools, minMaxTools)\n\t\topts.maxTools = minMaxTools\n\t}\n\tif opts.maxGitProcs < 0 {\n\t\treturn fmt.Errorf(\"--max-git-procs must be a non-negative integer (0 means use default 16)\")\n\t}\n\tif opts.maxTokens < 0 {\n\t\treturn fmt.Errorf(\"--max-tokens must be a non-negative integer (0 means use configured or template default)\")\n\t}\n\tif opts.maxTokensBudget < 0 {\n\t\treturn fmt.Errorf(\"--max-tokens-budget must be a non-negative integer (0 means unlimited)\")\n\t}\n\tif opts.effort != \"\" {\n\t\tif _, err := template.ParseEffort(opts.effort); err != nil {\n\t\t\treturn fmt.Errorf(\"--effort: %w\", err)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc validateScanOptions(opts *scanOptions) error {\n\tif err := validateAudience(opts.audience); err != nil {\n\t\treturn err\n\t}\n\tnormalizedFormat, err := validateOutputFormat(opts.outputFormat)\n\tif err != nil {","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/shared_flags.go#L133-L169","documentation":"--max-tokens caps the agent's token usage; negatives are invalid, while 0 means 'use the configured or template default'. validateReviewOptions rejects negative values with this message, immediately after the maxGitProcs check.","triggerScenarios":"Passing --max-tokens -1000 (or any negative) to review — the opts.maxTokens < 0 branch in validateReviewOptions, reached from the review command's anonymous caller.","commonSituations":"Budget math in scripts yielding negative numbers; confusing 'unlimited' (which is --max-tokens-budget 0) with a negative sentinel; stale config files containing -1 as a placeholder.","solutions":["Pass a non-negative value; --max-tokens 0 selects the configured/template default","Fix the budget calculation that produced the negative number","Remove the flag to inherit configuration defaults","Validate config-driven values before passing them through"],"exampleFix":"// before\nLIMIT=$(( TOTAL - SPENT )); ocr review --max-tokens \"$LIMIT\"   # negative\n// after\nLIMIT=$(( TOTAL > SPENT ? TOTAL - SPENT : 0 )); ocr review --max-tokens \"$LIMIT\"","handlingStrategy":"validation","validationCode":"case \"$MAX_TOKENS\" in ''|*[!0-9]*) echo \"max-tokens must be a non-negative integer, got: $MAX_TOKENS\"; exit 2;; esac","typeGuard":"function isNonNegativeInt(v) { return Number.isInteger(v) && v >= 0; }","tryCatchPattern":"ocr review --max-tokens \"$MAX_TOKENS\" 2>err.log || { grep -q 'max-tokens must be a non-negative' err.log && ocr review --max-tokens 0; }","preventionTips":["Remember 0 means 'configured/template default'; unlimited budget is --max-tokens-budget 0","Clamp budget math so it never emits negatives","Validate numbers coming from config files before forwarding","Omit the flag to rely on defaults"],"tags":["cli","flags","validation","numeric"],"backgroundTag":"invalid-numeric-argument","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}