Skip to content

Cron triggers, in standalone workerd and in a cluster - #8235

Merged
ry merged 15 commits into
mainfrom
ry/cluster-cron
Nov 9, 2026
Merged

ry merged 15 commits into
mainfrom
ry/cluster-cron

Conversation

@ry

@ry ry commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Part of merging celld into workerd, following #8172 (KV). Adds cron triggers: a Worker's scheduled() handler runs on a schedule, in standalone workerd or in a cluster, once per occurrence however many instances run the config.

Like KV, cron is plain config around a bundled module, bundled = "/workerd/cron.js". Its header documents the config as an interface for config generators: a Schedule Durable Object class on a local disk, and CRONS, each schedule's expressions keyed by a service binding to the Worker they run. triggers.crons in a wrangler.json given to workerd serve emits it. Requires --experimental. Nothing changes for configs that don't use the module, Miniflare's included.

How it works: each schedule is one Durable Object, whose alarm is the scheduler, so in a cluster the schedule fails over with the object. workerd sends each Worker that uses the module one scheduled event at startup, which arms its schedules. A missed occurrence runs once, late; a failed one retries with backoff, never past the next occurrence.

Expressions are Cloudflare's dialect, read the way its parser (saffron) reads them, ported to JavaScript so the module needs nothing native: weekdays 1-7 from Sunday, L, W, #, in UTC. Two of saffron's readings are refused rather than copied (a descending range, which it wraps one value too far, and * inside a list), as is an expression that never matches. The module checks its expressions when it loads, so a bad one fails the config at startup.

Tests: the parser and plan; a standalone server running each minute once, a failed attempt retried, and a bad expression refused; and a cluster test where the schedule object's owner is SIGKILLed and a survivor runs the next minute once. An earlier version of this design ran on a 3-node cluster on R2 for 16 minutes through two owner kills, with every minute exactly once.

@ry
ry requested review from a team as code owners November 5, 2026 15:01

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 4cebbde5.

This review, of 1eda2e62

💬 Approved with comments — Nothing found makes this unsafe to merge. One WARNING: the README's list of supported Wrangler fields is now wrong because it omits triggers.crons. Two INFO notes: an inaccurate doc comment and a possible flaky parse in the test.

Findings: 1 warning · 2 info (2 are inline comments on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.

🔧 Fix with your agent

Paste the following into your coding agent to investigate and fix these issues.

Fix the following code review issues found in pull request #8235.

Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
  for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

## WARNING (1)

### [Documentation] README.md lists the supported Wrangler fields and says any other is an error, but omits the newly supported `triggers.crons` (requires --experimental)
- **File:** README.md:115

## INFO (2)

### [Code Quality] Test output parser can drop a SCHEDULED line split across data chunks
- **File:** src/workerd/server/tests/cron/cron-test.mjs:69

### [Code Quality] MAX_LOOKAHEAD_DAYS comment understates how often the full walk runs
- **File:** src/workerd/server/server/cron.rs:39

📋 Code Quality: 💬 2 info

Logic looks correct. Two minor notes: a test output parser and an inaccurate doc comment.

Recommendation: 💬 Optional Nits

  • [INFO] Test output parser can drop a SCHEDULED line split across data chunks (src/workerd/server/tests/cron/cron-test.mjs:69)
  • [INFO] MAX_LOOKAHEAD_DAYS comment understates how often the full walk runs (src/workerd/server/server/cron.rs:39)
View full review
  • src/workerd/server/tests/cron/cron-test.mjs:63-70: the parser moves calls.consumed past text that may still hold an unfinished SCHEDULED {...} line. When the rest of that line arrives, the match starts before consumed and is thrown away. stdout and stderr also write into the same buffer, so their output can interleave mid-line.
  • src/workerd/server/server/cron.rs:38-39: the comment says only an unsatisfiable expression pays the full 146,097-day walk, "once, at arm time". In fact plan() walks every expression on every /plan request, two or three times per alarm. A script that pairs an unsatisfiable expression with satisfiable ones pays the full walk on every request.

📝 Documentation: ⚠️ 1 warning

README's list of supported Wrangler fields is now wrong

Recommendation: 📝 Minor Comments

  • [WARNING] README.md lists the supported Wrangler fields and says any other is an error, but omits the newly supported triggers.crons (requires --experimental) (README.md:115)
View full review
  • README.md:111-115 lists the Wrangler fields workerd serve accepts and ends with "any other field is an error". This pull request makes triggers.crons a supported field (with --experimental), so the README now gives users a false statement. Add triggers.crons next to kv_namespaces in the --experimental list.

✅ All other checks passed

🔒 Security: ✅ LGTM

No security issues found. workerd:cron-plan is bound only inside the built-in workerd:cron worker, so user Workers cannot reach it, and it parses its query parameters defensively. The target script is looked up through the TARGETS map using the name in the object's own storage. The cron parser checks field ranges and steps, and its lookahead walk is bounded. Both the capnp and wrangler paths require --experimental.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md issues in the lines this pull request changes.


⚡ Performance: ✅ LGTM

No performance issues found. Each occurrence adds a few plan fetches and storage writes, and each scheduled script gets one arm call at startup. The per-object state stays bounded.


Reviewed commit: 1eda2e62

Comment thread src/workerd/server/server/cron.rs Resolved
@ry
ry marked this pull request as draft November 5, 2026 15:07
@codecov-commenter

codecov-commenter commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 8.21918% with 134 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.19%. Comparing base (54fd5ff) to head (c1408b9).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/workerd/server/cli/wrangler.rs 0.00% 71 Missing ⚠️
src/workerd/server/server/cron.rs 14.75% 52 Missing ⚠️
src/workerd/server/tests/cluster/cluster-worker.js 0.00% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8235      +/-   ##
==========================================
- Coverage   65.23%   65.19%   -0.04%     
==========================================
  Files         757      758       +1     
  Lines      190745   190879     +134     
  Branches    30110    30110              
==========================================
+ Hits       124424   124436      +12     
- Misses      48796    48919     +123     
+ Partials    17525    17524       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jasnell

jasnell commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

For each of these, if reasonably possible, an example in the samples directory would be nice.

@ry
ry force-pushed the ry/cluster-cron branch from 1413767 to 5916624 Compare November 6, 2026 06:44
Base automatically changed from ry/kv-builtin to main November 7, 2026 02:27
ry added 3 commits November 6, 2026 20:45
A config runs cron triggers with the Worker `bundled = "/workerd/cron.js"`:
each schedule is a Durable Object whose alarm is the whole scheduler, so
an occurrence runs once however many instances of a cluster run the
config, and the alarm fails over with the object. Its header documents
the config as an interface, as kv.js does: the `Schedule` class on a
local disk, and `CRONS`, each schedule's expressions keyed by a service
binding to the Worker they run. A missed occurrence runs once, late; a
failed one retries with backoff, never past the next occurrence.

Expressions are Cloudflare's dialect, read as its parser (saffron) reads
them, ported to JavaScript so the module needs nothing native: weekdays
1-7 from Sunday, L, W and #. A descending range, `*` inside a list and
an expression that never matches are refused. The module checks its
expressions when it loads, so a bad one fails the config.

workerd sends each Worker using the module one scheduled event at
startup, which arms its schedules, and keeps serving until it drains,
sockets or not. The module calls its targets with Fetcher.scheduled(),
which needs service_binding_extra_handlers.

tests/cron: the parser and plan; and `workerd serve` armed with no
request or socket, each minute once, a failed first attempt retried with
the same scheduledTime.
A wrangler config's triggers.crons become the schedule of the Worker
`<name>-cron`, the built-in module /workerd/cron.js, with its objects in
.wrangler/state/workerd/cron/. Like kv_namespaces they need
--experimental, and a deployment cannot have them yet.
cluster-cron.wd-test is cluster-test.wd-test with a cron Worker running
main's scheduled() every minute, which records each occurrence in a
Counter. After the first, the schedule object's owner (its own.json in
the bucket) is SIGKILLed, and a survivor runs the next minute, once.

The suite is split by test name (CLUSTER_TESTS) into cluster-test and
cluster-cron-test, which waits real minutes, so each stays under the
240 s eternal timeout.
@ry
ry force-pushed the ry/cluster-cron branch from 5916624 to 4cebbde Compare November 8, 2026 04:57
@ry
ry marked this pull request as ready for review November 8, 2026 04:59

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of e490d098.

This review, of 4cebbde5

💬 Approved with comments — Nothing found makes this unsafe to merge. The earlier README WARNING is fixed, and the only remaining notes are two INFO items in test files.

Findings: 2 info (1 is an inline comment on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📋 Code Quality: 💬 2 info

No correctness problems; two low-impact test-file notes.

Recommendation: 💬 Optional Nits

  • [INFO] Test output parser can drop a SCHEDULED line split across data chunks (src/workerd/server/tests/cron/cron-test.mjs:86)
  • [INFO] Duplicate section number 13 in the cluster-test header (src/workerd/server/tests/cluster/cluster-test.mjs:40)
View full review

I found no correctness problems in the retry and alarm logic in cron.js, in server/cron.rs and run.rs (arming starts after the early return, stops on drain, and is skipped under workerd test), or in the order of services in wrangler.rs. Two notes on test files:

  • tests/cron/cron-test.mjs: the output parser can drop a SCHEDULED {...} line that arrives split across data chunks.
  • tests/cluster/cluster-test.mjs: the header gives the new cron entry the number 13, which the KV entry already uses.

✅ All other checks passed

🔒 Security: ✅ LGTM

No security issues found. Both the capnp and the wrangler paths require --experimental, and a deployment with triggers.crons is refused. The parser checks field ranges and steps, and its lookahead walk is bounded. The scheduled target comes from the config's own CRONS map.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md issues.


⚡ Performance: ✅ LGTM

No performance issues found.


📝 Documentation: ✅ LGTM

The README's list of supported Wrangler fields now includes triggers.crons.


Reviewed commit: 4cebbde5

ry added 2 commits November 7, 2026 21:07
A chunk of output can end mid-line, and the old parser skipped a
SCHEDULED line split across two chunks. Parse each stream's complete
lines instead.
A Worker's scheduled() handler run every minute and every five minutes
by the bundled module /workerd/cron.js.
@ry

ry commented Nov 8, 2026

Copy link
Copy Markdown
Member Author

[AI] Added samples/cron (e490d09): a Worker's scheduled() handler run by /workerd/cron.js. I ran it and it fires at the top of each minute. The README warning was already addressed: triggers.crons is listed next to kv_namespaces.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 3a51c5f5.

This review, of e490d098

💬 Approved with comments — Nothing makes this unsafe to merge. The parser fix holds, the new sample is consistent with the module, and the only open note is a duplicate section number in a test header comment (INFO).

Findings: 1 info

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📋 Code Quality: 💬 1 info

The parser fix holds. One INFO remains: a duplicate section number in a test header.

Recommendation: 💬 Optional Nits

  • [INFO] Duplicate section number 13 in the cluster-test header comment (src/workerd/server/tests/cluster/cluster-test.mjs:40)
View full review
  • The test output parser now buffers a partial line per stream and parses only complete lines (cron-test.mjs:83-95), so the earlier split-line note is fixed.
  • samples/cron/config.capnp matches the shape that cron.js and wrangler.rs emit.
  • tests/cluster/cluster-test.mjs:40: the cron entry in the header is numbered 13, but the KV entry already uses 13.

✅ All other checks passed

🔒 Security: ✅ LGTM

No security issues found. The expressions, the scheduled targets and the bindings all come from the operator's own config. The parser's lookahead walk is bounded, and both config paths require --experimental.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md issues.


⚡ Performance: ✅ LGTM

No performance issues found.


📝 Documentation: ✅ LGTM

The new samples/cron/README.md is accurate and follows the format of the existing samples.


Reviewed commit: e490d098

On Windows the path's backslashes were read as escapes in the capnp
string, so the config failed to parse.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 17181f17.

This review, of 3a51c5f5

✅ Approved — The Windows path quoting fix is correct, and the rest of the pull request has not changed since the earlier review, which found nothing unsafe to merge. One earlier minor note stays open.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security issues found.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md issues.


📋 Code Quality: ✅ LGTM

cron-test.mjs:35 now quotes the store path with JSON.stringify. Capnp text literals accept JSON's backslash escapes, so a Windows path now parses. One earlier INFO note, the duplicate section number in the cluster-test header comment, remains open.


⚡ Performance: ✅ LGTM

No performance issues found.


📝 Documentation: ✅ LGTM

No documentation issues found.


Reviewed commit: 3a51c5f5

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of c05d07e2.

This review, of 17181f17

✅ Approved — The Windows path quoting fix is correct, and the rest of the pull request has not changed since the earlier review, which found nothing unsafe to merge. One earlier minor note stays open.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security issues found.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md issues.


📋 Code Quality: ✅ LGTM

cron-test.mjs:35 now quotes the store path with JSON.stringify. Capnp text literals accept JSON's backslash escapes, so a Windows path now parses. One earlier INFO note, the duplicate section number in the cluster-test header comment, remains open.


⚡ Performance: ✅ LGTM

No performance issues found.


📝 Documentation: ✅ LGTM

No documentation issues found.


Reviewed commit: 17181f17 — same changes as 3a51c5f5, so this is that commit's review (no new review was run; line numbers are as of 3a51c5f5)

- L-nW on a Saturday target ran on both the Friday before and the
  Monday after; it now runs on the Friday, as saffron does.
- nW for a day past the month's end (31W in September) ran on the 30th
  when that was a Friday; it now skips the month, as saffron does.
- 1#2#3 was read as 1#2; it is refused.
- A CRONS name with no service binding failed every occurrence at run
  time; it now fails the config when it loads. Expressions are parsed
  once there instead of at every arm and alarm.
- Schedules, and cron Workers, are armed in parallel, so one failing
  Worker no longer delays the others' first run.
- Only a Worker whose main module is /workerd/cron.js is armed at
  startup, not one that merely imports it.
- The retry comment now matches the code; the min() clamp could never
  apply.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 660a6519.

This review, of c05d07e2

✅ Approved — The fixes in cron.js and cron.rs since the last review are correct, the one earlier note is fixed, and nothing new is unsafe to merge.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

Expressions come from the operator's config, not from request data. Parsing uses anchored regexes and bounded loops. The scheduled event goes only to the Worker's own service binding.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md issues.


📋 Code Quality: ✅ LGTM

I hand-checked the parser fixes in cron.js (L-nW, a nW day past the end of the month, 1#2#3, L-31) against the unit test expectations, and they match. The retry and arming logic in cron.js is consistent, and so is startup arming in cron.rs. The cluster test split has no overlap. The header comment in cluster-test.mjs now numbers its sections correctly.


⚡ Performance: ✅ LGTM

No performance issues found.


📝 Documentation: ✅ LGTM

No documentation issues found in the files changed since the last review.


Reviewed commit: c05d07e2

@piscisaureus piscisaureus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[🤖] Test gaps found while reviewing (the line comments cover the bugs):

  • No test restarts a server. A missed occurrence is handled correctly (SIGKILL after 20:19, restart at 20:21:10: 20:20 ran once, 70 s late, 20:21 was folded into it, 20:22 ran normally), but deleting the keep-existing-alarm early return in arm() would drop every missed occurrence and no test would fail. A stop/restart case in cron-test.mjs would cover it.
  • Parser mutants that every unit test survives: the t <= last guard; the W arm for a month ending on a Sunday (→ Friday); both Monday arms of L-nW; d + 7 > last changed to >=; the descending-range check (only caught incidentally by "never matches"); and step > 1 ? f.max : first changed to first.
  • 30/15 from 12:46 gives 13:30 under either reading of a step; starting from 12:31 and expecting 12:45 would tell them apart.
  • 31W in September 2026 can't exercise the month-end guard, since the 30th is a Wednesday.
  • The cluster cron test returns as soon as it sees 2 ticks, so a duplicate arriving a second later goes unseen; waiting a little past the second tick would catch one.
  • Not covered at all: retries after eviction and a restart during a pending retry (see the comment on #owed), and a handler that outlives the alarm limit.

Comment thread src/workerd/server/cron/cron.js Resolved
Comment thread src/workerd/server/cron/cron.js Resolved
Comment thread src/workerd/server/cron/cron.js Resolved
Comment thread src/workerd/server/cron/cron.js Resolved
Comment thread src/workerd/server/cron/cron.js Resolved
Comment thread src/workerd/server/cli/wrangler.rs Resolved
Comment thread src/workerd/server/server/cron.rs Resolved
Comment thread samples/cron/config.capnp Resolved
Comment thread samples/cron/README.md Resolved
ry added 2 commits November 9, 2026 13:02
- Retries are stored with the schedule, not held in memory: an idle
  object is evicted 10 s after its last request, so from the fourth
  retry on, and after any restart, the retry was dropped.
- Each run gets 10 minutes, under workerd's alarm limit, and counts as
  failed past that; the expressions due at one time run at once. One
  schedule's runs never overlap, and an occurrence that comes due
  during a run is skipped; this is now documented.
- A clock stepped back can no longer bring an occurrence round twice.
- Startup arms schedules with allSettled, so one failing schedule no
  longer cancels the others; Rust retries arming for about 31 s, past
  the cluster lease, and logs each failure.
- N/1 now reads as N to the end of the field, as saffron does.
- L-nW with a target before the 1st (L-28W in a 28-day February)
  matches nothing, as saffron does, and L-29W in February is refused.
- A CRONS value that is not a list fails with a clear error, and
  duplicate expressions run once.
- wrangler refuses a Worker named CRONS or SCHEDULE, which would
  collide with the cron Worker's own bindings.
- Tests: a pending retry and a missed occurrence across restarts; the
  cluster cron test waits past the second tick for a duplicate; parser
  cases for each arm a mutant could remove; refusals of 5,* and
  0,30-10 in place of *,5, which saffron refuses too.
- Sample: corrected the storage comment, and bazel run passes the
  disk's full path.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of b923ed30.

This review, of 660a6519

✅ Approved — Every point raised in the discussion is fixed at this commit, and the code changed since the last review introduces nothing unsafe to merge.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

Cron expressions come from the operator's config, not from request data. The parser's loops are bounded and its regexes are anchored. The scheduled event goes only to each Worker's own service binding.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md issues found.


📋 Code Quality: ✅ LGTM

The code changed since the last review is correct: cron.js, cron.rs, wrangler.rs, the tests and the sample. The parser and retry changes match their test fixtures. These points from the discussion are fixed: the N/1 step, the retries stored with the schedule, the arms run with allSettled, the L-nW guard for day 0, the 10-minute run limit, the clock step-back guard, the CRONS validation and dedupe, the refused binding names, and the longer, logged startup arming.


⚡ Performance: ✅ LGTM

The next() walk is bounded. It runs to full length only for an expression that never matches, and those are refused once, at load. plan() costs one next() per expression per alarm. Startup arming is a fixed number of retries with backoff.


📝 Documentation: ✅ LGTM

The sample README and config comments match the code. The README gives an absolute disk path for bazel run.


Reviewed commit: 660a6519

The cron tests waited for real minutes and polled with sleeps. Each
now waits for one occurrence at most per phase, and on output rather
than a timer:

- cron-test folds its two clock-bound cases into one: the first
  occurrence fails, workerd is killed before the retry, and the retry
  runs once it restarts, which also covers keeping a pending alarm at
  startup. Its until() resolves as workerd prints, not on a poll.
- The cluster cron test watches each node's stderr for the tick its
  handler logs (ClusterNode.waitForStderr); the node that logs it is the
  schedule's owner, so the bucket lookup and the Counter's /tick and
  /ticks routes go.

Also rustfmt in wrangler.rs.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 5439dc53.

This review, of b923ed30

💬 Approved with comments — Every finding from the discussion is fixed. The only new notes are two INFO items about test timing and a test comment.

Findings: 2 info (2 are inline comments on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📋 Code Quality: 💬 2 info

The changes since the last review are correct. There are two test-only notes: a narrow flake window in the cluster cron test, and a comment in the restart test that overstates what it covers.

Recommendation: 💬 Optional Nits

  • [INFO] The cluster cron test can flake: SIGKILL right after TICK may land before the next alarm is stored, so a survivor runs the same occurrence again. (src/workerd/server/tests/cluster/cluster-test.mjs:2826)
  • [INFO] The restart test comment claims the stored retry runs after the restart, but the assertion passes whether the restart runs a stored retry or runs the occurrence again. (src/workerd/server/tests/cron/cron-test.mjs:136)
View full review
  • src/workerd/server/tests/cluster/cluster-test.mjs:2826: the owner is SIGKILLed as soon as TICK is logged. That can land before alarm() stores the next alarm (cron.js, after the handler returns), so a survivor runs the same occurrence again and seen comes out as [t, t]. This is a rare flake.
  • src/workerd/server/tests/cron/cron-test.mjs:136: the comment says the kill comes before the retry and that the stored retry runs after the restart. The kill often lands before the retry is stored. The assertion passes whether the restart runs a stored retry or runs the occurrence again, so the test doesn't tell the two paths apart.

✅ All other checks passed

🔒 Security: ✅ LGTM

Cron expressions come from the operator's config, not from request data. Each scheduled event goes only to the Worker's own service binding.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md issues found.


⚡ Performance: ✅ LGTM

  • next() is bounded, and the load-time check refuses any expression that never matches.
  • plan() costs one next() per expression per alarm.
  • Startup arming retries a fixed number of times, with backoff.
  • The run timer is cleared in finally.

📝 Documentation: ✅ LGTM

The sample README and the config comments match the code.


Reviewed commit: b923ed30

As KV does, an optional TEST_CLOCK binding enables POST /clock?advance=
on the cron Worker: it moves this process's planning clock and re-arms
every schedule by it, while alarms keep the real clock. A test moves the
clock to a second before a minute and sees it run a second later.

arm() now waits out a run in progress, so an arm can no longer race the
alarm it replaces, and /clock returns only once runs have finished. The
cluster test needs that: it killed the owner mid-run, and the survivor
rightly ran the occurrence again.

cron-test now takes seconds, not a minute; the cluster cron test takes
about the 20 s lease takeover, not two minutes. Both match the occurrence
they set up, so a real minute passing before the clock moves is ignored.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 17a315c4.

This review, of 5439dc53

💬 Approved with comments — No correctness, security or performance problems found. The one remaining note is an INFO: the restart test's comment claims more than the test checks.

Findings: 1 info (1 is an inline comment on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📋 Code Quality: 💬 1 info

One INFO is still open: the restart test can't tell a stored retry from a rerun of the occurrence. The cluster test flake is fixed.

Recommendation: 💬 Optional Nits

  • [INFO] Restart test comment says the stored retry runs after the restart, but the assertion passes the same way if the occurrence reruns instead. (src/workerd/server/tests/cron/cron-test.mjs:159)
View full review
  • src/workerd/server/tests/cron/cron-test.mjs:159: the comment says the stored retry runs after the restart. But attempts is in-process, so the first call after the restart is always n: 1. A stored retry and a rerun of the occurrence therefore give the same runs().
  • The cluster cron flake is fixed. clock(nodes, 0) before the kill waits until the owner has stored its next alarm.

✅ All other checks passed

🔒 Security: ✅ LGTM

/clock returns 404 unless TEST_CLOCK is bound. Configs generated from wrangler never bind it. Cron expressions come from the operator's config, and scheduled events go only to the Worker's own service binding.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md issues found.


⚡ Performance: ✅ LGTM

No performance concerns in the changed code.


📝 Documentation: ✅ LGTM

The sample README and the config comments match the code.


Reviewed commit: 5439dc53

Right after start, a node's first arm can reach a peer that is not yet
listening; workerd retries its startup arm for that, but the test's
first /cron-clock failed at once. The test now waits for each node's
"cron ... armed" log, which workerd now writes, and moves the clock to
just before the next minute while the owner lives, then kills it: a
survivor adopts the overdue alarm when the lease runs out, with no
request to the dead owner.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of c1408b9d.

This review, of 17a315c4

💬 Approved with comments — No correctness, security or performance problems found. The one remaining note is an INFO: the restart test's comment claims more than the test checks.

Findings: 1 info

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📋 Code Quality: 💬 1 info

One INFO carried over: the restart test's comment overstates what its assertion checks. Nothing new in cron.rs or cluster-test.mjs.

Recommendation: 💬 Optional Nits

  • [INFO] Restart test comment says the stored retry runs after the restart, but the assertion passes the same way if the occurrence reruns instead. (src/workerd/server/tests/cron/cron-test.mjs:159)
View full review
  • src/workerd/server/tests/cron/cron-test.mjs:159: the comment says the stored retry runs after the restart. But attempts lives in the worker process, so the first call after the restart is always n: 1, which fails, and the in-process retry then logs n: 2. A stored retry and a full rerun of the occurrence therefore give the same runs().
  • server/cron.rs and tests/cluster/cluster-test.mjs (changed since the last review): no problems found.

✅ All other checks passed

🔒 Security: ✅ LGTM

Nothing in the files changed since the last review affects security.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md issues found.


⚡ Performance: ✅ LGTM

Startup arming makes a bounded number of attempts, with doubling backoff, per cron Worker. Arms run in parallel through Promise.allSettled, and the run timeout timer is cleared in finally.


📝 Documentation: ✅ LGTM

The sample README and the config comments match the code.


Reviewed commit: 17a315c4

ry added 2 commits November 9, 2026 13:50
After a run, the next alarm was planned from the later of the clock and
the occurrence, so that a clock stepped back never brings the
occurrence round again. That also put the retry's backoff after the
occurrence: a clock 50 s behind it delayed a 4 s retry by 50 s. plan()
now searches for the next occurrence after both, and times a retry
from the clock. cron-test caught it: after a restart drops the test
clock's skew, the retry was due almost a minute late.
Its attempts are counted in memory, so it cannot tell a stored retry
from the occurrence run afresh; it shows the restart drops neither.
@ry

ry commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

[AI] @piscisaureus, on the test gaps:

  • Restart: cron-test kills workerd while a failed occurrence's retry is pending, then checks that the restart doesn't drop the occurrence. Without the keep-existing-alarm return in arm(), startup re-arms for the next minute and the test fails. It can't tell a stored retry from the occurrence run afresh, because attempts are counted in memory; the comment now says so.
  • Parser mutants: each one you listed now fails a unit test. I checked each in node. 31W uses April 2027 (the 30th is a Friday) and January 2027 (the 31st is a Sunday). 30/15 from 12:31 expects 12:45.
  • Cluster duplicates: the test now kills the owner only after its run has finished, and counts every node's ticks from the occurrence it set up.
  • Retries after eviction and across restarts are now stored with the schedule. A handler that outlives the alarm limit is cut off at 10 minutes and counted as failed. Neither has its own test.

The cron tests no longer wait for real minutes or sleep. A TEST_CLOCK binding, as in KV, moves the cron Worker's clock, so cron-test takes seconds and the cluster test takes about the 20 s lease takeover.

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved — No correctness, security or performance problems in the code changed since the last review, and the one earlier note (the restart test's comment) is fixed.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

  • wrangler.rs builds the generated config through serde_json and the capnp builder, so no expression text is pasted into config source.
  • The /clock endpoint exists only when the TEST_CLOCK binding is set.
  • The parser's lookahead is bounded, and an expression that never matches is refused when the module loads.
  • The startup scheduled event goes only to Workers whose module is /workerd/cron.js.

📖 AGENTS.md: ✅ LGTM

No AGENTS.md issues found.


📋 Code Quality: ✅ LGTM

The restart test in cron-test.mjs now claims only that a restart does not drop the occurrence. Its assertion [first, { ...first, n: 2 }] passes whether the restart runs the stored retry or runs the occurrence again, so the claim and the check match.

In cron.js, a stored retry (owed) survives eviction and restart. arm() keeps an existing alarm that is no later than the planned one, and the alarm is set in clock time adjusted by skew. The W, L-nW and LW day arms give the dates the unit fixtures expect. #run clears its timeout in finally.


⚡ Performance: ✅ LGTM

No performance concerns in the changed code.


📝 Documentation: ✅ LGTM

The sample README and the config comments match the code.


Reviewed commit: c1408b9d

@ry
ry merged commit 07a394b into main Nov 9, 2026
23 checks passed
@ry
ry deleted the ry/cluster-cron branch November 9, 2026 22:38

@piscisaureus piscisaureus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[🤖] All points from my review are addressed. LGTM.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants