Repository navigation
Add ListSessionsConfig (pageSize, pageToken, afterTimestamp) to BaseSessionService.listSessions #2016
mohan-ganesh
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Summary
Propose extending
BaseSessionService.listSessionswith an optionalListSessionsConfig(pageSize,pageToken, and optionallyafterTimestamp) and addingOptional<String> nextPageToken()toListSessionsResponse, following the existing patterns already used byGetSessionConfigandListEventsResponse.Problem
Currently,
BaseSessionServiceexposes only:with no way to bound result size, paginate, or restrict by recency.
With ADK for Java now 1.5+ years into production use, long-lived deployments are reaching a point where a single
(appName, userId)accumulates hundreds or thousands of sessions. Because there is no way to filter or paginate results in the current API,listSessionsincreasingly degrades for active users:listSessions(such as rendering a recent-sessions list in an app UI) fetches every session record the user has ever created, driving up latency, memory usage, and backend read costs.listSessionsfast when a caller only needs the most recent N sessions or sessions updated within a recent window.sessionsREST endpoint supports AIP-132 pagination (pageSize,pageToken,nextPageToken), yetVertexAiClient.listSessionscurrently omits pagination parameters andListSessionsResponsehas nonextPageToken()to surface subsequent pages.Current Codebase References
There is already clear precedent in
core/src/main/java/com/google/adk/sessions/:GetSessionConfig+BaseSessionService.getSession:getSession(appName, userId, sessionId, Optional<GetSessionConfig>)already modelsnumRecentEvents()andafterTimestamp()to push filtering down to storage.ListEventsResponsevs.ListSessionsResponse:ListEventsResponsealready includesOptional<String> nextPageToken()for pagination, whereasListSessionsResponsecurrently only hassessions()andsessionIds().BaseSessionService.createSessionevolution: WhencreateSession(..., Map<String, Object>, ...)was added alongside the olderConcurrentMapoverload, it was added as adefaultmethod so existing implementations did not break.Implementations & callers affected today:
contrib/firestore-session-service/.../FirestoreSessionService.java(listSessionsexecutesgetSessionsCollection(userId).whereEqualTo(APP_NAME_KEY, appName)with no limit/cursor).core/.../VertexAiClient.java&VertexAiSessionService.java(listSessionssends?filter=user_id="..."withoutpageSize/pageToken).core/.../InMemorySessionService.java(listSessionsreturns all sessions fromConcurrentHashMap.values()).dev/.../SessionController.java(listSessionsloads all sessions and filterseval_IDs in memory).Proposed Solution (Backward-Compatible)
Keep the scope intentionally narrow and backend-portable (explicitly avoiding arbitrary
state-map predicates or generic filter DSLs that require per-field indexes or break Vertex AI AIP-160 constraints).Add
@AutoValueListSessionsConfig(mirroringGetSessionConfig):Add
nextPageTokentoListSessionsResponse(mirroringListEventsResponse):(Defaults to
Optional.empty()in the builder so existing callers are unaffected.)Add
defaultoverloads toBaseSessionService:Open Questions for Maintainers
defaultmethod behavior on un-updated implementations: If a third-partyBaseSessionServicehasn't overridden the 3-arg overload yet, should thedefaultmethod:configand delegate (or throwUnsupportedOperationExceptionifconfigis non-empty so callers aren't misled into thinking pagination was applied), ORafterTimestamp/ slicing in memory as a fallback?Ordering guarantees for cursor pagination: Pagination requires deterministic ordering. Should
listSessionsdefine an order (e.g.,lastUpdateTimedescending vs. ascending)?InMemorySessionServicecurrently iterates aConcurrentHashMapwith arbitrary order, andFirestoreSessionServicewould need a composite index(appName, updateTime)if.whereEqualTo("appName", ...)is combined with.orderBy("updateTime", ...)/ range filters onupdateTime.Config scope & cross-ADK parity: Should we start strictly with pagination (
pageSize,pageToken), or includeafterTimestamp(and/or sort order) right away to align withGetSessionConfigand ADK Python?Next Steps / Seeking Alignment
I'd like to align with the maintainers on the API shape and contract above (especially the open questions around
defaultfallback semantics, ordering, and parity with ADK Python).Once we have agreement on the design, I'd be happy to follow up with the implementation PR(s) — covering the
coreinterface/config changes and tests first, followed by updates acrossInMemorySessionService,VertexAiSessionService, andFirestoreSessionService(including Firestore composite index documentation).All reactions