Repository navigation
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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
Addresses the state-delta half of #7701 (the append boundary counterpart of #7676, which covers
create_session).Problem:
InMemorySessionService.append_event()appliesevent.actions.state_deltato storage with plain.update()calls, so nested values from the caller's delta are stored by reference, even with the default deep-copy setting. Mutating the caller's delta after the append returns silently changes the saved session state — without another event — and the nextget_session()returns the changed values. This affects session state as well as theapp:/user:scoped state routed byextract_state_delta().Reproduction (default feature settings, no model/network; from #7701):
The
SqliteSessionServicecontrol in #7701 returns the unmutated value.What changed
append_event()now routes the state delta through the existing_copy_state()helper beforeextract_state_delta(), mirroring what fix(sessions): snapshot initial state in in-memory sessions #7676 does for initial state increate_session(): under the default settings the delta values are deep-copied into storage; underIN_MEMORY_SESSION_SERVICE_LIGHT_COPYthe top level alone is copied and values stay aliased, matching that mode's documented design. Temporary keys are trimmed before the copy, so uncopyable temp values are never traversed (same reasoning as in fix(sessions): snapshot initial state in in-memory sessions #7676).test_append_event_does_not_retain_caller_state— passes on every registered backend with this change;test_append_event_does_not_retain_caller_event— passes on the persistent backends; registered as a written divergence for both in-memory backends, because append deliberately stores the caller's event object (events may hold values that cannot be copied, and append must not pay copy costs — pinned bytest_in_memory_list_sessions_omits_events_without_copying_themandtest_in_memory_get_session_copies_only_selected_events). The divergence entry documents the remaining half of InMemorySessionService retains appended Event references, allowing later mutations to change saved history and state #7701 as a pickable defect; resolving it needs a design decision about copying events at append time, which I did not want to make unilaterally.test_in_memory_append_event_state_uses_configured_copy_depthpins the new depth behavior in both modes and that the stored event itself stays aliased.Tests
{'items': ['coffee']}with this change (and{'items': ['coffee', 'tea']}onmain).pytest tests/unittests/sessions/: 650 passed, 3 xfailed (the registered divergences), with two failures that pre-date this change and reproduce on unmodifiedmainin my environment (missing optionalagentplatformand spanner-dialect dependencies).pyinkandisortpass on the changed files.AI usage disclosure
Developed with AI assistance (analysis, patch, tests); reviewed line by line, and I take full responsibility for correctness and design.