Tencent/WeKnora · error

wiki page %s returned knowledge base %s while resolving allo

Error message

wiki page %s returned knowledge base %s while resolving allowed scope %s

What it means

After a successful lookup, the resolver cross-checks that the returned page's KnowledgeBaseID matches the scope it was fetched from. A mismatch means the service returned a page claiming ownership by a different KB than the explicitly authorized scope — a consistency/authorization invariant violation. The error aborts resolution rather than allowing a page outside the allowed scope.

Source

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

		kbID string
	}
	var hits []hit
	for _, scope := range ordered {
		page, err := service.GetPageBySlug(ctx, scope.KnowledgeBaseID, slug)
		if err != nil {
			if errors.Is(err, repository.ErrWikiPageNotFound) {
				continue
			}
			return nil, "", fmt.Errorf(
				"failed to resolve wiki page %s in knowledge base %s: %w",
				slug, scope.KnowledgeBaseID, err,
			)
		}
		if page == nil {
			continue
		}
		if page.KnowledgeBaseID != "" && page.KnowledgeBaseID != scope.KnowledgeBaseID {
			return nil, "", fmt.Errorf(
				"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)
		}

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Re-index or repair the page record so its KnowledgeBaseID matches the KB it is stored in
  2. Investigate the service layer for cross-KB slug lookups/shortcuts returning foreign pages
  3. Purge any stale cache that holds the old KB ownership for the moved page
  4. If a page was legitimately moved, update references to use the new KB's scope

Example fix

// data repair
UPDATE wiki_pages SET knowledge_base_id = '<allowed-kb-id>' WHERE slug = '<slug>' AND knowledge_base_id = '<stale-kb-id>';
Defensive patterns

Strategy: validation

Validate before calling

page, err := service.GetPageBySlug(ctx, kbID, slug)
if err == nil && page != nil && page.KnowledgeBaseID != "" && page.KnowledgeBaseID != kbID {
    return fmt.Errorf("ownership mismatch: page in %s claims %s", kbID, page.KnowledgeBaseID)
}

Type guard

func pageOwnedBy(page *types.WikiPage, kbID string) bool {
    return page != nil && (page.KnowledgeBaseID == "" || page.KnowledgeBaseID == kbID)
}

Try / catch

page, kbID, err := resolveUniqueWikiPage(ctx, slug, kbIDs, routes)
if err != nil && strings.Contains(err.Error(), "while resolving allowed scope") {
    // flag data inconsistency to ops; do not auto-retry
}

Prevention

When it happens

Trigger: GetPageBySlug(ctx, scope.KnowledgeBaseID, slug) returns a page whose page.KnowledgeBaseID is non-empty and different from scope.KnowledgeBaseID.

Common situations: Replicated/stale data where a page was moved between KBs but cached copies still point to the old KB; service routing a slug lookup across KBs; manual data repair leaving inconsistent KnowledgeBaseID fields.

Related errors


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