{"record":{"id":"3cc151f68b0a5a4b","repo":"alibaba/open-code-review","slug":"invalid-max-tokens-in-app-config-must-be-a-positi","errorCode":null,"errorMessage":"invalid max_tokens in app config: must be a positive integer","messagePattern":"invalid max_tokens in app config: must be a positive integer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/shared.go","lineNumber":60,"sourceCode":"\t// true when requireGit was set; may be false when scan accepts non-git\n\t// directories.\n\tIsGitRepo bool\n}\n\n// resolveMaxTokens applies the per-run CLI override, then the saved setting,\n// and finally the embedded task-template default.\nfunc resolveMaxTokens(templateDefault int, cfg *Config, cliOverride int) (int, error) {\n\tif cliOverride < 0 {\n\t\treturn 0, fmt.Errorf(\"--max-tokens must be a non-negative integer\")\n\t}\n\tif cliOverride > 0 {\n\t\treturn cliOverride, nil\n\t}\n\tif cfg == nil || cfg.MaxTokens == 0 {\n\t\treturn templateDefault, nil\n\t}\n\tif cfg.MaxTokens < 0 {\n\t\treturn 0, fmt.Errorf(\"invalid max_tokens in app config: must be a positive integer\")\n\t}\n\treturn cfg.MaxTokens, nil\n}\n\n// resolveEffort applies the standard precedence for the review effort preset:\n// CLI flag > saved app config > EffortDefault.\nfunc resolveEffort(cfg *Config, cliOverride string) (template.Effort, error) {\n\tif cliOverride != \"\" {\n\t\treturn template.ParseEffort(cliOverride)\n\t}\n\tif cfg != nil && cfg.Effort != \"\" {\n\t\treturn template.ParseEffort(cfg.Effort)\n\t}\n\treturn template.EffortDefault, nil\n}\n\n// loadCommonContext validates the working directory, loads the embedded\n// template, raises MaxToolRequestTimes when maxTools exceeds the default,","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/shared.go#L42-L78","documentation":"resolveMaxTokens rejects a negative max_tokens saved in the app config file. The CLI override was absent (0), the saved cfg.MaxTokens was used, and it was negative — config files allow 0 (meaning 'unset') but not negative values.","triggerScenarios":"App config (~/.config/... ocr config) contains max_tokens: -1 or another negative number; config edited by hand or written by a buggy script/tool.","commonSituations":"Manual config editing mistakes; a migration or old version wrote an invalid sentinel like -1 for 'auto'.","solutions":["Open the app config and set max_tokens to a positive integer, or remove/zero it to use the template default","Re-set it via the CLI/settings command (`--max-tokens` with a positive value persisted to config)","If a tool wrote -1, fix the writer or reset config to defaults"],"exampleFix":"// before (config)\n\"max_tokens\": -1\n// after (config)\n\"max_tokens\": 20000   // or delete the key to use the template default","handlingStrategy":"validation","validationCode":"// sanitize config before passing to resolveMaxTokens\nif cfg != nil && cfg.MaxTokens < 0 {\n    return errors.New(\"max_tokens in app config must be >= 0\")\n}","typeGuard":"func validConfigMaxTokens(c *Config) bool { return c == nil || c.MaxTokens >= 0 }","tryCatchPattern":"limit, err := resolveMaxTokens(def, cfg, 0)\nif err != nil {\n    return fmt.Errorf(\"fix max_tokens in your app config: %w\", err)\n}","preventionTips":["Never write -1 or other negative sentinels into max_tokens; omit the key for defaults","Validate the config file after manual edits or migrations","Version config schema changes and reset invalid fields"],"tags":["go","config","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}