Skip to content

Support AbortSignal in step.run for cooperative cancellation #26

@coji

Description

@coji

Problem

When a run is cancelled via the API, the status is set to cancelled in the DB, but the currently executing step.run callback continues to run until completion. Durably only checks the cancellation status between steps, so long-running steps cannot be interrupted.

Example

A crawl job fetches 129 PRs inside a single step.run. Even after cancellation, all 129 PR fetches continue because the step callback is not aware of the cancellation.

await step.run('fetch:owner/repo', async () => {
  // This runs for 10+ minutes fetching 129 PRs one by one
  // No way to check if the run was cancelled
  await provider.fetch(orgId, repository, options)
})

Proposal

Pass an AbortSignal to the step.run callback so long-running operations can cooperatively check for cancellation:

await step.run('fetch:owner/repo', async (signal) => {
  await provider.fetch(orgId, repository, { ...options, signal })
})

When a run is cancelled, durably would abort the signal, and the callback can check signal.aborted or pass it to fetch calls / loops:

for (const pr of prs) {
  if (signal.aborted) break
  await fetchDetails(pr)
}

This keeps cancellation cooperative (no forced termination) while giving step authors the ability to respond to cancellation promptly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions