Repository navigation
fix(sessions): Order database sessions deterministically - #6276
Sehlani042 wants to merge 6 commits into
Conversation
DatabaseSessionService.list_sessions previously returned rows without an ORDER BY, so callers using sessions[-1] could receive an older session depending on database heap order. Order rows by create_time with stable primary-key tie breakers so the newest created session is last. Fixes google#6272
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Hi @Sehlani042 , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Your PR has been received by the team and is currently under review. We will provide feedback as soon as we have an update to share. |
|
Hi @wyf7107 , can you please review this. |
… into codex/fix-adk-list-sessions-order
|
Thank you @Sehlani042 for your contribution! 🎉 Your changes have been successfully imported and merged via Copybara in commit 8455cf8. Closing this PR as the changes are now in the main branch. |
Merge google#6276 Fixes google#6272 PiperOrigin-RevId: 959915485
Summary
DatabaseSessionService.list_sessions()byupdate_time ASCwith stableuser_id/idtie-breakersWhy
list_sessions()previously executed without anORDER BY, so consumers usingsessions[-1]for the most recently active session could receive an arbitrary row depending on database heap order.The first revision used
create_time, which made the result deterministic but did not match the reporter’s clarified contract: orphaned sessions can be newly created while having stale activity. The ordering therefore followsupdate_time, which maps to the returnedSession.last_update_time.Fixes #6272
Testing
uv run pytest tests/unittests/sessions/test_session_service.py::test_database_session_service_list_sessions_orders_by_update_time_then_id -qfailed because the stale orphan sorted last undercreate_timeuv run pytest tests/unittests/sessions/test_session_service.py -q(135 passed)uv run --extra dev pyink --check src/google/adk/sessions/database_session_service.py tests/unittests/sessions/test_session_service.pyuv run --extra dev ruff check src/google/adk/sessions/database_session_service.py tests/unittests/sessions/test_session_service.pygit diff --check