improvement(logs): state machine of workflow execution#2560
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
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
|
Collaborator
Author
|
@greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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