fix: batch upserts in miner to prevent ChromaDB 1.5.x compaction crashes#796
Open
IzmanIzy wants to merge 1 commit intoMemPalace:mainfrom
Open
fix: batch upserts in miner to prevent ChromaDB 1.5.x compaction crashes#796IzmanIzy wants to merge 1 commit intoMemPalace:mainfrom
IzmanIzy wants to merge 1 commit intoMemPalace:mainfrom
Conversation
The project miner previously upserted each chunk individually, which causes excessive WAL turnover in ChromaDB >= 1.5. The Rust compactor cannot keep up with the write rate, leading to either: - `InternalError: Failed to apply logs to the metadata segment` - Segfault (SIGSEGV, exit code 139) during background compaction This change batches all chunks from a single file into one `upsert()` call and introduces periodic checkpoints (every 200 files) that release and re-acquire the collection, giving the compactor time to flush. Tested on a 406-file knowledge base (3026 drawers) with ChromaDB 1.5.7 — zero crashes, clean completion with two checkpoint flushes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
This addresses the same WAL pressure issue we tackled in #629 — worth noting that PR also adds bulk mtime pre-fetch ( |
1 similar comment
Author
|
This addresses the same WAL pressure issue we tackled in #629 — worth noting that PR also adds bulk mtime pre-fetch ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
collection.upsert()call instead of upserting each chunk individually. This reduces WAL write pressure that causes the Rust compactor in ChromaDB >= 1.5 to crash.Problem
When mining projects with 100+ files, the miner issues thousands of individual upserts. On ChromaDB 1.5.x this causes:
InternalError: Failed to apply logs to the metadata segment— WAL entries accumulate faster than compaction can process themBoth errors are intermittent and depend on project size, making them hard to reproduce in small test suites but consistent on real-world knowledge bases (300+ files).
Root Cause
ChromaDB's Rust compactor (introduced in 1.5.x) runs in a background thread. Individual upserts create one WAL entry each, and 2000+ entries in rapid succession overwhelm the compactor's ability to merge them atomically. The previous code already had a comment about hnswlib's thread-unsafe
updatePointpath causing segfaults on macOS ARM — this is the same class of bug on the compaction side, now affecting all platforms.Testing
pytest tests/ -k "mine"— 37 passed, 0 failed)ruff check) and format (ruff format --check) passTest plan
ruff check .passesruff format --check .passespytest tests/ -v --ignore=tests/benchmarks -k "mine"— 37 passed🤖 Generated with Claude Code