You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug(kb): doc index dimension-mismatch rebuild does not invalidate retrieval caches #20992
_handle_dim_mismatch in autobot-backend/services/knowledge/doc_indexer.py (around line 656) is synchronous, so it cannot await the async invalidate_retrieval_caches(reason) hook from autobot-backend/knowledge/retrieval_invalidation.py. When the dimension-mismatch rebuild forces a re-index and finds no files to re-index, the retrieval epoch is never bumped, and cached doc results stay servable until their TTL expires.
#20958 invalidates the semantic and topic caches on every KB write, but this rebuild path is not a KB write call site, so it is not covered.
Fix options
Make _handle_dim_mismatch async and await the hook, or
Route the rebuild through an awaited caller that invokes the hook after the forced re-index, regardless of how many files were found.
Either way the invalidation must run even when the file list is empty.
Acceptance criteria
A dimension-mismatch rebuild bumps the retrieval epoch token, including the case where the forced re-index finds no files.
A test covers the dimension-mismatch rebuild path and asserts the epoch bump.
Closure check after #21835 merged (merge 17562e5). Evidence is quoted from origin/main.
AC
Status
Evidence
A recreate bumps the epoch, including when the re-index finds no files
✔ ticked
services/knowledge/doc_index_orphans.pyresolve_collection (~L57-76) awaits _bump_if_recreated on success, on error and on cancel. _bump_if_recreated (~L90-105) invokes _bump_after_recreate(), which carries @invalidates_retrieval_caches("docs_collection_recreated"), whenever indexer._needs_reindex was set by the resolve. That happens at resolve time, before any indexing, so the number of files found later does not matter. The docstring reads: "regardless of how many files the forced re-index later finds". It is called from doc_indexer.py:397.
A test covers the rebuild path and asserts the bump
✘ open
test_doc_index_dim_mismatch_invalidation.py::test_a_recreate_bumps_the_epoch_and_keeps_the_reindex_flag asserts bump.assert_awaited_once_with("docs_collection_recreated"). Its _Indexer is a stub whose _resolve_collection sets the flag, so the real _handle_dim_mismatch (doc_indexer.py:460) is not exercised. Still needed: a test that drives the real dimension-mismatch handling through resolve_collection, including a re-index that finds no files.
knowledge/retrieval_invalidation.py:91 registers WriteEntryPoint("services/knowledge/doc_index_orphans.py", "_bump_after_recreate", ...). The guard exempts _handle_dim_mismatch (retrieval_invalidation_20958_test.py:387-388) on the grounds that resolve_collection awaits the registered hook, but nothing checks that it still does. If that call were removed, the guard would stay green. Still needed: the guard, or a test it relies on, asserts that the rebuild path reaches the registered entry point.
AC2 and AC3 will be finished in a follow-up PR for this issue.
GET on the chroma empty-collections endpoint returns 200 as admin and 401 unauthenticated.
Not verified: whether the database records 20261121_118 as applied, and whether its two unique indexes (uq_approvals_pending_connector_credential_strip, uq_approvals_pending_empty_collection_delete) exist. This read-only check had no access to the database credentials.
Database check on the local install (owner-approved, read-only SELECT queries; install at main 9c2d82b):
alembic_version = 20261121_118 (1 row).
Both partial unique indexes exist:
uq_approvals_pending_connector_credential_strip: UNIQUE on approvals ((context->>'connector_id')) WHERE status='pending' AND action='connector_credential_strip'
uq_approvals_pending_empty_collection_delete: UNIQUE on approvals ((context->>'collection')) WHERE status='pending' AND action='chroma_empty_collection_delete'
This closes the database gap in the earlier host check.
Closure evidence for AC2/AC3 (merged in #21994, 95adb8e, ancestor of main):
AC2: autobot-backend/services/knowledge/test_doc_index_dim_mismatch_real_handler_20992.py drives the REAL handler through resolve_collection: test_real_handler_recreates_and_bumps_the_epoch (L66), no bump on a matching dimension (L77), flag off raises without deleting or bumping (L87), and the bump does not depend on the forced re-index finding files (L98).
AC3: autobot-backend/knowledge/retrieval_invalidation_20958_test.py lists _handle_dim_mismatch as an invalidating entry point (L387) and asserts its only caller is _resolve_collection (L478).
Activity
github-actions commentedon Nov 7, 2026
needs-structurecleared: goal milestone, matching phase label and native parent (or sub-issues) are all present (#19522).fix(knowledge): cleanup proposals are audited at creation, empty-coll…
fix(kb): close the pending-proposal race with partial unique indexes;…
feat(slm): knowledge-cleanup proposals on the Data hygiene page; drop…
21 remaining items
test(kb): widen the retry-interval bound and rename the KB cleanup mi…
fix(kb): re-parent the KB cleanup migration onto 20261120_117 (#20992)
refactor(kb): share the pair query in inspect_database (#20992)
chore(types): regenerate api.ts on the synced tree (#20992)
test(kb): the explorer admin-gate guard checks the served routes, inc…
Merge pull request #21835 from mrveiss/issue-20992-kb-defect-batch
github-actions commentedon Nov 21, 2026
Landed in #21835, merge
17562e568emrveiss commentedon Nov 21, 2026
Closure check after #21835 merged (merge 17562e5). Evidence is quoted from
origin/main.services/knowledge/doc_index_orphans.pyresolve_collection(~L57-76) awaits_bump_if_recreatedon success, on error and on cancel._bump_if_recreated(~L90-105) invokes_bump_after_recreate(), which carries@invalidates_retrieval_caches("docs_collection_recreated"), wheneverindexer._needs_reindexwas set by the resolve. That happens at resolve time, before any indexing, so the number of files found later does not matter. The docstring reads: "regardless of how many files the forced re-index later finds". It is called fromdoc_indexer.py:397.test_doc_index_dim_mismatch_invalidation.py::test_a_recreate_bumps_the_epoch_and_keeps_the_reindex_flagassertsbump.assert_awaited_once_with("docs_collection_recreated"). Its_Indexeris a stub whose_resolve_collectionsets the flag, so the real_handle_dim_mismatch(doc_indexer.py:460) is not exercised. Still needed: a test that drives the real dimension-mismatch handling throughresolve_collection, including a re-index that finds no files.knowledge/retrieval_invalidation.py:91registersWriteEntryPoint("services/knowledge/doc_index_orphans.py", "_bump_after_recreate", ...). The guard exempts_handle_dim_mismatch(retrieval_invalidation_20958_test.py:387-388) on the grounds thatresolve_collectionawaits the registered hook, but nothing checks that it still does. If that call were removed, the guard would stay green. Still needed: the guard, or a test it relies on, asserts that the rebuild path reaches the registered entry point.AC2 and AC3 will be finished in a follow-up PR for this issue.
fix(knowledge): invalidate retrieval caches on a dim-mismatch collect…
mrveiss commentedon Nov 21, 2026
Read-only check of the local install on 2026-11-21 (install at main d8cbd91). No data was changed.
20261121_118is byte-identical to main's copy.20261121_118as applied, and whether its two unique indexes (uq_approvals_pending_connector_credential_strip,uq_approvals_pending_empty_collection_delete) exist. This read-only check had no access to the database credentials.mrveiss commentedon Nov 21, 2026
Database check on the local install (owner-approved, read-only SELECT queries; install at main 9c2d82b):
alembic_version=20261121_118(1 row).uq_approvals_pending_connector_credential_strip: UNIQUE onapprovals ((context->>'connector_id'))WHERE status='pending' AND action='connector_credential_strip'uq_approvals_pending_empty_collection_delete: UNIQUE onapprovals ((context->>'collection'))WHERE status='pending' AND action='chroma_empty_collection_delete'This closes the database gap in the earlier host check.
Merge pull request #21994 from mrveiss/issue-20992-rebuild-path-tests
mrveiss commentedon Nov 22, 2026
Closure evidence for AC2/AC3 (merged in #21994, 95adb8e, ancestor of main):
autobot-backend/services/knowledge/test_doc_index_dim_mismatch_real_handler_20992.pydrives the REAL handler throughresolve_collection:test_real_handler_recreates_and_bumps_the_epoch(L66), no bump on a matching dimension (L77), flag off raises without deleting or bumping (L87), and the bump does not depend on the forced re-index finding files (L98).autobot-backend/knowledge/retrieval_invalidation_20958_test.pylists_handle_dim_mismatchas an invalidating entry point (L387) and asserts its only caller is_resolve_collection(L478).test(kb): drive the real dimension-mismatch handler and guard the reb…