You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
on_event_callback executes after append_event, preventing plugin modifications from being persisted #3990
The on_event_callback plugin hook is executed after the event has already been saved to the database via session_service.append_event(). This means any modifications made to events by plugins (e.g., adding/modifying custom_metadata) are only visible in the yielded event stream but are not persisted to the database.
Current Behavior:
In runners.py (lines ~767-777):
ifevent.partialisnotTrue:
awaitself.session_service.append_event(session=session, event=event)
# Step 3: Run the on_event callbacks to optionally modify the event.modified_event=awaitplugin_manager.run_on_event_callback(
invocation_context=invocation_context, event=event
)
yield (modified_eventifmodified_eventelseevent)
This causes:
✅ Event saved to DB (without plugin modifications)
✅ Plugin modifies event via on_event_callback
✅ Modified event yielded to client (client sees modifications)
❌ DB still contains original unmodified event (subsequent reads missing modifications)
Expected Behavior:
Plugin modifications to events via on_event_callback should be persisted to the database so that:
Real-time event stream and historical event retrieval return consistent data
Custom metadata added by plugins is preserved across sessions
Use Case:
We have a plugin that enriches events with contextual metadata (execution phase, workflow state) which is essential for our UI to display proper state. Currently, this metadata is only visible during initial streaming but disappears when fetching conversation history.
@selimseker You're absolutely right - this is a confirmed bug in runners.py.
The on_event_callback is executed AFTER append_event (lines 770-772 then 774-777), which means plugin modifications are only visible in the yielded stream but not persisted to the database.
The fix is straightforward: move run_on_event_callback BEFORE append_event so the modified event gets saved.
This matches the documented intention in base_plugin.py:158 which states the callback should modify events "before the event is handled."
Unfortunately there's no good workaround - this requires a code fix in runners.py that should be targeted to ensure consistent data between real-time streams and historical retrieval.
Thanks for the interest @svelezdevilla@Ponts - no fix has been merged yet, but this was just labeled "good first issue" yesterday so it's open for community contribution.
The fix is straightforward: in runners.py, move the run_on_event_callback() call (lines 835-837) BEFORE append_event() (lines 830-832) so plugin modifications get persisted.
If anyone wants to submit a PR, we would be happy to review.
I made a temporary fix in a plugin im developing that adds the event to the session instead of returning it, and in the before model callback removes it from the llm request.
Hopefully we can get the MR merged soon so I can remove that from my code :)
Activity
surajksharma07 commentedon Dec 30, 2025
@selimseker You're absolutely right - this is a confirmed bug in runners.py.
The on_event_callback is executed AFTER append_event (lines 770-772 then 774-777), which means plugin modifications are only visible in the yielded stream but not persisted to the database.
The fix is straightforward: move run_on_event_callback BEFORE append_event so the modified event gets saved.
This matches the documented intention in base_plugin.py:158 which states the callback should modify events "before the event is handled."
Unfortunately there's no good workaround - this requires a code fix in runners.py that should be targeted to ensure consistent data between real-time streams and historical retrieval.
surajksharma07 commentedon Dec 30, 2025
@DeanChensj Please have a look into it.
svelezdevilla commentedon Jan 21, 2026
Any news on this?
Ponts commentedon Jan 22, 2026
Would also like this fixed
surajksharma07 commentedon Jan 22, 2026
Thanks for the interest @svelezdevilla @Ponts - no fix has been merged yet, but this was just labeled "good first issue" yesterday so it's open for community contribution.
The fix is straightforward: in runners.py, move the
run_on_event_callback()call (lines 835-837) BEFOREappend_event()(lines 830-832) so plugin modifications get persisted.If anyone wants to submit a PR, we would be happy to review.
Ponts commentedon Jan 22, 2026
I made a temporary fix in a plugin im developing that adds the event to the session instead of returning it, and in the before model callback removes it from the llm request.
Hopefully we can get the MR merged soon so I can remove that from my code :)
surajksharma07 commentedon Jan 25, 2026
Thanks @Ponts for submitting PR #4239 - we're reviewing it now.
The fix looks straightforward (moving
run_on_event_callbackbeforeappend_event).We'll get this merged soon so you can remove your temporary workaround.
Appreciate everyone's patience here.
Team is looking more into it.
fix: run on_event_callback before append_event to persist plugin modi…
fix: execute on_event_callback before append_event to persist plugin …
fix: run on_event_callback before append_event to persist plugin modi…
fix: execute on_event_callback before append_event to persist plugin …
bharatbharat-creator commentedon Apr 24, 2026
We build upon the bug you just described and now we cant upgrade to latest adk!! This was a breaking change for many users
fix: execute on_event_callback before append_event to persist plugin …