alibaba/open-code-review · error
max_review_rounds must not be negative
Error message
max_review_rounds must not be negative
What it means
Template.Validate allows MaxReviewRounds == 0 (review disabled) but rejects negative values with 'max_review_rounds must not be negative', since a negative round count is meaningless and would corrupt loop logic. It indicates an arithmetic bug or bad manifest data rather than a missing field.
Source
Thrown at internal/config/template/template.go:320
}
if t.DedupTask != nil {
applyLanguage(t.DedupTask, instruction)
}
if t.ProjectSummaryTask != nil {
applyLanguage(t.ProjectSummaryTask, instruction)
}
applyLanguage(&t.MemoryCompressionTask, instruction)
}
func (t *Template) Validate() error {
if t.MaxTokens <= 0 {
return fmt.Errorf("max_tokens must be positive")
}
if t.MaxToolRequestTimes <= 0 {
return fmt.Errorf("max_tool_request_times must be positive")
}
if t.MaxReviewRounds < 0 {
return fmt.Errorf("max_review_rounds must not be negative")
}
if len(t.MainTask.Messages) == 0 {
return fmt.Errorf("main_task.messages must not be empty")
}
return nil
}
// Validate checks that a ScanTemplate has the minimum fields populated.
func (t *ScanTemplate) Validate() error {
if t.MaxTokens <= 0 {
return fmt.Errorf("scan: max_tokens must be positive")
}
if t.MaxToolRequestTimes <= 0 {
return fmt.Errorf("scan: max_tool_request_times must be positive")
}
if len(t.MainTask.Messages) == 0 {
return fmt.Errorf("scan: main_task.messages must not be empty")
}View on GitHub (pinned to 5cf97d0d15)
Solutions
- Set MaxReviewRounds to 0 to disable review rounds, or a positive number to enable them
- Fix the manifest/config source so MAX_REVIEW_ROUNDS is never negative; clamp user input with max(0, value)
- Check for arithmetic that can go negative when deriving the value from other settings
- Re-run Validate after correction; the check passes for any value >= 0
Example fix
// before
rounds := cfg.BaseRounds - cfg.SkippedRounds // can go negative
// after
rounds := cfg.BaseRounds - cfg.SkippedRounds
if rounds < 0 { rounds = 0 } Defensive patterns
Strategy: validation
Validate before calling
if tpl.MaxReviewRounds < 0 {
return fmt.Errorf("MaxReviewRounds must be >= 0, got %d", tpl.MaxReviewRounds)
}
if err := tpl.Validate(); err != nil { return err } Try / catch
if err := tpl.Validate(); err != nil {
if strings.Contains(err.Error(), "max_review_rounds must not be negative") {
tpl.MaxReviewRounds = 0 // treat negatives as 'review disabled'
err = tpl.Validate()
}
if err != nil { return err }
} Prevention
- Clamp user-supplied round counts with max(0, v)
- Use 0, not -1, to mean 'disabled'
- Review arithmetic deriving the value from other config for underflow
When it happens
Trigger: Calling (*Template).Validate() with t.MaxReviewRounds < 0 — e.g. "MAX_REVIEW_ROUNDS": -1 in task_template.json, a subtraction underflow when computing rounds from other config, or user-supplied config clamped incorrectly.
Common situations: A config UI allowing negative input for review rounds; code like MaxReviewRounds: base - extra that underflows; copy-pasting a template with -1 as a sentinel for 'off' (use 0 instead).
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- invalid max_tokens in app config: must be a positive integer
- invalid config: %w
- unsupported extension %q, only .md/.txt/.markdown allowed
- invalid effort %q: must be one of %s
- max_tokens must be positive
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/5be18c51a3304c1d.
Report an issue: GitHub.