fix(a2a): respect auto_create_session flag in A2A executor session preparation#5351
Open
nickchecan wants to merge 5 commits intogoogle:mainfrom
Open
fix(a2a): respect auto_create_session flag in A2A executor session preparation#5351nickchecan wants to merge 5 commits intogoogle:mainfrom
nickchecan wants to merge 5 commits intogoogle:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem:
When a
Runneris configured withauto_create_session=False, the A2A executorlayer completely bypasses this flag. Both
A2aAgentExecutor._prepare_session(legacy executor) and
_A2aAgentExecutor._resolve_session(new executor impl)call
runner.session_service.get_session()andrunner.session_service.create_session()directly, instead of going through
runner._get_or_create_session()(the methodthat actually checks the
auto_create_sessionflag). As a result, sessions arealways silently auto-created regardless of the flag value, making it impossible
to enforce explicit session management in A2A workflows.
Additionally,
to_a2a()'s internally createdRunnerdid not setauto_create_session=True, which would cause every incoming A2A request to failwith
SessionNotFoundErrorsince A2A clients never pre-create sessions.Solution:
session_servicecalls in_prepare_sessionand_resolve_sessionwithrunner._get_or_create_session(). This single methodalready encapsulates the
auto_create_sessionlogic and raisesSessionNotFoundErrorwhen the flag isFalseand the session is missing.auto_create_session=Trueinto_a2a()'s internalcreate_runner, topreserve backward-compatible behavior for users who rely on
to_a2a()to handlesession lifecycle automatically.
Testing Plan
Unit Tests:
Updated tests in
test_a2a_agent_executor.pyandtest_a2a_agent_executor_impl.pyto mock
runner._get_or_create_sessioninstead ofrunner.session_service.get_session/
create_session. Rewrotetest_resolve_session_creates_new_sessionto verifythe correct method and arguments are used.
Fixed
tests/unittests/a2a/integration/server.pyto passauto_create_session=Trueto
FakeRunner, restoring the pre-fix behavior for integration tests where sessionsare always created on-the-fly.
pytest tests/unittests/a2a/ -v
...
56 passed, 139 warnings
pytest tests/unittests/ -v
...
5456 passed, 1 skipped, 2240 warnings in 130.24s
Manual End-to-End (E2E) Tests:
Created a minimal A2A server using
to_a2a()with a LiteLLM-backed agent andtested three scenarios:
Scenario 1 —
auto_create_session=True(default viato_a2a):{ "result": { "status": { "state": "completed" }, "artifacts": [ { "parts": [{ "kind": "text", "text": "It's currently 2026-04-15 22:51:30 UTC." }] } ] } }Scenario 2 —
auto_create_session=Falsewith missing session:{ "result": { "status": { "state": "failed", "message": { "parts": [{ "kind": "text", "text": "Session not found: <session_id>" }] } } } }Scenario 3 —
auto_create_session=Falsewith pre-created session:Session pre-created via
lifespanhook → request succeeds withstate: completed.Checklist
Additional context
The
runner._get_or_create_session()method already existed and was usedcorrectly by all other runner entry points (
run_async,run_live,rewind_async). The A2A executor was the only layer that bypassed it, makingauto_create_sessionunreliable in A2A-based deployment.