Skip to content

fix: #3348 propagate add_items structure metadata failure#3527

Open
kimnamu wants to merge 1 commit into
openai:mainfrom
kimnamu:fix/3348-add-items-propagate-metadata-error
Open

fix: #3348 propagate add_items structure metadata failure#3527
kimnamu wants to merge 1 commit into
openai:mainfrom
kimnamu:fix/3348-add-items-propagate-metadata-error

Conversation

@kimnamu
Copy link
Copy Markdown

@kimnamu kimnamu commented May 29, 2026

Summary

Fixes #3348.

add_items() wraps _insert_structure_metadata() in a try/except that rolls back, logs, and runs orphan cleanup — but then returns normally, so callers can't tell a partial failure from a success.

This adds a single raise RuntimeError(...) from e after the existing cleanup block, so the failure surfaces to the caller while preserving the original exception via from e. The existing rollback, logging, and cleanup behaviour is untouched.

Before / After

Scenario Before (main) After (this PR)
_insert_structure_metadata() raises Exception swallowed; add_items() returns normally RuntimeError raised with original exception chained via from e
Caller observability Cannot distinguish partial failure from success Failure surfaces to the caller
Rollback / logging / orphan cleanup Performed Performed (unchanged)
Successful path Returns normally Returns normally (unchanged)

Test

Adds test_add_items_raises_on_structure_metadata_failure, which forces _insert_structure_metadata to raise, then asserts add_items() raises RuntimeError and that the orphaned message was still cleaned up.

$ uv run pytest tests/extensions/memory/test_advanced_sqlite_session.py::test_add_items_raises_on_structure_metadata_failure -v
============================= test session starts ==============================
tests/extensions/memory/test_advanced_sqlite_session.py::test_add_items_raises_on_structure_metadata_failure PASSED [100%]
============================== 1 passed in 0.18s ===============================

Note: this is one half of #3498, split into a single-issue PR as suggested for easier review. The other half (#3346) is in #3526.

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 feature:sessions

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