Repository navigation
fix(automations): repair cron step expansion and day restriction [HELD — semantic half] - #20202
Conversation
There was a problem hiding this comment.
ℹ️ No code issues found — one release-sequencing note below.
Reviewed changes
This run reviewed the semantic half of the cron repair (diff against fix/cron-parser): the field parsing change, the day-restriction rule, schedule classification, and the new drift detector/report.
- Open-ended
N/stepexpansion —parseCronFieldnow reads a bare value carrying a step asN-max/stepin every field, so5/15expands to[5,20,35,50]instead of collapsing to[5](src/shared/automation-cron-field-parsing.ts:112). - Lexical day restriction —
isCronDayFieldRestricteddecides restriction per comma term from the field text rather than from expanded set cardinality, andparseCronExpressionuses it for both day fields (src/shared/automation-cron-field-parsing.ts:145,src/shared/automation-schedule-parsing.ts:115). A star step stays a star, so*/1and*/2do not flip the day rule to OR. - Occurrence and classification — the OR/AND branch is unchanged but now keyed off the lexical flags (
src/shared/automation-cron-occurrence.ts:33), andclassifyParsedCronSchedulederives hourly/daily labels from matched-day coverage and gates weekdays/weekly on!matchesEitherDayField(src/shared/automation-schedules.ts:91). - Startup drift report —
describeAutomationScheduleDriftreconstructs the pre-repair reading and compares firing days plus clock sets;reportAutomationScheduleDriftlogs each affected saved automation once fromAutomationService.start()(src/shared/automation-schedule-drift.ts,src/main/automations/service.ts:114). - Tests — an independent hand-calendar oracle for the dialect, a drift corpus recorded from the parent build, and a report/spy test. I ran the five related files (48 tests) green and oxlint clean on all 11 changed files.
I independently checked the drift detector's pre-repair reconstruction against main:src/shared/automation-schedule-parsing.ts (which used end = start for a bare stepped value and cardinality-based day flags). The rewrite-then-reparse approach reproduces that parser exactly, so the detector's classification is faithful by construction, not only for the recorded corpus.
ℹ️ Persisted cadence changes while the user-visible notice is still deferred
The repair is correct, but it changes when already-saved custom cron schedules fire — up to roughly 4x more for 5/15-style steps, and roughly 8x fewer for */2-style day fields paired with a weekday — with no migration and no prompt. The only in-product mitigation in this PR is a console.warn at startup; the notice tracked in #20195 is not included. That is the author's release gate rather than a code defect, so no change is requested — flagging it only so the hold is lifted deliberately rather than by a routine review pass.
Technical details
# Deferred user-visible notice for persisted cadence changes
## Affected sites
- `src/main/automations/schedule-drift-report.ts:20` — the startup `console.warn` is the only signal; packaged builds surface it only in logs.
- `src/shared/automation-schedule-drift.ts:90` — detector is correct and already available for #20195 to build on.
## Required outcome
- Ship the semantic repair only with an explicit owner sign-off, and land #20195 (persisted-UI-state notice across 7 locale catalogs) for affected users.openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
9f01c71 to
80837f2
Compare
a0c345c to
fe1fada
Compare
80837f2 to
731d28a
Compare
fe1fada to
ad548a5
Compare
ad548a5 to
e5c9c49
Compare
📝 WalkthroughWalkthroughThe change updates cron parsing for bare stepped values and lexical day-field restrictions. Schedule classification now uses parsed day coverage with the corresponding OR or AND semantics. New drift detection compares current schedules with pre-repair interpretations over a 730-day scan. Automation startup reports affected schedules and their changed annual frequencies. Tests cover parsing, classification, drift detection, and warning output. Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🔵 Low · up to Startup drift reporting can regress silently without failing current service tests. Add a service-level assertion before merging. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Linked Issues checkExplanation
Resolution Implement scheduler isolation for ✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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: 81215c0a-5bd5-4fd0-adea-74340d730813
📒 Files selected for processing (11)
src/main/automations/schedule-drift-report.test.tssrc/main/automations/schedule-drift-report.tssrc/main/automations/service.tssrc/shared/automation-cron-dialect.test.tssrc/shared/automation-cron-field-parsing.tssrc/shared/automation-cron-occurrence.tssrc/shared/automation-schedule-drift.test.tssrc/shared/automation-schedule-drift.tssrc/shared/automation-schedule-parsing.tssrc/shared/automation-schedules.test.tssrc/shared/automation-schedules.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.
| void this.evaluateDueRuns() | ||
| }, this.tickMs) | ||
| this.completionWatcher?.reconcileRetainedRuns(this.store.listAutomationRuns()) | ||
| reportAutomationScheduleDrift(this.store.listAutomations()) | ||
| // Why: headless serve never gets a renderer-ready IPC, but due runs still | ||
| // need the same startup catch-up pass desktop gets after renderer attach. | ||
| if (this.rendererReady || this.headlessDispatcher) { |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Add a service-level assertion for startup drift reporting. src/main/automations/service.test.ts calls AutomationService.start() but only asserts dispatch and persisted run state. schedule-drift-report.test.ts tests reportAutomationScheduleDrift directly. A regression that removes or moves the start() call can therefore pass the current service tests.
c3c4c68 to
b2dccf2
Compare
The semantic half of the cron repair. Both defects change what an already-saved schedule does, so they ship together and behind a decision. #15723: parseCronField set end = start for a bare numeric field even with a slash step, so 5/15 expanded to [5] and fired hourly instead of every fifteen minutes. N/step is the open-ended N-max/step sequence now. #15896: day restriction came from expanded set cardinality, so 1-31 read as unrestricted and */2 as restricted. Restriction is lexical now: a day field restricts iff no term of it ranges over a star, matching vixie cron and robfig/cron rather than crontab(5)'s prose. Verified differentially against robfig/cron v1.2.0 across 22 expressions, 424 days, zero divergences. The two cannot ship apart: 0 9 1/1 * 1 matches 124 days under the old parser, 104 under #15723 alone, and 730 under both, because the old cardinality flags react to the corrected expansion. describeAutomationScheduleDrift reads a saved expression under both semantics and reports the ones that moved, so neither direction is silent; the service names them once at startup. No expression Orca's own presets generate drifts. Fixes #15723 Fixes #15896
b2dccf2 to
daa2a06
Compare
…blyai#20202) The semantic half of the cron repair. Both defects change what an already-saved schedule does, so they ship together and behind a decision. stablyai#15723: parseCronField set end = start for a bare numeric field even with a slash step, so 5/15 expanded to [5] and fired hourly instead of every fifteen minutes. N/step is the open-ended N-max/step sequence now. stablyai#15896: day restriction came from expanded set cardinality, so 1-31 read as unrestricted and */2 as restricted. Restriction is lexical now: a day field restricts iff no term of it ranges over a star, matching vixie cron and robfig/cron rather than crontab(5)'s prose. Verified differentially against robfig/cron v1.2.0 across 22 expressions, 424 days, zero divergences. The two cannot ship apart: 0 9 1/1 * 1 matches 124 days under the old parser, 104 under stablyai#15723 alone, and 730 under both, because the old cardinality flags react to the corrected expansion. describeAutomationScheduleDrift reads a saved expression under both semantics and reports the ones that moved, so neither direction is silent; the service names them once at startup. No expression Orca's own presets generate drifts. Fixes stablyai#15723 Fixes stablyai#15896

ELI5
Orca was misreading two kinds of cron schedule, so a schedule that said one thing was doing another.
If you asked for "every 15 minutes, starting at 5 past" (
5/15 * * * *), Orca threw away the "every 15 minutes" part and ran it once an hour — four times less often than you asked. And if you combined a day-of-month with a day-of-week, Orca got confused about when to treat that as "either day" versus "only when both match", so those automations ran on the wrong days.This fixes both. The catch: schedules you already saved will start running on a different cadence — that is the bug being fixed, but it is a real change that happens under you at upgrade. Some fire more often, some less. Schedules Orca itself created for you (Hourly, Daily, Weekdays, Weekly) are completely unaffected — only a hand-written "Custom cron" can change.
The two defects
5/15runs hourly, and validates #15723 — a bare stepped value dropped its step.parseCronFieldsetend = startfor a bare numeric field even when a slash step followed, so5/15expanded to[5]instead of[5,20,35,50].N/stepnow expands as the open-endedN-max/stepsequence, in every field; a bareNwith no step is still only itself.*— OR/AND day matching diverges from vixie #15896 — day restriction was derived from set cardinality, not from the field text.dayOfMonthRestrictedwasdaysOfMonth.size !== 31, so1-31read as unrestricted (AND) and*/2read as restricted (OR). Restriction is now lexical — see the dialect note below.These two cannot be split from each other
0 9 1/1 * 1, matching days over a 730-day window:Shipping the step fix without the dialect fix produces a third behaviour matching neither, because the old cardinality-based day flags react to the corrected expansion. They ship together or not at all. #16303 and #15895 had no such dependency, which is why they are in #20152.
Declared dialect, and the vixie divergence
A day field is restricted iff no comma-term of it ranges over a star. So
1-31and1,15restrict;*,*/2and*/3,5do not. When both day fields are restricted the day matches on either; otherwise on both.This resolves an open question flagged during implementation. The original implementation used the stricter rule "restricted iff the field is not the literal
*", which makes*/2restricted. That reading has real support —crontab(5)says:But vixie's own
entry.csetsDOM_STAR/DOW_STARfrom the field's first character, so vixie itself treats*/2as a star, contradicting its own man page.robfig/crondoes the same and pins it in its test suite (parser_test.go:31asserts*/2carriesstarBit).We follow the implementations over the prose. Measured against
robfig/cronv1.2.0, the stricter reading was the only source of disagreement, and it diverged badly in the over-firing direction:*"0 9 */2 * 10 9 */1 * 1*/1is also a regression against shipped Orca behavior — the old cardinality rule expanded it to 31 days and therefore already treated it as unrestricted (AND). Since Orca automations launch agents that consume tokens and create worktrees, silently firing a persisted*/2schedule 8x more often is the worst available failure mode.Note the reported #15896 defect —
1-31reading as unrestricted — is fixed either way; the two candidate rules agree on it.One knowing divergence remains: the star test is applied per comma term, so
5,*/2is unrestricted here and in robfig, while vixie's first-character test would call it restricted. Nobody writes that, and the per-term rule is explicable in one sentence where vixie's positional accident is not.Verification
Differential proof against an independent oracle. Expectations were not computed with the code under test.
robfig/cronv1.2.0 (Go) was driven as the oracle over 22 expressions x 424 days (2026-01-01..2027-02-28) plus 60 minutes each: zero divergences.robfig/croncaps day-of-week at 6 and cannot express Sunday-as-7, so that class was anchored by equivalence against oracle-validated forms:Real end-to-end scheduler run. The actual
AutomationServicewas driven against a realStorewith real JSON persistence, with a poison cron row sorted before a healthy one:DST / timezone,
America/New_York, real boundaries:Tests,
oxlint,oxfmt --checkandpnpm tcall pass (265 tests across the 29 affected files).Why this changes when existing automations fire
Because the parser was misreading saved expressions. A schedule that said one thing was doing another. Correcting the reading necessarily changes the doing — there is no way to fix the misreading and leave the behaviour alone, because the behaviour was the misreading.
This is not a redefinition of cron. Nothing about the cron language changed. Orca is starting to obey what the user already wrote, the way every other cron implementation already does — verified against
robfig/cronv1.2.0 across 22 expressions x 424 days with zero divergences.Three expression shapes change. Nothing else does.
1. A value carrying a step —
5/15(#15723):05only — once an hour. The parser kept the start value and silently dropped the step.:05, :20, :35, :505/15means5-59/15in every cron implementation.Same shape in any field:
9/4(hours),1/7(day-of-month),MAR/3(months),1/2(weekday).2. A full range spelled out next to a specific weekday —
0 9 1-31 * 1(#15896)crontab(5)documents.3. A stepped star in a day field next to a specific weekday —
0 9 */2 * 1(#15896)*/2is still a star: they asked for a stride across all days, not a list of particular days. vixie cron androbfig/cronboth read it this way.This is the only shape where the correction makes an automation fire less often, and it is the one worth reviewing by hand.
Schedules Orca created are not affected
All 256 expressions Orca's own preset builder can generate — Hourly, Daily, Weekdays, Weekly, across every hour/minute/weekday — were run through the drift detector: zero drift. Only a hand-written "Custom cron" expression in one of the three shapes above can change. A user who never opened the advanced cron field sees no change at all.
Detection shipped with this PR
describeAutomationScheduleDriftreads a saved expression under the pre-repair semantics and under the current ones and reports the ones that moved. It needs no second parser: pre-repair reading is reproduced by rewriting a bare stepped term to its value (5/15->5) and deriving the day flags from set cardinality, then re-using the current parser. Cost is a parse plus a 730-day day-match walk — trivially affordable at startup.It compares what a schedule fires, not how it parsed: the restriction flags move on several expressions whose firing days do not (
0 9 * * 0-6,0 9 */2 * *,0 9 1-31 * *,0 9 * * */2), and naming those would train the reader to ignore the report. Classification is tested against behaviour recorded from the real pre-repair build.The service names each affected record once at startup. A user-visible one-time notice is tracked in #20195, which needs a persisted-UI-state field and copy across 7 locale catalogs.
This is not a pure bug fix. Automations users already saved will fire on a different schedule after upgrade, in both directions, with no migration and no prompt. Measured by running the same expressions through the real parent build and this branch:
5/15 * * * *0 9 1-31 * 10 9 1/7 * *0 9 */2 * 10 9 */3 * 1Two distinct hazards, and the second is the one that will not get reported:
new_per_runmode, 4× the worktrees — starting the moment a user upgrades.Both behaviours are correct — the old readings were the bugs in #15723 and #15896, and preserving them would mean preserving the bugs. This section is not asking for a compatibility shim; it is asking for an explicit, informed sign-off that this is shipped knowingly.
What this PR does about it. Affected records are detected and named once at startup, so both directions are findable instead of silent:
That is real output from the running app. Detection is exact about which schedules it names: it compares what a schedule fires, not how it parsed, because the day-restriction flags move on several expressions whose firing days do not change (
0 9 * * 0-6,0 9 */2 * *,0 9 1-31 * *,0 9 * * */2) — naming those would train people to ignore the report. The classification is tested against behaviour recorded from the real pre-repair build.What it does not do: there is no in-product notice yet. That needs a persisted-UI-state field and copy across 7 locale catalogs, which is its own change — tracked in #20195, which already has the detector to build on.
Things a user will notice that are not in the table:
*/90 * * * *,0 */25 * * *,0 9 * * */8) is now refused as new input. Already-saved ones keep running and stay editable, but an older client or script that submits one to an updated host gets a validation error where it previously succeeded.5/15-style schedules now read "Custom schedule" instead of "Hourly at :05". The old label was wrong, but it is a readability downgrade.0 9 */1 * 1is unchanged — it fired on Mondays before and fires on Mondays now. An earlier draft of this description claimed otherwise; that was measured against an intermediate dialect that was overturned and never shipped.Visual proof
Captured against the real Electron app via CDP on a hidden renderer (
ORCA_BACKGROUND_LAUNCH=1), same seeded automations on both sides. The sidebar in each shot self-identifies the build.#15723 in the automations list — parent
729491597f3vs this branchAn automation saved as
5/15 * * * *, meaning "every 15 minutes starting at :05". On the parent, Orca labels it "Hourly at :05" and schedules the next run 36 minutes out. On this branch the same row is a genuine 15-minute cadence with the next run 3 minutes out. Both next-run values were computed by the build in the screenshot, not seeded.Before — parent commit (sidebar:
Detached HEAD @ 7294915)After — this branch (sidebar:
fix/cron-parser)5/15 * * * *0 9 */2 * 10 9 * * 1-5The middle row is the #15896 dialect change made visible: the same expression moves off Sunday and onto Monday.
Legacy oversized-step schedule stays editable
A row holding
*/90 * * * *, written into persistence directly to stand in for one saved by an older build. Opening it must not demand re-authoring a schedule that is still firing.The first screenshot is the second commit of this PR, where the save gate was fixed but
AutomationSchedulePickerstill ran the strict validator directly — the field is red and reads "Enter a valid five-field cron before saving." This screenshot is what caught that gap; the unit tests had not. The third commit routes the picker through the same gate.Before — red field, "Enter a valid five-field cron before saving."
After — normal field, status reads "Hourly at :00" (
aria-invalidmeasured astrue->false)Renaming that row was then exercised over the real
automation.updateRPC against the running app:updateOk: true, name changed,rrulestill*/90 * * * *— the strictAutomationScheduleparam never rejects it, because the save transaction omits an unchangedrrule.Gap, stated rather than papered over: the rename was driven through the RPC and through the gate's unit tests, not by typing into the editor's name field and clicking Save. I could not reliably drive that React input through CDP. What is proven in the real UI is that the editor opens with the schedule intact, raises no warning, and leaves Save Changes enabled (measured
disabled: false).Known limitation, pre-existing and not fixed here
nextAutomationOccurrenceAftercannot advance past the second repeat of an ambiguous fall-back hour.floorToMinutedecomposes to local wall-clock fields, and local01:30on a fall-back date maps to two instants; reconstruction picks the earlier (EDT) one, so the forward scan lands back on the EST repeat and returns the input unchanged. BecauseadvanceAutomationNextRuncomputesnextRunAtfromnow, an automation scheduled inside the repeated hour can havenextRunAt <= nowand re-fire once per tick until local time leaves that hour — roughly once a year, for schedules landing in01:00-02:00local.This is pre-existing and untouched by this PR (the occurrence math changes by one comment; for
30 1 * * *the parsed sets are byte-identical before and after). It is now pinned by an explicit test so a future DST fix has to update it deliberately.Tracked as #20154, which carries the full repro, the
floorToMinutecause, the proof it is not a regression, and the policy question a fix must settle first (should a fall-back repeat fire once or twice?).Fixes #15723
Fixes #15895
Fixes #15896
Fixes #16303
Fixes #15723
Fixes #15896