Skip to content

on_event_callback executes after append_event, preventing plugin modifications from being persisted #3990

Closed

Description

@selimseker

Description:

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

if event.partial is not True:
    await self.session_service.append_event(session=session, event=event)

# Step 3: Run the on_event callbacks to optionally modify the event.
modified_event = await plugin_manager.run_on_event_callback(
    invocation_context=invocation_context, event=event
)
yield (modified_event if modified_event else event)

This causes:

  1. ✅ Event saved to DB (without plugin modifications)
  2. ✅ Plugin modifies event via on_event_callback
  3. ✅ Modified event yielded to client (client sees modifications)
  4. ❌ 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.

Activity

  1. added
    core[Component] This issue is related to the core interface and implementation
    on Dec 20, 2025
  2. added theissue type on Dec 20, 2025
  3. surajksharma07 commented on Dec 30, 2025

    @surajksharma07
    Collaborator

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

  4. surajksharma07 commented on Dec 30, 2025

    @surajksharma07
    Collaborator

    @DeanChensj Please have a look into it.

  5. svelezdevilla commented on Jan 21, 2026

    @svelezdevilla

    Any news on this?

  6. Ponts commented on Jan 22, 2026

    @Ponts

    Would also like this fixed

  7. surajksharma07 commented on Jan 22, 2026

    @surajksharma07
    Collaborator

    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.

  8. Ponts commented on Jan 22, 2026

    @Ponts

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

  9. surajksharma07 commented on Jan 25, 2026

    @surajksharma07
    Collaborator

    Thanks @Ponts for submitting PR #4239 - we're reviewing it now.

    The fix looks straightforward (moving run_on_event_callback before append_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.

  10. self-assigned this
    on Apr 10, 2026
  11. added a commit that references this issue on Apr 13, 2026
    14cc801
  12. added a commit that references this issue on Apr 15, 2026
    454188d
  13. added a commit that references this issue on Apr 16, 2026
    7781b67
  14. added a commit that references this issue on Apr 21, 2026
    654bcd0
  15. bharatbharat-creator commented on Apr 24, 2026

    @bharatbharat-creator

    We build upon the bug you just described and now we cant upgrade to latest adk!! This was a breaking change for many users

  16. added a commit that references this issue on Aug 11, 2026
    8ff687e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

core[Component] This issue is related to the core interface and implementationgood first issue[Community] This issue is good for newcomers to participateneeds review[Status] The PR/issue is awaiting review from the maintainer

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions