fix(sessions): use async iteration for VertexAiSessionService.list_sessions pagination#4435
fix(sessions): use async iteration for VertexAiSessionService.list_sessions pagination#4435anmolg1997 wants to merge 4 commits intogoogle:mainfrom
Conversation
…ssions pagination The sessions_iterator returned by api_client.agent_engines.sessions.list() is an AsyncPager that only fetches additional pages when consumed via async iteration (__aiter__/__anext__). Using a synchronous `for` loop only retrieved the first page (~100 sessions), silently dropping all subsequent pages. Changed `for` to `async for` to enable proper async pagination, allowing all sessions to be returned regardless of count. Fixes google#4302
|
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. |
Summary of ChangesHello @anmolg1997, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical pagination issue within the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Response from ADK Triaging Agent Hello @anmolg1997, thank you for your contribution! It looks like the Contributor License Agreement (CLA) check has failed. Please sign the CLA so we can proceed with reviewing this PR. Thanks! |
There was a problem hiding this comment.
Code Review
This pull request correctly addresses a critical pagination bug in VertexAiSessionService.list_sessions by switching from a synchronous for loop to an async for loop, which is the proper way to consume an AsyncPager and retrieve all pages of results. The test suite has been thoughtfully updated to reflect this change, with the introduction of AsyncIterableList to accurately mock the behavior of the async pager. The changes are well-contained and the fix is solid. I have one minor suggestion to improve the conciseness of the new test helper class.
bbf14a1 to
e7713de
Compare
|
I have signed the CLA - @googlebot please verify. |
e7713de to
1fddf90
Compare
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…ssions pagination Merge #4435 ### Link to Issue or Description of Change - Closes: #4302 **Problem:** `VertexAiSessionService.list_sessions()` only returns the first ~100 sessions. The `sessions_iterator` from `api_client.agent_engines.sessions.list()` is an `AsyncPager` — it implements `__aiter__`/`__anext__` for fetching subsequent pages, but the code uses a plain `for` loop which only calls `__iter__`/`__next__`, so it never fetches beyond the first page. **Solution:** Changed `for api_session in sessions_iterator` to `async for api_session in sessions_iterator` so the `AsyncPager` actually paginates. Updated the test mock to return an `AsyncIterableList` (supports both sync and async iteration) instead of a bare list, so the tests properly simulate real `AsyncPager` behaviour. ### Testing Plan **Unit Tests:** ``` $ pytest tests/unittests/sessions/ 115 passed, 1 warning in 2.25s ``` The existing `test_list_sessions`, `test_list_sessions_with_pagination`, and `test_list_sessions_all_users` all continue to pass with the updated mock. Co-authored-by: Liang Wu <wuliang@google.com> COPYBARA_INTEGRATE_REVIEW=#4435 from anmolg1997:fix/vertex-ai-session-service-pagination 14c71b6 PiperOrigin-RevId: 868466166
|
Thank you @anmolg1997 for your contribution! 🎉 Your changes have been successfully imported and merged via Copybara in commit 758d337. Closing this PR as the changes are now in the main branch. |
Link to Issue or Description of Change
Problem:
VertexAiSessionService.list_sessions()only returns the first ~100 sessions. Thesessions_iteratorfromapi_client.agent_engines.sessions.list()is anAsyncPager— it implements__aiter__/__anext__for fetching subsequent pages, but the code uses a plainforloop which only calls__iter__/__next__, so it never fetches beyond the first page.Solution:
Changed
for api_session in sessions_iteratortoasync for api_session in sessions_iteratorso theAsyncPageractually paginates. Updated the test mock to return anAsyncIterableList(supports both sync and async iteration) instead of a bare list, so the tests properly simulate realAsyncPagerbehaviour.Testing Plan
Unit Tests:
The existing
test_list_sessions,test_list_sessions_with_pagination, andtest_list_sessions_all_usersall continue to pass with the updated mock.