fix(advanced-sqlite-session): re-raise structure metadata write failures (fixes #3348)#3508
Open
LeSingh1 wants to merge 1 commit into
Open
fix(advanced-sqlite-session): re-raise structure metadata write failures (fixes #3348)#3508LeSingh1 wants to merge 1 commit into
LeSingh1 wants to merge 1 commit into
Conversation
AdvancedSQLiteSession.add_items() commits the base messages table write, then writes message_structure rows. If the structure write fails, the previous implementation logged the error and returned successfully without raising. Subsequent get_items() calls join through message_structure and see nothing, so the caller could observe a 'successful' add_items() followed by missing reads with no way to know whether to retry. Re-raise the original exception after the orphan cleanup attempt so the caller learns add_items() did not succeed. The cleanup path that deletes the orphaned base rows still runs first, so the on-disk state stays internally consistent. Fixes openai#3348.
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 #3348.
Bug
AdvancedSQLiteSession.add_items()writes rows to the base messages table, commits them, and only then writesmessage_structurerows. If the structure metadata write fails, the previous implementation logs the error and returns without raising:So a caller can observe a successful
add_items()call even though subsequentget_items()calls join throughmessage_structureand see nothing. The session looks empty, the caller has no way to know whether to retry, and if cleanup also fails the base table keeps invisible orphan rows.Fix
Re-raise the original exception at the end of the outer
except, after the orphan cleanup attempt. The cleanup path still runs first, so the on-disk state stays internally consistent (no orphaned base rows), and the caller now learns the call failed:One-line behavioral change.
Verification
Added
test_add_items_propagates_structure_metadata_errorsintests/extensions/memory/test_advanced_sqlite_session.py. The test subclassesAdvancedSQLiteSessionto make_insert_structure_metadataraiseRuntimeError, callsadd_items(), and asserts:add_items()propagates theRuntimeErrorto the caller.get_items()returns[](no invisible orphan rows in the base table).Local A/B:
make format,make lint, andmake typecheckon the touched files are all clean.Scope
4-line behavior change in
src/agents/extensions/memory/advanced_sqlite_session.pyplus 29 lines of test coverage. No public API change.