Skip to content

fix(sessions): preserve original Event.id from raw_event in VertexAiSessionService - #6531

Open
chelsealong wants to merge 1 commit into
google:mainfrom
chelsealong:fix-vertex-session-event-id-6530
Open

fix(sessions): preserve original Event.id from raw_event in VertexAiSessionService#6531
chelsealong wants to merge 1 commit into
google:mainfrom
chelsealong:fix-vertex-session-event-id-6530

Conversation

@chelsealong

Copy link
Copy Markdown

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Problem:
VertexAiSessionService.get_session returns each Event.id as the Vertex
event resource name (api_event_obj.name.split('/')[-1]) instead of the
original ADK Event.id that was generated during the run. The original id
is persisted inside raw_event, but _from_api_event deep-copies
raw_event and then unconditionally overwrites id before validating. As a
result the same logical event has two different ids depending on whether it
is observed live (streaming) or reloaded via get_session, which breaks any
caller that correlates events by id across the two paths.

Solution:
In _from_api_event, when raw_event is present, keep the id already in
raw_event and only fall back to the Vertex resource name if raw_event
doesn't have one (older data written before this field existed).

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Added test_get_session_preserves_original_event_id_from_raw_event in
tests/unittests/sessions/test_vertex_ai_session_service.py, which asserts
that get_session returns the id stored in raw_event rather than the
Vertex resource name suffix. Verified the new test fails against the
pre-fix code (AssertionError: ... assert '658731057016733696' == 'c452feb0-b9ad-48b1-b863-c7dd2f085378') and passes with the fix applied.

$ pytest tests/unittests/sessions/test_vertex_ai_session_service.py -v
...
45 passed, 5 warnings in 4.09s

pre-commit run --files src/google/adk/sessions/vertex_ai_session_service.py tests/unittests/sessions/test_vertex_ai_session_service.py also passes.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have added tests that prove my fix is effective.
  • New and existing unit tests pass locally with my changes.

Additional context

This change was prepared with AI coding assistance (Claude Code) and reviewed by me before submission.

…essionService

_from_api_event overwrote the id restored from raw_event with the Vertex
event resource name, so get_session returned a different Event.id than the
one seen during the live run/streaming for the same logical event. Only
fall back to the resource name when raw_event has no id (older data).

Fixes google#6530
@adk-bot adk-bot added the services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc label Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.get_session replaces Event.id with the Vertex resource name, discarding the persisted raw_event.id

3 participants