Skip to content

Commit 931d75c

Browse files
author
Rishab Motgi
committed
fix: guard non-positive session limit in AdvancedSQLiteSession.get_items
AdvancedSQLiteSession.get_items() passed the resolved session_limit directly to SQL LIMIT without checking whether the value is non-positive. MongoDBSession, RedisSession, DaprSession, AsyncSQLiteSession, and SQLAlchemySession all guard this with: if session_limit is not None and session_limit <= 0: return [] AdvancedSQLiteSession was the only SQLite-backed implementation missing the guard. SQLite treats LIMIT -1 as 'no limit', so passing limit=-1 would return the full conversation history instead of an empty list, diverging from every other backend. Adds limit=0 and limit=-1 assertions to the existing explicit-limit override test so the behaviour is pinned.
1 parent 656baf8 commit 931d75c

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

src/agents/extensions/memory/advanced_sqlite_session.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ async def get_items(
172172
"""
173173
session_limit = resolve_session_limit(limit, self.session_settings)
174174

175+
if session_limit is not None and session_limit <= 0:
176+
return []
177+
175178
if branch_id is None:
176179
branch_id = self._current_branch_id
177180

tests/extensions/memory/test_advanced_sqlite_session.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,12 @@ async def test_get_items_explicit_limit_overrides_session_settings():
12881288
assert retrieved[0].get("content") == "Message 8"
12891289
assert retrieved[1].get("content") == "Message 9"
12901290

1291+
# Non-positive limits must return [] for parity with MongoDB/Redis/AsyncSQLite.
1292+
# SQLite treats LIMIT -1 as "no limit", so without an explicit guard a negative
1293+
# limit would incorrectly return all rows instead of an empty list.
1294+
assert await session.get_items(limit=0) == []
1295+
assert await session.get_items(limit=-1) == []
1296+
12911297
session.close()
12921298

12931299

0 commit comments

Comments
 (0)