fix(sessions): preserve original Event.id from raw_event in VertexAiSessionService - #6531
Open
chelsealong wants to merge 1 commit into
Open
fix(sessions): preserve original Event.id from raw_event in VertexAiSessionService#6531chelsealong wants to merge 1 commit into
chelsealong wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
VertexAiSessionService.get_sessionreturns eachEvent.idas the Vertexevent resource name (
api_event_obj.name.split('/')[-1]) instead of theoriginal ADK
Event.idthat was generated during the run. The original idis persisted inside
raw_event, but_from_api_eventdeep-copiesraw_eventand then unconditionally overwritesidbefore validating. As aresult the same logical event has two different ids depending on whether it
is observed live (streaming) or reloaded via
get_session, which breaks anycaller that correlates events by id across the two paths.
Solution:
In
_from_api_event, whenraw_eventis present, keep theidalready inraw_eventand only fall back to the Vertex resource name ifraw_eventdoesn't have one (older data written before this field existed).
Testing Plan
Unit Tests:
Added
test_get_session_preserves_original_event_id_from_raw_eventintests/unittests/sessions/test_vertex_ai_session_service.py, which assertsthat
get_sessionreturns the id stored inraw_eventrather than theVertex 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.pre-commit run --files src/google/adk/sessions/vertex_ai_session_service.py tests/unittests/sessions/test_vertex_ai_session_service.pyalso passes.Checklist
Additional context
This change was prepared with AI coding assistance (Claude Code) and reviewed by me before submission.