fix(sessions): defer local state/event mutation until Vertex append succeeds - #6999
Open
chelsealong wants to merge 1 commit into
Open
fix(sessions): defer local state/event mutation until Vertex append succeeds#6999chelsealong wants to merge 1 commit into
chelsealong wants to merge 1 commit into
Conversation
…ucceeds VertexAiSessionService.append_event() called the base class's append_event() (which applies normal state, appends the event, and mutates temp state) before the remote Agent Engine append. If the remote call failed, the exception propagated but the local session was already mutated, so a retry after recovery re-applied the state delta and appended the event a second time. Temp-scoped state is still applied to the in-memory session and stripped from the outgoing event before the remote call, matching DatabaseSessionService/SqliteSessionService/FirestoreSessionService. Normal state and the event are now only applied after the remote append succeeds. Fixes google#6998
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.
Fixes #6998
Problem
VertexAiSessionService.append_event()calledsuper().append_event()— which applies the normal state delta, mutates temp-scoped state, and
appends the event to
session.events— before making the remoteAgent Engine
appendcall. If the remote call raised, the exceptionpropagated to the caller, but the local session had already been
mutated. A retry of the same event after the remote service recovered
then re-applied the state delta and appended the event a second time.
DatabaseSessionService,SqliteSessionService, andFirestoreSessionServiceall apply temp-scoped state (and strip itfrom the event) before persisting, but defer the normal state update
and the event append until after storage succeeds.
VertexAiSessionServicedid not follow this pattern.
Fix
In
VertexAiSessionService.append_event():the outgoing event before the remote call (unchanged data still
goes out over the wire, temp state remains available in-memory for
the rest of the invocation).
session.eventsafter the remote append call succeeds.This mirrors the ordering already used by the other three
BaseSessionServiceimplementations.Testing plan
Added
test_append_event_does_not_mutate_session_on_remote_failure,adapted directly from the issue's minimal reproduction: a remote
appendcall that fails once then succeeds.Confirmed the test fails without the fix (stashed the source change,
kept the test):
And passes with the fix applied:
Full
sessionsunit test suite also passes:isortandpyinkboth report the changed files as clean.AI assistance disclosure
This change was authored with the assistance of an AI coding agent
(Claude), including the fix implementation, regression test, and this
PR description. All changes were reviewed and verified locally before
submission (tests run and shown to fail without the fix / pass with
it, lint run).