Skip to content

fix: include rewind_before_invocation_id in VertexAiSessionService.append_event#4978

Open
yuting0624 wants to merge 4 commits intogoogle:mainfrom
yuting0624:fix/4930-vertex-session-rewind
Open

fix: include rewind_before_invocation_id in VertexAiSessionService.append_event#4978
yuting0624 wants to merge 4 commits intogoogle:mainfrom
yuting0624:fix/4930-vertex-session-rewind

Conversation

@yuting0624
Copy link
Copy Markdown

Summary

Fixes #4930

VertexAiSessionService.append_event() was not including rewind_before_invocation_id in the actions dict sent to the Vertex AI Agent Engine API. This caused rewind events to lose their target invocation ID when persisted, making session rewind non-functional for Agent Engine deployments.

Changes

  • src/google/adk/sessions/vertex_ai_session_service.py: Added rewind_before_invocation_id to the actions dict in append_event() (3 lines)
  • tests/unittests/sessions/test_vertex_ai_session_service.py: Added test_append_event_with_rewind to verify the field round-trips correctly through append and get

Root Cause

The actions dict construction in append_event() explicitly maps each field from EventActions to the API payload, but rewind_before_invocation_id was omitted. Other fields like transfer_to_agent, state_delta, skip_summarization, etc. were all present.

…pend_event (google#4930)

VertexAiSessionService.append_event() was not including
rewind_before_invocation_id in the actions dict sent to the
Vertex AI API. This caused rewind events to lose their target
invocation ID when persisted, making session rewind non-functional
for Agent Engine deployments.

Added the missing field to the actions dict and a round-trip test.

Fixes google#4930
@adk-bot
Copy link
Copy Markdown
Collaborator

adk-bot commented Mar 24, 2026

Response from ADK Triaging Agent

Hello @yuting0624, thank you for your contribution!

It looks like the pyink-check is failing. You can fix this by running the auto-formatting script from the root of the repository:

./autoformat.sh

This will ensure your changes adhere to the project's coding style. Thanks!

@adk-bot adk-bot added the services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc label Mar 24, 2026
@rohityan rohityan self-assigned this Mar 24, 2026
@rohityan rohityan added the request clarification [Status] The maintainer need clarification or more information from the author label Mar 24, 2026
@lucasbarzotto-axonify
Copy link
Copy Markdown

lucasbarzotto-axonify commented Apr 1, 2026

Hi @yuting0624, does this fix works?

I tried it and got the following error:

Error rewinding session 137352779248173056: 1 validation error for _AppendAgentEngineSessionEventRequestParameters

config.actions.rewind_before_invocation_id

Extra inputs are not permitted [type=extra_forbidden, input_value='p-146156f2-8f8e-42ae-af2a-75d00a48130c', input_type=str]

For further information visit https://errors.pydantic.dev/2.12/v/extra_forbidden

Looking at this, it looks like the rewind_before_invocation_id field is not allowed?

Should we use custom_metadata instead? The same way it's done for event compaction?

    # Store compaction data in custom_metadata since the Vertex AI service
    # does not yet support the compaction field.
    # TODO: Stop writing to custom_metadata once the Vertex AI service
    # supports the compaction field natively in EventActions.
    if event.actions and event.actions.compaction:
      compaction_dict = event.actions.compaction.model_dump(
          exclude_none=True, mode='json'
      )
      _set_internal_custom_metadata(
          metadata_dict,
          key=_COMPACTION_CUSTOM_METADATA_KEY,
          value=compaction_dict,
      )

…dantic validation error

The Vertex AI SDK's Pydantic model does not yet support
rewind_before_invocation_id in EventActions, causing 'Extra inputs
are not permitted' errors. Store it in custom_metadata following the
same pattern used for compaction.

Addresses feedback from lucasbarzotto-axonify on PR google#4978.
@yuting0624
Copy link
Copy Markdown
Author

Thanks for catching this @lucasbarzotto-axonify! You're absolutely right — the Vertex AI SDK doesn't support rewind_before_invocation_id in EventActions yet.

I've pushed a fix that stores it in custom_metadata following the same pattern as compaction:

  • Write path: rewind_before_invocation_id is now stored via _set_internal_custom_metadata() instead of directly in the actions dict
  • Read path: Extracted from custom_metadata and restored into EventActions on retrieval

All 25 session service tests pass. The Pydantic validation error should no longer occur.

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

Labels

request clarification [Status] The maintainer need clarification or more information from the author services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VertexAiSessionService.append_event drops rewind_before_invocation_id, breaking rewind filtering on subsequent reads

4 participants