{"record":{"id":"87303540e76416d5","repo":"Tencent/WeKnora","slug":"chunk-s-is-not-within-the-current-mention-scope","errorCode":null,"errorMessage":"chunk %s is not within the current @mention scope","messagePattern":"chunk (.+?) is not within the current @mention scope","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/scope_authorization.go","lineNumber":132,"sourceCode":"\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\n// resolveAuthorizedSourceRefs validates Wiki source_refs/suspected IDs against\n// the same Agent scope and rebuilds the stored \"uuid|title\" representation\n// from server data instead of trusting a model-supplied title suffix.","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/agent/tools/scope_authorization.go#L114-L150","documentation":"Document-level mention-scope rejection for a chunk: KB containment and enablement passed, but the chunk's owning document is not within the @mention/allowed document scope, so the fine-grained check denies access to the chunk.","triggerScenarios":"Thrown at internal/agent/tools/scope_authorization.go:132 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Include the owning document in the mention/allowed scope","Verify scope resolution maps the chunk to the expected document","Adjust scope bindings rather than bypassing the check"],"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"}