Tencent/WeKnora · error · errWikiPageAmbiguous

%w: slug %s belongs to %s

Error message

%w: slug %s belongs to %s

What it means

When the same slug resolves to pages in two or more allowed knowledge bases, the resolver cannot pick a unique target and returns errWikiPageAmbiguous wrapped with the slug and the comma-joined list of owning KB IDs. This prevents mutating or reading the wrong page when a slug is duplicated across scopes.

Source

Thrown at internal/agent/tools/wiki_route_resolver.go:167

				"wiki page %s returned knowledge base %s while resolving allowed scope %s",
				slug, page.KnowledgeBaseID, scope.KnowledgeBaseID,
			)
		}
		kbID := scope.KnowledgeBaseID
		hits = append(hits, hit{page: page, kbID: kbID})
		routes.rememberPage(page, kbID)
	}
	switch len(hits) {
	case 0:
		return nil, "", fmt.Errorf("%w: %s", errWikiPageNotFoundInScope, slug)
	case 1:
		return hits[0].page, hits[0].kbID, nil
	default:
		owners := make([]string, 0, len(hits))
		for _, item := range hits {
			owners = append(owners, item.kbID)
		}
		return nil, "", fmt.Errorf("%w: slug %s belongs to %s", errWikiPageAmbiguous, slug, strings.Join(owners, ", "))
	}
}

// resolveWikiCreateKB selects a creation target only when server-side context
// is unambiguous: one cached provenance owner or one Wiki KB in scope.
func resolveWikiCreateKB(
	slug string,
	kbIDs []string,
	routes *WikiRouteResolver,
	serverHints ...string,
) (string, error) {
	scopes := NewWikiScopesFromKBIDs(kbIDs)
	preferred := routes.scopesForSlug(strings.TrimSpace(slug), scopes)
	allowed := make(map[string]struct{}, len(scopes))
	for _, scope := range scopes {
		allowed[scope.KnowledgeBaseID] = struct{}{}
	}
	candidates := make([]string, 0, len(preferred)+len(serverHints))

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Narrow the allowed KB scopes so only one contains the slug, or pass the specific KB ID with the request
  2. Rename one of the duplicate pages so slugs are unique across KBs
  3. Prompt the model/user to disambiguate by listing the owning KBs from the error message
  4. Use resolveWikiCreateKB-style provenance (cached owner) for follow-up operations on the same page

Example fix

// before: ambiguous scope
kbIDs := allKBs
page, _, err := resolveUniqueWikiPage(ctx, "onboarding", kbIDs, routes)
// after: pin the KB
kbIDs := []string{"kb-team-platform"}
page, _, err := resolveUniqueWikiPage(ctx, "onboarding", kbIDs, routes)
Defensive patterns

Strategy: fallback

Validate before calling

owners := kbIDsContainingSlug(ctx, slug, allowedKBs) // pre-check with list/search
if len(owners) > 1 {
    return fmt.Errorf("slug %q exists in KBs %v; pick one", slug, owners)
}

Type guard

null

Try / catch

page, kbID, err := resolveUniqueWikiPage(ctx, slug, kbIDs, routes)
if err != nil && errors.Is(err, errWikiPageAmbiguous) {
    // surface the KB list from err to the user and retry with a single KB scope
}

Prevention

When it happens

Trigger: resolveUniqueWikiPage found len(hits) >= 2: GetPageBySlug succeeded for the same slug in multiple KBs within the allowed scopes (e.g. update/delete calls where no specific KB was pinned).

Common situations: Teams copying pages across knowledge bases keeping identical slugs; template pages replicated per project KB; overly broad KB scope list including several spaces that all define the slug.

Related errors


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/d6fb70aa9c7e4aac. Report an issue: GitHub.