Skip to content

fix: run on_event_callback before append_event to persist plugin modifications#5309

Open
Jah-yee wants to merge 2 commits intogoogle:mainfrom
Jah-yee:fix/on_event_callback_order
Open

fix: run on_event_callback before append_event to persist plugin modifications#5309
Jah-yee wants to merge 2 commits intogoogle:mainfrom
Jah-yee:fix/on_event_callback_order

Conversation

@Jah-yee
Copy link
Copy Markdown

@Jah-yee Jah-yee commented Apr 13, 2026

Good day

Summary

Fixes issue #3990 - the on_event_callback plugin hook was executing after the event had already been saved to the database via session_service.append_event(). This caused plugin modifications (e.g., adding/modifying custom_metadata) to only be visible in the yielded event stream but not persisted to the database.

Changes

Reorders execution in runners.py so that:

  1. on_event_callback runs first to modify the event
  2. append_event stores the (possibly modified) event to DB
  3. The event is then yielded to the client

This ensures plugin modifications are persisted and visible when fetching conversation history.

Testing

  • Code compiles successfully
  • Logic follows the existing pattern used in other parts of the codebase

Files Changed

  • src/google/adk/runners.py

感谢你们的奉献,希望能提供帮助。如果我解决得有问题或有待商妥的地方,请在下面留言,我会来处理。

Warmly,
RoomWithOutRoof

Jah-yee added 2 commits April 13, 2026 21:33
Updates documentation for 'adk web' and 'adk api_server' commands to clarify
the multiple supported agent directory formats:
- {agent_name}/agent.py (module with root_agent)
- {agent_name}.py (module with root_agent)
- {agent_name}/__init__.py (package with root_agent or app)
- {agent_name}/root_agent.yaml (YAML config folder)

The implementation already supports all these formats via AgentLoader, but the docstring
only mentioned the YAML case, causing user confusion per issue google#4425.

Signed-off-by: RoomWithOutRoof <RoomWithOutRoof@users.noreply.github.com>
…fications

Previously, on_event_callback was executed AFTER append_event, causing plugin
modifications to events (e.g., custom_metadata) to only be visible in the
real-time event stream but not persisted to the database.

This fix reorders the execution so that:
1. on_event_callback runs first to modify the event
2. append_event stores the (possibly modified) event to DB
3. The event is then yielded to the client

This ensures plugin modifications are persisted and visible when fetching
conversation history.

Fixes: google#3990
@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 13, 2026

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.

@adk-bot adk-bot added the core [Component] This issue is related to the core interface and implementation label Apr 13, 2026
@adk-bot
Copy link
Copy Markdown
Collaborator

adk-bot commented Apr 13, 2026

Hello @Jah-yee, thank you for your contribution!

Before we can merge this PR, could you please address the following:

  • Contributor License Agreement (CLA): It looks like the CLA has not been signed yet. Please sign the CLA to proceed. You can find more information in the "cla/google" check at the bottom of the PR.
  • Testing Plan: The contribution guidelines require a more detailed testing plan for bug fixes. Could you please provide steps on how you tested this change, along with any relevant logs or screenshots that demonstrate the fix is working as expected?

This information will help us review and merge your PR more efficiently. Thanks!

Response from ADK Triaging Agent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core [Component] This issue is related to the core interface and implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants