Can I send an abortSignal to a workflow?

HEAD
c614456Pass `teamId` to the run-key endpoint (#1183)
This post might have stale content, as HEAD is 82 commits ahead.

can i send an abortSignal to a workflow?

Avatar of anthropic/claude-opus-4.6
Claude Opus 4.6
commented

Now I have a comprehensive understanding. Here's the answer:


No, you cannot send an AbortSignal to a workflow run itself — but there are other mechanisms for cancellation, and AbortSignal is supported in specific sub-contexts.

###Cancelling a Workflow Run

Workflows don't accept an AbortSignal when started. The start() function (packages/core/src/runtime/start.ts) only accepts these options:

export interface StartOptions {
  deploymentId?: string;
  world?: World;
  specVersion?: number;
}

Instead, cancellation is done after the fact via the event-sourced run_cancelled event. You have two ways to cancel a running workflow:

  1. Programmatically using the Run object (packages/core/src/runtime/run.ts:69-73):

    const run = await start(myWorkflow, args);
    // later...
    await run.cancel();
    
  2. Via the cancelRun function (packages/core/src/runtime/runs.ts:88):

    import { cancelRun } from '@workflow/core/runtime';
    await cancelRun(world, runId);
    
  3. Via the CLI:

    npx workflow cancel <run_id>
    

This sets the run's status to 'cancelled' and throws a WorkflowRunCancelledError if you're awaiting the returnValue.

###Why No AbortSignal?

Workflows are durable and event-sourced — they survive across serverless invocations and can be suspended/resumed. A JavaScript AbortSignal is an in-process, in-memory construct that doesn't survive across those boundaries. The cancellation model is instead based on persisted events (run_cancelled), which fits the durable execution model.

###Where AbortSignal is Supported

###Summary

What you want to doHow
Cancel a workflow runrun.cancel(), cancelRun(world, runId), or npx workflow cancel <id>
Abort an AI generation within a stepPass abortSignal to durableAgent()
Cancel reading a workflow streamPass signal to the fetch/stream reader

END OF POST

Can I send an abortSignal to a workflow? — vercel/workflow