Repository navigation
feat(coderd/schedule/cron): add Standard schedule constructor - #32063
Conversation
…chedules Automations store a five-field cron expression and an IANA time zone. Standard parses both and gives a repeated local time one run and a nonexistent local time one run after the clock change, which the robfig/cron Next used by Weekly and Daily does not do. MinInterval returns the shortest gap between runs for the API check, because Min only samples one week from 1970-01-01.
|
@codex review |
|
@codex security review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c265185114
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
… MinInterval Next searches again when robfig/cron gives up after five years, so a leap day schedule keeps running across 2100. The zone period walk starts 26 hours before the reading, so historic offsets above 14 hours still find the first instance of a repeated time. MinInterval scans 28 years, which holds every calendar a year can have, so schedules that set both day fields get their true shortest gap. It stops once it sees two days in a row, and searches from midnight, so common schedules take microseconds.
Go reports wrong zone period bounds after the last transition in a zone's data, so the walk over zone periods never ended on December 31 of a leap year. A reading is now resolved from the offsets of the zone around it, with fixed bounds on every loop, and Next returns the zero time instead of spinning when a step does not move forward. MinInterval drops the calendar scan and returns the shortest distance between two times of day around the clock. Standard rejects the zone data files localtime, posixrules and Factory.
…a through 2100 The differential test runs over every clock change of five zones and December 31 in years up to 2100, with the zone data of the host and the data that Go embeds. Every Next call in the termination test has a deadline. The model of cron comes from robfig/cron, not from the code under test.
…limits No two runs are closer than MinInterval while the UTC offset of the zone does not change. An offset change can shorten a gap that spans it, and a pair across midnight counts without days in a row. Tests pin both.
|
@codex review |
|
@codex security review |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
A zone name with an empty, dot or dot-dot segment is rejected, because time.LoadLocation cleans the path and ./localtime reached the host file. Tests start Next inside repeated periods of up to a whole day, so the bound on the readings that Next walks is pinned, and a test from a zone with a local mean time offset above 15 hours pins the range of offsets that Next reads. The comment on the search for later runs now states 16 years, which is what robfig's year limit gives.
|
@codex review |
|
@codex security review |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…the zone once A zone name is rejected when its first segment is posix or right, because right counts leap seconds and gives wrong runs on hosts that have it. The files that are not zones are rejected in any directory. The error for an unknown zone holds the name once. A test starts Next in Juneau, where the walk visits 1,441 readings, one more than the repeated day of Sitka.
|
@codex review |
|
@codex security review |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
ethanndickson
left a comment
There was a problem hiding this comment.
The RFC says the browser previews unsaved schedules with cron-parser (4.9.0 in site/package.json), and the server stays authoritative. cron-parser accepts these specs, but Standard rejects them:
0 9 * * 7(7 as Sunday)0 9 L * *(last day of the month)0 9 * * 1#2(second Monday)0 0 9 * * *(six fields:cron-parserreads the first field as seconds and previews daily at 09:00)
For each of these, the user sees a valid preview, and then the save fails.
On clock-change days, the previewed times also differ from the times the server runs. In America/New_York:
30 2 * * *on 2026-03-08: the preview shows 03:30 EDT, but the server runs at 03:00 EDT.*/15 * * * *on 2026-11-01: the preview shows runs at 01:00 EST, 01:15 EST and so on, but the server runs nothing between 01:45 EDT and 02:00 EST.
This is not a bug in this PR, but this PR sets the syntax and the daylight saving rules that the server uses. Is there a plan to keep the browser preview and the server in agreement?
🤖
|
Thanks, this is a real gap, and the RFC does not close it. It says "The browser previews the next runs of an unsaved schedule with the The plan:
I did not change the server's syntax here. Generated with |
Why
Automations store a five-field cron expression and an IANA time zone. The scheduler and the management API will parse both with
coderd/schedule/cron, as the "Schedules" section of the Automations RFC says. This adds the parser they will call.Part of CODAGT-1135.
What changed
cron.Standard(spec, timeZone)parses a five-field spec that runs on the wall clock of an IANA zone. Every field can be restricted. It returns an error for an empty spec, a wrong field count, aCRON_TZ=orTZ=prefix, an empty or unknown zone, a zone name with an empty,.or..segment such as./localtime, a name that starts withposix/orright/(directories of zone data that some hosts have, with other versions of the zones),Local(a Go name for the host's zone), a name whose last segment islocaltime,posixrulesorFactory(files in a host's zone data that are not zones), and a spec that never runs, such as0 0 30 2 *.Nexton aStandardschedule follows the RFC's daylight saving rule. A repeated local time runs once, at its first instance. A nonexistent local time runs at the first local time after the change.robfig/crondoes neither: in America/New_York it runs30 1 * * *twice on 2026-11-01 and skips30 2 * * *on 2026-03-08. SoStandardwalks the matching wall-clock readings and resolves each one to an instant from the zone's UTC offsets. Every loop has a fixed bound, andNextalways returns a later time for aStandardschedule. It searches at least 16 years ahead, past the eight years between two leap days across 2100.Weekly,DailyandTimeRangekeep their behavior.Schedule.MinInterval()returns the shortest distance between two times of day at which the schedule runs, counted around the clock. One time of day gives 24 hours. The management API will compare it with the deployment's minimum interval.Scope
This PR adds no minimum interval policy and no configuration. Nothing calls the new code yet. The scheduler loop and the API come in later PRs.
Tradeoffs
MinIntervalreads only the hour and minute fields, with no calendar. The RFC allows a minimum interval of one minute to 24 hours, so the value only has to be right below 24 hours, and a scan over the calendar kept missing cases. While the zone's UTC offset does not change, no two runs are closer than the value. The doc comment states two limits, and a test pins each.1,58 1,3 * * *in America/New_York gives 57 minutes, and its runs on 2026-03-08 are 3 minutes apart.0,58 0,23 * * 1gives 2 minutes, but its runs are 58 minutes apart at least, so a check can reject a schedule that the minimum allows.*/15 * * * *does not run during the second pass of a repeated hour. In America/New_York on 2026-11-01 it runs at 01:45 EDT and next at 02:00 EST.Standardresolves a reading from the zone's offsets and does not use Go's zone period bounds, which are wrong after the last transition in a zone's data.Live check
None. This is a library that nothing calls yet.
Generated with
xum• Model:anthropic:claude-sonnet-5-5• Thinking:xhigh