Repository navigation
fix(google-adk): preserve async stream lifecycle and tracing context - #268
Closed
jabrailkhalil wants to merge 3 commits into
Closed
jabrailkhalil wants to merge 3 commits into
jabrailkhalil wants to merge 3 commits into
Conversation
This was referenced Oct 18, 2026
Contributor
Author
|
I checked the native ADK integration now on |
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.
What does this PR do?
Fixes #267.
Runner.run_async()andBaseAgent.run_async()now return a traced native async generator. Direct iteration,asend(),athrow()andaclose()keep their normal behavior; stream cleanup finishes its span, and the event objects pass through unchanged.Why?
The previous proxy only implemented
__aiter__(). Direct iteration raisedTypeError, closing the proxy bypassed the tracing iterator's cleanup, and its active context leaked into event-processing code. One shared generator now forwards control operations and restores the consumer's context at every yield, while retaining any nested agent context for the next resume.How was it tested?
26 new cases cover direct iteration, exhaustion, early close, lazy close, send/throw, source and cleanup errors, cancellation, nested spans, interleaved sessions, suppression and the real ADK Runner with an in-memory session service.
The original source fails 22 of those cases. The patched source passes all 46 tests, including the existing 20 Google ADK tests, with no skips.
Linux validation covers Python 3.10 / ADK 1.2.1 and Python 3.12 / ADK 1.32.0 and 2.1.0: complete reports and commands. The workflow checks out
9696d4e43ac0246bd6ef2272c99b754e5dc1d7f9directly; validation files are excluded from this PR.Windows / Python 3.12 / ADK 2.1.0 also passes all 46 tests. Six local mutation checks catch omitted close, context detach/snapshot, send/throw forwarding and span termination.
Legacy mock-only tests use
monkeypatchso singleton method overrides are restored before the integration tests run. CI runs those legacy tests first.Ruff correctness checks, Black on the new helper/tests, import sorting, diff checks and Mypy 1.18.2 pass in all three CI environments; before/after type reports are included.
Unit tests added / updated.
Offline integration tests pass with real ADK Runner and BaseAgent; no LLM provider or gateway calls.
SDK behavior and close-on-early-exit usage documented in the README and changelog.
Checklist
main.docs/VOCABULARY.mdis absent on this base.Notes for reviewers
Normal exhaustion marks a span OK; errors are recorded once. Explicit close and cancellation finish an incomplete span without marking it successful. The underlying generator is closed in
finally. Live Gemini/provider behavior was not tested.ADK 1.2.1 finalizes nested Runner streams asynchronously. The integration test checks the invocation span ends immediately, then waits for the nested agent's cleanup; direct close of either wrapper is verified separately.
A Python 3.9 attempt could not collect tests even against the original source: the existing
EvalTag.eval_name: str | EvalNameannotation infi_instrumentation/fi_types.pyfails at import. Python 3.9 therefore remains unverified; no runtime floor or unrelated core code is changed here.Implementation and regression tests written with an OpenAI assistant under my supervision.