-
Notifications
You must be signed in to change notification settings - Fork 3k
improvement(logs): state machine of workflow execution #2560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile SummaryRefactored workflow execution state management from derived states to an explicit state machine with a dedicated Key Changes:
Migration:
The refactoring improves clarity and correctness of execution state tracking throughout the system. Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant UI as UI Component
participant Hook as useWorkflowExecution
participant Core as execution-core.ts
participant Engine as ExecutionEngine
participant Session as LoggingSession
participant DB as Database
User->>UI: Clicks Run or Cancel
alt Start Execution
UI->>Hook: handleRunWorkflow()
Hook->>Session: safeStart()
Session->>DB: INSERT with status='running'
Hook->>Core: executeWorkflowCore()
Core->>Engine: execute()
loop While hasWork()
Engine->>Engine: Check isCancelled flag
alt Not Cancelled
Engine->>Engine: processQueue()
Engine->>Engine: executeNodeAsync()
else Cancelled and executing.size === 0
Engine-->>Engine: Break loop
end
end
Engine-->>Core: ExecutionResult with status
alt Status: cancelled
Core->>Session: safeCompleteWithCancellation()
Session->>DB: UPDATE status='cancelled'
else Status: paused
Core->>Session: (Skip completion, keep running)
Session->>DB: UPDATE status='pending'
else Status: completed/failed
Core->>Session: safeComplete/safeCompleteWithError()
Session->>DB: UPDATE status='completed/failed'
end
Core-->>Hook: result
Hook-->>UI: Update execution state
else Cancel Execution
UI->>Hook: handleCancelExecution()
Hook->>Hook: Set context.isCancelled = true
Hook->>Hook: Cancel stream reader
Hook->>Hook: Reset execution state
Note over Engine: Currently executing block<br/>continues to finish
Engine->>Engine: Check isCancelled on next iteration
Engine-->>Core: status='cancelled'
Core->>Session: completeWithCancellation()
Session->>DB: UPDATE status='cancelled'
end
alt Resume from Pause
User->>UI: Provides input for paused execution
UI->>Hook: Resume execution
Hook->>DB: UPDATE status='running'
Hook->>Core: executeWorkflowCore (resume mode)
Core->>Engine: execute()
Note over Engine: Continues from snapshot
Engine-->>Core: ExecutionResult
Core->>Session: Update parent execution log
Session->>DB: UPDATE status based on result
end
|
Summary
State machine of workflow execution made explicit. No more derived states during execution or persisting logs. Last block executing when cancelled continues to finish executing retaining state as running until it's done before transitioning to cancelled.
Type of Change
Testing
Tested manually.
Checklist