Skip to content

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

@lucasbarzotto-axonify

Description

@lucasbarzotto-axonify

🔴 Required Information

Describe the Bug:

VertexAiSessionService.append_event does not serialize EventActions.rewind_before_invocation_id when writing events to the Vertex AI API. The field is omitted from the config['actions'] dict (lines 261–274 of vertex_ai_session_service.py). On subsequent reads, _from_api_event never reconstructs it, so the field is permanently lost.

This means ADK's own rewind filtering in contents.py (lines 432–449) — which depends on event.actions.rewind_before_invocation_id — silently becomes a no-op for any session backed by VertexAiSessionService. After a rewind, the rewound events are not filtered out of the LLM context on subsequent agent invocations.

Steps to Reproduce:

  1. Create an ADK application using VertexAiSessionService (i.e. agentengine:// session URI)
  2. Run a few agent invocations to build up session events
  3. Call runner.rewind_async(user_id=..., session_id=..., rewind_before_invocation_id="<target_invocation_id>")
  4. Verify: runner.rewind_async creates an event with actions.rewind_before_invocation_id set and calls session_service.append_event (runners.py:672–684) — this succeeds
  5. Call session_service.get_session(...) to reload the session
  6. Inspect the last event (the rewind event): session.events[-1].actions.rewind_before_invocation_id is None
  7. Trigger another agent invocation — the LLM context in contents.py includes the events that should have been annulled by the rewind

Expected Behavior:

After calling rewind_async, reloading the session should preserve rewind_before_invocation_id on the rewind event. The rewind filtering in contents.py:432-449 should correctly annul the targeted events from the LLM context.

Observed Behavior:

rewind_before_invocation_id is silently dropped during append_event serialization. On the next get_session call, the rewind event has actions.rewind_before_invocation_id = None. The rewind filtering in contents.py has no effect, so the LLM sees the full un-rewound event history.

Root Cause:

In vertex_ai_session_service.py, append_event manually constructs the config['actions'] dict (lines 261–274) with an explicit allowlist of fields:

config['actions'] = {
    'skip_summarization': event.actions.skip_summarization,
    'state_delta': event.actions.state_delta,
    'artifact_delta': event.actions.artifact_delta,
    'transfer_agent': event.actions.transfer_to_agent,
    'escalate': event.actions.escalate,
    'requested_auth_configs': { ... },
    # TODO: add requested_tool_confirmations, agent_state once
    # they are available in the API.
}

rewind_before_invocation_id is not in this allowlist.

Similarly, _from_api_event (lines 362–437) reconstructs EventActions via actions.model_dump()EventActions.model_validate(), which would round-trip the field correctly if it were persisted — but since it was never written, it's absent from the API response.

Note: The _compaction field had the same problem and was solved by stashing it in custom_metadata (see lines 296–307 of append_event and lines 378–387 of _from_api_event). A similar approach could work for rewind_before_invocation_id, or the field could simply be added to the config['actions'] allowlist.

Environment Details:

  • ADK Library Version: 1.27.1
  • Desktop OS: macOS (darwin 24.6.0)
  • Python Version: 3.13

Model Information:

  • Are you using LiteLLM: No
  • Which model is being used: gemini-2.5-flash

🟡 Optional Information

How often has this issue occurred?:

  • Always

Metadata

Metadata

Assignees

No one assigned

    Labels

    services[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions