Conversation
314094b to
14683da
Compare
Signed-off-by: Josh Bell <joshadambell@me.com> Signed-off-by: jobell <jobell@ancestry.com>
14683da to
fb3d207
Compare
There was a problem hiding this comment.
Pull request overview
This pull request implements session resilience features to automatically recover from deleted sessions and reconnect to in-flight tasks after page reloads.
Changes:
- Backend session recovery: Added
_recreate_session()method in_session_service.pythat recreates deleted sessions and detects in-flight tasks, with 404 handling inappend_event()to trigger recreation before retrying - Frontend stream reconnection: Implemented
resubscribeTask()method and enhancedextractMessagesFromTasks()to detect pending tasks (working/submitted states), with auto-resubscription on page load in ChatInterface - Bug fix: Corrected
get_session()to populate events (changedevents=[]toevents=events)
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
python/packages/kagent-adk/src/kagent/adk/_session_service.py |
Added session recreation logic and 404 handling; fixed events population bug |
python/packages/kagent-adk/tests/unittests/test_session_service.py |
Complete test rewrite with comprehensive coverage for append_event recovery and session recreation |
ui/src/lib/messageHandlers.ts |
Enhanced to return TaskExtractionResult with pending task detection |
ui/src/lib/a2aClient.ts |
Added resubscribeTask() method and updated request type parameters |
ui/src/lib/__tests__/messageHandlers.test.ts |
Updated tests for new return type and added pending task detection tests |
ui/src/lib/__tests__/a2aClient.test.ts |
New comprehensive test suite for A2A client methods |
ui/src/components/chat/ChatInterface.tsx |
Added pending task detection and auto-resubscription logic with proper cleanup |
ui/src/components/chat/AgentCallDisplay.tsx |
Updated to use new extractMessagesFromTasks return type |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| id=session_data["id"], | ||
| user_id=session_data["user_id"], | ||
| events=[], | ||
| events=events, |
There was a problem hiding this comment.
The bug fix in get_session() changing events=[] to events=events lacks test coverage. While new tests were added for the append_event recovery logic, the tests that previously validated event loading in get_session were removed entirely. There should be at least one test ensuring that events returned from the API are properly populated in the session object.
| export interface TaskExtractionResult { | ||
| messages: Message[]; | ||
| pendingTask?: { taskId: string; state: string }; |
There was a problem hiding this comment.
The pendingTask return type uses state: string which is less precise than needed. Since the state is guaranteed to be either 'working' or 'submitted' (from the conditions on lines 22-23), consider typing this as { taskId: string; state: 'working' | 'submitted' } or { taskId: string; state: TaskState } for better type safety. This would eliminate the need for the as TaskState cast on line 162 of ChatInterface.tsx.
Summary
Adds session resilience: automatic session recovery on backend and stream reconnection on frontend for seamless experience when sessions are deleted or pages reload during active tasks.
working/submittedstate) when page is reloadedevents=eventsinstead ofevents=[])What Changed
Backend (
python/packages/kagent-adk)_session_service.py: New_recreate_session()method handles 404 duringappend_event()— recreates the session preserving ID/user/agent, handles 409 conflicts from concurrent recreation, fetches and logs in-flight tasks after recovery. Single retry prevents infinite recursion._session_service.py: Bug fix —get_session()now returnsevents=eventsinstead of empty listtest_session_service.py: 9 new tests covering append 404 recovery, session recreation, conflict handling, and in-flight task detectionFrontend (
ui/src)a2aClient.ts: NewresubscribeTask()method sendstasks/resubscribeJSON-RPC to resume SSE streamsmessageHandlers.ts:extractMessagesFromTasks()now returnsTaskExtractionResultwith optionalpendingTaskfor in-flight task detectionChatInterface.tsx: On page load, detects pending tasks and auto-resubscribes to their streams. Properly cleans up abort controller on unmount. HITL approval takes priority over resubscribe when both apply.AgentCallDisplay.tsx: Updated for newextractMessagesFromTasksreturn typeTests
a2aClient.test.ts: New test suite forresubscribeTask()and existing client methodsmessageHandlers.test.ts: New tests for pending task detection (working, submitted, completed states)How It Works
extractMessagesFromTasksresubscribeTask()→ Reconnects to SSE stream for the in-flight task!hasPendingApproval)