fix(knowledge): count documents through the reader's access and only where counts are shown
Merged
WA
1mo ago+350+350+012345678901234567890123456789-221-221-012345678901234567890123456789
Summary
- v1 knowledge base list, detail, and update returned
docCount/tokenCountover every document in the base, including connector documents the caller cannot read. They now count through the caller's access (resolveV1KnowledgeReadAccess), the same way the v1 documents routes already do. v1 detail also now returns its realconnectorTypes - The internal KB list joined
documentthrough the full access predicate on every call, but only the Knowledge page shows the totals. The list contract gainsincludeCounts(default false), and without it the query reads onlyknowledge_basecolumns. The service option iscountsFor: access, so a count without an access filter can't be written - React Query: counted lists get their own key beside
list(), used only by the Knowledge page and its server prefetch. Document, upload, and connector mutations refresh only the counted lists; KB create, rename, delete, restore, and move refresh both - Removed
getKnowledgeBaseById, whose unfiltered count join ran on every context resolution. Callers usegetActiveKnowledgeBaseReference, and single-base totals come only fromattachKnowledgeBaseConnectors(kb, access) - The v2 list keeps returning totals, since its public contract requires them
Type of Change
- Bug fix
Testing
- New
app/api/v1/knowledge/route.integration.ts(real Postgres, only auth mocked): a read-role caller seesdocCount: 1for a base holding one upload plus one admin-only connector document on v1 list and detail. All 3 tests fail on the old code - Search-index policy integration suite and the knowledge service, application, and context unit suites updated and passing
- Type-check, lint, and
check:auditspass
Checklist
- Code follows project style guidelines
- Self-reviewed my changes
- Tests added/updated and passing
- No new warnings introduced
- I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)