Skip to content

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

@selimseker

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions