{"record":{"id":"7300f675f3fc5e81","repo":"Tencent/WeKnora","slug":"cannot-choose-a-knowledge-base-for-new-wiki-page-7300f6","errorCode":null,"errorMessage":"cannot choose a knowledge base for new wiki page %s from %d allowed scopes","messagePattern":"cannot choose a knowledge base for new wiki page (.+?) from (.+?) allowed scopes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/wiki_route_resolver.go","lineNumber":207,"sourceCode":"\tfor _, kbID := range serverHints {\n\t\tif _, ok := allowed[kbID]; ok {\n\t\t\tcandidates = append(candidates, kbID)\n\t\t}\n\t}\n\tcandidates = dedupNonEmptyStrings(candidates)\n\tif len(candidates) == 1 {\n\t\treturn candidates[0], nil\n\t}\n\tif len(candidates) > 1 {\n\t\treturn \"\", fmt.Errorf(\n\t\t\t\"cannot choose a knowledge base for new wiki page %s: server provenance conflicts across %s\",\n\t\t\tslug, strings.Join(candidates, \", \"),\n\t\t)\n\t}\n\tif len(scopes) == 1 {\n\t\treturn scopes[0].KnowledgeBaseID, nil\n\t}\n\treturn \"\", fmt.Errorf(\"cannot choose a knowledge base for new wiki page %s from %d allowed scopes\", slug, len(scopes))\n}\n\nfunc wikiKnowledgeBasesForSourceRefs(\n\tctx context.Context,\n\trefs []string,\n\tknowledgeService interfaces.KnowledgeService,\n\tallowedKBIDs []string,\n) ([]string, error) {\n\tif len(refs) == 0 {\n\t\treturn nil, nil\n\t}\n\tif knowledgeService == nil {\n\t\treturn nil, fmt.Errorf(\"knowledge service is unavailable\")\n\t}\n\tallowed := make(map[string]struct{}, len(allowedKBIDs))\n\tfor _, kbID := range dedupNonEmptyStrings(allowedKBIDs) {\n\t\tallowed[kbID] = struct{}{}\n\t}","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/agent/tools/wiki_route_resolver.go#L189-L225","documentation":"When there are no conflicting provenance owners but more than one (or zero) allowed KB scopes, resolveWikiCreateKB cannot infer a unique creation target and fails with this error naming the scope count. It is the resolver's 'the model must tell me which KB to create in' error.","triggerScenarios":"Create call with a novel slug (no server provenance) while the request allows len(scopes) != 1 knowledge bases — e.g. 0 or 2+ KBs in scope.","commonSituations":"Agent session authorized across several KBs and the model omitted the target KB; slug never used before so there is no cached owner; scopes misconfigured to include extra KBs.","solutions":["Have the tool require/ask for the target knowledge_base_id when more than one KB is in scope","Restrict the agent's wiki scopes to a single KB if all writes target one space","Create the page first in a pinned KB and reuse its provenance for follow-ups","Surface the scope count to the model so it can disambiguate on the next turn"],"exampleFix":"// tool argument handling\nkbArg, _ := args[\"knowledge_base_id\"].(string)\nif kbArg == \"\" && len(scopes) != 1 {\n    return &types.ToolResult{Success: false, Error: fmt.Sprintf(\"specify a knowledge base (%d allowed)\", len(scopes))}, nil\n}\nkbID, err := resolveWikiCreateKB(ctx, slug, scopes, routes)","handlingStrategy":"validation","validationCode":"kbArg, _ := args[\"knowledge_base_id\"].(string)\nif kbArg == \"\" && len(allowedScopes) != 1 {\n    return &types.ToolResult{Success: false,\n        Error: fmt.Sprintf(\"specify one of %d allowed knowledge bases for creation\", len(allowedScopes))}, nil\n}","typeGuard":"null","tryCatchPattern":"kbID, err := resolveWikiCreateKB(ctx, slug, scopes, routes)\nif err != nil && strings.Contains(err.Error(), \"allowed scopes\") {\n    // re-prompt with the scope list so the model can choose a KB\n}","preventionTips":["Make knowledge_base_id a required create parameter when the session has multiple KBs","Restrict agent write scopes to one KB where workflows allow","Emit the allowed KB list in tool descriptions so the model self-disambiguates","Test create flows with 0, 1, and N scopes"],"tags":["go","wiki","ambiguity","create","validation"],"backgroundTag":"ambiguous-target-kb","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}