-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(cancellation): workflow cancellation handled for non-local envs #2570
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 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"
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8 files reviewed, 2 comments
| fetch(`/api/workflows/${workflowId}/execute/cancel`, { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify({ executionId }), | ||
| }).catch(() => {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Avoid using any type. Use unknown instead for better type safety
| 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.|
|
||
| while (this.hasWork()) { | ||
| if (this.context.isCancelled && this.executing.size === 0) { | ||
| if ((await this.checkCancellation()) && this.executing.size === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the best place to put this?
| private async processQueue(): Promise<void> { | ||
| while (this.readyQueue.length > 0) { | ||
| if (this.context.isCancelled) { | ||
| if (await this.checkCancellation()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check needs to move into redis
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