Durable Trigger Cancel
Define one cooperative durable trigger, enqueue it, request cancellation, and observe the terminal cancellation fact.
What You Build
Section titled “What You Build”An app-owned trigger with acquire, commit, and commitCancelled, registered
through the Cloudflare DO facade.
Prerequisites
Section titled “Prerequisites”-
Define a cooperative trigger:
const trigger = {kind: "tutorial.cancelable",intentEventKind: "tutorial.cancelable.requested",cancellation: "cooperative",parseIntent,acquire: (intent, ctx) => runExternalWork(intent, { signal: ctx.signal }),commit: (outcome, tx) => {tx.insertEvent({ kind: "tutorial.cancelable.done", payload: outcome });},commitCancelled: (intent, cancellation, tx) => {tx.insertEvent({kind: "tutorial.cancelable.cancelled",payload: { id: intent.id, reason: cancellation.reason ?? null },});},} satisfies DurableTrigger<TutorialIntent, TutorialOutcome>; -
Register it:
export const AgentDO = defineAgentDO<Env>({bindings: [],triggers: [trigger],}); -
Enqueue work and keep the returned intent id:
const intent = await agent.enqueueTrigger({triggerKind: "tutorial.cancelable",payload: { id: "job-1" },at: Date.now(),}); -
Request cancellation:
const cancel = await agent.cancelTrigger({triggerKind: "tutorial.cancelable",intentEventId: intent.id,reason: "user",}); -
Read ledger events or your app projection for
tutorial.cancelable.cancelled.
Checkpoint
Section titled “Checkpoint”Interpret cancel.status as the request path:
cancelled pending row was terminally cancelled nowrequested running row was marked and ctx.signal was abortedignored trigger declared cancellation: "ignored"not_found no matching pending work existsalready_completed terminal success won before cancellationThe terminal user-visible fact still comes from commit or
commitCancelled. Cancellation is cooperative; it is not a hidden timeout or
forced discard of an already completed provider call.
Add live progress with output-only attached streams.