test: regression tests for #5282 (after_run_callback on BaseNode roots)#5301
Draft
surfai wants to merge 1 commit intogoogle:mainfrom
Draft
test: regression tests for #5282 (after_run_callback on BaseNode roots)#5301surfai wants to merge 1 commit intogoogle:mainfrom
surfai wants to merge 1 commit intogoogle:mainfrom
Conversation
…e roots) Three tests for Runner._run_node_async plugin lifecycle on Workflow roots: - Baseline: pre-run + event hooks fire (PASSED on 2.0.0a3) - Regression anchor: after_run_callback strict xfail (remove when runners.py:427 TODO is wired — flips green as the signal) - Workaround proof: Runner subclass wrapping run_async dispatches after_run_callback post-drain (PASSED on 2.0.0a3) Closes google#5282
surfai
added a commit
to surfai/adk-python
that referenced
this pull request
Apr 14, 2026
…gle#5282) Runner._run_node_async had a TODO at runners.py:427 for node runtime plugin lifecycle, and never dispatched plugin_manager.run_after_run_callback. Because both Workflow(BaseNode) and (post a3 refactor) LlmAgent roots funnel through _run_node_async, any BasePlugin subclass that overrides after_run_callback silently no-op'd — breaking the canonical pattern for memory persistence, metrics emission, and post-run audit hooks. This wires one dispatch call after _consume_event_queue drains, mirroring the legacy path in _exec_with_plugin at runners.py:1230 exactly: outside the finally block, so semantics match legacy (fires on natural drain only, skipped on error in the loop, skipped on caller-break via GeneratorExit). Also: - Narrows the TODO at runners.py:427 from "tracing and plugin lifecycle" to "tracing" since plugin lifecycle is now wired. - Incidental pyink reformat at runners.py:1451: pre-existing 82-char line on v2 HEAD, unrelated to google#5282 but required by the pyink CI gate. Companion to test-only PR google#5301 (which established the regression anchor). This PR ships the fix plus flips the anchor by replacing the WorkaroundRunner scaffolding with a direct positive assertion. Alternatives considered and rejected: - Wrap in finally to fire on error/break — changes legacy contract. - Lift dispatch to run_async call sites — requires plumbing ic out of _run_node_async, bigger blast radius. - Extract a shared _with_plugin_lifecycle context manager — right long-term shape, but refactors the legacy path too and expands scope. Fixes google#5282 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 tasks
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.
Summary
Regression test for #5282:
Runner._run_node_asyncdoes not dispatchplugin_manager.run_after_run_callbackon the BaseNode path (therunners.py:427TODO).on_user_message_callback,before_run_callback, andon_event_callbackall fire on a Workflow root (they do, via_consume_event_queueatrunners.py:619).xfailassertingafter_run_callback == 1. Passes as xfail on stock 2.0.0a3. When the TODO is wired, delete the@xfaildecorator and it flips green.WorkaroundRunnersubclass wrappingrun_asyncto dispatchrun_after_run_callbackpost-drain. Confirms the fix shape is a singleawait ic.plugin_manager.run_after_run_callback(invocation_context=ic)after the event queue drains.The fix itself (one dispatch call after the
_consume_event_queueloop in_run_node_async) is left to the maintainer — this PR provides the test harness and regression guard.ContextVar note for WorkaroundRunner adopters
The
WorkaroundRunnerin the test usesself._last_icto stash theInvocationContext. This is safe for single-invocation tests but races under concurrentrun_asynccalls on a shared Runner instance — the second call overwrites_last_icbefore the first call's post-drain dispatch. Production use of this pattern should storeicon acontextvars.ContextVarscoped to the async task instead ofself.adk api_serverinjection gapThe
WorkaroundRunnersubclass is only viable for teams instantiatingRunnerdirectly.adk api_serverhardcodesRunner(...)atadk_web_server.py:737with no injection point for a custom subclass. Teams usingadk api_server(oradk web) have no workaround short of monkey-patching or the in-graph terminal-FunctionNodepattern described in #5282. Worth considering when therunners.py:427fix lands — ensuring_run_node_asyncdispatches natively covers both paths.Test plan
test_workflow_root_dispatches_pre_run_and_event_hooks— PASSED on 2.0.0a3test_workflow_root_after_run_callback_not_dispatched— XFAIL (strict) on 2.0.0a3test_workaround_runner_dispatches_after_run_callback— PASSED on 2.0.0a3When
runners.py:427is resolved:@pytest.mark.xfailfromtest_workflow_root_after_run_callback_not_dispatched— it should PASSFixes #5282