{"record":{"id":"c394f798efa0f608","repo":"alibaba/open-code-review","slug":"scan-max-tool-request-times-must-be-positive","errorCode":null,"errorMessage":"scan: max_tool_request_times must be positive","messagePattern":"scan: max_tool_request_times must be positive","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/template/template.go","lineNumber":334,"sourceCode":"\tif t.MaxToolRequestTimes <= 0 {\n\t\treturn fmt.Errorf(\"max_tool_request_times must be positive\")\n\t}\n\tif t.MaxReviewRounds < 0 {\n\t\treturn fmt.Errorf(\"max_review_rounds must not be negative\")\n\t}\n\tif len(t.MainTask.Messages) == 0 {\n\t\treturn fmt.Errorf(\"main_task.messages must not be empty\")\n\t}\n\treturn nil\n}\n\n// Validate checks that a ScanTemplate has the minimum fields populated.\nfunc (t *ScanTemplate) Validate() error {\n\tif t.MaxTokens <= 0 {\n\t\treturn fmt.Errorf(\"scan: max_tokens must be positive\")\n\t}\n\tif t.MaxToolRequestTimes <= 0 {\n\t\treturn fmt.Errorf(\"scan: max_tool_request_times must be positive\")\n\t}\n\tif len(t.MainTask.Messages) == 0 {\n\t\treturn fmt.Errorf(\"scan: main_task.messages must not be empty\")\n\t}\n\treturn nil\n}\n\n// LlmConversation is a preset prompt with settings.\ntype LlmConversation struct {\n\tMessages []ChatMessage `json:\"messages\"`\n}\n\n// ChatMessage represents a single message in a conversation.\ntype ChatMessage struct {\n\tRole    string `json:\"role\"`\n\tContent string `json:\"content\"`\n}\n","sourceCodeStart":316,"sourceCodeEnd":352,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/config/template/template.go#L316-L352","documentation":"ScanTemplate.Validate rejects a template whose MaxToolRequestTimes field is zero or negative. The library requires a positive cap on how many tool requests a scan conversation may make, so a template missing this setting (Go zero value 0) fails validation before any LLM run starts. It is a fast-fail config guard, not a runtime condition.","triggerScenarios":"Calling Validate() on a ScanTemplate literal that leaves MaxToolRequestTimes unset (defaults to 0) or explicitly sets it to a negative number.","commonSituations":"Hand-written YAML/JSON scan templates missing the max_tool_request_times key; templates copied from older versions before the field existed; typos in the field name causing the value not to be deserialized.","solutions":["Set max_tool_request_times to a positive integer in the template config","If the field was renamed/missing, fix the key so it deserializes into MaxToolRequestTimes","Pick a sane default (e.g. 20-50) based on how many tool calls a scan typically needs"],"exampleFix":"// before\ntemplate := template.ScanTemplate{ MaxTokens: 4096 }\nif err := template.Validate(); err != nil { ... } // fails\n// after\ntemplate := template.ScanTemplate{ MaxTokens: 4096, MaxToolRequestTimes: 30 }\nif err := template.Validate(); err != nil { ... }","handlingStrategy":"validation","validationCode":"func validTemplate(t template.ScanTemplate) bool { return t.MaxToolRequestTimes > 0 }","typeGuard":null,"tryCatchPattern":"if err := t.Validate(); err != nil { return fmt.Errorf(\"invalid scan template: %w\", err) }","preventionTips":["Always populate max_tool_request_times in template files","Validate templates at config load time, before queuing a scan","Use a JSON/YAML schema that marks the field required"],"tags":["config","validation","scan-template"],"backgroundTag":"invalid-config-value","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}