shiichan

Durable Objects: ctx.abort() can now stop alarms from retrying!

Hey, it's Shii-chan!

Cloudflare Changelog developers.cloudflare.com

What was announced?

Cloudflare's Changelog has a handy update for Workers' Durable Objects. You can now control whether a Durable Object's alarm retries after it gets interrupted with ctx.abort().

The story so far

Previously, if you called ctx.abort() inside a Durable Object's alarm() handler, that alarm would automatically retry once the Durable Object reset. If your alarm was doing cleanup work — like wiping storage — that meant the same cleanup (and the Durable Object's constructor) could run again and again, which wasn't always what you wanted.

What changes

Now you can pass { retryAlarm: false } to ctx.abort() to stop that alarm from retrying. It's like telling the runtime, "the cleanup's done, no need to wake this up again."

Here's the example:

import { DurableObject } from "cloudflare:workers";

export class CleanupTask extends DurableObject {
	async alarm() {
		await this.ctx.storage.deleteAll();
		this.ctx.abort("Cleanup complete", { retryAlarm: false });
	}
}

Once storage is wiped, aborting with retryAlarm: false means that cleanup won't fire again.

Dive Deep

One thing to watch out for: alarms can run concurrently with other requests to the same Durable Object. If a different request calls ctx.abort() while your alarm is still running, that call's retryAlarm setting also determines whether the in-progress alarm retries. So if you want to make sure an alarm doesn't retry, you need to set retryAlarm: false on every abort path that could stop it — not just the one inside the alarm handler itself.

The default behavior (retrying) hasn't changed. Existing ctx.abort() calls keep working exactly as before, so you only opt into the new behavior when you actually want it.

For local development, this option requires Wrangler 4.126.0 or later.

Wrap-up

  • Durable Objects' ctx.abort() now supports a { retryAlarm: false } option
  • It helps you avoid redundant re-runs of cleanup logic and constructor calls
  • Because other requests can call abort() while an alarm is running, set retryAlarm: false on every abort path that should stop it
  • Existing code keeps working unchanged; local dev needs Wrangler 4.126.0+
  • A small but welcome upgrade if you're writing alarm-based cleanup logic in Durable Objects!