{"record":{"id":"ca6bf3bd977762d0","repo":"Tencent/WeKnora","slug":"failed-to-validate-chunk-scope-w","errorCode":null,"errorMessage":"failed to validate chunk scope: %w","messagePattern":"failed to validate chunk scope: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/scope_authorization.go","lineNumber":129,"sourceCode":"\t}\n\tchunk, err := chunkService.GetChunkByIDOnly(ctx, chunkID)\n\tif err != nil || chunk == nil {\n\t\tif err == nil {\n\t\t\terr = fmt.Errorf(\"empty result\")\n\t\t}\n\t\treturn nil, fmt.Errorf(\"chunk %s not found: %w\", chunkID, err)\n\t}\n\tif !chunk.IsEnabled {\n\t\treturn nil, fmt.Errorf(\"chunk %s is disabled\", chunk.ID)\n\t}\n\tif !searchTargets.ContainsKB(chunk.KnowledgeBaseID) {\n\t\treturn nil, fmt.Errorf(\"knowledge base %s is not within the current Agent scope\", chunk.KnowledgeBaseID)\n\t}\n\tallowed, err := searchTargetsAllowKnowledgeID(\n\t\tctx, searchTargets, chunk.KnowledgeID, chunk.KnowledgeBaseID, knowledgeService,\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to validate chunk scope: %w\", err)\n\t}\n\tif !allowed {\n\t\treturn nil, fmt.Errorf(\"chunk %s is not within the current @mention scope\", chunk.ID)\n\t}\n\treturn chunk, nil\n}\n\n// validateKnowledgeBaseIDsInSearchTargets rejects hallucinated, stale, or\n// out-of-scope bN values after the model-context registry resolves them.\nfunc validateKnowledgeBaseIDsInSearchTargets(searchTargets types.SearchTargets, kbIDs []string) error {\n\tfor _, kbID := range dedupNonEmptyStrings(kbIDs) {\n\t\tif !searchTargets.ContainsKB(kbID) {\n\t\t\treturn fmt.Errorf(\"knowledge base %s is not within the current Agent scope\", kbID)\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/agent/tools/scope_authorization.go#L111-L147","documentation":"The fine-grained document-scope check for the chunk's owning document errored (service failure inside searchTargetsAllowKnowledgeID), so authorization cannot be decided and fails closed with a wrapped validation error.","triggerScenarios":"Thrown at internal/agent/tools/scope_authorization.go:129 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the chained inner error for the failing service call","Check knowledge service availability","Retry transient failures during chunk scope validation"],"exampleFix":null,"handlingStrategy":"try-catch","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"}