Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • Keyed all execution state (isExecuting, activeBlockIds, lastRunPath, lastRunEdges, etc.) by workflow ID using Map<string, WorkflowExecutionState>
  • Added granular selector hooks (useIsBlockActive, useLastRunPath, useLastRunEdges) to prevent performance regression from full-object selectors
  • Updated useExecutionStream to support concurrent executions via per-workflow AbortController maps
  • Threaded workflowId through all 30+ setter call sites in use-workflow-execution.ts
  • Updated all consumer components (workflow-edge, use-block-state, use-block-visual, chat, action-bar, workflow.tsx)
  • Added 36 comprehensive store tests covering isolation, immutability, and execution lifecycle

Type of Change

  • Bug fix

Testing

  • 36 new store tests covering per-workflow isolation, immutability, execution lifecycle
  • All 203 store tests passing
  • TypeScript: 0 errors
  • Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Feb 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Feb 11, 2026 1:04am

Request Review

@waleedlatif1
Copy link
Collaborator Author

@greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 10, 2026

Greptile Overview

Greptile Summary

This PR scopes all execution-related Zustand state (isExecuting, active block IDs, run path/edges, debug context, etc.) by workflow ID using a Map<string, WorkflowExecutionState> to prevent cross-workflow bleed when multiple workflows are open or executing.

To avoid broad re-renders, it adds granular selector hooks (useIsBlockActive, useLastRunPath, useLastRunEdges, plus useCurrentWorkflowExecution) and updates all call sites to pass workflowId into setters. useExecutionStream is also updated to support concurrent executions via per-workflow AbortController/execution-id maps. Finally, it adds a comprehensive test suite for isolation/immutability/lifecycle behavior and updates Vitest mocks accordingly.

Confidence Score: 4/5

  • Mostly safe to merge once the remaining state-keying edge cases are addressed.
  • Core refactor is cohesive (execution state keyed by workflowId, concurrent SSE execution support, and broad test coverage). Two issues remain that can create incorrect store entries or confusing behavior: (1) activeWorkflowId! non-null assertions can write execution state under an invalid key; (2) getWorkflowExecution returns a non-persisted default object, which can be accidentally mutated or relied on for referential stability without actually entering the store map.
  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts; apps/sim/stores/execution/store.ts

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/action-bar/action-bar.tsx Switched execution state reads to useCurrentWorkflowExecution() while keeping snapshot access via store actions; looks consistent with per-workflow scoping.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/chat/chat.tsx Updated chat to read isExecuting from useCurrentWorkflowExecution() to avoid cross-workflow bleed; straightforward change.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/hooks/use-block-state.ts Replaced full-store selector with useIsBlockActive(blockId) for granular updates; aligns with new execution store API.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-edge/workflow-edge.tsx Edge styling now derives from useLastRunEdges() instead of global lastRunEdges; minimal and consistent.
apps/sim/stores/execution/store.ts Refactors execution store to key all execution state by workflowId and adds selector hooks; main concern is getWorkflowExecution returning non-persisted default objects and potential invalid workflowId writes in callers.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts Threads workflowId through execution lifecycle setters and updates cancellation to be per-workflow; still contains activeWorkflowId! non-null assertions in handleRunUntilBlock that can write under an invalid key.
apps/sim/hooks/use-execution-stream.ts Updates SSE execution hook to manage AbortControllers/execution IDs per workflow, enabling concurrent executions; cancel now optionally targets a specific workflowId.
apps/sim/stores/execution/types.ts Introduces WorkflowExecutionState and defaultWorkflowExecutionState; ExecutionState now stores a map keyed by workflowId.
apps/sim/stores/execution/index.ts Re-exports new selector hooks and types for execution store.
apps/sim/stores/execution/store.test.ts Adds comprehensive tests for per-workflow isolation, lifecycle behavior, snapshots, and immutability; tests assume unique workflow IDs to avoid cross-test interference.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-block-visual.ts Switches block visual run-path lookup to per-workflow useLastRunPath selector.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/utils/workflow-execution-utils.ts Updates copilot execution logging helper to pass workflowId into execution store setters; uses activeWorkflowId snapshot as wfId.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx Switches workflow page subscriptions to per-workflow execution state (useCurrentWorkflowExecution) and keeps snapshot getter from store.
apps/sim/lib/copilot/client-sse/run-tool-execution.ts Adjusts copilot client run-tool execution guard to check isExecuting per active workflow via getWorkflowExecution; threads workflowId into setIsExecuting.
apps/sim/stores/terminal/console/store.ts Updates clearWorkflowConsole to clear run path for the specified workflowId.
apps/sim/vitest.setup.ts Extends vitest mocks for execution store to include new per-workflow APIs and selector hooks.

Sequence Diagram

sequenceDiagram
  participant UI as Workflow UI (per workflowId)
  participant ExecHook as useWorkflowExecution
  participant ExecStore as useExecutionStore
  participant Stream as useExecutionStream
  participant API as /api/workflows/:id/execute

  UI->>ExecHook: handleRunWorkflow(workflowId)
  ExecHook->>ExecStore: setIsExecuting(workflowId,true)
  ExecHook->>Stream: execute({workflowId, callbacks})
  Stream->>API: POST execute (signal from AbortController[workflowId])
  API-->>Stream: SSE events + X-Execution-Id
  Stream-->>ExecHook: callbacks.onBlockStarted/Completed/Error
  ExecHook->>ExecStore: setActiveBlocks(workflowId, Set)
  ExecHook->>ExecStore: setBlockRunStatus(workflowId, blockId, status)
  ExecHook->>ExecStore: setEdgeRunStatus(workflowId, edgeId, status)
  Stream-->>ExecHook: callbacks.onExecutionCompleted
  ExecHook->>ExecStore: setIsExecuting(workflowId,false)

  UI->>ExecHook: handleCancelExecution(workflowId)
  ExecHook->>Stream: cancel(workflowId)
  Stream->>API: POST cancel (executionId for workflowId)
  Stream->>Stream: abort AbortController[workflowId]
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

16 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@cursor review

@waleedlatif1
Copy link
Collaborator Author

@cursor review

…oid re-renders from lastRunPath/lastRunEdges changes
@waleedlatif1
Copy link
Collaborator Author

@cursor review

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@waleedlatif1 waleedlatif1 merged commit 78fef22 into staging Feb 11, 2026
12 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/run branch February 11, 2026 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant