π OpenHands: AI-Driven Development
feat: refactor status indicators (#10983)
sp.wack774caf0607de
diff --git a/frontend/src/components/features/chat/custom-chat-input.tsx b/frontend/src/components/features/chat/custom-chat-input.tsxindex 5870cfbc14..6040879bbb 100644--- a/frontend/src/components/features/chat/custom-chat-input.tsx+++ b/frontend/src/components/features/chat/custom-chat-input.tsx@@ -2,8 +2,6 @@ import React, { useRef, useCallback, useState, useEffect } from "react";import { useDispatch, useSelector } from "react-redux";import { useTranslation } from "react-i18next";import { ConversationStatus } from "#/types/conversation-status";-import { ServerStatus } from "#/components/features/controls/server-status";-import { AgentStatus } from "#/components/features/controls/agent-status";import { ChatSendButton } from "./chat-send-button";import { ChatAddFileButton } from "./chat-add-file-button";import { cn, isMobileDevice } from "#/utils/utils";@@ -20,6 +18,8 @@ import {} from "#/state/conversation-slice";import { CHAT_INPUT } from "#/utils/constants";import { RootState } from "#/store";+import { ServerStatus } from "../controls/server-status";+import { AgentStatus } from "../controls/agent-status";export interface CustomChatInputProps {disabled?: boolean;diff --git a/frontend/src/context/ws-client-provider.tsx b/frontend/src/context/ws-client-provider.tsxindex 8a62c351cc..77a02e2d39 100644--- a/frontend/src/context/ws-client-provider.tsx+++ b/frontend/src/context/ws-client-provider.tsx@@ -263,8 +263,8 @@ export function WsClientProvider({}sio.io.opts.query = sio.io.opts.query || {};sio.io.opts.query.latest_event_id = lastEventRef.current?.id;- updateStatusWhenErrorMessagePresent(data);+ updateStatusWhenErrorMessagePresent(data);setErrorMessage(hasValidMessageProperty(data) ? data.message : "");}@@ -296,8 +296,29 @@ export function WsClientProvider({if (!conversationId) {throw new Error("No conversation ID provided");}- if (conversation?.status !== "RUNNING" && !conversation?.runtime_status) {- return () => undefined; // conversation not yet loaded++ // Clear error messages when conversation is intentionally stopped+ if (conversation && conversation.status === "STOPPED") {+ removeErrorMessage();+ setWebSocketStatus("DISCONNECTED");+ return () => undefined; // conversation intentionally stopped+ }++ // Set connecting status when conversation is starting+ if (conversation && conversation.status === "STARTING") {+ removeErrorMessage();+ setWebSocketStatus("CONNECTING");+ return () => undefined; // conversation is starting, will connect when ready+ }++ // Only connect when conversation is fully loaded and running+ if (+ !conversation ||+ conversation.status !== "RUNNING" ||+ !conversation.runtime_status ||+ conversation.runtime_status === "STATUS$STOPPED"+ ) {+ return () => undefined; // conversation not ready for WebSocket connection}let sio = sioRef.current;diff --git a/frontend/src/hooks/mutation/use-stop-conversation.ts b/frontend/src/hooks/mutation/use-stop-conversation.tsindex abb1ae801e..d23f5e14ae 100644--- a/frontend/src/hooks/mutation/use-stop-conversation.ts+++ b/frontend/src/hooks/mutation/use-stop-conversation.ts@@ -1,8 +1,13 @@import { useMutation, useQueryClient } from "@tanstack/react-query";+import { useNavigate, useParams } from "react-router";import ConversationService from "#/api/conversation-service/conversation-service.api";export const useStopConversation = () => {const queryClient = useQueryClient();+ const navigate = useNavigate();+ const { conversationId: currentConversationId } = useParams<{+ conversationId: string;+ }>();return useMutation({mutationFn: (variables: { conversationId: string }) =>@@ -32,5 +37,14 @@ export const useStopConversation = () => {// Also invalidate the conversations list for consistencyqueryClient.invalidateQueries({ queryKey: ["user", "conversations"] });},+ onSuccess: (_, variables) => {+ // Only redirect if we're stopping the conversation we're currently viewing+ if (+ currentConversationId &&+ variables.conversationId === currentConversationId+ ) {+ navigate("/");+ }+ },});};diff --git a/frontend/src/routes/conversation.tsx b/frontend/src/routes/conversation.tsxindex d4f7933a06..fc3a5c8d3f 100644--- a/frontend/src/routes/conversation.tsx+++ b/frontend/src/routes/conversation.tsx@@ -1,6 +1,7 @@import React from "react";import { useNavigate } from "react-router";import { useDispatch } from "react-redux";+import { useQueryClient } from "@tanstack/react-query";import { useConversationId } from "#/hooks/use-conversation-id";import { clearTerminal } from "#/state/command-slice";@@ -19,7 +20,6 @@ import { useActiveConversation } from "#/hooks/query/use-active-conversation";import { displayErrorToast } from "#/utils/custom-toast-handlers";import { useDocumentTitleFromState } from "#/hooks/use-document-title-from-state";-import ConversationService from "#/api/conversation-service/conversation-service.api";import { useIsAuthed } from "#/hooks/query/use-is-authed";import { ConversationSubscriptionsProvider } from "#/context/conversation-subscriptions-provider";import { useUserProviders } from "#/hooks/use-user-providers";@@ -28,16 +28,19 @@ import { ConversationMain } from "#/components/features/conversation/conversatioimport { ConversationName } from "#/components/features/conversation/conversation-name";import { ConversationTabs } from "#/components/features/conversation/conversation-tabs/conversation-tabs";+import { useStartConversation } from "#/hooks/mutation/use-start-conversation";function AppContent() {useConversationConfig();const { conversationId } = useConversationId();const { data: conversation, isFetched, refetch } = useActiveConversation();+ const { mutate: startConversation } = useStartConversation();const { data: isAuthed } = useIsAuthed();const { providers } = useUserProviders();const dispatch = useDispatch();const navigate = useNavigate();+ const queryClient = useQueryClient();// Fetch batch feedback data when conversation is loadeduseBatchFeedback();@@ -45,6 +48,13 @@ function AppContent() {// Set the document title to the conversation title when availableuseDocumentTitleFromState();+ // Force fresh conversation data when navigating to prevent stale cache issues+ React.useEffect(() => {+ queryClient.invalidateQueries({+ queryKey: ["user", "conversation", conversationId],+ });+ }, [conversationId, queryClient]);+React.useEffect(() => {if (isFetched && !conversation && isAuthed) {displayErrorToast(@@ -52,13 +62,25 @@ function AppContent() {);navigate("/");} else if (conversation?.status === "STOPPED") {- // start the conversation if the state is stopped on initial load- ConversationService.startConversation(- conversation.conversation_id,- providers,- ).then(() => refetch());+ // If conversation is STOPPED, attempt to start it+ startConversation(+ { conversationId: conversation.conversation_id, providers },+ {+ onError: (error) => {+ displayErrorToast(`Failed to start conversation: ${error.message}`);+ // Refetch the conversation to ensure UI consistency+ refetch();+ },+ },+ );}- }, [conversation?.conversation_id, isFetched, isAuthed, providers]);+ }, [+ conversation?.conversation_id,+ conversation?.status,+ isFetched,+ isAuthed,+ providers,+ ]);React.useEffect(() => {dispatch(clearTerminal());