fix: run on_event callbacks for before_run early exits - #7008
Open
jaywang172 wants to merge 1 commit into
Open
Conversation
Route synthesized before_run early-exit events through the same private event-processing helper used by normal runner events. This keeps on_event callback modifications aligned between yielded and persisted events across legacy, node, and live execution. Fixes google#7007
jaywang172
force-pushed
the
fix/before-run-early-exit-event-callback
branch
from
September 4, 2026 08:36
4a87c8e to
7b088bc
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.
Link to Issue or Description of Change
Problem:
before_run_callbackmay halt a run by returningtypes.Content. The runnerconverts that content into an event, but the early-exit paths currently persist
and yield the event without invoking
on_event_callback.This affects legacy agent execution, node /
LlmAgentexecution, and liveexecution. It means event plugins used for logging, auditing, redaction, or
metadata enrichment do not observe these runner-produced responses.
Solution:
Route early-exit events through the same private event-processing step used by
normal runner events:
metadata → on_event_callback → mergebefore persistence and yielding. Keeping this processing in a private
Runnerhelper prevents the normal and early-exit paths from drifting while introducing
no public API.
Before:
before_run → early-exit Event → persist / yieldAfter:
before_run → early-exit Event → on_event_callback → merge → persist / yieldPersistence eligibility remains based on the original event, preserving the
existing live-event persistence policy.
Testing Plan
Unit Tests:
Added a parameterized regression test for legacy async, node async, and live
runner execution. It verifies that:
on_event_callbackis invoked for the early-exit event;Validation:
main(c7ffcfa8): 13,959 passed,85 skipped, 27 xfailed, 2 xpassed, and 24 subtests passed;
git diff --check: passed;No Google API key or Application Default Credentials are required.
Manual End-to-End (E2E) Tests:
Ran a local
Runnersmoke test withInMemorySessionService. A plugin returnedcontent from
before_run_callback, replaced the synthesized event inon_event_callback, and the script verified that the processed event was bothyielded and persisted. The early exit prevented any model request.
Checklist
Additional context
This is a focused runtime lifecycle fix. It does not change plugin ordering,
event merge behavior, or any public API.