Fix: RedisSessionService.list_sessions() state loss bug#45
Open
BaskaranNM wants to merge 1 commit intogoogle:mainfrom
Open
Fix: RedisSessionService.list_sessions() state loss bug#45BaskaranNM wants to merge 1 commit intogoogle:mainfrom
BaskaranNM wants to merge 1 commit intogoogle:mainfrom
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. |
## Problem
RedisSessionService.list_sessions() was clearing session state by setting
`session.state = {}` at line 178, causing loss of app-level and user-level
state data when listing sessions.
This differed from InMemorySessionService.list_sessions() which correctly
preserves state by calling `self._merge_state()`.
## Impact
- Session state (including custom fields like 'title', '_ag_ui_thread_id')
was lost when listing sessions via the API
- Frontend applications couldn't display session metadata in session lists
- State was only available when fetching individual sessions via get_session()
## Root Cause
The list_sessions() method was directly clearing state instead of merging
app/user state from Redis hashes, breaking the state management contract.
## Solution
Replace `session.state = {}` with `session = await self._merge_state(app_name, user_id, session)`
to match the behavior of InMemorySessionService.list_sessions()
## Changes
- Line 178: Changed from `session.state = {}` to merge_state() call
- Ensures consistent state handling across all session operations
- Maintains backward compatibility (events still cleared as intended)
## Testing
- Updated test_create_and_list_sessions to verify state is preserved
- Added test_list_sessions_preserves_app_user_state for explicit state verification
- All 16 tests pass
830bb56 to
dfb7f91
Compare
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.
Description
Fixes a bug in RedisSessionService.list_sessions() where session state was being cleared instead of preserved, causing loss of app-level and user-level state data.
Problem
RedisSessionService.list_sessions() was clearing session state by setting session.state = {} at line 178, which caused:
Root Cause
The method was directly clearing state instead of merging app/user state from Redis hashes, breaking the state management contract that other methods (get_session(), create_session()) correctly implement.
Solution
Replace session.state = {} with session = await self._merge_state(app_name, user_id, session) to match the behavior of:
Changes
Testing
Verified that: