vxcontrol/pentagi · error
invalid TaskStatus: %s
Error message
invalid TaskStatus: %s
What it means
TaskStatus is the lifecycle enum for a flow task: created, running, waiting, finished, failed. TaskStatus.Valid() rejects any other string with this error, and the GORM Validate callback enforces it whenever a Task row is saved.
Source
Thrown at backend/pkg/server/models/tasks.go:34
TaskStatusFinished TaskStatus = "finished"
TaskStatusFailed TaskStatus = "failed"
)
func (s TaskStatus) String() string {
return string(s)
}
// Valid is function to control input/output data
func (s TaskStatus) Valid() error {
switch s {
case TaskStatusCreated,
TaskStatusRunning,
TaskStatusWaiting,
TaskStatusFinished,
TaskStatusFailed:
return nil
default:
return fmt.Errorf("invalid TaskStatus: %s", s)
}
}
// Validate is function to use callback to control input/output data
func (s TaskStatus) Validate(db *gorm.DB) {
if err := s.Valid(); err != nil {
db.AddError(err)
}
}
// Task is model to contain task information
// nolint:lll
type Task struct {
ID uint64 `form:"id" json:"id" validate:"min=0,numeric" gorm:"type:BIGINT;NOT NULL;PRIMARY_KEY;AUTO_INCREMENT"`
Status TaskStatus `form:"status" json:"status" validate:"valid,required" gorm:"type:TASK_STATUS;NOT NULL;default:'created'"`
Title string `form:"title" json:"title" validate:"required" gorm:"type:TEXT;NOT NULL;default:'untitled'"`
Input string `form:"input" json:"input" validate:"required" gorm:"type:TEXT;NOT NULL"`
Result string `form:"result" json:"result" validate:"omitempty" gorm:"type:TEXT;NOT NULL;default:''"`View on GitHub (pinned to ea665308ba)
Solutions
- Use exactly created, running, waiting, finished, or failed — preferably via the models.TaskStatus* constants from backend/pkg/server/models/tasks.go.
- Normalize/validate status strings at the API boundary before constructing the model (call Valid() and return a clear 400).
- Audit transition code for string-built statuses (fmt.Sprintf) and replace with constant references.
- Repair bad existing rows via migration so subsequent updates no longer trip Valid().
Example fix
// before
task := models.Task{Status: models.TaskStatus("done")}
// after
task := models.Task{Status: models.TaskStatusFinished} // "finished" Defensive patterns
Strategy: validation
Validate before calling
func isValidTaskStatus(v string) bool {
switch models.TaskStatus(v) {
case models.TaskStatusCreated, models.TaskStatusRunning,
models.TaskStatusWaiting, models.TaskStatusFinished,
models.TaskStatusFailed:
return true
}
return false
} Type guard
func asTaskStatus(v string) (models.TaskStatus, bool) {
s := models.TaskStatus(v)
return s, s.Valid() == nil
} Try / catch
if err := status.Valid(); err != nil {
return fmt.Errorf("illegal task status %q: %w", status, err)
} Prevention
- Use models.TaskStatus* constants in every transition; ban fmt.Sprintf-built statuses via lint/review.
- Reject unknown statuses in API handlers with 400 before touching the model.
- Migrate any legacy status values ('done', 'cancelled') to the canonical five with a data migration.
- Mirror the whitelist in the frontend zod schemas for task updates.
When it happens
Trigger: Assigning Task.Status an out-of-whitelist value like 'completed', 'cancelled', or '' during a task state transition; REST/GraphQL updates passing a client-defined status; scanning legacy DB rows whose TASK_STATUS value predates the current enum.
Common situations: Terminology mismatch between callers ('done'/'complete') and the enum's 'finished'; orchestrator code that mutates statuses via string formatting; manual DB edits or migration scripts using foreign status vocabularies.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- invalid SubtaskStatus: %s
- invalid MsgchainType: %s
- invalid MsglogType: %s
- invalid MsglogResultFormat: %s
- invalid PromptType: %s
AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01).
Data as JSON: /api/errors/fcc458214520f542.
Report an issue: GitHub.