Skip to content

Restore chat status/subscription when loading a chat#1333

Open
dobesv wants to merge 1 commit intokagent-dev:mainfrom
dobesv:chat-resume-subscription
Open

Restore chat status/subscription when loading a chat#1333
dobesv wants to merge 1 commit intokagent-dev:mainfrom
dobesv:chat-resume-subscription

Conversation

@dobesv
Copy link

@dobesv dobesv commented Feb 18, 2026

Previously the UI would just assume a chat was idle when loading it. This fetches the chat status and displays an appropriate state. It will resubscribe for live updates in some cases as well.

This makes the experience a lot nicer when switching between chats or reloading the page while looking at a chat.

Copilot AI review requested due to automatic review settings February 18, 2026 23:03
@dobesv dobesv requested a review from peterj as a code owner February 18, 2026 23:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves chat reload/switching behavior by restoring the UI status from stored tasks and (when appropriate) resubscribing to an in-progress A2A task’s SSE stream so the UI reflects the real runtime state rather than assuming “idle”.

Changes:

  • Introduces a StreamEvent union type for A2A SSE events and updates message handling to accept it.
  • Adds tasks/resubscribe support to the UI A2A client for reconnecting to in-progress task streams.
  • Updates ChatInterface initialization to derive chat status from task state and auto-resubscribe for “submitted/working” tasks, while reusing a shared stream-consumption helper.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
ui/src/lib/messageHandlers.ts Adds StreamEvent type and updates handler signature to accept all SSE event shapes.
ui/src/lib/a2aClient.ts Adds resubscribeToTask() JSON-RPC call and refactors proxy URL creation.
ui/src/components/chat/ChatInterface.tsx Restores chat status on load and resubscribes to live updates when a task is still running.
Comments suppressed due to low confidence (1)

ui/src/components/chat/ChatInterface.tsx:170

  • On resubscribe failure you set chatStatus("ready"), but the streaming UI state (isStreaming / streamingContent) is not cleared here. If the resubscribe stream delivered some events before failing, handleMessageEvent may have set isStreaming true and appended partial content, leaving the UI in a stuck/incorrect state.

Consider resetting streaming state in this failure path (similar to the send-message error handler) before returning control to the user.

          setStoredMessages(extractMessagesFromTasks(refreshed.data));
          setTokenStats(extractTokenStatsFromTasks(refreshed.data));
        }
      }
      setChatStatus("ready");

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +146 to +148
const controller = new AbortController();
abortControllerRef.current = controller;

Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attemptResubscribe writes to the shared abortControllerRef.current and then unconditionally clears it in finally. If another stream is started while this resubscribe is in-flight (e.g. user sends a message before initializeChat finishes), the resubscribe can overwrite the ref and later clear it, breaking cancel/cleanup for the newer request and potentially leaving a stream running.

Consider: (1) abort any existing controller before replacing it, and/or (2) only clear abortControllerRef.current if it still points at this function's controller (identity check) in the finally block.

Copilot uses AI. Check for mistakes.
Previously the UI would just assume a chat was idle when loading it.  This fetches the chat status and displays an appropriate state.  It will resubscribe for live updates in some cases as well.

This makes the experience a lot nicer when switching between chats or reloading the page while looking at a chat.

Signed-off-by: Dobes Vandermeer <dobes.vandermeer@newsela.com>
@dobesv dobesv force-pushed the chat-resume-subscription branch from c1485b6 to 0e92736 Compare February 19, 2026 07:05
@dobesv
Copy link
Author

dobesv commented Feb 19, 2026

I've been using this for a while today and it's a big improvement although I still feel like I'm not always getting updates to the chat unless I actually sent the last message without navigating away and back. So maybe this still has something missing.

Copy link
Contributor

@EItanya EItanya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking forward to this, will definitely a big improvement, gonna assign our UI maintainer @peterj

@EItanya
Copy link
Contributor

EItanya commented Feb 19, 2026

Verifying locally now

@EItanya
Copy link
Contributor

EItanya commented Feb 19, 2026

Screenshot 2026-02-19 at 18 17 31

So it doesn't quite work. When I hit refresh during some tool calls it does get the stream back, but then it won't allow me to send another message. So probably just need to figure out how to update that state properly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments