Skip to content

fix: prevent mutation of input event during temporary state delta stripping by creating a shallow copy#1128

Merged
hanorik merged 2 commits into
google:mainfrom
hanorik:statedelta_mutation
Jul 8, 2026
Merged

fix: prevent mutation of input event during temporary state delta stripping by creating a shallow copy#1128
hanorik merged 2 commits into
google:mainfrom
hanorik:statedelta_mutation

Conversation

@hanorik

@hanorik hanorik commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Fixes an issue where trimTempDeltaState permanently mutated caller-provided event pointers in-place when filtering out temporary state deltas (keys prefixed with temp:).

Changes

  • Prevent In-Place Mutation: Updated trimTempDeltaState across inmemory, database, and vertexai session service implementations to create a shallow copy of the event object when temporary state delta keys are stripped.
  • Optimize No-Op Case: Added an early return when no temporary keys are removed (len(filteredStateDelta) == len(event.Actions.StateDelta)), avoiding unnecessary struct allocation when the state delta is unchanged.
  • Test Coverage: Added unit tests across all three session service packages to verify that input events remain immutable during temporary state delta trimming.

Testing Plan

  • Run go test -race ./session/... to verify existing session service tests and new immutability test cases pass.
  • Verify no regressions in temporary state delta filtering across inmemory, database, and vertexai session backends.

@hanorik hanorik requested a review from baptmont July 6, 2026 17:22
@hanorik hanorik merged commit b09bad9 into google:main Jul 8, 2026
9 checks passed
@hanorik hanorik deleted the statedelta_mutation branch July 8, 2026 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants