fix(runners): honor before_run_callback early-exit on the node execution path - #6829
Closed
Dratatus wants to merge 1 commit into
Closed
fix(runners): honor before_run_callback early-exit on the node execution path#6829Dratatus wants to merge 1 commit into
Dratatus wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Dratatus
force-pushed
the
fix/honor-before-run-early-exit-node-path
branch
from
August 20, 2026 11:32
a2e2417 to
3173ae7
Compare
…ion path The node execution path (_run_node_async) invoked plugin_manager.run_before_run_callback but discarded its return value, so a plugin returning types.Content (the documented signal to halt the run) was ignored and execution continued. The legacy path (_exec_with_plugin) already honors this contract. This affects every root that dispatches through the node path: a Workflow root and a root LlmAgent (chat/task mode), which means plugin-based guardrails (e.g. safety filters that block a turn in before_run_callback) are silently bypassed for those shapes. Fix mirrors the _exec_with_plugin early-exit contract: the returned Content becomes the final response event (with RunConfig custom_metadata applied), is appended to the session, and the run ends. after_run callbacks and post-invocation compaction are run explicitly (the finally that normally runs them belongs to the main loop, which a halted run never enters), matching the success path and the legacy early-exit behavior. Adapted from the stale PR google#6032 by @garyzava (rebased onto current main and extended with a root-LlmAgent regression test). Fixes google#6828
Dratatus
force-pushed
the
fix/honor-before-run-early-exit-node-path
branch
from
August 20, 2026 11:46
3173ae7 to
847b851
Compare
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.
Fixes #6828 (reopen of #6013, which was closed by the stale bot without a fix).
Supersedes #6032, which no longer merges cleanly and has had no author activity since 2026-07-03. The core change is adapted from that PR with credit to @garyzava; this PR rebases it onto current main and extends coverage.
Problem
_run_node_asynccallsplugin_manager.run_before_run_callback(...)and discards the return value. A plugin returningtypes.Content(the documented signal to halt the run) is silently ignored and execution continues. The legacy path (_exec_with_plugin) honors the contract. Affected shapes: rootWorkflowand rootLlmAgent— i.e. plugin-based guardrails are bypassed for the most common application shape.Fix
Mirror the
_exec_with_pluginearly-exit contract on the node path: the returnedContentbecomes the final response event (authormodel, withRunConfig.custom_metadataapplied), is appended to the session, and the run returns.after_runcallbacks and post-invocation compaction are run explicitly before returning (thefinallythat normally runs them belongs to the main loop, which a halted run never enters), matching both the success path and the legacy early-exit behavior — the regression tests assertafter_runfires on a halted run.Testing Plan
Two regression tests in
tests/unittests/workflow/test_workflow_failures.py:test_workflow_halts_when_before_run_callback_returns_content— rootWorkflow: the node never executes, the plugin content is the final event.test_llm_agent_root_halts_when_before_run_callback_returns_content— rootLlmAgentwith a mock model: the model is never called (mock_model.requestsstays empty), the plugin content is the final event.Both tests fail without the fix (verified) and pass with it. Full local runs:
tests/unittests/test_runners.py+tests/unittests/workflow/→ 738 passed, 11 skipped, 10 xfailed. No API surface changes; a plugin returningNonebehaves exactly as before.