fix(sessions): stop returned sessions aliasing scoped state - #7105
Open
VedanthB wants to merge 1 commit into
Open
fix(sessions): stop returned sessions aliasing scoped state#7105VedanthB wants to merge 1 commit into
VedanthB wants to merge 1 commit into
Conversation
App- and user-scoped values were merged into returned in-memory sessions after the session copy, preserving nested references to stored state. Copy scoped dictionaries at the same configured depth so default reads cannot mutate storage while light-copy mode retains intentional aliasing.
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
No existing issue; described below following the bug-report structure.
Describe the Bug:
InMemorySessionServicecopies its storedSessionbefore returning it, but_merge_state()then inserts app- and user-scoped nested values into the copyby reference.
With the default deep-copy configuration, mutating a nested
app:oruser:value on a session returned by
create_session(),get_session(), orlist_sessions()therefore mutates service storage. A later session observesthe change even though no
append_event()or state delta occurred.Steps to Reproduce:
On current
main, run:Save the snippet as
/tmp/repro.pyand runpython /tmp/repro.py.Expected Behavior:
Mutating a returned deep-copied session does not mutate stored scoped state. A
later session prints:
Observed Behavior:
Current
mainprints:Environment Details:
mainat37aa7308(2.9.0)Model Information:
Frequency: Always (100%)
Solution:
Copy app and user state using the same configured depth as the session itself
before merging it into a returned session. Default mode deep-copies scoped
state;
IN_MEMORY_SESSION_SERVICE_LIGHT_COPYretains its intentional shallowcopy behavior.
Testing Plan
Unit Tests:
full matrix reproduce identically on unmodified
main; details below.)Added parameterized regression coverage for
create_session(),get_session(), andlist_sessions(), with nested app- and user-scoped valuesunder both copy modes.
mainplus the regression test:3 failed, 3 passed— exactlythe three default-copy cases failed; all light-copy cases passed.
6 passed.8 passed.271 passed, 3 xfailed.484 passed, 3 xfailed.toxmatrix: Python 3.10, 3.11, and 3.13 passed in full(
14,627,14,634, and14,627passed). Python 3.12 and 3.14 eachcompleted
14,625passing tests with two unrelated import-loading failures:this machine's
sitecustomizemodule appeared outside the allowlist. Bothfailures reproduce identically on unmodified
mainunder the same toxenvironments.
740baseline errors,740patched errors, zeronew errors.
uv build: source distribution and wheel built successfully.Manual End-to-End (E2E) Tests:
The keyless public-API reproduction creates a session with nested
app:anduser:values, mutates the returned object, and then creates a second session.On
main, the second session exposes the mutations. With this change, defaultmode retains the original values, while light-copy mode continues to share
nested objects by design. No model, credentials, or network access is required.
Checklist
CONTRIBUTING.mddocument.environment-specific failures reproduce identically on unmodified
main.)modules. (N/A; this change has no dependencies.)
Additional context
This is an internal copy-isolation fix. It does not change public API
signatures or surface and does not require an
adk-docsupdate.AI assistance disclosure
OpenAI Codex assisted with implementation, test preparation, and review.
Patched results were run against commit
2234ac92; baseline comparisons wererun against unmodified
mainat37aa7308under matching environments.