Commit 5b6262c
Rishab Motgi
fix: guard non-positive session limits and close() race in SQLite sessions
AsyncSQLiteSession.get_items() and SQLAlchemySession.get_items() passed
the resolved session_limit directly to SQL LIMIT without checking whether
the value is non-positive. MongoDB and Redis already guard this:
if session_limit is not None and session_limit <= 0:
return []
Without the guard, SQLite treats LIMIT -1 as 'no limit' and returns all
rows, while MongoDB/Redis would return []. This inconsistency means the
same SessionSettings(limit=-1) produces different histories depending on
which backend is used.
Also fix a TOCTOU race in AsyncSQLiteSession.close(): the None check
happened outside the asyncio lock, so two concurrent close() calls could
both pass the guard and the second one would call .close() on a None
connection. Add a second check inside the lock (standard double-checked
pattern).
Changes:
- src/agents/extensions/memory/async_sqlite_session.py: add non-positive
limit guard in get_items(); add inside-lock None re-check in close()
- src/agents/extensions/memory/sqlalchemy_session.py: add non-positive
limit guard in get_items()
- tests: extend existing limit tests with limit=-1 assertions for both
AsyncSQLiteSession and SQLAlchemySession1 parent 656baf8 commit 5b6262c
4 files changed
Lines changed: 18 additions & 0 deletions
File tree
- src/agents/extensions/memory
- tests/extensions/memory
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
122 | 125 | | |
123 | 126 | | |
124 | 127 | | |
| |||
259 | 262 | | |
260 | 263 | | |
261 | 264 | | |
| 265 | + | |
| 266 | + | |
262 | 267 | | |
263 | 268 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
288 | 288 | | |
289 | 289 | | |
290 | 290 | | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
291 | 294 | | |
292 | 295 | | |
293 | 296 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
141 | 147 | | |
142 | 148 | | |
143 | 149 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
186 | 190 | | |
187 | 191 | | |
188 | 192 | | |
| |||
0 commit comments