feat(ui): reconnect to in-progress tasks on page load#1903
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a UI reconnect path so that if a user reloads the chat page while an agent task is still running, the client detects the in-progress task and resubscribes to its SSE stream via tasks/resubscribe instead of leaving the UI stale.
Changes:
- Added
KagentA2AClient.resubscribeStream()to open an SSE stream for an existing task via JSON-RPCtasks/resubscribe. - Updated
ChatInterfaceinitialization to detect active (submitted/working) tasks and automatically resubscribe on page load. - Refactored shared stream consumption logic into a reusable
consumeStream()helper and added a best-effort DB reload after resubscribe completion.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| ui/src/lib/a2aClient.ts | Adds a new client method to resubscribe to an existing task’s SSE stream via tasks/resubscribe. |
| ui/src/components/chat/ChatInterface.tsx | Detects in-progress tasks on load, resubscribes to the stream, and centralizes SSE consumption/timeout handling. |
Comments suppressed due to low confidence (2)
ui/src/components/chat/ChatInterface.tsx:468
streamResubscribedTaskunconditionally callssetChatStatus("ready")infinally. This can override statuses set byhandleMessageEventduring the stream (notablyinput_requiredfor HITL interrupts, orerror/auth_required), leaving the UI in the wrong state. Align this cleanup withsendApprovalDecision’s pattern (only reset transient states likethinking/submitted/working, or derive the final status from the reloaded tasks).
} finally {
abortControllerRef.current = null;
setChatStatus("ready");
setIsStreaming(false);
setStreamingContent("");
}
ui/src/components/chat/ChatInterface.tsx:462
- The PR description mentions handling transient network failures with retry/backoff, but
streamResubscribedTaskcurrently makes a singletasks/resubscribeattempt and then falls back toreloadSessionFromDB()on any non-terminal error. If retries/backoff are intended, add a retry loop (respectingAbortErrorand terminal errors) before giving up, otherwise the UI may stop following a still-running task after a brief network blip.
} catch (error: unknown) {
if (error instanceof Error && error.name !== "AbortError" && !isTerminalError(error)) {
console.error("Resubscribe failed:", error);
}
// Terminal, AbortError, or unexpected error — reload whatever state we have.
if (!(error instanceof Error && error.name === "AbortError")) {
await reloadSessionFromDB();
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+182
to
+185
| if (activeTask) { | ||
| setChatStatus(mapA2AStateToStatus(activeTask.status?.state as TaskState)); | ||
| await streamResubscribedTask(activeTask.id); | ||
| } |
Contributor
Author
There was a problem hiding this comment.
The project has no component-level tests for ChatInterface at all at present.
7088994 to
9a54141
Compare
When a user reloads the chat page while the agent is still running, detect the active task and resubscribe to its SSE stream via tasks/resubscribe rather than showing a stale UI. Handles clean stream end, terminal errors, and AbortError cancellation. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> Signed-off-by: Brian Fox <[email protected]>
9a54141 to
e301da9
Compare
EItanya
approved these changes
May 22, 2026
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.
When a user reloads the chat page while the agent is still running, detect the active task and resubscribe to its SSE stream via tasks/resubscribe rather than showing a stale UI. Handles clean stream end, terminal errors, transient network failures with retry/backoff, and AbortError cancellation.
Current behaviour:
current.mp4
With reconnect:
with-fix.mp4