Skip to content

fix(copilot): fix execute workflow from diff store - #1894

Merged
Sg312 merged 2 commits into
stagingfrom
fix/copilot-diff-store
Nov 11, 2025
Merged

fix(copilot): fix execute workflow from diff store#1894
Sg312 merged 2 commits into
stagingfrom
fix/copilot-diff-store

Conversation

@Sg312

Copy link
Copy Markdown
Collaborator

Summary

Fix copilot run from diff store

Type of Change

  • Bug fix

Testing

Manual

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

vercelBot commented Nov 11, 2025

Copy link
Copy Markdown

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

1 Skipped Deployment
ProjectDeploymentPreviewCommentsUpdated (UTC)
docsSkippedSkippedNov 11, 2025 7:05pm

@Sg312
Sg312 merged commit c86f2a0 into stagingNov 11, 2025
9 checks passed
@greptile-apps

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

Implemented execution of diff workflows (AI-proposed workflow changes) by threading a workflowStateOverride parameter through the entire execution pipeline, from client hooks to the core executor.

Key changes:

  • Added workflowStateOverride field to API schema, execution metadata, and stream options to pass diff workflow state (blocks, edges, loops, parallels)
  • Modified executeWorkflowCore to prioritize workflowStateOverride over useDraftState and deployed state when present
  • Updated useWorkflowExecution hook to detect active diff workflows from store and pass override to execution API
  • Refactored executeWorkflowWithFullLogging (copilot tool execution) from non-SSE to SSE streaming to support diff workflow execution and enable real-time console logging

The implementation correctly handles the precedence order: workflowStateOverride → draftState → deployedState, ensuring diff workflows execute with the AI-proposed changes rather than the current canvas state.

Confidence Score: 5/5

  • Safe to merge - well-structured feature addition with proper type safety and clear execution flow
  • The changes are clean, focused, and follow established patterns throughout the codebase. Type definitions are properly extended across all layers, the override parameter is correctly threaded through the execution pipeline with proper precedence handling, and the refactored copilot execution path improves observability by switching to SSE streaming
  • No files require special attention

Important Files Changed

File Analysis

FilenameScoreOverview
apps/sim/app/api/workflows/[id]/execute/route.ts5/5Added workflowStateOverride parameter to execute diff workflows, properly threaded through validation, metadata, and execution paths
apps/sim/lib/workflows/executor/execution-core.ts5/5Added conditional logic to use workflowStateOverride before useDraftState, enabling diff workflow execution
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts5/5Integrated diff workflow detection logic, passes workflowStateOverride to execution API when diff workflow is active
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/utils/workflow-execution-utils.ts4/5Refactored copilot execution from non-SSE to SSE streaming, added diff workflow detection and console logging

Sequence Diagram

sequenceDiagram
participant Client as Client/Copilot
participant Hook as useWorkflowExecution
participant Utils as workflow-execution-utils
participant DiffStore as WorkflowDiffStore
participant API as /api/workflows/[id]/execute
participant Core as executeWorkflowCore
participant Executor as Workflow Executor
Note over Client,Hook: User executes workflow (manual/copilot)
Client->>Hook: executeWorkflow()
Hook->>DiffStore: Check hasActiveDiffWorkflow
DiffStore-->>Hook: isDiffReady && isShowingDiff && diffWorkflow
alt Diff workflow active
Hook->>Hook: Set executionWorkflowState = diffWorkflow
Note right of Hook: Use diff blocks/edges instead of current
else No diff workflow
Hook->>Hook: Use currentWorkflow.blocks/edges
end
Hook->>API: POST /execute with workflowStateOverride
Note right of Hook: Payload includes:<br/>- workflowStateOverride (if diff active)<br/>- useDraftState: true<br/>- stream: true
API->>API: Validate request body
API->>API: Create ExecutionMetadata with workflowStateOverride
API->>Core: executeWorkflowCore(snapshot)
alt workflowStateOverride provided
Core->>Core: Use override.blocks/edges/loops/parallels
Note right of Core: Priority: override > draftState > deployed
else useDraftState
Core->>Core: Load from normalized tables
else deployed
Core->>Core: Load deployed state
end
Core->>Executor: Execute workflow with selected state
Executor-->>Core: ExecutionResult
Core-->>API: ExecutionResult
API->>Client: SSE Stream (block:completed, execution:completed)
Note over Client,Executor: Copilot execution path
Client->>Utils: executeWorkflowWithFullLogging()
Utils->>DiffStore: Check hasActiveDiffWorkflow
DiffStore-->>Utils: Diff workflow state
Utils->>API: POST /execute with workflowStateOverride
API-->>Utils: SSE Stream
Utils->>Utils: Parse SSE events & add to console
Utils-->>Client: ExecutionResult
Loading

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

6 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

waleedlatif1 pushed a commit that referenced this pull request Nov 12, 2025
* Fix run from diff store
* Fix copilot run workflow
waleedlatif1 pushed a commit that referenced this pull request Nov 12, 2025
* Fix run from diff store
* Fix copilot run workflow
@waleedlatif1waleedlatif1 mentioned this pull request Nov 12, 2025
10 tasks
@waleedlatif1
waleedlatif1 deleted the fix/copilot-diff-store branch November 18, 2025 01:28
Sign up for freeto 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

@Sg312