Commit dfb7f91
committed
Fix: RedisSessionService.list_sessions() state loss bug
## 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 pass1 parent cc56a5e commit dfb7f91
2 files changed
Lines changed: 54 additions & 4 deletions
File tree
- src/google/adk_community/sessions
- tests/unittests/sessions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
178 | | - | |
| 178 | + | |
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | | - | |
| 181 | + | |
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
| |||
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
215 | | - | |
| 215 | + | |
216 | 216 | | |
217 | | - | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
218 | 268 | | |
219 | 269 | | |
220 | 270 | | |
| |||
0 commit comments