Skip to content

Fix transaction isolation in AdvancedSQLiteSession.add_items#3455

Open
Doondi-Ashlesh wants to merge 1 commit into
openai:mainfrom
Doondi-Ashlesh:fix/sessions-add-items-atomicity
Open

Fix transaction isolation in AdvancedSQLiteSession.add_items#3455
Doondi-Ashlesh wants to merge 1 commit into
openai:mainfrom
Doondi-Ashlesh:fix/sessions-add-items-atomicity

Conversation

@Doondi-Ashlesh
Copy link
Copy Markdown

Summary

AdvancedSQLiteSession.add_items committed message rows to the database before writing structure metadata. If the metadata write failed, the subsequent rollback had no effect because the message insert was already committed. This left orphaned rows in the messages table that get_items could never return (it joins through message_structure), so callers had no way to tell whether the operation actually succeeded.

Both writes now share a single transaction. If anything fails, an explicit rollback removes the message rows too and the exception propagates to the caller so they can handle or retry it cleanly.

Test plan

Added test_add_items_is_atomic_on_structure_metadata_failure which:

  • Patches _insert_structure_metadata to raise a RuntimeError
  • Checks that add_items raises instead of silently succeeding
  • Checks that zero rows remain in the messages table after the failure
  • Checks that a subsequent successful add_items call works normally

All 37 existing tests in test_advanced_sqlite_session.py continue to pass. No regressions in the wider test suite.

Issue number

Closes #3348

Checks

  • I've added new tests (if relevant)
  • I've added/updated the relevant documentation
  • I've run make lint and make format
  • I've made sure tests pass

The method was committing message rows before writing structure metadata.
If the metadata write failed, the rollback had no effect since the messages
were already committed, leaving orphaned rows that get_items could not read.

Both writes now share a single transaction with an explicit rollback on
failure so callers get a clean exception and no partial state is left behind.

Added a regression test that patches the metadata write to fail and checks
that no orphaned rows remain and that a subsequent successful call works.
@seratch seratch added the duplicate This issue or pull request already exists label May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AdvancedSQLiteSession.add_items can report success after structure metadata failure

2 participants