From 3b7b2fd8cc59f096850116d44b76e5a54d242285 Mon Sep 17 00:00:00 2001
From: Mariam Saeed <69825646+Mariam-Saeed@users.noreply.github.com>
Date: Tue, 16 Dec 2025 15:39:15 +0200
Subject: [PATCH] fix(frontend): Separate pause state from agent loading
(#12041)
Co-authored-by: amanape <83104063+amanape@users.noreply.github.com>
---
.../conversation/agent-status.test.tsx | 71 +++++++++++++++++++
.../features/controls/agent-status.tsx | 21 +++---
2 files changed, 84 insertions(+), 8 deletions(-)
create mode 100644 frontend/__tests__/components/features/conversation/agent-status.test.tsx
diff --git a/frontend/__tests__/components/features/conversation/agent-status.test.tsx b/frontend/__tests__/components/features/conversation/agent-status.test.tsx
new file mode 100644
index 0000000000..a121ed37a8
--- /dev/null
+++ b/frontend/__tests__/components/features/conversation/agent-status.test.tsx
@@ -0,0 +1,71 @@
+import { render, screen } from "@testing-library/react";
+import { describe, it, expect, vi } from "vitest";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { MemoryRouter } from "react-router";
+import { AgentStatus } from "#/components/features/controls/agent-status";
+import { AgentState } from "#/types/agent-state";
+import { useAgentState } from "#/hooks/use-agent-state";
+import { useConversationStore } from "#/state/conversation-store";
+
+vi.mock("#/hooks/use-agent-state");
+
+vi.mock("#/hooks/use-conversation-id", () => ({
+ useConversationId: () => ({ conversationId: "test-id" }),
+}));
+
+const wrapper = ({ children }: { children: React.ReactNode }) => (
+
+
+ {children}
+
+
+);
+
+const renderAgentStatus = ({
+ isPausing = false,
+}: { isPausing?: boolean } = {}) =>
+ render(
+ ,
+ { wrapper },
+ );
+
+describe("AgentStatus - isLoading logic", () => {
+ it("should show loading when curAgentState is INIT", () => {
+ vi.mocked(useAgentState).mockReturnValue({
+ curAgentState: AgentState.INIT,
+ });
+
+ renderAgentStatus();
+
+ expect(screen.getByTestId("agent-loading-spinner")).toBeInTheDocument();
+ });
+
+ it("should show loading when isPausing is true, even if shouldShownAgentLoading is false", () => {
+ vi.mocked(useAgentState).mockReturnValue({
+ curAgentState: AgentState.AWAITING_USER_INPUT,
+ });
+
+ renderAgentStatus({ isPausing: true });
+
+ expect(screen.getByTestId("agent-loading-spinner")).toBeInTheDocument();
+ });
+
+ it("should NOT update global shouldShownAgentLoading when only isPausing is true", () => {
+ vi.mocked(useAgentState).mockReturnValue({
+ curAgentState: AgentState.AWAITING_USER_INPUT,
+ });
+
+ renderAgentStatus({ isPausing: true });
+
+ // Loading spinner shows (because isPausing)
+ expect(screen.getByTestId("agent-loading-spinner")).toBeInTheDocument();
+
+ // But global state should be false (because shouldShownAgentLoading is false)
+ const { shouldShownAgentLoading } = useConversationStore.getState();
+ expect(shouldShownAgentLoading).toBe(false);
+ });
+});
diff --git a/frontend/src/components/features/controls/agent-status.tsx b/frontend/src/components/features/controls/agent-status.tsx
index 078eb5f40f..675b5881a3 100644
--- a/frontend/src/components/features/controls/agent-status.tsx
+++ b/frontend/src/components/features/controls/agent-status.tsx
@@ -59,13 +59,15 @@ export function AgentStatus({
);
const shouldShownAgentLoading =
- isPausing ||
curAgentState === AgentState.INIT ||
curAgentState === AgentState.LOADING ||
(webSocketStatus === "CONNECTING" && taskStatus !== "ERROR") ||
isTaskPolling(taskStatus) ||
isTaskPolling(subConversationTaskStatus);
+ // For UI rendering - includes pause state
+ const isLoading = shouldShownAgentLoading || isPausing;
+
const shouldShownAgentError =
curAgentState === AgentState.ERROR ||
curAgentState === AgentState.RATE_LIMITED ||
@@ -93,25 +95,28 @@ export function AgentStatus({
- {shouldShownAgentLoading &&
}
- {!shouldShownAgentLoading && shouldShownAgentStop && (
+ {isLoading &&
}
+ {!isLoading && shouldShownAgentStop && (
)}
- {!shouldShownAgentLoading && shouldShownAgentResume && (
+ {!isLoading && shouldShownAgentResume && (
)}
- {!shouldShownAgentLoading && shouldShownAgentError && (
-
+ {!isLoading && shouldShownAgentError && (
+
)}
- {!shouldShownAgentLoading &&
+ {!isLoading &&
!shouldShownAgentStop &&
!shouldShownAgentResume &&
!shouldShownAgentError &&
}