@@ -1916,6 +1916,26 @@ export function useWorkflowExecution() {
19161916 handler ( data )
19171917 }
19181918
1919+ const cleanupFailedReconnect = ( ) => {
1920+ const currentId = useExecutionStore . getState ( ) . getCurrentExecutionId ( reconnectWorkflowId )
1921+ if ( currentId && currentId !== capturedExecutionId ) return
1922+
1923+ const hasRunningEntry = useTerminalConsoleStore
1924+ . getState ( )
1925+ . getWorkflowEntries ( reconnectWorkflowId )
1926+ . some ( ( entry ) => entry . isRunning && entry . executionId === capturedExecutionId )
1927+
1928+ if ( activated || hasRunningEntry ) {
1929+ cancelRunningEntries ( reconnectWorkflowId )
1930+ }
1931+
1932+ if ( currentId === capturedExecutionId ) {
1933+ setCurrentExecutionId ( reconnectWorkflowId , null )
1934+ setIsExecuting ( reconnectWorkflowId , false )
1935+ setActiveBlocks ( reconnectWorkflowId , new Set ( ) )
1936+ }
1937+ }
1938+
19191939 const attemptReconnect = async ( attempt : number ) : Promise < void > => {
19201940 if ( cleanupRan || reconnectionComplete ) return
19211941
@@ -2004,17 +2024,7 @@ export function useWorkflowExecution() {
20042024 reconnectionComplete = true
20052025 activeReconnections . delete ( reconnectWorkflowId )
20062026 clearExecutionPointer ( reconnectWorkflowId )
2007- if ( activated ) {
2008- const currentId = useExecutionStore
2009- . getState ( )
2010- . getCurrentExecutionId ( reconnectWorkflowId )
2011- if ( currentId === capturedExecutionId ) {
2012- cancelRunningEntries ( reconnectWorkflowId )
2013- setCurrentExecutionId ( reconnectWorkflowId , null )
2014- setIsExecuting ( reconnectWorkflowId , false )
2015- setActiveBlocks ( reconnectWorkflowId , new Set ( ) )
2016- }
2017- }
2027+ cleanupFailedReconnect ( )
20182028 return
20192029 }
20202030
@@ -2026,6 +2036,12 @@ export function useWorkflowExecution() {
20262036 if ( ! cleanupRan && ! reconnectionComplete && attempt < MAX_ATTEMPTS ) {
20272037 return attemptReconnect ( attempt + 1 )
20282038 }
2039+ if ( ! cleanupRan && ! reconnectionComplete ) {
2040+ reconnectionComplete = true
2041+ activeReconnections . delete ( reconnectWorkflowId )
2042+ cleanupFailedReconnect ( )
2043+ return
2044+ }
20292045 }
20302046
20312047 if ( ! reconnectionComplete && ! cleanupRan ) {
0 commit comments