Skip to content

Conversation

@Sg312
Copy link
Contributor

@Sg312 Sg312 commented Nov 11, 2025

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
Copy link

vercel bot commented Nov 11, 2025

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

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Nov 11, 2025 7:05pm

@Sg312 Sg312 merged commit c86f2a0 into staging Nov 11, 2025
9 checks passed
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 11, 2025

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

Filename Score Overview
apps/sim/app/api/workflows/[id]/execute/route.ts 5/5 Added workflowStateOverride parameter to execute diff workflows, properly threaded through validation, metadata, and execution paths
apps/sim/lib/workflows/executor/execution-core.ts 5/5 Added conditional logic to use workflowStateOverride before useDraftState, enabling diff workflow execution
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts 5/5 Integrated 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.ts 4/5 Refactored 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

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.

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
@waleedlatif1 waleedlatif1 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 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.

2 participants