fix(retain): make lazy bank creation atomic (#2695)#2802
Open
ijevin wants to merge 1 commit into
Open
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.
Summary
conn.transaction()Why
The dedicated-connection path in
get_or_create_bank_profile()acquired an autocommit connection and then calledget_or_create_bank_profile_on_conn(). A new bank row could therefore commit beforecreate_bank_vector_indexes()ran. If that DDL failed, the empty bank remained even though setup did not complete.This implements the fix described by @benfrank241 in #2695: the existing connection-bound helper stays unchanged, while the wrapper that owns the connection supplies the missing transaction boundary.
Test plan
uv run pytest tests/test_bank_utils.py -v -n 0uv run pytest tests/test_vector_index.py tests/test_bank_utils.py -v -n 0— 20 passeduv run ruff check hindsight_api/engine/retain/bank_utils.py tests/test_bank_utils.pyuv run ruff format --check hindsight_api/engine/retain/bank_utils.py tests/test_bank_utils.pyuv run ty check hindsight_api/engine/retain/bank_utils.pypy_compilefor both changed Python filesEnvironment note
A broader local selection that includes DB-backed hierarchical-config tests could not start because the optional
pg0-embeddeddependency is not installed in this environment. The focused regression test uses a transaction-aware fake connection so it deterministically exercises the pre-fix autocommit behavior without requiring embedded PostgreSQL.Fixes #2695