{"record":{"id":"548222b668f6ffdb","repo":"Tencent/WeKnora","slug":"abnormal-model-status","errorCode":null,"errorMessage":"abnormal model status","messagePattern":"abnormal model status","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/model.go","lineNumber":203,"sourceCode":"\tlogger.Infof(ctx, \"Model found, name: %s, status: %s\", model.Name, model.Status)\n\n\t// Check model status\n\tif model.Status == types.ModelStatusActive {\n\t\treturn model, nil\n\t}\n\n\tif model.Status == types.ModelStatusDownloading {\n\t\tlogger.Warn(ctx, \"Model is currently downloading\")\n\t\treturn nil, errors.New(\"model is currently downloading\")\n\t}\n\n\tif model.Status == types.ModelStatusDownloadFailed {\n\t\tlogger.Error(ctx, \"Model download failed\")\n\t\treturn nil, errors.New(\"model download failed\")\n\t}\n\n\tlogger.Error(ctx, \"Model status is abnormal\")\n\treturn nil, errors.New(\"abnormal model status\")\n}\n\n// ListModels returns all models belonging to the tenant\nfunc (s *modelService) ListModels(ctx context.Context) ([]*types.Model, error) {\n\tlogger.Info(ctx, \"Start listing models\")\n\n\ttenantID := types.MustTenantIDFromContext(ctx)\n\tlogger.Infof(ctx, \"Listing models for tenant ID: %d\", tenantID)\n\n\t// List models from repository with no additional filters\n\tmodels, err := s.repo.List(ctx, tenantID, \"\", \"\")\n\tif err != nil {\n\t\tlogger.ErrorWithFields(ctx, err, map[string]interface{}{\n\t\t\t\"tenant_id\": tenantID,\n\t\t})\n\t\treturn nil, err\n\t}\n","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/model.go#L185-L221","documentation":"This is the catch-all branch of GetModelByID's status checks: if the model's status is not Active, Downloading, or DownloadFailed, the service treats the row as corrupt/unknown and returns errors.New(\"abnormal model status\"). It guards against unknown or invalid enum values in model.Status (e.g. empty string, legacy value, or data written by a newer/older version).","triggerScenarios":"GetModelByID (or GetEmbeddingModel/GetRerankModel) fetches a model whose Status field holds a value outside the known set of types.ModelStatus* constants — e.g. empty status, a status added by a newer binary but persisted by an older one, or manually edited DB rows.","commonSituations":"Schema/version skew after upgrading the service while old rows retain legacy status strings; a migration bug that left status NULL/empty; manual database edits or an import script writing raw values; concurrent state machine bugs that set an undefined status.","solutions":["Query the model row in the database and inspect its status value; identify what out-of-range value was stored.","Write a migration/repair to reset the invalid status to a valid value (e.g. re-download path or ModelStatusDownloadFailed) or delete and re-register the model.","Confirm all service replicas run the same binary version, so the set of known statuses matches what is persisted.","Harden the status enum mapping (e.g. a FromString parser that rejects unknown values at write time) so invalid statuses cannot be persisted again."],"exampleFix":"// before (db row)\n// models.status = \"provisionning\" (typo / unknown value)\n// after\nUPDATE models SET status = 'download_failed' WHERE id = ?; -- then re-trigger download\n// or delete and re-register the model so it goes through the normal lifecycle","handlingStrategy":"type-guard","validationCode":"validStatuses := map[string]bool{\"active\": true, \"downloading\": true, \"download_failed\": true}\nif !validStatuses[m.Status] { /* repair row / re-register model */ }","typeGuard":"func hasKnownStatus(m *types.Model, known map[string]bool) bool { return m != nil && known[m.Status] }","tryCatchPattern":"model, err := svc.GetModelByID(ctx, modelID)\nif err != nil {\n    if strings.Contains(err.Error(), \"abnormal model status\") {\n        return nil, fmt.Errorf(\"model %s has corrupt/unknown status; re-register it\", modelID)\n    }\n    return nil, err\n}","preventionTips":["Keep all service replicas on the same version so status enums match persisted data.","Validate status values at write time with a strict parser.","Avoid manual DB edits on model rows; use the provided lifecycle APIs.","Add a data-integrity check/migration that flags out-of-range status values."],"tags":["go","data-integrity","enum","state-machine"],"backgroundTag":"invalid-enum-value","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}