fix(knowledge): count list documents once instead of per 400-base batch - #7759
Merged
Merged
Conversation
#7730 switched the knowledge base lists to a KnowledgeAccessProvider, which turned the single joined count into a per-400-base loop of count plus candidate-discovery queries. The staging integ workspace holds 21k archived bases, so GET /api/knowledge?scope=archived went from ~4s to ~100s and the archive-kb integ check timed out at 30s. The stored-ACL count moves back into the list's own join. Only documents a live source (GitHub, Confluence) authorizes beyond that are counted afterwards, once for the whole list, bounded by the list filter (unpaged) or the page's ids. The provider now reports whether the reader holds any live-source credential, and the shared batch generator skips candidate discovery entirely when it does not, since the discovered predicate would be provably empty. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Lm5mdDU9bi1vb4oAvPtbjn
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Staging alarm
sim-staging-us-east-1-integ-failure(2026-09-10/11):integ-session-kb-document-lifecycle/archive-kbhits its 30 s client timeout onGET /api/knowledge?scope=archived. The request completes with 200 server-side but takes 90 to 122 s.Root cause. #7730 switched the knowledge base lists to pass a
KnowledgeAccessProvider, which flippedreadKnowledgeBaseRowsonto a new path: the document join becamesql\false`andreadKnowledgeBaseDocumentCountsran a count query plusknowledgeReadAccessBatches` candidate discovery per batch of 400 bases. The integ workspace holds 21,763 archived bases (fixtures archived since June, never purged), so one unpaged list became ~55 batches / 110+ sequential queries. Integ log shows archive-kb at 3 to 5 s until 11:02 UTC and 30 s timeouts from 11:29 UTC, 14 minutes after #7730 merged.Changes
readKnowledgeBaseRowsresolves the scope once and counts stored-ACL documents in the list's own join again, as before fix(search): verify Atlassian access and clarify source setup #7730.KnowledgeAccessProvidergains an optionalhasLiveSourceReaders().knowledgeReadAccessBatchesskips candidate discovery when it returns false: without a live-source credentialgetForConnectorsreturns the ordinary scope, so the discovered predicate isNOT ordinary AND ordinaryand provably empty. This applies to every generator call site (documents, tags, files, connectors), not just the list.attachKnowledgeBaseConnectorsuses the same two helpers for the single-base path.Semantics are unchanged: for a reader with live-source credentials, ordinary plus live counts sum exactly as #7730 intended; for everyone else the result is the pre-#7730 single query.
Verification
bun run type-check,bun run check:audits: pass.vitest run lib/knowledge app/api/knowledge app/api/files app/api/v1/knowledge app/api/v2/knowledge: 202 files, 3033 tests pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01Lm5mdDU9bi1vb4oAvPtbjn