You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Google ADK streams lose iterator semantics and leave spans active after close #267
Instrumenting Google ADK changes the async-generator contract of both Runner.run_async() and BaseAgent.run_async():
Direct await stream.__anext__() fails with TypeError: '_AsyncGenerator' object is not an async iterator.
After iterator = stream.__aiter__(); await iterator.__anext__(), await stream.aclose() closes the original source but leaves the tracing iterator and its span open.
The stream's span/context stays current in the consumer between yielded events. Consumer spans and interleaved invocations can consequently acquire the wrong parent/session.
Reproduction
Use an InMemoryRunner with a local BaseAgent whose _run_async_impl yields two Event objects. Instrument it with GoogleADKInstrumentor().instrument(tracer_provider=provider), where provider exports through SimpleSpanProcessor(InMemorySpanExporter()).
iterator=stream.__aiter__()
awaititerator.__anext__()
# get_current_span() is the stream's span here, rather than the consumer's.awaitstream.aclose()
# No completed invocation/agent spans have reached the in-memory exporter.awaititerator.aclose() # Additional cleanup the original API never required.
Expected
Retain the original generator protocol and event objects. Finish tracing and release the underlying generator on close, failure or cancellation; activate its context only while executing it. Preserve nested span context when resuming.
Verification
I reproduced this without a provider call or API key, including through the real ADK Runner. Of 26 new regression cases, 22 fail against the original implementation. The patch passes all 46 Google ADK tests, including the existing suite, on ADK 1.2.1, 1.32.0 and 2.1.0. Full commands, before/after reports and versions are in the linked PR's validation artifacts.
Implementation and regression tests written with an OpenAI assistant under my supervision.
Thanks for reporting and independently validating the replacement. #445 removed the stream wrapper that changed direct iteration and early close; the native adapter shipped in Google ADK 0.1.7. This closes the traceAI wrapper defect, not all upstream ADK 1.x tracing behavior.
Activity
nik13 commentedon Nov 18, 2026
Thanks for reporting and independently validating the replacement. #445 removed the stream wrapper that changed direct iteration and early close; the native adapter shipped in Google ADK 0.1.7. This closes the traceAI wrapper defect, not all upstream ADK 1.x tracing behavior.