[Bug] VertexAiSessionService.get_session() fails with httpx client closure during event pagination (>100 events)
Expected behavior
get_session() should successfully retrieve all events regardless of how many pages are required for pagination. The API client should remain open until all events have been fetched.
Desktop (please complete the following information):
- OS: Linux (GCP Cloud Run / Vertex AI Agent Engine)
- Python version: 3.11
- ADK version: 1.19.0
Model Information:
- Are you using LiteLLM: No
- Which model is being used: gemini-2.5-pro
Additional context
The bug is in src/google/adk/sessions/vertex_ai_session_service.py. The async for event in events_iterator loop is placed outside the async with self._get_api_client() as api_client: block, causing the client to close before pagination completes.
Proposed fix: https://github.com/google/adk-python/pull/3756
The fix moves the event iteration inside the async with block so the API client remains open during the entire pagination process.
This is a critical bug for production deployments as it makes sessions with extended conversations (>100 events) completely unusable.
@AlexisMarasigan this is a critical scope issue in get_session().
The event iteration loop (lines 183-184) is placed outside the async with self._get_api_client() block that ends at line 165,
so the httpx client closes before pagination can fetch page 2 for sessions with >100 events.
Moving the iteration inside the context manager (as PR #3756 does) keeps the client open during pagination and fixes this production-breaking bug.
The list_sessions() method in the same file already uses this correct pattern.
Thanks!
@surajksharma07 Thanks, if the fix is accepted should I expect it to be in the .19 version?