Repository navigation
Fix data loss and stale state in multi-node builds - #41
Merged
Merged
Conversation
- Shard merge commits each shard before DETACH and raises when a shard can't be detached, so producers 10 and up are no longer lost (#1). - Segment ingest deletes a file only after a save covers its vectors and, on rerun, skips IDs an HNSW index already holds (#2). The consumer no longer repeats the ingesters' final save, and the resume script counts claimed .npz.ingesting files. - Producer checkpoints advance only after the tar-boundary finalize() (#3). - The consumer glob and has_segment_files() ignore *_pending.npz (#4). - A successful consume removes producer_N.done markers; producers and vector_build_multi.sbatch remove stale ones at start (#5). - Batch scripts, the cluster guide and cli.py comments name the real writer guard, sqlite/faiss_writer.guard (#15). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Bill Hlavacek <bill.hlavacek@gmail.com>
This was referenced Dec 2, 2026
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.
Fixes six bugs in multi-node (producer/consumer) builds. Each fix has a regression test that fails on
mainand passes here.Fixes #1
Fixes #2
Fixes #3
Fixes #4
Fixes #5
Fixes #15
#1: shard merge stops after 10 shards
merge_shard_databases()now commits each shard's INSERTs beforeDETACH DATABASE. A shard whose merge fails is rolled back (merged completely or not at all) and kept for a rerun. A failed DETACH is no longer ignored: it raisesShardDetachError(asqlite3.OperationalError) and ends the merge, because a shard left attached makes every ATTACH after the tenth fail.Tests (
tests/test_db.py): merging 12 shard databases brings in all 12 papers, chunks and files rows and leaves no shard attached (main: 10 of 12,too many attached databases - max 10). A connection that leaves a query open on the shard after each commit makes DETACH fail with "is locked" once shard 0's merge is committed; the merge now raises and stops before shard 1 (main: no error).#2: consumer deletes segment files before their vectors are saved
Both segment ingesters keep each claimed
.ingestingfile until a successful save covers its vectors: the immediate save after an add, the periodic save, or a new forced save at the end of the function. Files that error after their vectors were added stay claimed instead of being renamed back.A job killed after a save but before the delete leaves a claimed file whose vectors are already saved. On rerun, a claimed file skips IDs that an HNSW index already holds, so the paper index (which can't remove vectors) doesn't get duplicates; other indexes replace those vectors as before.
run_consume_only_mode()no longer force-saves both indexes at the end, since each ingest function now saves what it added; that avoids a second full write of each index.vector_resume_consumer.sbatchcounts the*.npz.ingestingfiles that a stopped consumer keeps, so the documented resume path doesn't report "Nothing to do".Tests (
tests/test_segments.py), with_SAVE_MIN_SECthrottled so only the first forced save runs:main.tests/integration/test_multi_node.py: the resume script's segment count includes a claimed.npz.ingestingfile (main: not counted; skipped on Windows).#3: producer checkpoint covers segments that are later deleted
In producer mode, mid-tar flushes no longer advance the checkpoint, so it advances only at the tar boundary, after
finalize().Why not finalize at mid-tar flushes: the paper and chunk buffers flush independently (different batch sizes). At a paper flush, chunks for the same articles are usually still in memory, so finalizing there would publish paper vectors whose chunks may never be written, and a checkpoint advanced at that point would still cover articles whose chunk vectors exist nowhere on disk. Checkpointing only after the tar boundary, when both buffers are written and finalized, avoids both. Cost: a producer that stops mid-tar re-scans that tar on restart.
Remaining gap (#13, not fixed here): each article is committed on its own when its savepoint is released (#13). A producer restarted without
--rebuild(the batch scripts' default) still skips those articles through the files table, whatever the checkpoint says. This PR makes the checkpoint correct; the files-table path needs #13.Test (
tests/test_segments.py): a producer withpaper_batch=2flushes papers once mid-tar, then its chunk embedder fails on the tar-boundary batch (as a CUDA OOM would). The checkpoint counts no article of that tar (main: 2), and a restart (with--rebuild, so only the checkpoint decides) produces segments for all 3 articles.#4: consumer picks up
*_pending.npz_glob_segment_files()andhas_segment_files()exclude names ending in_pending.npz, so the consumer,--rebuild's "unconsumed segments" check and shard validation see only finalized segments.Test: the existing strict-xfail
test_consumer_does_not_see_pending_segmentsnow passes; its marker is removed.#5: producer
.donemarkers are never removedrun_consume_only_mode()callscleanup_done_files()after a successful consume. Producers call the newProducerCoordinator.clear_stale_marker()at startup, before any work, to remove their own marker from an earlier run. With node-local staging (the default invector_build_multi.sbatch), producers write markers locally and rsync them to the sharedemb_segments/at the end, so they can't see an old marker there; the script therefore removesproducer_*.donefrom the shared directory at job start, before launching producers.Tests:
tests/test_segments.py: a consume that times out keeps the finished producer's marker; once both producers are done, the consume indexes everything and leaves no segments or markers (main: both markers remain).tests/integration/test_multi_node.py, running the real CLI with the fake embedders: two producers and a consumer index all 3 papers and 6 chunks, leave onlybuild_meta.json, and a following--rebuildis not blocked (main: blocked with "Prior multi-node run (not consumed)"). A producer that fails right after starting has removed its own stale marker and left the other shard's (main: stale marker kept). The multi-node script removes the markers before it starts any producer (main: no such line).Related, not fixed here (#40):
vector_resume_consumer.sbatchwrites.shard_XX_completemarkers, which the consumer never reads. Since a successful consume now removes the real markers, rerunning that script after a consume that left some segments uningested waits for producers until it times out.#15: batch scripts delete the wrong writer guard
The three batch scripts now
rm -f .../sqlite/faiss_writer.guard. Invector_build_multi.sbatchthe producer line uses${PRODUCER_LOCAL_STAGE_HOST}/sqlite/faiss_writer.guard, since producers run withLITKIT_WORKSPACE=/local_stage, which is bound to that host directory. The troubleshooting step inLITKIT_CLUSTER_GUIDE.mdand the comments incli.pyname the same path.Test (
tests/integration/test_writer_locking.py): derives the guard path fromWorkspacePaths, fails if any shipped script, doc or source file names.writer_guard(CHANGELOG.md, which records the old path, is skipped), and checks that each batch script removes the real guard and the guide tells users to (main: 5 files name.writer_guard).litkit_documentation.pdfstill saysrm workspace/.writer_guard. It's generated from the README and guides with pandoc and would also pick up every other doc change since it was last built, so it isn't regenerated here.Testing
pytest testsgives 353 passed, 8 xfailed, 1 skipped, versus 338 passed and 10 xfailed onmain. The twotest_cpu_installcases fail in both runs because litkit isn't installed as a package in that venv; CI covers them.🤖 Generated with Claude Code