{"record":{"id":"30727b58f427bb6c","repo":"Tencent/WeKnora","slug":"document-s-not-found-w","errorCode":null,"errorMessage":"document %s not found: %w","messagePattern":"document (.+?) not found: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/scope_authorization.go","lineNumber":77,"sourceCode":"func authorizeKnowledgeInSearchTargets(\n\tctx context.Context,\n\tsearchTargets types.SearchTargets,\n\tknowledgeID string,\n\tknowledgeService interfaces.KnowledgeService,\n) (*types.Knowledge, error) {\n\tknowledgeID = strings.TrimSpace(knowledgeID)\n\tif knowledgeID == \"\" {\n\t\treturn nil, fmt.Errorf(\"knowledge_id is required\")\n\t}\n\tif knowledgeService == nil {\n\t\treturn nil, fmt.Errorf(\"knowledge service is unavailable\")\n\t}\n\tknowledge, err := knowledgeService.GetKnowledgeByIDOnly(ctx, knowledgeID)\n\tif err != nil || knowledge == nil {\n\t\tif err == nil {\n\t\t\terr = fmt.Errorf(\"empty result\")\n\t\t}\n\t\treturn nil, fmt.Errorf(\"document %s not found: %w\", knowledgeID, err)\n\t}\n\tif !searchTargets.ContainsKB(knowledge.KnowledgeBaseID) {\n\t\treturn nil, fmt.Errorf(\"knowledge base %s is not within the current Agent scope\", knowledge.KnowledgeBaseID)\n\t}\n\tallowed, err := searchTargetsAllowKnowledgeID(\n\t\tctx, searchTargets, knowledge.ID, knowledge.KnowledgeBaseID, knowledgeService,\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to validate document scope: %w\", err)\n\t}\n\tif !allowed {\n\t\treturn nil, fmt.Errorf(\"document %s is not within the current @mention scope\", knowledge.ID)\n\t}\n\treturn knowledge, nil\n}\n\n// authorizeChunkInSearchTargets is the chunk/FAQ counterpart of\n// authorizeKnowledgeInSearchTargets. A chunk ID is accepted only after the","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/agent/tools/scope_authorization.go#L59-L95","documentation":"Knowledge authorization lookup failed: GetKnowledgeByIDOnly returned an error or an empty result for the given knowledge ID, so the document cannot be verified against the Agent's search scope and access is denied with a not-found error (avoiding existence disclosure).","triggerScenarios":"Thrown at internal/agent/tools/scope_authorization.go:77 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Confirm the knowledge ID exists","Check storage connectivity if the inner error is not 'empty result'","Return a stable not-found response regardless of missing vs unauthorized"],"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"}