fix: #3348 AdvancedSQLiteSession.add_items silent partial save#3379
Open
john-rocky wants to merge 2 commits into
Open
fix: #3348 AdvancedSQLiteSession.add_items silent partial save#3379john-rocky wants to merge 2 commits into
john-rocky wants to merge 2 commits into
Conversation
`_type_to_str` unconditionally read `__name__` on each typing arg, which raised `AttributeError` for `Literal["ok"]` because the literal value is a `str` instance rather than a class. The schema itself built fine but `name()` (and therefore the agent trace path) crashed when starting a run with a structured output type that contained any literal. Fall back to `repr()` for non-type args and to `_name`/`str(origin)` for typing constructs that lack `__name__`. Adds a focused regression test for `Literal["ok"]`, multi-member `Literal`, nested `list[Literal[...]]`, and non-string `Literal[1, 2]` cases. Fixes openai#3357.
`add_items` previously committed the base message rows before writing the `message_structure` rows. If the structure write raised, the base rows had already been committed, so the rollback at that point was a no-op. Best-effort cleanup deleted the orphans when it worked, but masked the original error either way; when cleanup itself failed, callers got a silent success and the base table kept invisible orphan rows that advanced reads (joined through `message_structure`) could never see. Both writes now share a single transaction and the original exception propagates to the caller, so retries see either a fully landed batch or a clean slate. 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.
Summary
AdvancedSQLiteSession.add_itemsfirst inserted the base message rows, committed them, and only then wrotemessage_structurerows. If the structure write failed, the matchingconn.rollback()was a no-op because the base rows were already committed. A best-effort orphan cleanup ran next, but the original exception was always swallowed byself._logger.error(...), so the caller saw a successfuladd_items()even though:get_items()(which joins throughmessage_structure) returned the rows as missing, andThe fix is to share a single transaction for both writes and let the original exception propagate.
_insert_structure_metadataalready reads back the just-inserted message IDs through aSELECT, which SQLite serves from the uncommitted state of the same transaction, so no intermediate commit is needed for correctness — only the false success was load-bearing.Test plan
Added
test_add_items_rolls_back_when_structure_metadata_fails. It subclassesAdvancedSQLiteSessionwith a toggleable_insert_structure_metadatathat fails the first time and succeeds on retry, and verifies that:RuntimeError,get_items()and direct counts on<messages_table>andmessage_structurecome back empty,Issue number
Closes #3348. Related to #3346 (orphan rows after
delete_branch), which is a separate path and not touched here.Checks