Skip to content

Plugin framework: on_state_change_callback is never invoked #4393

Closed

Description

@mportdata

Description

The plugin framework provides hooks for various lifecycle events (before/after agent, tool, model callbacks, etc.), but there is no mechanism to notify plugins when session state changes occur via event.actions.state_delta.

The BigQueryAgentAnalyticsPlugin already implements an on_state_change_callback() method, demonstrating real demand for this hook, but the framework never invokes it because:

  1. BasePlugin has no default on_state_change_callback method
  2. PluginManager has no dispatcher for it
  3. The runner never detects state deltas and triggers the callback

Expected Behavior

When an event with a non-empty state_delta is yielded from the runner, all registered plugins should have their on_state_change_callback invoked with the state delta (as a copy, to prevent mutation).

Proposed Solution

  1. Add on_state_change_callback to BasePlugin as a default no-op method
  2. Add "on_state_change_callback" to PluginCallbackName and a run_on_state_change_callback dispatcher to PluginManager
  3. In Runner._exec_with_plugin, after yielding the final event, check for state_delta and invoke the callback

The callback should be observational (return value ignored) and receive a copy of the state delta to prevent plugins from mutating event state.

Activity

  1. added
    core[Component] This issue is related to the core interface and implementation
    on Feb 6, 2026
  2. added theissue type on Feb 6, 2026
  3. mportdata commented on Feb 9, 2026

    @mportdata
    Author

    Fix awaiting review here: #4395

  4. added
    bq[Component] This issue is related to Big Query integration
    and removed
    core[Component] This issue is related to the core interface and implementation
    on Feb 9, 2026
  5. changed the issue type fromtoon Feb 9, 2026
  6. wuliang229 commented on Feb 9, 2026

    @wuliang229
    Collaborator

    @haiyuan-eng-google please take a look.

  7. haiyuan-eng-google commented on Feb 10, 2026

    @haiyuan-eng-google
    Collaborator

    Confirmation

    You are absolutely correct. We have verified that:

    1. BigQueryAgentAnalyticsPlugin implements on_state_change_callback, but it is effectively dead code.
    2. BasePlugin and PluginManager do not define or support this callback.
    3. The Runner does not dispatch any specific callback when yielding events with state_delta.

    This is a clear gap in the plugin lifecycle hooks. While on_event_callback exists, a dedicated on_state_change_callback is cleaner and semantically more appropriate for state mutations, especially given that BigQueryAgentAnalyticsPlugin already expects it.

    Plan

    1. Framework Update: Add on_state_change_callback to BasePlugin (no-op default) and PluginManager.
    2. Runner Integration: Update Runner._exec_with_plugin (and potentially _append_new_message_to_session) to invoke this callback whenever an event contains a non-empty state_delta.
    3. Safety: Ensure the callback receives a copy of the delta to prevent accidental mutation of the event itself.
  8. mportdata commented on Feb 10, 2026

    @mportdata
    Author

    Confirmation

    You are absolutely correct. We have verified that:

    1. BigQueryAgentAnalyticsPlugin implements on_state_change_callback, but it is effectively dead code.
    2. BasePlugin and PluginManager do not define or support this callback.
    3. The Runner does not dispatch any specific callback when yielding events with state_delta.

    This is a clear gap in the plugin lifecycle hooks. While on_event_callback exists, a dedicated on_state_change_callback is cleaner and semantically more appropriate for state mutations, especially given that BigQueryAgentAnalyticsPlugin already expects it.

    Plan

    1. Framework Update: Add on_state_change_callback to BasePlugin (no-op default) and PluginManager.
    2. Runner Integration: Update Runner._exec_with_plugin (and potentially _append_new_message_to_session) to invoke this callback whenever an event contains a non-empty state_delta.
    3. Safety: Ensure the callback receives a copy of the delta to prevent accidental mutation of the event itself.

    I have raised a fix here: #4395

    This has added an on_state_change_callback no-op method to the BasePlugin and PluginManager as described above.
    STATE_DELTA was already being logged as part of after_tool_callback, my fix includes removing this implementation to not cause duplicate STATE_DELTA logs.

    RE: _append_new_message_to_session I have now added a fix so that _append_new_message_to_session calls the appropriate plug-in method when state_delta is not none.

    RE: Safety: please let me know if this has not been addressed by my fix already.
    In my fix we call on_state_change_callback within Runner._exec_with_plugin when any event has a non-empty actions.state_delta.

  9. wuliang229 commented on Feb 10, 2026

    @wuliang229
    Collaborator

    @haiyuan-eng-google FYI, the ADK team doesn't want to add a on_state_change_callback to the framework. Is there a way to fix it without introducing a framework change?

  10. removed their assignment
    on Feb 11, 2026
  11. added a commit that references this issue on Feb 14, 2026
    8faf613
  12. adk-bot commented on Feb 18, 2026

    @adk-bot
    Collaborator

    This issue has been automatically marked as stale because it has not had recent activity for 7 days after a maintainer requested clarification. It will be closed if no further activity occurs within 7 days.

  13. added
    stale[Status] Issues which have been marked inactive since there is no user response
    request clarification[Status] The maintainer need clarification or more information from the author
    on Feb 18, 2026
  14. haiyuan-eng-google commented on Feb 18, 2026

    @haiyuan-eng-google
    Collaborator

    The issue has been fixed in ea03487 with on_event_callback @wuliang229

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

Metadata

Metadata

Labels

bq[Component] This issue is related to Big Query integrationrequest clarification[Status] The maintainer need clarification or more information from the authorstale[Status] Issues which have been marked inactive since there is no user response

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions