{"record":{"id":"b0f0a7d34cfc4ce8","repo":"Tencent/WeKnora","slug":"knowledge-base-s-is-not-within-the-current-agent","errorCode":null,"errorMessage":"knowledge base %s is not within the current Agent scope","messagePattern":"knowledge base (.+?) is not within the current Agent scope","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/scope_authorization.go","lineNumber":80,"sourceCode":"\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\n// server resolves its owning document and validates that document against the\n// full KB/document/tag scope.\nfunc authorizeChunkInSearchTargets(","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/agent/tools/scope_authorization.go#L62-L98","documentation":"Scope authorization rejection: the document exists, but its owning knowledge base ID is not contained in the server-owned search targets for this Agent execution, so the KB-level containment check fails and access is denied to prevent cross-tenant/cross-KB data leaks.","triggerScenarios":"Thrown at internal/agent/tools/scope_authorization.go:80 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Add the knowledge base to the Agent's search targets","Verify the correct Agent/session scope was passed","Do not widen scope client-side; fix the binding configuration instead"],"exampleFix":null,"handlingStrategy":"validation","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"}