Skip to content

fix(knowledge): dim-mismatch rebuild invalidates retrieval caches; credential and empty-collection cleanup proposals (#20992) - #21835

Merged
mrveiss merged 51 commits into
mainfrom
issue-20992-kb-defect-batch
Nov 21, 2026
Merged

mrveiss merged 51 commits into
mainfrom
issue-20992-kb-defect-batch

Conversation

@mrveiss

@mrveiss mrveiss commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Thinking Path

This PR was opened for an existing branch that never had one (triage status UNFINISHED). The branch carries 4ahead commit(s) of work not on main, linked to #20992 (bug(kb): doc index dimension-mismatch rebuild does not invalidate retrieval caches). It still needs a conflict sync with main and a review before it can merge. Acceptance criteria have not been verified against this branch.

What Changed

Commits on the branch (not on main):

Diff summary: 19 files changed, 1139 insertions(+), 12 deletions(-)

Verification

Not yet verified. No CI evidence: this is a draft, and CI runs were cancelled on open pending a conflict sync with main and review.

Model Used

Branch authored by earlier Claude sessions; PR opened by Claude Sonnet 5.5.

Refs #20992

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added an admin Data Hygiene section to review stored connector credentials and empty knowledge-base collections. Findings are read-only, with unreadable or unscannable items reported separately.
    • Admins can submit eligible cleanup requests for approval. Connector cleanup is limited to credential copies also held in the secrets store; empty collections are checked again before deletion.
  • Improvements
    • Knowledge-base collection operations are coordinated to reduce conflicts between updates and approved cleanup.

@mrveiss mrveiss added the phase:M1.8 Knowledge base: upload, web sources and chat retrieval work end to end label Nov 18, 2026
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 46 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 5bf8ad0 and 5f50b90.

Files ignored due to path filters: 2

  • autobot-frontend/src/types/generated/api.ts is excluded by !**/generated/**
  • scripts/python_file_size_known_large.py is excluded by !scripts/python_file_size_known_large.py
Files selected for processing: 56

  • autobot-backend/api/_connector_keys.py
  • autobot-backend/api/admin_connector_credentials.py
  • autobot-backend/api/admin_connector_credentials_test.py
  • autobot-backend/api/knowledge_chroma.py
  • autobot-backend/api/knowledge_chroma_admin_16666_test.py
  • autobot-backend/api/knowledge_chroma_empty.py
  • autobot-backend/api/knowledge_chroma_empty_test.py
  • autobot-backend/api/knowledge_connectors.py
  • autobot-backend/api/schemas_connector_credentials.py
  • autobot-backend/api/schemas_knowledge_chroma.py
  • autobot-backend/knowledge/retrieval_invalidation.py
  • autobot-backend/knowledge/retrieval_invalidation_20958_test.py
  • autobot-backend/knowledge/vector_repair.py
  • autobot-backend/migrations/baseline.py
  • autobot-backend/migrations/versions/20261121_118_approvals_pending_kb_cleanup_unique.py
  • autobot-backend/models/approval.py
  • autobot-backend/npu_semantic_search.py
  • autobot-backend/services/audit/taxonomy.py
  • autobot-backend/services/chroma_empty_collections.py
  • autobot-backend/services/connector_credential_cleanup_action.py
  • autobot-backend/services/connector_credential_scan.py
  • autobot-backend/services/kb_cleanup_proposals.py
  • autobot-backend/services/kb_cleanup_proposals_race_20992_test.py
  • autobot-backend/services/knowledge/doc_index_orphans.py
  • autobot-backend/services/knowledge/doc_indexer.py
  • autobot-backend/services/knowledge/test_doc_index_dim_mismatch_invalidation.py
  • autobot-backend/tests/migrations/test_index_marker_adoption_20992.py
  • autobot-backend/tests/migrations/test_probe_ladder_selfcheck.py
  • autobot-backend/utils/async_chromadb_client.py
  • autobot-backend/utils/async_chromadb_delete_if_empty_test.py
  • autobot-backend/utils/chromadb_client.py
  • autobot-backend/utils/collection_lease_fail_open_20992_test.py
  • autobot-backend/utils/leased_chroma.py
  • autobot-slm-frontend/src/composables/useKnowledgeCleanupApi.ts
  • autobot-slm-frontend/src/locales/ar.json
  • autobot-slm-frontend/src/locales/de.json
  • autobot-slm-frontend/src/locales/en.json
  • autobot-slm-frontend/src/locales/es.json
  • autobot-slm-frontend/src/locales/fa.json
  • autobot-slm-frontend/src/locales/fr.json
  • autobot-slm-frontend/src/locales/he.json
  • autobot-slm-frontend/src/locales/lv.json
  • autobot-slm-frontend/src/locales/pl.json
  • autobot-slm-frontend/src/locales/pt.json
  • autobot-slm-frontend/src/locales/ur.json
  • autobot-slm-frontend/src/views/settings/admin/DataHygieneView.vue
  • autobot-slm-frontend/src/views/settings/admin/KnowledgeCleanupSection.vue
  • autobot_shared/coordination/claim_waitlist.py
  • autobot_shared/coordination/collection_lease.py
  • autobot_shared/coordination/work_claims.py
  • autobot_shared/coordination/work_claims_sync.py
  • autobot_shared/env_registry_kb_graph.py
  • docs/developer/AGENT_COORDINATION.md
  • docs/developer/ARCHITECTURE_EXCEPTIONS.md
  • docs/developer/ENV_VARS.md
  • repo_tests/kb_destructive_paths_allowlist_21383.py
Walkthrough

The pull request adds admin reporting and approval-gated cleanup for stored connector credentials and empty knowledge collections. It adds shared proposal and collection-lease controls, integrates cleanup into the Data Hygiene view, and updates document-index cache invalidation after collection recreation.

Changes: Knowledge cleanup and Chroma coordination

Layer / File(s) Summary
Proposal concurrency and uniqueness
autobot-backend/services/kb_cleanup_proposals.py, autobot-backend/models/approval.py, autobot-backend/migrations/versions/*, autobot-backend/migrations/baseline.py, autobot-backend/services/audit/taxonomy.py, autobot-backend/services/kb_cleanup_proposals_race_20992_test.py, autobot-backend/tests/migrations/*
Shared helpers create, reuse, and audit cleanup proposals, including concurrent insert handling. Partial unique indexes limit pending proposals by connector or collection. Migration detection and tests cover these indexes.
Connector credential scan and cleanup
autobot-backend/api/_connector_keys.py, autobot-backend/api/admin_connector_credentials.py, autobot-backend/api/knowledge_connectors.py, autobot-backend/api/schemas_connector_credentials.py, autobot-backend/services/connector_credential_scan.py, autobot-backend/services/connector_credential_cleanup_action.py, autobot-backend/api/admin_connector_credentials_test.py
The admin API reports sensitive field names and secrets-store-copy status without returning credential values. An approval action validates matching stored values before conditionally removing sensitive fields from a connector record.
Shared and exclusive collection leases
autobot_shared/coordination/work_claims.py, autobot_shared/coordination/work_claims_sync.py, autobot_shared/coordination/claim_waitlist.py, autobot_shared/coordination/collection_lease.py, autobot_shared/env_registry_kb_graph.py, docs/developer/AGENT_COORDINATION.md, docs/developer/ENV_VARS.md, autobot-backend/utils/collection_lease_fail_open_20992_test.py, repo_tests/kb_destructive_paths_allowlist_21383.py
The coordination API adds synchronous work-claim operations and renewable shared writer and exclusive delete leases. Settings, documentation, and tests cover lease behaviour and failure handling.
Empty collection reporting and deletion
autobot-backend/api/knowledge_chroma.py, autobot-backend/api/knowledge_chroma_empty.py, autobot-backend/api/schemas_knowledge_chroma.py, autobot-backend/services/chroma_empty_collections.py, autobot-backend/utils/leased_chroma.py, autobot-backend/utils/chromadb_client.py, autobot-backend/utils/async_chromadb_client.py, autobot-backend/knowledge/vector_repair.py, autobot-backend/npu_semantic_search.py, autobot-backend/api/knowledge_chroma_empty_test.py, autobot-backend/utils/async_chromadb_delete_if_empty_test.py
The service reports empty and unreadable knowledge-base collections. Admin endpoints create approval requests, and approved deletion rechecks the collection under an exclusive lease. Chroma client writes and selected blocking operations run through worker threads.
Admin cleanup interface and translations
autobot-slm-frontend/src/composables/useKnowledgeCleanupApi.ts, autobot-slm-frontend/src/views/settings/admin/DataHygieneView.vue, autobot-slm-frontend/src/views/settings/admin/KnowledgeCleanupSection.vue, autobot-slm-frontend/src/locales/*.json
The Data Hygiene view displays both reports, warnings, and per-item proposal results. The composable supplies report and proposal calls, and locale files add translated labels and messages.

Document collection cache invalidation

Layer / File(s) Summary
Collection recreation and cache invalidation
autobot-backend/services/knowledge/doc_index_orphans.py, autobot-backend/services/knowledge/doc_indexer.py, autobot-backend/knowledge/retrieval_invalidation.py, autobot-backend/knowledge/retrieval_invalidation_20958_test.py, autobot-backend/services/knowledge/test_doc_index_dim_mismatch_invalidation.py
The indexer resolves collections through an asynchronous helper. The helper preserves the reindex flag and invalidates retrieval caches after recreation, including after cancellation waits for the worker to finish.
Merge Risk: Moderate · previous review 5bf8a

This change adds approval-gated cleanup and collection write leases. Under rare registry-outage or process-stall conditions, an approved empty-collection delete can still remove vectors written at the same time. Cached Chroma handles can also go stale after a cleanup or a cancelled delete, which breaks later writes until restart. Resolve or explicitly accept these before merging, and run CI after syncing with main.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names two of the changes in this PR: the dimension-mismatch rebuild that invalidates retrieval caches, and the credential and empty-collection cleanup proposals. Both appear in the raw summa…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names two of the changes in this PR: the dimension-mismatch rebuild that invalidates retrieval caches, and the credential and empty-collection cleanup proposals. Both appear in the raw summary (doc_index_orphans.resolve_collection, admin_connector_credentials, knowledge_chroma_empty). The title does not mention the per-collection Chroma write lease, the migration and index changes, or the shared work-claims refactor, which are also large parts of the changeset. The title is therefore partially related: it covers real aspects of the change but omits some of the main work. The title is also long, at 125 characters, which is above typical short-title guidance.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@mrveiss

mrveiss commented Nov 19, 2026

Copy link
Copy Markdown
Owner Author

Decision (owner, 2026-11-19): the two cleanup-proposal surfaces (connector credentials, empty KB collections) are wired into the SLM Data hygiene page (#17038), not allowlisted as HTTP-only. The approval itself stays in the existing approval queue. Rework follows in this PR, together with the re-review findings (pending-proposal race closed by a partial unique index, function length, KB re-check in the delete handler).

@mrveiss mrveiss added the land-next Landing set: CI capacity goes to these PRs first (owner direction 2026-09-18, #15397) label Nov 21, 2026
@mrveiss mrveiss removed the land-next Landing set: CI capacity goes to these PRs first (owner direction 2026-09-18, #15397) label Nov 21, 2026
@mrveiss mrveiss added the land-next Landing set: CI capacity goes to these PRs first (owner direction 2026-09-18, #15397) label Nov 21, 2026
@mrveiss mrveiss added the land-next Landing set: CI capacity goes to these PRs first (owner direction 2026-09-18, #15397) label Nov 21, 2026
@mrveiss
mrveiss merged commit 17562e5 into main Nov 21, 2026
71 checks passed
@mrveiss
mrveiss deleted the issue-20992-kb-defect-batch branch November 21, 2026 17:56
@mrveiss mrveiss removed the land-next Landing set: CI capacity goes to these PRs first (owner direction 2026-09-18, #15397) label Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

phase:M1.8 Knowledge base: upload, web sources and chat retrieval work end to end

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant