Repository navigation
fix(automations): advance cron and hourly schedules past a DST fall-back hour - #20179
Conversation
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 7ffaed2c-af35-4d24-b62c-94bbc4c0af99
📥 Commits
Reviewing files that changed from the base of the PR and between 6252f81 and f6ac69320416fbced509741a2b54ce8ea4da2d50.
📒 Files selected for processing (2)
src/shared/automation-cron-occurrence.tssrc/shared/automation-schedule-occurrences.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
There was a problem hiding this comment.
Important
The cron fix is correct and the regression tests are real, but the FREQ=HOURLY RRULE path reproduces the same non-advancing nextRunAt loop, so #20154 is only half closed. Please extend the fix or explicitly scope the hourly path out.
Reviewed changes
- UTC floor in
floorToMinute: now floors withtimestamp - (timestamp % 60_000)instead of recomposing local wall-clock fields, so an ambiguous fall-back minute can no longer resolve to the earlier (EDT) offset and move backwards in absolute time. - DST regression suite: a new
America/New_Yorksuite pins both repeats of the fall-back minute, the strictly-after contract across the repeated hour, and the skipped spring-forward minute.
⚠️ The FREQ=HOURLY branch still returns a nextRunAt at or before now through fall-back
nextAutomationOccurrenceAfter's hourly branch uses the same local-field recomposition the cron fix just removed, so an hourly automation still stays due and re-dispatches every tick for the rest of the repeated hour — the exact blast radius #20154 describes. This PR closes that issue, so either the hourly path needs the symmetric fix or the residual scope should be called out.
Technical details
# `FREQ=HOURLY` keeps `nextRunAt` non-advancing through the repeated hour
## Affected sites
- `src/shared/automation-schedule-occurrences.ts:110-119` — the `FREQ=HOURLY` branch calls `base.setMinutes(rule.byMinute, 0, 0)`. On an ambiguous fall-back minute V8 resolves that local time to the earlier (EDT) offset, so `candidate` lands an hour *before* `after`; the single `candidate += HOUR_MS` then returns the same wall-clock minute, i.e. `candidate <= after`.
- `src/shared/automation-schedule-occurrences.ts:146-153` — `latestAutomationOccurrenceAtOrBefore`'s hourly branch has the mirrored defect: `base.setMinutes(...)` resolves to the earlier offset and reports the first-pass occurrence for a second-pass `now`.
- `src/main/automations/service.ts:236` — `evaluateDueRuns` only skips when `nextRunAt > now`, and `src/main/persistence/scheduling-automations/automation-definition-operations.ts:111` defaults `missedRunGraceMinutes` to 720, so the hourly run proceeds to dispatch each tick.
## Evidence
Driving the real hourly branch with `TZ=America/New_York`, `BYMINUTE=30`, `after` inside the second `01:xx` pass (epoch 06:30Z–06:59Z):
```
after 2026-11-01T06:30:00.000Z -> next 2026-11-01T06:30:00.000Z (not strictly after)
after 2026-11-01T06:30:30.000Z -> next 2026-11-01T06:30:00.000Z
after 2026-11-01T06:31:00.000Z -> next 2026-11-01T06:30:00.000Z
after 2026-11-01T06:35:00.000Z -> next 2026-11-01T06:30:00.000Z
```
The cron tests in this PR do not exercise this branch; `automation-schedules.test.ts` has no hourly fall-back case.
## Required outcome
- `nextAutomationOccurrenceAfter` returns a value strictly greater than `after` for `FREQ=HOURLY` schedules through the fall-back hour, or the hourly residual is explicitly scoped out of #20154.
## Suggested approach (optional)
- Fix the hourly branch symmetrically (absolute-time arithmetic, or enforce the `> after` postcondition after computing the candidate as #20154 originally suggested), and add a `FREQ=HOURLY` fall-back case to the new suite.
## Open questions for the human (optional)
- Is `FREQ=HOURLY` intentionally out of scope for this fix? If so, #20154 should stay open or note the residual.openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
|
Good catch on the TZ restore — fixed in 0dec56f7: the original |
There was a problem hiding this comment.
Important
0dec56f resolves the TZ-capture nit and adds docstrings, but the prior review's blocking concern is still open: this PR closes #20154 while the FREQ=HOURLY (hourly preset) path keeps the same non-advancing nextRunAt behavior through a fall-back hour.
Reviewed changes
- Restored the process timezone correctly in the DST suite:
process.env.TZis now captured before the override and restored inafterAll, deleting it when it was originally unset, so later tests in a shared worker run under their own timezone. - Documented the touched functions:
floorToMinute's inline// Why:note became a JSDoc block (same explanation), and the test helpers gained docstrings.
⚠️ The FREQ=HOURLY path still returns nextRunAt <= now through fall-back
The hourly preset is a first-class automation option, and nextAutomationOccurrenceAfter's hourly branch still uses the local-field recomposition this PR just removed from floorToMinute. Through the second pass of a repeated hour, candidate resolves an hour earlier, the single += HOUR_MS lands back on after, and advanceAutomationNextRun writes a non-advancing nextRunAt — so an hourly automation still re-dispatches every tick, the exact blast radius #20154 describes. Either fix this branch symmetrically or explicitly scope it out of this PR.
Technical details
# `FREQ=HOURLY` keeps `nextRunAt` non-advancing through the repeated hour
## Affected sites
- `src/shared/automation-schedule-occurrences.ts:110-119` — the `FREQ=HOURLY` branch calls `base.setMinutes(rule.byMinute, 0, 0)`. On an ambiguous fall-back minute V8 resolves that local time to the earlier (EDT) offset, so `candidate` lands an hour before `after`; the single `candidate += HOUR_MS` returns `after` itself.
- `src/shared/automation-schedule-occurrences.ts:146-153` — `latestAutomationOccurrenceAtOrBefore`'s hourly branch has the mirrored defect.
- `src/renderer/src/components/automations/automation-orca-save.ts:71-79` — the hourly preset is persisted via `buildAutomationRrule`, which emits `FREQ=HOURLY;BYMINUTE=…`, so this branch is the production path for `preset: 'hourly'` (e.g. the `maintenance-hourly` template).
- `src/main/automations/service.ts:236` — `evaluateDueRuns` only skips when `nextRunAt > now`, so the non-advancing value re-dispatches each tick.
## Evidence
Reproduced this run with `TZ=America/New_York`, `after = 2026-11-01T06:30:00Z` (second EST pass):
`base.setMinutes(30, 0, 0)` → `2026-11-01T05:30:00Z`; `candidate <= after` → `+HOUR_MS` → `2026-11-01T06:30:00Z`, i.e. equal to `after`, not strictly greater.
## Required outcome
- `nextAutomationOccurrenceAfter` returns a value strictly greater than `after` for `FREQ=HOURLY` schedules through the fall-back hour, or the hourly residual is explicitly scoped out of this PR/#20154.openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
|
Valid catch — fixed symmetrically in 73eb8aa4. Both |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Changes since the prior pullfrog review (0dec56f) — commit 73eb8aa:
- Fixed the
FREQ=HOURLYbranches to walk absolute minutes: bothnextAutomationOccurrenceAfter(src/shared/automation-schedule-occurrences.ts:109-124) andlatestAutomationOccurrenceAtOrBefore(:151-162) now anchor onfloorToMinuteand step minute-by-minute matchinggetMinutes() === rule.byMinute, replacing the ambiguoussetMinutes(rule.byMinute, 0, 0)recomposition that could returnafteritself (or the earlier pass) through a fall-back hour. This closes the blocking concern from the prior review. - Added three hourly DST regression tests: both repeats of an hourly minute fire,
nextAutomationOccurrenceAfteradvances past the repeated hour rather than returningafter, andlatestAutomationOccurrenceAtOrBeforereturns the EST-pass minute. All assert exact instants, so they fail against the previous implementation. - Documented the walk rationale: inline
// Why:notes on both branches referencing #20154, plus thefloorToMinuteJSDoc.
Verified the full suite passes under TZ=America/New_York (vitest run src/shared/automation-schedule-occurrences.test.ts src/shared/automation-schedules.test.ts — 31 passed), and traced the boundary cases (exact-minute after, dtstart off-minute and after after, strict-after contract) by hand; the walk preserves the pre-existing non-DST behavior and now advances correctly in both DST directions.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
One more hardening from the CodeRabbit inline suggestion (it landed on #20579's snapshot but belongs to this PR): |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Changes since the prior pullfrog review (73eb8aa) — commit b0a879f:
- Made
floorToMinutefloor toward negative infinity: replacedtimestamp - (timestamp % 60_000)withMath.floor(timestamp / 60_000) * 60_000, so pre-epoch inputs round down rather than toward zero. For the actual input domain (positive epoch ms) the result is identical. - Added
floorToMinuteunit tests: positive-minute flooring (including the exact-minute0) and pre-epoch cases (-15_000,-1,-60_000), all of which fail against the sign-preserving%form. - Documented the sign rationale: the JSDoc now explains why
Math.flooris used instead of%.
Verified TZ=America/New_York vitest run src/shared/automation-schedule-occurrences.test.ts src/shared/automation-schedules.test.ts — 33 passed. Traced Math.floor(timestamp / 60_000): the division is exact for multiples of 60 000 and correctly-rounded otherwise, and for Date-range magnitudes the 1/60 000 fractional step exceeds the half-ULP, so rounding can never cross an integer boundary and change the floor. All previous review concerns are addressed; the only prior inline thread is already resolved.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
b0a879f to
8bfa301
Compare
floorToMinute recomposed local wall-clock fields via setSeconds(0, 0), and the FREQ=HOURLY branches used setMinutes. Inside a repeated fall-back hour both resolve to the earlier offset, so nextAutomationOccurrenceAfter could return `after` itself and latestAutomationOccurrenceAtOrBefore could return the first pass's instant. Run dedupe by scheduledFor prevents duplicate launches, but the second pass was mishandled: a `30 1 * * *` cron's second run started 30 minutes late (or was recorded as skipped_missed past its grace window), the 01:00 EST run of `FREQ=HOURLY;BYMINUTE=0` was dropped, and the scheduler re-evaluated and flushed state on roughly every tick for the hour because nextRunAt stayed in the past. Floor with epoch arithmetic and route cron and hourly schedules through one absolute-minute walk, so each pass of a repeated minute fires once, on time. Fixes stablyai#20154 Co-authored-by: Neil <[email protected]>
8bfa301 to
c09efed
Compare

ELI5
When clocks "fall back" in autumn, the hour from 1:00 to 2:00 happens twice. During the second pass of that hour, Orca's scheduler mixed it up with the first pass. A run meant for the second 1:30 could start 30 minutes late, or be marked as missed. An hourly run at the second 1:00 could be dropped entirely. The scheduler also kept re-checking and re-saving the schedule about once a minute for that whole hour. This fix rounds times in a way that can never move them backwards, so each pass of the repeated hour runs once, on time.
What Changed
Before: inside the repeated fall-back hour,
nextAutomationOccurrenceAftercould returnafteritself (breaking its strictly-after contract), andlatestAutomationOccurrenceAtOrBeforecould return the first pass's instant while the clock was in the second pass.After: every next run is strictly later than
after, and cron andFREQ=HOURLYschedules fire once per pass of a repeated minute, on time.Mechanism:
src/shared/automation-cron-occurrence.ts:floorToMinutenow uses epoch arithmetic (Math.floor(ts / 60_000) * 60_000) instead ofdate.setSeconds(0, 0). Rebuilding from local wall-clock fields makes an ambiguous minute resolve to the earlier offset, up to an hour before the input.src/shared/automation-schedule-occurrences.ts: cron and HOURLY, both next and latest, now share one absolute-minute walk (nextMatchingMinute/latestMatchingMinute, which take a matcher). This replaces the HOURLYsetMinutes+HOUR_MSlogic, which had the same rewind problem.src/shared/automation-cron-input-validation.test.ts: the assertion that pinned the buggy result ("Pin existing DST ambiguity (Automation scheduler can re-fire every tick through a DST fall-back hour #20154)") now expects the next day's run. Added an hourly regression covering first pass -> second pass -> next hour, pluslatestinside the second pass.Why
Runs are deduped by
(automationId, scheduledFor), so main never launched the same run twice. The second pass was still handled wrong, though. Simulating the scheduler's evaluate/createRun/advance loop with 60s ticks inAmerica/New_Yorkon 2026-11-01:30 1 * * *: the 01:30 EST run started at 02:00 EST, 30 minutes late (or becameskipped_missedpast its grace window). 32 evaluations in the window.FREQ=HOURLY;BYMINUTE=0: the 01:00 EST run was dropped. 63 evaluations.Epoch flooring is always
<=its input and within 60s of it. Every modern offset is a whole number of minutes (including :30 and :45 zones), so a UTC minute boundary is also a local one. Sharing one minute walk across cron and HOURLY keeps a single source of truth, so the two paths can't drift apart again.Linked Issue
Fixes #20154
Visual Proof
N/A. This is scheduler time arithmetic with no UI or interaction change. The behavioral before/after is the probe output under Testing.
Testing
On macOS (arm64):
expected 1793514600000 to be 1793601000000andexpected 1793514600000 to be 1793518200000). With this branch they pass.30 1 * * *,30 * * * *,FREQ=HOURLY;BYMINUTE=30,*/15 1 * * *,45 1 * * 0,0 2 * * *,FREQ=DAILY;BYHOUR=1;BYMINUTE=30,15 0 * * *), across 5 DST windows (New York fall-back and spring-forward, London fall-back, both Lord Howe 30-minute transitions). Main: 14 of 40 cases fail. Branch: 40 of 40 pass. Daily30 1fires twice on fall-back day, matching the existing "fires both repeats" policy, and spring-forward still skips the nonexistent 02:00.pnpm test src/shared/automation src/main/persistence/scheduling-automations src/main/automations: 50 files, 451 tests pass.oxlintandoxfmt --checkare clean on the touched files.The DST suite uses
vi.stubEnv('TZ', ...)and is skipped on win32, where Node ignores runtimeTZchanges. The change itself is platform-independent epoch arithmetic. It has no remote/SSH, mobile, folder-workspace, wire, or persistence-format impact.Original fix by @eatmoreduck in #20179 (author preserved on the commit).
Review
:MM, so a skipped minute moves to the next real:MM.Agent skill upstream boundary
Notes
Checked for security, cross-platform (pure epoch arithmetic), remote SSH and mixed versions (no RPC or persistence change), mobile (N/A), backwards compatibility, and performance (the HOURLY walk is bounded at about 60 iterations per call). No issues found.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)