{"record":{"id":"e893a0e6cf51ca5f","repo":"Tencent/WeKnora","slug":"model-is-not-active","errorCode":null,"errorMessage":"model is not active","messagePattern":"model is not active","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/model.go","lineNumber":539,"sourceCode":"\n\t// Fetch model from repository using the specified tenant ID\n\tmodel, err := s.repo.GetByID(ctx, tenantID, modelId)\n\tif err != nil {\n\t\tlogger.ErrorWithFields(ctx, err, map[string]interface{}{\n\t\t\t\"model_id\":  modelId,\n\t\t\t\"tenant_id\": tenantID,\n\t\t})\n\t\treturn nil, err\n\t}\n\n\tif model == nil {\n\t\tlogger.Error(ctx, \"Model not found for specified tenant\")\n\t\treturn nil, ErrModelNotFound\n\t}\n\n\tif model.Status != types.ModelStatusActive {\n\t\tlogger.Errorf(ctx, \"Model is not active, status: %s\", model.Status)\n\t\treturn nil, errors.New(\"model is not active\")\n\t}\n\n\tlogger.Infof(ctx, \"Getting cross-tenant embedding model: %s, source: %s, tenant: %d\", model.Name, model.Source, tenantID)\n\n\tappID, appSecret := s.resolveWeKnoraCloudCredentials(ctx, &model.Parameters)\n\n\tembedder, err := embedding.NewEmbedder(embedding.ConfigFromModel(model, appID, appSecret), s.pooler, s.ollamaService)\n\tif err != nil {\n\t\tlogger.ErrorWithFields(ctx, err, map[string]interface{}{\n\t\t\t\"model_id\":   model.ID,\n\t\t\t\"model_name\": model.Name,\n\t\t\t\"tenant_id\":  tenantID,\n\t\t})\n\t\treturn nil, err\n\t}\n\n\tlogger.Info(ctx, \"Cross-tenant embedding model initialized successfully\")\n\treturn embedder, nil","sourceCodeStart":521,"sourceCodeEnd":557,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/model.go#L521-L557","documentation":"GetEmbeddingModelForTenant only serves models whose status is exactly types.ModelStatusActive. Unlike GetModelByID, it does not distinguish downloading/failed — any non-active status returns errors.New(\"model is not active\"), because a cross-tenant embedder must be fully ready to guarantee vector compatibility. It can also be transient (still downloading) or permanent (download failed/disabled).","triggerScenarios":"Calling GetEmbeddingModelForTenant for a model whose Status is anything other than ModelStatusActive — still downloading, download failed, disabled, or deleted — typically right after provisioning a model or after it was disabled in the target tenant.","commonSituations":"Cross-tenant KB sharing references a source-tenant embedding model that was just created and has not finished downloading; the model was disabled/deactivated by an admin after sharing was set up; the model row failed download earlier; status changed between when the share was created and when it is used.","solutions":["Check the source-tenant model's status (admin UI or GetModelByID) to see whether it is downloading or failed/disabled, and wait for it to become active or fix the underlying download failure.","If the model was intentionally disabled, re-enable it or update the shared knowledge base to use a different active embedding model.","Re-trigger the model download if it is in a failed state, then retry once status is active.","Add a retry-with-backoff for the transient downloading case, and alert on permanently non-active models referenced by active cross-tenant shares."],"exampleFix":"// before\nembedder, err := modelService.GetEmbeddingModelForTenant(ctx, modelID, sourceTenantID)\n// after\nfor i := 0; i < 12; i++ {\n    embedder, err = modelService.GetEmbeddingModelForTenant(ctx, modelID, sourceTenantID)\n    if err == nil { break }\n    time.Sleep(15 * time.Second) // transient \"model is not active\" while downloading\n}","handlingStrategy":"retry","validationCode":"m, err := svc.GetModelByID(ctx, modelID)\nif err == nil && m.Status != types.ModelStatusActive {\n    // wait or repair before cross-tenant use\n}","typeGuard":"func isActiveModel(m *types.Model) bool { return m != nil && m.Status == types.ModelStatusActive }","tryCatchPattern":"embedder, err := svc.GetEmbeddingModelForTenant(ctx, modelID, tenantID)\nif err != nil {\n    if strings.Contains(err.Error(), \"model is not active\") {\n        // check whether transient (downloading) or permanent (failed/disabled)\n    }\n    return nil, err\n}","preventionTips":["Verify source-tenant model status is active before creating cross-tenant shares.","Re-check status after model re-provisioning or admin disable actions.","Alert when active shares reference non-active models.","Only retry when the underlying state is transient (downloading), not when disabled/failed."],"tags":["go","model-status","cross-tenant","not-ready"],"backgroundTag":"model-not-ready","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}