docs/src/content/en/reference/workflows/run-methods/cancel.mdx
The .cancel() method cancels a workflow run, stopping execution and cleaning up resources.
This method aborts any running steps and updates the workflow status to 'canceled'. It works for both actively running workflows and suspended/waiting workflows.
const run = await workflow.createRun()
await run.cancel()
// Returns: { message: 'Workflow run canceled' }
<PropertiesTable content={[ { name: 'No parameters', type: 'void', description: 'This method takes no parameters', isOptional: false, }, ]} />
<PropertiesTable content={[ { name: 'result', type: 'Promise<{ message: string }>', description: "A promise that resolves with { message: 'Workflow run canceled' } when cancellation succeeds", }, ]} />
When called, the workflow will:
Steps that check the abortSignal parameter can respond to cancellation:
abortSignal.addEventListener('abort', callback)if (abortSignal.aborted) { ... }Note: Steps must actively check the abort signal to be canceled mid-execution. Steps that don't check the signal will run to completion, but subsequent steps won't execute.
const run = await workflow.createRun()
try {
const result = await run.start({ inputData: { value: 'initial data' } })
} catch (error) {
await run.cancel()
}
const step = createStep({
id: 'long-running-step',
execute: async ({ inputData, abortSignal, abort }) => {
const timeout = new Promise(resolve => {
const timer = setTimeout(() => resolve('done'), 10000)
// Clean up if canceled
abortSignal.addEventListener('abort', () => {
clearTimeout(timer)
resolve('canceled')
})
})
const result = await timeout
// Check if aborted after async operation
if (abortSignal.aborted) {
return abort() // Stop execution
}
return { result }
},
})