{"record":{"id":"445c4ae13d03c420","repo":"Tencent/WeKnora","slug":"graph-result-document-s-belongs-to-knowledge-base","errorCode":null,"errorMessage":"graph result document %s belongs to knowledge base %s, expected %s","messagePattern":"graph result document (.+?) belongs to knowledge base (.+?), expected (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/scope_authorization.go","lineNumber":267,"sourceCode":"\t\ttargetKnowledgeIDs, targetTagIDs := searchTargetScope(target)\n\t\texplicitIDs = append(explicitIDs, targetKnowledgeIDs...)\n\t\ttagIDs = append(tagIDs, targetTagIDs...)\n\t}\n\tif !matchedKB {\n\t\treturn nil, fmt.Errorf(\"knowledge base %s is not within the current Agent scope\", kbID)\n\t}\n\n\texplicitSet := make(map[string]struct{}, len(explicitIDs))\n\tfor _, id := range dedupNonEmptyStrings(explicitIDs) {\n\t\texplicitSet[id] = struct{}{}\n\t}\n\tremainingIDs := make([]string, 0, len(results))\n\tfor _, result := range results {\n\t\tif result == nil || result.KnowledgeID == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tif result.KnowledgeBaseID != \"\" && result.KnowledgeBaseID != kbID {\n\t\t\treturn nil, fmt.Errorf(\n\t\t\t\t\"graph result document %s belongs to knowledge base %s, expected %s\",\n\t\t\t\tresult.KnowledgeID, result.KnowledgeBaseID, kbID,\n\t\t\t)\n\t\t}\n\t\tif _, ok := explicitSet[result.KnowledgeID]; !ok {\n\t\t\tremainingIDs = append(remainingIDs, result.KnowledgeID)\n\t\t}\n\t}\n\tvar tagMatches map[string]bool\n\tif len(tagIDs) > 0 {\n\t\tif knowledgeService == nil {\n\t\t\treturn nil, fmt.Errorf(\"knowledge service is unavailable for tag-scoped graph filtering\")\n\t\t}\n\t\tvar err error\n\t\ttagMatches, err = knowledgeIDsMatchingAnyTag(\n\t\t\tctx, remainingIDs, tagIDs, knowledgeService.GetKnowledgeTags,\n\t\t)\n\t\tif err != nil {","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/agent/tools/scope_authorization.go#L249-L285","documentation":"Data-integrity guard while filtering graph search results: a returned graph result claims a knowledge base ID that differs from the KB the query was issued against, indicating cross-KB contamination or corrupted result metadata; the filter aborts rather than silently returning out-of-scope documents.","triggerScenarios":"Thrown at internal/agent/tools/scope_authorization.go:267 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Log the offending result and investigate index cross-contamination","Drop the mismatched result instead of failing the whole filter if acceptable","Verify the graph index isolates documents per knowledge base"],"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"}