From 10da5e8f9da4583e558edd63e5d8746035c23b46 Mon Sep 17 00:00:00 2001 From: Wu Tianwei <30284043+WTW0313@users.noreply.github.com> Date: Wed, 15 Jul 2026 14:59:25 +0800 Subject: [PATCH] fix: restore responding state after HITL resume (#38992) --- .../base/chat/chat/__tests__/hooks.spec.tsx | 33 +++++++++++++++++++ web/app/components/base/chat/chat/hooks.ts | 1 + 2 files changed, 34 insertions(+) diff --git a/web/app/components/base/chat/chat/__tests__/hooks.spec.tsx b/web/app/components/base/chat/chat/__tests__/hooks.spec.tsx index 8bbbb3b4c73..889719c1738 100644 --- a/web/app/components/base/chat/chat/__tests__/hooks.spec.tsx +++ b/web/app/components/base/chat/chat/__tests__/hooks.spec.tsx @@ -590,6 +590,39 @@ describe('useChat', () => { expect(result.current.isResponding).toBe(false) // from onError }) + it('should restore responding state when a paused human input workflow resumes', async () => { + let initialCallbacks: HookCallbacks + let resumedCallbacks: HookCallbacks + + vi.mocked(ssePost).mockImplementation(async (_url, _params, options) => { + initialCallbacks = options as HookCallbacks + }) + vi.mocked(sseGet).mockImplementation(async (_url, _params, options) => { + resumedCallbacks = options as HookCallbacks + }) + + const { result } = renderHook(() => useChat()) + + act(() => { + result.current.handleSend('test-url', { query: 'human input test' }, {}) + }) + act(() => { + initialCallbacks.onWorkflowStarted({ workflow_run_id: 'wr-1', task_id: 't-1' }) + initialCallbacks.onWorkflowPaused({ data: { workflow_run_id: 'wr-1' } }) + }) + await act(async () => { + await initialCallbacks.onCompleted() + }) + + expect(result.current.isResponding).toBe(false) + + act(() => { + resumedCallbacks.onWorkflowStarted({ workflow_run_id: 'wr-1', task_id: 't-1' }) + }) + + expect(result.current.isResponding).toBe(true) + }) + it('should handle file uploads in onFile', () => { let callbacks: HookCallbacks diff --git a/web/app/components/base/chat/chat/hooks.ts b/web/app/components/base/chat/chat/hooks.ts index 338658a3316..b78999fe461 100644 --- a/web/app/components/base/chat/chat/hooks.ts +++ b/web/app/components/base/chat/chat/hooks.ts @@ -1242,6 +1242,7 @@ export const useChat = ( }) }, onWorkflowStarted: ({ workflow_run_id, task_id, conversation_id, message_id }) => { + handleResponding(true) // If there are no streaming messages, we still need to set the conversation_id to avoid create a new conversation when regeneration in chat-flow. if (conversation_id) { conversationIdRef.current = conversation_id