Skip to content

fix(a2a): forward get_session_config in _prepare_session()#6412

Open
vnykdfd wants to merge 2 commits into
google:mainfrom
vnykdfd:fix/a2a-session-config-forwarding
Open

fix(a2a): forward get_session_config in _prepare_session()#6412
vnykdfd wants to merge 2 commits into
google:mainfrom
vnykdfd:fix/a2a-session-config-forwarding

Conversation

@vnykdfd

@vnykdfd vnykdfd commented Jul 16, 2026

Copy link
Copy Markdown

Link to Issue

Closes: #6410

Problem Description

Environment

  • ADK Version: 2.4.0 (latest main branch)
  • Python: 3.10-3.14 (tested on 3.13)
  • Component: A2A executor (legacy path)

Bug Summary

_prepare_session() in A2aAgentExecutor ignores GetSessionConfig(num_recent_events=N) by not forwarding it to session_service.get_session(), causing the entire event history to be loaded instead of respecting the configured limit.

Reproduction

from google.adk.agents.run_config import RunConfig
from google.adk.sessions.base_session_service import GetSessionConfig

# Configure to load only 10 recent events
run_config = RunConfig(
    get_session_config=GetSessionConfig(num_recent_events=10)
)

# Bug: _prepare_session() calls get_session() WITHOUT config parameter
# Result: All events loaded (e.g., 291 events instead of 10)

Expected Behavior

Session service should load at most 10 events when num_recent_events=10 is configured.

Observed Behavior

Session service loads ALL events regardless of get_session_config setting.

Root Cause

_prepare_session() (line 320-324) calls session_service.get_session() without passing config= parameter:

# BEFORE (missing config parameter)
session = await runner.session_service.get_session(
    app_name=runner.app_name,
    user_id=user_id,
    session_id=session_id,
    # ← Missing: config=get_session_config
)

Impact

For sessions with hundreds of events:

  • 10-100x more database I/O than configured
  • 200-300ms added latency per request (observed in production)
  • Higher memory usage (~300KB vs ~10KB)
  • Higher token costs (sending excessive context to LLM)

Solution

Extract get_session_config from run_request.run_config and forward it to session_service.get_session():

# AFTER (with fix)
get_session_config = None
if run_request.run_config:
    get_session_config = run_request.run_config.get_session_config

session = await runner.session_service.get_session(
    app_name=runner.app_name,
    user_id=user_id,
    session_id=session_id,
    config=get_session_config,  # ← ADDED
)

Testing Plan

Unit Tests Added

  • test_prepare_session_passes_get_session_config - Verifies config is forwarded correctly
  • test_prepare_session_none_run_config - Handles run_config=None gracefully
  • test_prepare_session_no_get_session_config - Handles missing get_session_config

Test 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:

$ pre-commit run --all-files
All checks passed ✅

Manual E2E Verification

Reproduction script confirms the fix works (script available on request).

Changes Made

Files Modified

  1. src/google/adk/a2a/executor/a2a_agent_executor.py (+4 lines)

    • Extract get_session_config from run request
    • Pass it to session_service.get_session(config=...)
  2. tests/unittests/a2a/executor/test_a2a_agent_executor.py (+103 insertions, -14 deletions)

    • Added 3 new unit tests
    • Fixed existing tests: replaced Mock(spec=RunConfig) with RunConfig() 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_config is None
✅ All 372 A2A tests pass

Checklist

  • Read CONTRIBUTING.md
  • Self-review performed
  • Added code comments for clarity
  • Added unit tests proving fix works
  • Tests pass locally
  • Pre-commit hooks pass
  • License headers present on all files
  • No dependent changes required
  • CLA signed

Additional Context

This bug only affects the legacy A2aAgentExecutor path. The newer _A2aAgentExecutor implementation already handles session loading more efficiently by passing num_recent_events=0 during existence checks.

Tested locally on Python 3.13. CI will verify compatibility with Python 3.10-3.14.

vnykdfd added 2 commits July 17, 2026 01:34
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.
@adk-bot adk-bot added the services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc label Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GetSessionConfig ignored in A2aAgentExecutor._prepare_session()

3 participants