Skip to content

fix: guard non-positive session limit in AdvancedSQLiteSession.get_items#3416

Closed
rmotgi1227 wants to merge 1 commit into
openai:mainfrom
rmotgi1227:fix/advanced-sqlite-session-negative-limit
Closed

fix: guard non-positive session limit in AdvancedSQLiteSession.get_items#3416
rmotgi1227 wants to merge 1 commit into
openai:mainfrom
rmotgi1227:fix/advanced-sqlite-session-negative-limit

Conversation

@rmotgi1227
Copy link
Copy Markdown

Summary

AdvancedSQLiteSession.get_items() was the only SQLite-backed session implementation missing the non-positive limit guard that all other backends enforce.

Root cause

Five backends already short-circuit with return [] when session_limit <= 0:

AdvancedSQLiteSession passed the resolved limit directly to LIMIT ? without this guard. SQLite interprets LIMIT -1 as "no limit" (SQLite docs), so get_items(limit=-1) silently returned the full conversation history instead of [].

Fix

Add the same early-return guard before the SQL branch:

if session_limit is not None and session_limit <= 0:
    return []

Test plan

Extended the existing test_get_items_explicit_limit_overrides_session_settings test with:

assert await session.get_items(limit=0) == []
assert await session.get_items(limit=-1) == []

These pin the correct behaviour (empty list for any non-positive limit) and would have caught the LIMIT -1 bug.

Issue number

Companion to #3413 (same root cause, different file).

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

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.
@seratch seratch added feature:sessions wontfix This will not be worked on labels May 15, 2026
@seratch seratch closed this May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature:sessions wontfix This will not be worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants