fix: remove exclusive locks from read-only storage operations#4854
Merged
Conversation
…inate lock contention read operations like search, list_scopes, get_scope_info, count across LanceDB, ChromaDB, and RAG adapters were holding exclusive locks unnecessarily. under multi-process prefork workers this caused RedisLock contention triggering a portalocker bug where AlreadyLocked is raised with the exceptions module as its arg. - remove store_lock from 7 LanceDB read methods since MVCC handles concurrent reads - remove store_lock from ChromaDB search/asearch which are thread-safe since v0.4 - remove store_lock from RAG core query and LanceDB adapter query - wrap lock_store BaseLockException with actionable error message - add exception handling in encoding_flow/recall_flow ThreadPoolExecutor calls - fix flow.py double-logging of ancestor listener errors
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
both branches of the if/else and the except all produced the same candidates = [scope_prefix] result, making the get_scope_info call and conditional pointless
the try/except wrapped the yield inside the contextmanager, which meant any BaseLockException raised by the caller's code inside the with block would be caught and re-raised with a misleading "Failed to acquire lock" message. split into acquire-then-yield so only actual acquisition failures get the actionable error message.
akaKuruma
approved these changes
Mar 14, 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.

Summary
store_lockfrom read-only storage operations across LanceDB, ChromaDB, and RAG adapters that were causing exclusive lock contention under multi-process prefork workerslock_storeBaseLockExceptionwith an actionable error message pointing users to setREDIS_URLencoding_flow/recall_flowThreadPoolExecutorcalls so a failed storage search degrades gracefully instead of crashing the flowflow.pydouble-logging where ancestor listeners re-logged downstream errorsContext
under prefork workers with 8 concurrency, read operations like
search,list_scopes,get_scope_info,countwere all holding exclusive Redis locks viaportalocker.RedisLock. with 8 workers x N threads all fighting for the same lock channel, contention triggered a portalocker bug whereAlreadyLockedis raised with theexceptionsmodule object as its argument, producing the uninformative<module 'portalocker.exceptions'>error.LanceDB uses MVCC and ChromaDB is thread-safe since v0.4 — neither needs exclusive locks for reads.
Test plan
Note
Medium Risk
Touches concurrency/locking around storage reads and modifies error handling in memory flows; behavior under multi-process load could change (e.g., races or previously-serialized reads now concurrent) and should be validated in real deployments.
Overview
Reduces lock contention by removing exclusive
store_lockusage from read-only operations across LanceDB/ChromaDB integrations (e.g., LanceDB adapterquery, RAGquery, ChromaDB clientsearch/asearch, and multipleLanceDBStorageread paths likesearch,get_record,list_scopes,get_scope_info,count, etc.).Improves resilience and diagnostics under concurrency by (1) wrapping
portalockerlock acquisition failures with a clearerLockExceptionmessage inlock_store.py, (2) makingEncodingFlowandRecallFlowdegrade gracefully when parallel storage searches/listing fail (log warning + skip/fallback instead of crashing), and (3) preventing duplicate listener error logs inFlow._execute_single_listenerby marking exceptions as already logged.Written by Cursor Bugbot for commit 91bad3b. This will update automatically on new commits. Configure here.