fix(a2a): forward get_session_config in _prepare_session()#6412
fix(a2a): forward get_session_config in _prepare_session()#6412vnykdfd wants to merge 2 commits into
Conversation
Add 3 unit tests to verify _prepare_session() forwards get_session_config: - test_prepare_session_passes_get_session_config - test_prepare_session_none_run_config - test_prepare_session_no_get_session_config Also update existing tests to use RunConfig() instances instead of Mock(spec=RunConfig) which doesn't expose Pydantic v2 fields.
|
Hi @vnykdfd, this change is targeting the legacy |
|
Thanks for clarifying..... Yes, I can confirm the issue does exist in a2a_agent_executor_impl as well. As per src/google/adk/a2a/executor/a2a_agent_executor_impl.py (lines 265-279): The bug Impact: Sessions always load with 0 events regardless of caller configuration, causing the same performance issue (database loads all events, then filters in-memory). Should I close this PR and submit a new one targeting |
|
You're right, and there is some parallel internal work on slightly changing the way the session is retrieved and shared to the runner in the a2a integration. This work is also fixing this code You might wait to open your PR as it should be fixed in the coming releases |
|
Got it. |
Link to Issue
Closes: #6410
Problem Description
Environment
Bug Summary
_prepare_session()inA2aAgentExecutorignoresGetSessionConfig(num_recent_events=N)by not forwarding it tosession_service.get_session(), causing the entire event history to be loaded instead of respecting the configured limit.Reproduction
Expected Behavior
Session service should load at most 10 events when
num_recent_events=10is configured.Observed Behavior
Session service loads ALL events regardless of
get_session_configsetting.Root Cause
_prepare_session()(line 320-324) callssession_service.get_session()without passingconfig=parameter:Impact
For sessions with hundreds of events:
Solution
Extract
get_session_configfromrun_request.run_configand forward it tosession_service.get_session():Testing Plan
Unit Tests Added
test_prepare_session_passes_get_session_config- Verifies config is forwarded correctlytest_prepare_session_none_run_config- Handlesrun_config=Nonegracefullytest_prepare_session_no_get_session_config- Handles missingget_session_configTest Results
Local pytest (Python 3.13):
$ pytest tests/unittests/a2a/executor/test_a2a_agent_executor.py -v ==================== 29 passed, 1 skipped in 1.50s ====================Full A2A test suite:
$ pytest tests/unittests/a2a/ -v ==================== 372 passed, 17 skipped in 2.54s ====================Pre-commit hooks:
Manual E2E Verification
Reproduction script confirms the fix works (script available on request).
Changes Made
Files Modified
src/google/adk/a2a/executor/a2a_agent_executor.py (+4 lines)
get_session_configfrom run requestsession_service.get_session(config=...)tests/unittests/a2a/executor/test_a2a_agent_executor.py (+103 insertions, -14 deletions)
Mock(spec=RunConfig)withRunConfig()instances(Pydantic v2 fields not accessible via class-level Mock spec)
Backward Compatibility
✅ Fully backward compatible - no breaking changes
✅ Existing behavior unchanged when
get_session_configisNone✅ All 372 A2A tests pass
Checklist
Additional Context
This bug only affects the legacy
A2aAgentExecutorpath. The newer_A2aAgentExecutorimplementation already handles session loading more efficiently by passingnum_recent_events=0during existence checks.Tested locally on Python 3.13. CI will verify compatibility with Python 3.10-3.14.