Skip to content

fix(memory): enforce closed state on SQLite session empty add_items - #4231

Merged
seratch merged 1 commit into
openai:mainfrom
adityasingh2400:fix-sqlite-closed-empty-add-items
Aug 5, 2026
Merged

fix(memory): enforce closed state on SQLite session empty add_items#4231
seratch merged 1 commit into
openai:mainfrom
adityasingh2400:fix-sqlite-closed-empty-add-items

Conversation

@adityasingh2400

Copy link
Copy Markdown
Contributor

SQLiteSession.add_items and AdvancedSQLiteSession.add_items return early on an empty list before they ever reach _get_connection, so await session.add_items([]) succeeds on a session that has already been closed while every non-empty call raises RuntimeError("SQLiteSession is closed"). The sibling backends all order this the other way: AsyncSQLiteSession, RedisSession, and DaprSession call _check_not_closed() before the fast path, and MongoDBSession carries an explicit comment saying the check has to come first for exactly this reason.

This moves the closed check ahead of the empty-list fast path in both SQLite sessions and factors the existing inline check in _get_connection into a _check_not_closed helper so there is one source of truth for the error, matching the sibling shape. Nothing else changes: a closed session already raised for every other operation, and an open session is untouched.

Two regression tests, one per session class, close the session and then call add_items([]). Both fail on main with Failed: DID NOT RAISE <class 'RuntimeError'> and pass with this change. make lint, make typecheck (mypy and pyright, 0 errors), and the touched test modules are green.

SQLiteSession.add_items and AdvancedSQLiteSession.add_items return early on an
empty list before touching a connection, so add_items([]) succeeds on a session
that has already been closed. AsyncSQLiteSession, MongoDBSession, RedisSession,
and DaprSession all run their closed check before the empty-list fast path.
Check the closed state first in both SQLite sessions so every backend behaves
the same.
@seratch seratch added this to the 0.20.x milestone Aug 5, 2026
@seratch
seratch enabled auto-merge (squash) August 5, 2026 23:49
@seratch
seratch merged commit cce949a into openai:main Aug 5, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants