fix: serialize persistent embedding cache writes - #8
Merged
Conversation
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.
Outcome
Serialize persistent embedding-cache writes that target the same SQLite path within one process.
The shared path lock now protects both database initialization and the complete
INSERT/ prune / commit transaction. Reads remain concurrent under WAL, while locks held by another process still use the configured SQLite busy timeout and retain the existing fail-open behavior.Root cause
The cache already shared an initialization lock across embedder instances, but each
put_many()transaction ran outside it. Sixteen same-process writers could therefore consume the 25 ms SQLite busy timeout while contending with another cache write or a sibling instance's initialization. That is why both first attempts of the PR #7 push and pull-request workflows failed at the same concurrency assertion, then passed unchanged on rerun.Retrying SQLite operations would blur the intentional external-lock latency bound. Serializing only writes owned by this process removes avoidable contention without changing cross-process fallback semantics.
Regression coverage
The existing 16-embedder regression now:
The separate externally locked-cache test still verifies a write fails open in under 500 ms.
Validation
pytest tests/test_embeddings.py::test_parallel_embedders_share_cache_path_lock tests/test_embeddings.py::test_locked_cache_write_fails_open_quicklytest_parallel_embedders_share_cache_path_lockpytest— 308 passed, 14 skippedruff check .git diff --checkBoundary review