fix(cancellation): workflow cancellation handled for non-local envs#2570
Closed
icecrasher321 wants to merge 3 commits intostagingfrom
Closed
fix(cancellation): workflow cancellation handled for non-local envs#2570icecrasher321 wants to merge 3 commits intostagingfrom
icecrasher321 wants to merge 3 commits intostagingfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
Greptile Summary
Important Files Changed
Confidence score: 4/5
Sequence DiagramsequenceDiagram
participant User
participant "Route Handler" as Route
participant "Auth System" as Auth
participant "Preprocessing" as Preprocess
participant "Execution Core" as Core
participant "DAG Executor" as DAG
participant "Execution Engine" as Engine
participant "Cancellation Service" as Cancel
participant "Logging Session" as Log
User->>Route: "POST /api/workflows/[id]/execute"
Route->>Auth: "checkHybridAuth(req)"
Auth-->>Route: "auth result"
Route->>Route: "parse and validate request body"
Route->>Preprocess: "preprocessExecution()"
Preprocess-->>Route: "workflow record & actor user"
Route->>Core: "executeWorkflowCore()"
Core->>Log: "loggingSession.safeStart()"
Core->>Core: "load workflow state"
Core->>DAG: "new Executor()"
Core->>DAG: "execute(workflowId, triggerBlockId)"
DAG->>Engine: "run(triggerBlockId)"
loop "While has work"
Engine->>Cancel: "isCancellationRequested(executionId)"
Cancel-->>Engine: "cancellation status"
alt "not cancelled"
Engine->>Engine: "processQueue()"
Engine->>Engine: "executeNode()"
else "cancelled"
Engine->>Engine: "break execution loop"
end
end
Engine-->>DAG: "execution result"
DAG-->>Core: "execution result"
Core->>Log: "safeComplete() or safeCompleteWithError()"
Core-->>Route: "execution result"
Route-->>User: "JSON response"
|
Comment on lines
+241
to
+245
| fetch(`/api/workflows/${workflowId}/execute/cancel`, { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify({ executionId }), | ||
| }).catch(() => {}) |
Contributor
There was a problem hiding this comment.
style: The catch block silently ignores cancellation API errors. Consider logging the error to help with debugging cancellation issues in production.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/hooks/use-execution-stream.ts
Line: 241:245
Comment:
**style:** The catch block silently ignores cancellation API errors. Consider logging the error to help with debugging cancellation issues in production.
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.| return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 }) | ||
| } | ||
|
|
||
| let body: any = {} |
Contributor
There was a problem hiding this comment.
style: Avoid using any type. Use unknown instead for better type safety
Suggested change
| let body: any = {} | |
| let body: unknown = {} |
Context Used: Context from dashboard - TypeScript conventions and type safety (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/app/api/workflows/[id]/execute/cancel/route.ts
Line: 21:21
Comment:
**style:** Avoid using `any` type. Use `unknown` instead for better type safety
```suggestion
let body: unknown = {}
```
**Context Used:** Context from `dashboard` - TypeScript conventions and type safety ([source](https://app.greptile.com/review/custom-context?memory=b4f0be8d-a787-4d5a-9098-a66b1449df25))
How can I resolve this? If you propose a fix, please make it concise.
Sg312
reviewed
Dec 24, 2025
|
|
||
| while (this.hasWork()) { | ||
| if (this.context.isCancelled && this.executing.size === 0) { | ||
| if ((await this.checkCancellation()) && this.executing.size === 0) { |
Collaborator
There was a problem hiding this comment.
Is this the best place to put this?
Sg312
reviewed
Dec 24, 2025
| private async processQueue(): Promise<void> { | ||
| while (this.readyQueue.length > 0) { | ||
| if (this.context.isCancelled) { | ||
| if (await this.checkCancellation()) { |
Collaborator
There was a problem hiding this comment.
This check needs to move into redis
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
Locally workflow aborts work. But in Prod/Staging envs the abort signal does not actually propagate correctly. Need to use an executor set / redis to make this work. This PR does it using the standard pattern of redis with in memory fallback we have.
Type of Change
Testing
Tested both paths manually
Checklist