beam icon indicating copy to clipboard operation
beam copied to clipboard

[Bug]: ADKAgentModelHandler fails with AlreadyExistsError when a session_id is reused

Open alisha-1000 opened this issue 2 weeks ago • 1 comments

What happened?

ADKAgentModelHandler fails on the second call that uses the same session_id, so the stateful multi-turn mode described in the class docstring does not work.

Cause

In _invoke_agent (sdks/python/apache_beam/ml/inference/agent_development_kit.py):

try:
  await runner.session_service.get_session(session_id)
except Exception as e:
  await runner.session_service.create_session(
      app_name=app_name, user_id=user_id, session_id=session_id)
  1. ADK's get_session takes keyword-only arguments (*, app_name, user_id, session_id, config=None), so the positional call always raises TypeError, whether or not the session exists.
  2. except Exception swallows it and calls create_session. For a new session this happens to work, which is why stateless runs pass.
  3. For an existing session, create_session raises AlreadyExistsError: Session with id <id> already exists.

Fixing only the arguments is not enough: with correct arguments, InMemorySessionService.get_session returns None for a missing session instead of raising, so the except branch would never run.

Reproduction

Direct calls against InMemorySessionService (google-adk 2.14.1):

Call Result
get_session("sid") TypeError: ... takes 1 positional argument but 2 were given
get_session(app_name=..., user_id=..., session_id=...), missing session returns None
second create_session with the same id AlreadyExistsError

Through the handler: two RunInference runs with inference_args={"session_id": "fixed-session-1"} and a shared InMemorySessionService passed via session_service_factory. Run 1 succeeds. Run 2 fails with the TypeError at the get_session line followed by AlreadyExistsError from create_session.

The failure happens before the model is called, so it does not depend on the model. I reproduced it with a local model (LiteLlm + Ollama).

Environment

  • apache-beam 2.78.0.dev0 (master at 7ab792f471f), DirectRunner
  • google-adk 2.14.1, Python 3.13.6, macOS arm64

The same code is present in the 2.75.0 release, and the same call is unchanged in draft PR #39074 (line 463 there).

I would like to work on a fix.

Issue Priority

Priority: 2 (default / most bugs should be filed as P2)

Issue Components

  • [x] Component: Python SDK
  • [ ] Component: Java SDK
  • [ ] Component: Go SDK
  • [ ] Component: Typescript SDK
  • [ ] Component: IO connector
  • [ ] Component: Beam YAML
  • [ ] Component: Beam examples
  • [ ] Component: Beam playground
  • [ ] Component: Beam katas
  • [ ] Component: Website
  • [ ] Component: Infrastructure
  • [ ] Component: Spark Runner
  • [ ] Component: Flink Runner
  • [ ] Component: Prism Runner
  • [ ] Component: Hazelcast Jet Runner
  • [ ] Component: Google Cloud Dataflow Runner

alisha-1000 avatar Nov 13 '26 15:11 alisha-1000

.take-issue

alisha-1000 avatar Nov 13 '26 15:11 alisha-1000