Skip to content

feat: add pagination and sorting to listSessions#331

Open
adwibha wants to merge 2 commits into
google:mainfrom
adwibha:feat/pagination-listSessions
Open

feat: add pagination and sorting to listSessions#331
adwibha wants to merge 2 commits into
google:mainfrom
adwibha:feat/pagination-listSessions

Conversation

@adwibha
Copy link
Copy Markdown

@adwibha adwibha commented May 7, 2026

What this does

Adds pagination and sorting to the listSessions function, as requested in #324.

You can now:

  • Sort sessions by last update time (ascending or descending)
  • Paginate results with limit and offset, or use page for convenience
  • Get metadata back (total count, total pages, current page)

And it's backward compatible, existing code that doesn't use these features works exactly as before.

How it works

  • When you pass limit, you get paginated results with metadata
  • When you pass offset alone, it slices from that position
  • When you pass neither, you get all sessions (old behavior)
  • Sorting is optional, if you don't specify order, there's no sorting overhead

Both the database and in-memory implementations work the same way.

Link to Issue or Description of Change

1. Link to an existing issue:

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Test results: 1306 tests passed (23 new tests added for pagination and sorting)

Test Files  116 passed (116)
Tests  1306 passed (1306)

Manual testing:
Direct service calls work as expected:

// Paginated
await service.listSessions({ appName, userId, limit: 10, page: 1, order: 'desc' })
// Returns: { sessions: [...], page: 1, limit: 10, totalItems: N, totalPages: M }

// Backward compatible
await service.listSessions({ appName, userId })
// Returns: { sessions: [...], page: 1, limit: allCount, totalItems: N, totalPages: 1 }

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have added tests that prove my feature works.
  • New and existing unit tests pass locally with my changes.

Additional context

This PR implements the core service layer fully per spec. The HTTP API layer (dev/src/server routes and AdkApiClient) to expose these features is intentionally left as a follow-up to keep this focused.

@adwibha
Copy link
Copy Markdown
Author

adwibha commented May 11, 2026

I see core/src/sessions/vertex_ai_session_service.ts was merged while this PR was under review. I will rebase and include fix in this PR shortly. Thanks for your approval.

adwibha added 2 commits May 12, 2026 18:03
Add pagination and sorting capabilities to the session listing API.

Changes:
- ListSessionsRequest now accepts limit, offset, page, and order parameters
- ListSessionsResponse now includes page, limit, totalItems, and totalPages
- Sorting by updateTime (ascending or descending) with id as tie-breaker
- Pagination logic: use limit if provided, fall back to offset-only slicing, or return all
- Pagination metadata always included in response for consistency
- Database layer counts total items efficiently for offset-only requests
- Both DatabaseSessionService and InMemorySessionService implement identically
- Added 23 test cases covering pagination edge cases and sorting

Closes google#324
@adwibha adwibha force-pushed the feat/pagination-listSessions branch from b2971e0 to dcde2db Compare May 12, 2026 23:42
@adwibha
Copy link
Copy Markdown
Author

adwibha commented May 12, 2026

Hello @kalenkevich,

Rebased onto latest main to incorporate vertex_ai_session_service.ts (which was merged after this PR was opened). Updated the implementation in that service to align with the new ListSessionsResponse contract and to correctly handle limit, offset, page and order parameters, previously it was returning the full session list without pagination applied.

Note: userId in ListSessionsRequest is currently marked as required, but all three service implementations treat it as optional. Leaving this as a follow-up to keep the scope of this PR focused.

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.

Pagination Limit and sorting for sessionService.listSessions

2 participants