Bug RHOAIENG-46360: Fix session deletion delay with optimistic updates#542
Bug RHOAIENG-46360: Fix session deletion delay with optimistic updates#542Gkrumbach07 wants to merge 2 commits intoambient-code:mainfrom
Conversation
Issue: Mouse click not recognized when deleting sessions - users experience a delay of several seconds when clicking OK on the deletion confirmation popup. The UI waits for the backend DELETE request to complete before updating the interface. Root Cause: The useDeleteSession hook only performed cache invalidation after the backend responded, with no optimistic update. This resulted in a poor UX where users had to wait for the network request to complete. Solution: Implemented optimistic updates with proper rollback: - onMutate: Immediately removes the session from all cached queries (both paginated and non-paginated list formats) - Cancels ongoing refetches to prevent race conditions - Snapshots previous data for rollback on error - onError: Restores all previous query data if deletion fails - onSuccess: Removes detail query and marks list as stale The implementation handles: - Multiple query keys (different pagination params) - Both paginated (ListAgenticSessionsPaginatedResponse) and non-paginated (array) list query formats - Race condition prevention via query cancellation - Type-safe filtering and restoration Result: Session now disappears immediately from UI when user clicks OK, providing instant feedback. If the backend delete fails, the session reappears with proper error handling. Testing: - Verified type safety (AgenticSession type guards) - Verified error rollback logic - Verified both paginated and legacy list format support - Verified race condition prevention Jira: https://issues.redhat.com/browse/RHOAIENG-46360 Co-Authored-By: Claude (claude-sonnet-4-5) <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
Claude Code ReviewSummaryThis PR implements optimistic updates for session deletion to provide instant UI feedback. The implementation follows React Query best practices with proper type guards, error rollback, and cache invalidation. Issues by SeverityCritical Issues1. Missing Type Import for ListAgenticSessionsPaginatedResponse 2. Inconsistent Cache Invalidation Major Issues3. Fragile Query Key Access Minor Issues4. Unused projectName in onError - Line 262 Positive Highlights✅ Excellent problem analysis RecommendationsPriority 1:
Priority 2: Priority 3: Final Verdict✅ Approve with Minor Changes - Solid implementation. Critical issues are minor type safety improvements. Great work on the UX improvement! 🔍 View AI decision process (logs available for 90 days) 📋 View memory system files loaded (click to expand)What Amber Loaded for Code ReviewAmber automatically loaded these repository standards from the memory system:
Impact: This review used your repository's specific code quality standards, security patterns, and best practices from the memory system (PRs #359, #360) - not just generic code review guidelines. |
Summary
Fixes session deletion delay by implementing optimistic updates in the
useDeleteSessionReact Query hook.Problem
Users experienced a delay when deleting sessions - after clicking OK on the confirmation popup, it took several seconds for the session to disappear from the UI. The click appeared unresponsive because the UI waited for the backend DELETE request to complete.
Root Cause
The
useDeleteSessionhook incomponents/frontend/src/services/queries/use-sessions.tsonly performed cache invalidation after the backend responded (inonSuccess). There was no optimistic update, so users had to wait for the network request to complete before seeing any UI change.Solution
Implemented optimistic updates with proper error rollback:
Changes to
useDeleteSessionhook:onMutate: Immediately removes the session from all cached queries before the API call
ListAgenticSessionsPaginatedResponse) and non-paginated (array) list formatsonError: Restores all previous query data if the deletion fails
onSuccess: Cleans up and ensures cache consistency
Benefits
Testing
Jira
https://issues.redhat.com/browse/RHOAIENG-46360
Files Changed
components/frontend/src/services/queries/use-sessions.ts(useDeleteSession hook)Complexity
Medium - Standard React Query optimistic update pattern
Estimated Effort
1-2 hours (investigation + implementation)