Skip to content

Commit 78fef22

Browse files
authored
fix(execution): scope execution state per workflow to prevent cross-workflow bleed (#3183)
* fix(execution): scope execution state per workflow to prevent cross-workflow bleed * fix(execution): use validated workflowId param instead of non-null assertion in handleRunUntilBlock * improvement(execution): use individual selectors to avoid unnecessary re-renders from unselectored store hook * improvement(execution): use useShallow selector in workflow.tsx to avoid re-renders from lastRunPath/lastRunEdges changes
1 parent 6d16f21 commit 78fef22

File tree

16 files changed

+931
-179
lines changed

16 files changed

+931
-179
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/action-bar/action-bar.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/provide
77
import { useWorkflowExecution } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks'
88
import { validateTriggerPaste } from '@/app/workspace/[workspaceId]/w/[workflowId]/utils'
99
import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
10-
import { useExecutionStore } from '@/stores/execution'
10+
import { useCurrentWorkflowExecution, useExecutionStore } from '@/stores/execution'
1111
import { useNotificationStore } from '@/stores/notifications'
1212
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
1313
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
@@ -114,7 +114,8 @@ export const ActionBar = memo(
114114
)
115115

116116
const { activeWorkflowId } = useWorkflowRegistry()
117-
const { isExecuting, getLastExecutionSnapshot } = useExecutionStore()
117+
const { isExecuting } = useCurrentWorkflowExecution()
118+
const getLastExecutionSnapshot = useExecutionStore((s) => s.getLastExecutionSnapshot)
118119
const userPermissions = useUserPermissionsContext()
119120
const edges = useWorkflowStore((state) => state.edges)
120121

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/chat/chat.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import { useWorkflowExecution } from '@/app/workspace/[workspaceId]/w/[workflowI
5151
import type { BlockLog, ExecutionResult } from '@/executor/types'
5252
import { useChatStore } from '@/stores/chat/store'
5353
import { getChatPosition } from '@/stores/chat/utils'
54-
import { useExecutionStore } from '@/stores/execution'
54+
import { useCurrentWorkflowExecution } from '@/stores/execution'
5555
import { useOperationQueue } from '@/stores/operation-queue/store'
5656
import { useTerminalConsoleStore } from '@/stores/terminal'
5757
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
@@ -256,7 +256,7 @@ export function Chat() {
256256
const hasConsoleHydrated = useTerminalConsoleStore((state) => state._hasHydrated)
257257
const entriesFromStore = useTerminalConsoleStore((state) => state.entries)
258258
const entries = hasConsoleHydrated ? entriesFromStore : []
259-
const { isExecuting } = useExecutionStore()
259+
const { isExecuting } = useCurrentWorkflowExecution()
260260
const { handleRunWorkflow, handleCancelExecution } = useWorkflowExecution()
261261
const { data: session } = useSession()
262262
const { addToQueue } = useOperationQueue()

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/hooks/use-block-state.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useCallback } from 'react'
22
import type { DiffStatus } from '@/lib/workflows/diff/types'
33
import { hasDiffStatus } from '@/lib/workflows/diff/types'
4-
import { useExecutionStore } from '@/stores/execution'
4+
import { useIsBlockActive } from '@/stores/execution'
55
import { useWorkflowDiffStore } from '@/stores/workflow-diff'
66
import type { CurrentWorkflow } from '../../../hooks/use-current-workflow'
77
import type { WorkflowBlockProps } from '../types'
@@ -67,7 +67,7 @@ export function useBlockState(
6767
const isDeletedBlock = !isShowingDiff && diffAnalysis?.deleted_blocks?.includes(blockId)
6868

6969
// Execution state
70-
const isActiveBlock = useExecutionStore((state) => state.activeBlockIds.has(blockId))
70+
const isActiveBlock = useIsBlockActive(blockId)
7171
const isActive = data.isActive || isActiveBlock
7272

7373
return {

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-edge/workflow-edge.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { X } from 'lucide-react'
33
import { BaseEdge, EdgeLabelRenderer, type EdgeProps, getSmoothStepPath } from 'reactflow'
44
import { useShallow } from 'zustand/react/shallow'
55
import type { EdgeDiffStatus } from '@/lib/workflows/diff/types'
6-
import { useExecutionStore } from '@/stores/execution'
6+
import { useLastRunEdges } from '@/stores/execution'
77
import { useWorkflowDiffStore } from '@/stores/workflow-diff'
88

99
/** Extended edge props with optional handle identifiers */
@@ -49,7 +49,7 @@ const WorkflowEdgeComponent = ({
4949
isDiffReady: state.isDiffReady,
5050
}))
5151
)
52-
const lastRunEdges = useExecutionStore((state) => state.lastRunEdges)
52+
const lastRunEdges = useLastRunEdges()
5353

5454
const dataSourceHandle = (data as { sourceHandle?: string } | undefined)?.sourceHandle
5555
const isErrorEdge = (sourceHandle ?? dataSourceHandle) === 'error'

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-block-visual.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useBlockState } from '@/app/workspace/[workspaceId]/w/[workflowId]/comp
33
import type { WorkflowBlockProps } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/types'
44
import { useCurrentWorkflow } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-current-workflow'
55
import { getBlockRingStyles } from '@/app/workspace/[workspaceId]/w/[workflowId]/utils/block-ring-utils'
6-
import { useExecutionStore } from '@/stores/execution'
6+
import { useLastRunPath } from '@/stores/execution'
77
import { usePanelEditorStore, usePanelStore } from '@/stores/panel'
88
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
99

@@ -64,7 +64,7 @@ export function useBlockVisual({
6464
)
6565
const isEditorOpen = !isPreview && isThisBlockInEditor && activeTabIsEditor
6666

67-
const lastRunPath = useExecutionStore((state) => state.lastRunPath)
67+
const lastRunPath = useLastRunPath()
6868
const runPathStatus = isPreview ? undefined : lastRunPath.get(blockId)
6969

7070
const setCurrentBlockId = usePanelEditorStore((state) => state.setCurrentBlockId)

0 commit comments

Comments
 (0)