{"record":{"id":"c4001d3f373ab784","repo":"Tencent/WeKnora","slug":"tenant-repository-is-unavailable","errorCode":null,"errorMessage":"tenant repository is unavailable","messagePattern":"tenant repository is unavailable","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/knowledge_summary_refresh.go","lineNumber":68,"sourceCode":"\t\tif latestChunk.ContentRevision != sourceChunk.ContentRevision ||\n\t\t\tlatestChunk.IsEnabled != sourceChunk.IsEnabled {\n\t\t\treturn true, nil\n\t\t}\n\t}\n\treturn false, nil\n}\n\n// restoreSummaryRefreshTenantInfo rebuilds the tenant context normally added\n// by the HTTP authentication middleware. Summary refreshes run in an Asynq\n// worker, and the retrieve-engine factory needs the full tenant configuration,\n// not only TenantIDContextKey, when it reindexes the summary chunk.\nfunc restoreSummaryRefreshTenantInfo(\n\tctx context.Context,\n\ttenantRepo interfaces.TenantRepository,\n\ttenantID uint64,\n) (context.Context, error) {\n\tif tenantRepo == nil {\n\t\treturn ctx, fmt.Errorf(\"tenant repository is unavailable\")\n\t}\n\ttenant, err := tenantRepo.GetTenantByID(ctx, tenantID)\n\tif err != nil {\n\t\treturn ctx, fmt.Errorf(\"get tenant %d for summary refresh: %w\", tenantID, err)\n\t}\n\tif tenant == nil {\n\t\treturn ctx, fmt.Errorf(\"tenant %d not found for summary refresh\", tenantID)\n\t}\n\treturn context.WithValue(ctx, types.TenantInfoContextKey, tenant), nil\n}\n\n// enqueueSummaryRefresh marks an existing summary as queued and enqueues an\n// independent refresh task. The pending status is written before Enqueue\n// because the Lite executor may run the task synchronously inside Enqueue.\nfunc enqueueSummaryRefresh(\n\tctx context.Context,\n\trepo interfaces.KnowledgeRepository,\n\ttaskEnqueuer interfaces.TaskEnqueuer,","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/knowledge_summary_refresh.go#L50-L86","documentation":"Sentinel guard in restoreSummaryRefreshTenantInfo: the injected TenantRepository is nil, so the worker cannot rebuild the full tenant context (TenantInfoContextKey) required by the retrieve-engine factory when reindexing a summary chunk. A wiring/dependency-injection defect at startup, not a runtime data fault.","triggerScenarios":"Thrown at internal/application/service/knowledge_summary_refresh.go:68 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix service construction to inject a non-nil TenantRepository into the summary-refresh worker","Add a startup sanity check that fails fast on missing dependencies","Cover the wiring with a DI/unit test (see TestRestoreSummaryRefreshTenantInfo)"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}