alibaba/open-code-review · error
scan: main_task.messages must not be empty
Error message
scan: main_task.messages must not be empty
What it means
ScanTemplate.Validate rejects a template whose MainTask.Messages slice is empty. The main task conversation must contain at least one message (typically the system/user prompt driving the scan); an empty list means the LLM would be invoked with nothing to do. Validation fails fast before any request is made.
Source
Thrown at internal/config/template/template.go:337
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")
}
return nil
}
// LlmConversation is a preset prompt with settings.
type LlmConversation struct {
Messages []ChatMessage `json:"messages"`
}
// ChatMessage represents a single message in a conversation.
type ChatMessage struct {
Role string `json:"role"`
Content string `json:"content"`
}
View on GitHub (pinned to 5cf97d0d15)
Solutions
- Add at least one message (role + content) under main_task.messages in the template
- Check the template file for a misspelled or misplaced messages key so it actually unmarshals
- Copy a known-good template and adapt the prompt instead of starting from an empty struct
Example fix
// before
MainTask: LlmTask{ Settings: settings } // no messages
// after
MainTask: LlmTask{ Settings: settings, Messages: []Message{{Role: "user", Content: scanPrompt}} } Defensive patterns
Strategy: validation
Validate before calling
func hasMessages(t template.ScanTemplate) bool { return len(t.MainTask.Messages) > 0 } Try / catch
if err := t.Validate(); err != nil { return fmt.Errorf("invalid scan template: %w", err) } Prevention
- Never commit template files with empty main_task.messages
- Add a CI check that validates every shipped template with Validate()
- Start from a known-good template when authoring new prompts
When it happens
Trigger: Calling Validate() on a ScanTemplate where MainTask is the zero value or where the messages array in the config file is empty ([]) or absent.
Common situations: Template files with main_task section omitted entirely; a prompt refactoring that emptied the messages list; deserializing a template where the messages key is misspelled so nothing is populated.
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 %q: must be a positive integer
- unknown config key: %s Supported keys: %s Provider fields: a
- invalid URL for %s: %w
- invalid model list for %s: %w
- invalid retry codes for %s: %w
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/8db6af7bd53eea4e.
Report an issue: GitHub.