Skip to content

bug(kb): doc index dimension-mismatch rebuild does not invalidate retrieval caches #20992

Closed

Description

@mrveiss

Found while implementing #20958.

Problem

_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

Activity

  1. added
    bugSomething isn't working
    knowledgeKnowledge base system
    area: kb-retrievalWave 5 · cluster J — Knowledge-base retrieval quality
    phase:M1.8Knowledge base: upload, web sources and chat retrieval work end to end
    on Nov 7, 2026
  2. added
    needs-structureMissing goal milestone, matching phase label or native parent (#19522)
    on Nov 7, 2026
  3. github-actions commented on Nov 7, 2026

    @github-actions
    Contributor

    needs-structure cleared: goal milestone, matching phase label and native parent (or sub-issues) are all present (#19522).

  4. removed
    needs-structureMissing goal milestone, matching phase label or native parent (#19522)
    on Nov 7, 2026
  5. 21 remaining items

  6. github-actions commented on Nov 21, 2026

    @github-actions
    Contributor

    Landed in #21835, merge 17562e568e

  7. mrveiss commented on Nov 21, 2026

    @mrveiss
    OwnerAuthor

    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.py resolve_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.
    The #20958 guard lists the rebuild path ✘ open 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.

  8. mrveiss commented on Nov 21, 2026

    @mrveiss
    OwnerAuthor

    Read-only check of the local install on 2026-11-21 (install at main d8cbd91). No data was changed.

  9. mrveiss commented on Nov 21, 2026

    @mrveiss
    OwnerAuthor

    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.

  10. added a commit that references this issue on Nov 22, 2026
  11. mrveiss commented on Nov 22, 2026

    @mrveiss
    OwnerAuthor

    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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: kb-retrievalWave 5 · cluster J — Knowledge-base retrieval qualitybackendbugSomething isn't workingknowledgeKnowledge base systemknowledge-basephase:M1.8Knowledge base: upload, web sources and chat retrieval work end to endpriority: high

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions