Procházet zdrojové kódy

fix: improve WebSocket reconnect handling to always reset stuck running state

- Always check execution state on reconnect, not just when pendingExecIdRef exists
- Clear executingNodeId on every reconnect
- Prevents UI from showing stuck execution after WebSocket disconnection
fszontagh před 6 měsíci
rodič
revize
b26d6dd3e6
1 změnil soubory, kde provedl 16 přidání a 15 odebrání
  1. 16 15
      webui/src/pages/WorkflowEditorPage.tsx

+ 16 - 15
webui/src/pages/WorkflowEditorPage.tsx

@@ -808,25 +808,26 @@ function WorkflowEditorInner() {
 
     // Handle WebSocket reconnection - reset execution state to prevent stuck workflows
     const handleReconnect = () => {
-      console.log('WebSocket reconnected - resetting execution state')
-      // If there was a pending execution, it's now stale - reset it
+      // Clear pending refs
       if (pendingExecIdRef.current) {
         pendingExecIdRef.current = null
         pendingEventsRef.current = []
-        setExecutionState((prev) => {
-          // Only reset if execution was still running
-          if (prev.status === 'running') {
-            showToast('info', 'Connection restored - execution state reset. Please re-run if needed.')
-            return {
-              executionId: null,
-              status: 'idle',
-              nodeStates: {},
-            }
-          }
-          return prev
-        })
-        setExecutingNodeId(null)
       }
+
+      // Always check and reset running state on reconnect
+      setExecutionState((prev) => {
+        if (prev.status === 'running') {
+          console.log('WebSocket reconnected - resetting stuck running execution')
+          showToast('info', 'Connection restored - execution state reset. Please re-run if needed.')
+          return {
+            executionId: null,
+            status: 'idle',
+            nodeStates: {},
+          }
+        }
+        return prev
+      })
+      setExecutingNodeId(null)
     }
 
     wsClient.onReconnect(handleReconnect)