Skip to content

fix(preflight): stop the probe from creating the collection with Chroma's default EF - #253

Merged
lyonzin merged 2 commits into
masterfrom
fix/248-preflight-default-ef
Oct 25, 2026
Merged

lyonzin merged 2 commits into
masterfrom
fix/248-preflight-default-ef

Conversation

@lyonzin

@lyonzin lyonzin commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fresh installs and new data directories fail to start on v4.10.0 and v4.11.0 with Embedding function conflict: new: fastembed-… vs persisted: default (#248, #252).

Root cause: since v3.9.0 the preflight probe ran get_or_create_collection(name) without an embedding function. On a fresh data_dir it created the collection, and ChromaDB persisted its default EF. Up to v4.9.x, _safe_get_collection() deleted and recreated the collection on any EF conflict, which hid the problem. v4.10.0 (#234) correctly stopped deleting on open errors, and that exposed it: every fresh install, and every new Docker volume, now crashes at startup.

Closes #248
Closes #252

Type of change

  • feat — new feature
  • fix — bug fix
  • docs — documentation only
  • refactor — no behavior change
  • perf — performance improvement
  • test — adding or improving tests
  • chore — tooling, deps, CI
  • BREAKING CHANGE (explain in Migration section below)

What changed

  • mcp_server/preflight.py: the probe opens the collection with get_collection(..., embedding_function=None) and prints missing on NotFoundError. It never creates anything.
  • mcp_server/server.py: when opening fails, _safe_get_collection() calls _drop_empty_default_ef_collection(), which drops the collection only if it is empty and its persisted EF is ChromaDB's default — the leftover of the old probe — and then recreates it with FastEmbed. A collection holding data is never dropped, and the original error is still raised ("Existing index preserved").
  • Tests: the real probe child against real ChromaDB (fresh dir → missing with nothing created; existing collection → counted), plus two storage-safety tests (the empty leftover is recreated and survives the next start; a default-EF collection with data is never dropped).

Why

Reproduced end to end on unmodified master: on a fresh KNOWLEDGE_RAG_DIR the real probe leaves knowledge_base with {'type': 'known', 'name': 'default'}, and opening it the way the server does fails with the exact error from both issues. Same result on chromadb 1.4.0 (minimum supported) and 1.5.9.

collection.modify(configuration={"embedding_function": ...}) cannot rebind the EF in place (ChromaDB requires is_legacy() on the EF), so recreating the empty leftover is the smallest fix. Limiting it to empty collections keeps the v4.10.0 guarantee that data is never discarded on open errors.

The probe test runs the real child instead of mocking it: the probe must never fail on a healthy index, because three failures quarantine the index.


7 Pillars Quality Gate

1. Security

  • No new secrets, tokens, or credentials in the diff (gitleaks will block)
  • No new use of eval, exec, subprocess shell=True, pickle.loads on untrusted input, or arbitrary deserialization
  • New dependencies (if any) reviewed for known CVEs and license compatibility — none added
  • Path traversal, command injection, and SSRF surfaces explicitly considered for any new I/O code — no new I/O surface

2. Stability

  • All existing tests pass on Linux, Windows and macOS × Python 3.11/3.12/3.13 — verified locally on Windows / 3.12; CI matrix pending
  • New behavior has regression tests; concurrency tests use explicit synchronization and bounded waits
  • Coverage does not regress (codecov gate)
  • No tests were skipped, deleted, or marked xfail to make the PR pass

3. Memory leak

  • Long-lived objects (orchestrator, watcher, cache) are bounded
  • New caches have eviction policy — no new caches
  • No new global state that grows unbounded with usage
  • If you added a new module that loads heavy resources, consider lazy initialization — no new module

4. Versatility

  • Works on Linux, Windows, macOS (paths, line endings, locale considered)
  • Works on Python 3.11, 3.12, 3.13 (no Python-version-specific syntax without fallback)
  • No hardcoded paths, locales, or encodings
  • If you touched a parser, the format smoke matrix and affected parser tests pass — no parser touched

5. Scalability

  • No O(n²) or worse algorithms on user-controlled inputs
  • Benchmark impact considered
  • If perf regression > 10% in any metric, justification provided below
  • Concurrency safety: no new shared mutable state without lock or documented thread confinement

Performance impact: N/A — no hot-path change. The new code runs only when opening the collection fails at startup.

6. Versioning

  • Version agrees in pyproject.toml, mcp_server/__init__.py, and npm/package.json (no bump in this PR)
  • If this is a breaking change: … — not breaking
  • User-facing changes have an entry under ### Unreleased in CHANGELOG.md
  • Public API surface unchanged (check_api_surface.py --check OK)

7. Quality

  • ruff check passes
  • ruff format --check passes
  • Type hints on new functions
  • Docstrings on new functions (interrogate 90.6%)
  • Cyclomatic complexity reasonable
  • No dead code (vulture clean)
  • PR is reasonably sized (127+/11−)

Migration / Breaking changes

N/A. Installs that already hit the error start normally after upgrading: the empty leftover collection is recreated once, with a [RECOVERY] line on stderr.

Test plan

  • pytest tests/ passed locally — 1267 passed, 1 skipped (Windows 11, Python 3.12, chromadb 1.5.9)
  • New tests also pass with chromadb 1.4.0
  • ruff, ruff format, bandit, interrogate, vulture, check_api_surface, check_version_sync, check_changelog, check_test_count, git diff --check — clean
  • Manual smoke test: fresh KNOWLEDGE_RAG_DIR → real preflight probe → server-style open, on chromadb 1.4.0 and 1.5.9. Before the fix it fails with the reported error; after it the probe prints missing, creates nothing, and the open succeeds.

Documentation

  • Updated README.md (if user-facing) — not needed
  • Updated docs/ (if applicable) — not needed
  • Added entry to ### Unreleased in CHANGELOG.md

Reviewer checklist

  • Reviewed line-by-line
  • Verified the 7 pillars CI status checks are green
  • Verified no obvious adversarial implications
  • Approved performance impact

By submitting this PR I confirm I read CONTRIBUTING.md and agree to the Code of Conduct.

Summary by CodeRabbit

  • Bug Fixes
    • Fresh installations and new data directories can now start without the startup check creating a collection.
    • Empty collections left by the previous startup check are recovered automatically on startup.
    • Collections containing data are preserved; if recovery is not possible, startup reports an error.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge, with the previous coverage gap addressed and no new blocking issues found.

Summary

The PR stops the startup probe from creating collections and recovers empty collections left with ChromaDB's default embedding function.

  • Startup checks leave missing Chroma collections untouched.
  • Startup repairs empty leftovers tied to Chroma’s default embedding.

Reviews (2) · Last reviewed commit: "test(preflight): probe a production Fast..." · Reviewed by Greptile

…ma's default EF

On a fresh data_dir the preflight child ran get_or_create_collection()
without an embedding function, so ChromaDB persisted its `default` EF.
The server then opened the collection with FastEmbed and ChromaDB raised
"Embedding function conflict: new: fastembed-... vs persisted: default".
v4.10.0 removed the destructive recovery that used to hide this, so every
fresh install and every new Docker volume failed to start.

- The probe reads the collection with get_collection() and reports
  "missing" when it does not exist yet.
- _safe_get_collection() recreates the collection the old probe left
  behind, only when it is empty and bound to the default EF. A collection
  with data is never dropped; the error is raised as before.

Closes #248
Closes #252

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

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 51 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7accf792-5f91-4810-ad50-4918d43da28b
Commits

Reviewing files that changed from the base of the PR and between d78cd16 and 6f40e67.

Files selected for processing: 1
  • tests/test_preflight.py

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a853925e-68bc-41a5-af1f-1d9f2704359b
Commits

Reviewing files that changed from the base of the PR and between 639e357 and d78cd16.

Files selected for processing: 5
  • CHANGELOG.md
  • mcp_server/preflight.py
  • mcp_server/server.py
  • tests/test_preflight.py
  • tests/test_storage_safety.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Walkthrough

The preflight probe now reads the configured collection without creating it. During startup, an empty collection that uses Chroma’s default embedding function can be replaced. Collections containing records are preserved.

Changes: Startup collection handling

Layer / File(s) Summary
Read-only preflight probe
mcp_server/preflight.py, tests/test_preflight.py, CHANGELOG.md
The probe reports missing when the collection does not exist and does not create it. A subprocess test checks the missing and existing collection cases.
Empty collection recovery
mcp_server/server.py, tests/test_storage_safety.py
Startup retries collection access after removing an empty collection bound to Chroma’s default embedding function. Tests verify that an empty collection is replaced and a populated collection is preserved.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: hohlas

Merge Risk: Minimal · up to d78cd

The change stops the preflight probe from creating a default-embedding collection, so fresh installs should start. It deletes only empty default-embedding collections and keeps populated ones. A remaining race needs unsupported concurrent multi-writer startup, so merge risk is minimal.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 64.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 4 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the primary change: preventing the preflight probe from creating the collection with Chroma's default embedding function.
Linked Issues check Passed The PR meets the coding requirements in [#248] and [#252]. mcp_server/preflight.py now calls get_collection(..., embedding_function=None) and reports missing after NotFoundError, so a fresh da…
Out of Scope Changes check Passed The changes stay within the linked issue scope. The preflight change prevents the reported startup failure. The server recovery change supports migration from the stale empty collection without discar…
Full details: Linked Issues check

Explanation

The PR meets the coding requirements in [#248] and [#252]. mcp_server/preflight.py now calls get_collection(..., embedding_function=None) and reports missing after NotFoundError, so a fresh data directory does not create a default-EF collection. mcp_server/server.py opens the production collection with self.embed_fn. Recovery drops and recreates only an empty collection whose persisted embedding function is default. Collections with data remain intact, and the original open error includes Existing index preserved. Tests cover the real read-only probe, empty default-EF recovery, and preservation of populated default-EF collections.

Full details: Out of Scope Changes check

Explanation

The changes stay within the linked issue scope. The preflight change prevents the reported startup failure. The server recovery change supports migration from the stale empty collection without discarding indexed data. The added tests verify the issue behavior and storage safety. The changelog entry documents the fix.

Full details: Docstring Coverage

Explanation

Docstring coverage is 64.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 4 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 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

Comment @coderabbitai help to get the list of available commands.

Comment thread tests/test_preflight.py Resolved
…e default-EF leftover

The real-probe test only seeded a collection bound to Chroma's default EF.
Existing users have collections written through FastEmbedEmbeddings,
persisted as a legacy EF, and three probe failures would quarantine them.
Seed that case with data, then the empty default-EF leftover.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lyonzin

lyonzin commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner Author

Applying skip-perf-gate: the Pillar 5 failures are measurement noise, not a regression.

Run Head Flagged
1 d78cd16 (fix) none — gate passed
2 6f40e67 (test-only commit) test_bench_query_cache_miss +18.9% (700 → 832 ns; pytest-benchmark calibrated 7 iterations/round on the master side, 1 on the branch)
3 same run, failed jobs re-run test_bench_fts5_lexical_hot[MDR-AD002] +16.5%, [T1078.001] +15.6%; query_cache_miss now flat (397 vs 396 ns)

The production code is identical in all three runs, and this PR touches neither the query cache nor FTS5. Its only runtime change sits in the startup error path. A different random subset of sub-100 µs benchmarks crosses ±10% on each run.

@lyonzin lyonzin added the skip-perf-gate Bypass performance regression gate (use only for release PRs or measurement-noise regressions) label Oct 25, 2026
@lyonzin
lyonzin merged commit ab98f95 into master Oct 25, 2026
80 of 84 checks passed
@lyonzin
lyonzin deleted the fix/248-preflight-default-ef branch October 25, 2026 15:10
lyonzin added a commit that referenced this pull request Oct 25, 2026
…ma's default EF (#253)

On a fresh data_dir the preflight child ran get_or_create_collection()
without an embedding function, so ChromaDB persisted its `default` EF.
The server then opened the collection with FastEmbed and ChromaDB raised
"Embedding function conflict: new: fastembed-... vs persisted: default".
v4.10.0 removed the destructive recovery that used to hide this, so every
fresh install and every new Docker volume failed to start.

- The probe reads the collection with get_collection() and reports
  "missing" when it does not exist yet.
- _safe_get_collection() recreates the collection the old probe left
  behind, only when it is empty and bound to the default EF. A collection
  with data is never dropped; the error is raised as before.
- Tests run the real probe child against a fresh data_dir, a production
  FastEmbed collection with data and the empty default-EF leftover.

Closes #248
Closes #252
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-perf-gate Bypass performance regression gate (use only for release PRs or measurement-noise regressions)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Fresh Docker deployment fails with ChromaDB embedding function conflict when using multilingual profile [Bug] Embedding function already exists

1 participant