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
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