Skip to content

After a restart, an alarm due in the next minute fires only at the 60 s scan #308

Open

Description

@ddebowczyk

Summary

celld dev 0.6.3 (macOS arm64). A Durable Object calls setAlarm(Date.now() + 6000). The process is SIGKILLed and restarted (about 0.4 s of downtime) before the alarm is due.

  • If the alarm is due in the same wall-clock minute as the restart, it fires on time.
  • If it is due in the next minute, it fires about 55–60 s late, at celld's next periodic scan. Nothing logs or fails.

A request to the cell after the restart makes the alarm fire on time. So does an alarm that was already overdue during the downtime. The local bucket stores alarms as wake/entries/<YYYY-MM-DDTHH:MM>/<cell>/…. It looks as though the restart scan reads only the current minute's bucket (plus overdue entries), and a later minute is first read at the next scan.

Expected: after a restart, a persisted alarm fires at its scheduled time whether or not the cell receives a request, as on Cloudflare.

Repro

wrangler.json:

{"name":"alarmrepro","main":"worker.js","compatibility_date":"2025-01-01",
 "durable_objects":{"bindings":[{"name":"CELL","class_name":"Cell"}]},
 "migrations":[{"tag":"v1","new_sqlite_classes":["Cell"]}]}

worker.js (one DO):

import { DurableObject } from "cloudflare:workers";
export class Cell extends DurableObject {
  async fetch(req) {
    const ms = Number(new URL(req.url).searchParams.get("ms") ?? 6000);
    const at = Date.now() + ms;
    await this.ctx.storage.setAlarm(at);
    return new Response(String(at));
  }
  async alarm() { console.log("ALARM_FIRED", Date.now()); }
}
export default {
  async fetch(req, env) {
    if (new URL(req.url).pathname === "/readyz") return new Response("ok");
    return env.CELL.get(env.CELL.idFromName("one")).fetch(req);
  },
};
  1. celld dev . --port 9886 --no-watch --logs
  2. At wall-clock second :56, curl 'localhost:9886/arm?ms=6000' (due at :02 of the next minute).
  3. SIGKILL celld and its children; restart at once; poll only /readyz.
  4. Compare the ALARM_FIRED time with the deadline.

Measurements

Armed at second Armed ahead Due Late by
:20 6 s same minute 4 ms
:56 6 s next minute 54.5 s
:20 6 s, inside storage.transaction() same minute 1 ms
:56 6 s, inside storage.transaction() next minute 54.6 s
any 20 s, one request to the cell after restart — 0
any overdue during 8 s of downtime — fires at startup

Impact: an application that relies on an alarm to recover after process death recovers up to a minute late whenever the deadline crosses a minute boundary.

Workaround we use: when the earliest deadline is in a later minute but less than a minute out, set the alarm to the last millisecond of the current minute, then set the real time from the early alarm() while the process is live.

Activity

  1. ryuzdev commented on Nov 25, 2026

    @ryuzdev

    After a restart Cello, the celld fork we maintain, wakes at the next alarm's minute instead of the 60 s tick, so your next-minute alarm fires on time. Ran your SIGKILL repro against 0.3.1 — fired 3 ms after its scheduled time, no cell traffic. ryuzcorp#71, in since 0.1.0. There hasn't been a celld release since 0.6.3 in October; binaries at https://github.com/ryuzcorp/cello if you want to rerun it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions