Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: restore responding state after HITL resume (#38992)

Wu Tianwei10da5e8f9da4
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