Skip to content

fix(searcher): guard CLI divergence before Chroma open - #2016

Merged
igorls merged 2 commits into
developfrom
agent/fix-cli-divergence-preopen
Jul 14, 2026
Merged

fix(searcher): guard CLI divergence before Chroma open#2016
igorls merged 2 commits into
developfrom
agent/fix-cli-divergence-preopen

Conversation

@igorls

@igorls igorls commented Jul 14, 2026

Copy link
Copy Markdown
Member

What changed

  • Probe Chroma HNSW capacity before get_collection() in CLI search.
  • Route diverged Chroma palaces to the existing SQLite BM25 fallback without constructing a Chroma client.
  • Keep healthy Chroma and every non-Chroma backend on their normal vector path.
  • Render fallback source names consistently with normal CLI results.

Why

#1967 guarded only col.query(), after collection opening. That ordering still allowed Chroma client construction and embedder-identity enforcement (including a possible collection.count()) to touch damaged native index state before the guard ran. The MCP path already probes before _get_client; the CLI path needs the same boundary.

This draft supersedes #1967 with the pre-open ordering fix while retaining its useful BM25 fallback. Original design and implementation credit: @trek-e.

Local validation

  • uv run pytest tests/test_searcher.py tests/test_hnsw_capacity.py tests/test_backends.py -q — 169 passed
  • Focused pre-open/healthy/non-Chroma guard tests — 3 passed
  • Ruff check and format checks pass
  • Real disposable-palace smoke on this Mac: created a Chroma palace with an actual drawer and SQLite FTS5 data, forced the divergence gate, made get_collection() raise if called, and confirmed CLI search returned the exact stored sentence through BM25 without opening Chroma.

Co-authored-by: Tom Boucher <trekkie@nomorestars.com>
@igorls
igorls marked this pull request as ready for review July 14, 2026 22:31
@igorls
igorls requested a review from milla-jovovich as a code owner July 14, 2026 22:31
Copilot AI review requested due to automatic review settings July 14, 2026 22:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aligns the CLI search() path with the MCP path by probing for Chroma HNSW divergence before attempting to open a Chroma collection, and falls back to the existing SQLite BM25-only search when divergence is detected—avoiding native crashes while keeping output formatting consistent.

Changes:

  • Add a pre-open Chroma HNSW divergence probe for CLI search and route diverged palaces to BM25-only output.
  • Introduce a dedicated CLI BM25-only result printer that mirrors the normal vector-path output shape and includes an actionable repair notice.
  • Add regression tests covering diverged/healthy Chroma paths and ensuring non-Chroma backends don’t invoke the Chroma-specific probe.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
mempalace/searcher.py Adds pre-open HNSW divergence gating and a BM25-only CLI fallback printer to avoid Chroma open/query crashes.
tests/test_searcher.py Adds regression coverage for diverged vs healthy Chroma behavior and ensures other backends aren’t fenced by the Chroma probe.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread mempalace/searcher.py Outdated
@igorls
igorls merged commit 88e454c into develop Jul 14, 2026
8 checks passed
@igorls
igorls deleted the agent/fix-cli-divergence-preopen branch July 14, 2026 23:28
@igorls igorls mentioned this pull request Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants