{"record":{"id":"38a8f3739a7a6f6f","repo":"vxcontrol/pentagi","slug":"invalid-assistantstatus-s","errorCode":null,"errorMessage":"invalid AssistantStatus: %s","messagePattern":"invalid AssistantStatus: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/server/models/assistants.go","lineNumber":35,"sourceCode":"\tAssistantStatusFinished AssistantStatus = \"finished\"\n\tAssistantStatusFailed   AssistantStatus = \"failed\"\n)\n\nfunc (s AssistantStatus) String() string {\n\treturn string(s)\n}\n\n// Valid is function to control input/output data\nfunc (s AssistantStatus) Valid() error {\n\tswitch s {\n\tcase AssistantStatusCreated,\n\t\tAssistantStatusRunning,\n\t\tAssistantStatusWaiting,\n\t\tAssistantStatusFinished,\n\t\tAssistantStatusFailed:\n\t\treturn nil\n\tdefault:\n\t\treturn fmt.Errorf(\"invalid AssistantStatus: %s\", s)\n\t}\n}\n\n// Validate is function to use callback to control input/output data\nfunc (s AssistantStatus) Validate(db *gorm.DB) {\n\tif err := s.Valid(); err != nil {\n\t\tdb.AddError(err)\n\t}\n}\n\n// Assistant is model to contain assistant information\n// nolint:lll\ntype Assistant struct {\n\tID                 uint64           `form:\"id\" json:\"id\" validate:\"min=0,numeric\" gorm:\"type:BIGINT;NOT NULL;PRIMARY_KEY;AUTO_INCREMENT\"`\n\tStatus             AssistantStatus  `form:\"status\" json:\"status\" validate:\"valid,required\" gorm:\"type:ASSISTANT_STATUS;NOT NULL;default:'created'\"`\n\tTitle              string           `form:\"title\" json:\"title\" validate:\"required\" gorm:\"type:TEXT;NOT NULL;default:'untitled'\"`\n\tModel              string           `form:\"model\" json:\"model\" validate:\"max=70,required\" gorm:\"type:TEXT;NOT NULL\"`\n\tModelProviderName  string           `form:\"model_provider_name\" json:\"model_provider_name\" validate:\"max=70,required\" gorm:\"type:TEXT;NOT NULL\"`","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/server/models/assistants.go#L17-L53","documentation":"AssistantStatus.Valid() in backend/pkg/server/models/assistants.go only accepts the defined lifecycle constants (including running, waiting, finished, failed, plus earlier states like creating defined above the excerpt). Any other value triggers this error through the GORM Validate callback when an assistant record is saved or validated.","triggerScenarios":"Creating or updating an assistant with a status string outside the AssistantStatus constants, e.g. \"stopped\", \"pending\", \"ok\", or an empty string; setting a status manually via API/DB.","commonSituations":"Integration code inventing its own status vocabulary; case-sensitivity mistakes; copying status names from a different entity (Flow/Container) that has a different state set; older clients using pre-rename status names.","solutions":["Use one of the AssistantStatus constants exactly (e.g. creating/running/waiting/finished/failed — see the type definition in assistants.go).","Do not map statuses from other entities; AssistantStatus has its own lifecycle.","Check casing — the switch compares exact values.","Let the backend drive status transitions instead of setting them from client code where possible."],"exampleFix":"// before\n{\"status\": \"stopped\"}\n// after\n{\"status\": \"finished\"}","handlingStrategy":"validation","validationCode":"const ASSISTANT_STATUSES = [\"creating\", \"running\", \"waiting\", \"finished\", \"failed\"] as const;\nfunction isValidAssistantStatus(s: string): boolean {\n  return (ASSISTANT_STATUSES as readonly string[]).includes(s);\n}\nif (!isValidAssistantStatus(input.status)) throw new Error(`invalid AssistantStatus: ${input.status}`);","typeGuard":"function isAssistantStatus(v: unknown): v is \"creating\" | \"running\" | \"waiting\" | \"finished\" | \"failed\" {\n  return [\"creating\", \"running\", \"waiting\", \"finished\", \"failed\"].includes(v as string);\n}","tryCatchPattern":"try {\n  await api.updateAssistant(id, { status });\n} catch (err) {\n  if (String(err).includes(\"invalid AssistantStatus\")) {\n    console.error(\"Bad assistant status, allowed set in models/assistants.go:\", err);\n  } else throw err;\n}","preventionTips":["Avoid writing status from clients; let backend transitions drive assistant lifecycle.","Never reuse Flow/Container status strings for assistants.","Verify the exact constant list in assistants.go before scripting bulk updates.","Add schema-level enum validation in the client form."],"tags":["validation","enum","assistants","gorm"],"backgroundTag":"invalid-enum-value","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}