Skip to content

feat: add pagination support to DatabaseSessionService.list_sessions - #1

Open
stakeswky wants to merge 1 commit into
mainfrom
feat/list-sessions-pagination
Open

stakeswky wants to merge 1 commit into
mainfrom
feat/list-sessions-pagination

Conversation

@stakeswky

Copy link
Copy Markdown
Owner

Summary

Resolves google#4621

DatabaseSessionService.list_sessions() (and all other session service implementations) now support pagination via page_size and page_token parameters.

Changes

base_session_service.py

  • Added next_page_token: Optional[str] field to ListSessionsResponse
  • Updated list_sessions abstract signature with page_size and page_token kwargs
  • Added shared pagination helpers: _resolve_page_size, _encode_page_token, _decode_page_token

database_session_service.py

  • Added ORDER BY update_time DESC + LIMIT/OFFSET to the SQL query
  • Fetches page_size + 1 rows to detect next page without a separate COUNT query
  • Returns next_page_token when more results exist

in_memory_session_service.py

  • Sorts sessions by last_update_time descending
  • Applies offset/limit slicing with the same pagination contract

sqlite_session_service.py

  • Same ORDER BY update_time DESC LIMIT ? OFFSET ? approach as DatabaseSessionService

vertex_ai_session_service.py

  • Signature updated for compatibility (pagination not yet wired to the upstream API)

Tests

  • 8 new test cases covering: default page size, custom page size, max clamping, full iteration, exact-fit boundary, empty results, backward compatibility, and ordering

Backward Compatibility

All parameters are optional with sensible defaults:

  • page_size defaults to 20 (max 100)
  • page_token defaults to None (first page)
  • Existing callers that pass no pagination args continue to work — they receive the first page of up to 20 sessions with next_page_token=None when there are ≤20 results

All 88 existing + new tests pass.

Add page_size and page_token parameters to list_sessions across all
session service implementations (DatabaseSessionService,
InMemorySessionService, SqliteSessionService, VertexAiSessionService).

- page_size defaults to 20, clamped to max 100
- page_token is base64-encoded offset for stateless cursor pagination
- Results ordered by update_time DESC (most recent first)
- ListSessionsResponse gains next_page_token field
- Fully backward compatible: existing callers without pagination args
  get the first page (up to 20 sessions)

Closes google#4621
@ecanlar

ecanlar commented Mar 13, 2026 •

Copy link
Copy Markdown

Hi team @wuliang229 @klateefa! We're currently planning our next deployment cycle and were wondering if this pagination fix is likely to be merged soon. Do you have a rough ETA or a target version for this update? Appreciate the support!

@ferponse

Copy link
Copy Markdown

/gemini review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DatabaseSessionService.list_sessions lacks pagination support

3 participants