Repository navigation
fix(automations): isolate the scheduler tick and refuse oversized cron steps - #20152
Conversation
There was a problem hiding this comment.
ℹ️ No critical issues — one cross-platform rough edge in the new DST tests.
Reviewed changes
- Cron step expansion (#15723) —
parseCronFieldnow expands a bareN/stepas the open-endedN-max/stepsequence in every field, while a bareNwith no step stays a single value. - Oversized-step input validation (#15895) — a
rejectOversizedStepoption rejects steps wider than a field's distinct-value count at input time, while runtime parsing stays lenient so persisted rows keep their saved cadence. - Lexical day restriction (#15896) —
dayOfMonthRestricted/dayOfWeekRestrictednow derive from the field text (isCronDayFieldRestricted) rather than set cardinality, matching vixie/robfig (*/2is a star, so it stays AND). - Tick isolation (#16303) —
evaluateDueRunsisolates each automation and folds oneskipped_unavailablerun for a poison schedule instead of aborting the whole tick.
The differential proof against robfig/cron v1.2.0 and the end-to-end scheduler run are convincing. The lexical-restriction dialect (following vixie/robfig over the crontab(5) prose, since the stricter reading over-fires by ~8x) and the deliberate "no migration, runtime stays lenient" posture for persisted cadences are both well-argued — no objection to the sign-off the PR body requests.
ℹ️ Nitpicks
recordUnevaluableAutomationlogsconsole.errorbefore therepeatSkipfold, so a permanently-broken automation logs every tick (once per minute) forever even though it only writes one run row. Consider moving the log inside the no-fold branch or rate-limiting it.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between 9f01c71 and 80837f2fce0298b9241799985b67176ecb6a4a96. 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe changes add shared cron-field parsing with strict input validation and runnable persisted-schedule parsing. The scheduler now records unevaluable schedules as skipped runs and continues evaluating later automations. Finalized run usage writes use a shared helper that handles retention eviction. The editor preserves saved schedules so legacy cadences remain editable while new or modified schedules use strict validation. Tests cover cron steps, daylight-saving transitions, scheduler isolation, and legacy schedule editing. Priority: ⬆️ High Merge Risk: 🟡 Moderate · up to Unreadable schedules can repeatedly consume scheduler ticks and generate errors, while some dispatch failures can leave runs stuck in progress. Resolve these scheduler-state issues before merging. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Linked Issues checkExplanation The PR satisfies
✨ 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: f986042d-7d57-4a01-966d-ead95c250902
📒 Files selected for processing (10)
src/main/automations/dispatch-refusal.tssrc/main/automations/run-usage-collection.tssrc/main/automations/service.test.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-parsing.tssrc/shared/automation-schedules.test.tssrc/shared/automation-schedules.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.
There was a problem hiding this comment.
Important
The input-gate vs read-back split leaves the external/Hermes save path strict — a provider-owned row with a legacy oversized-step schedule opens cleanly but blocks on save. See the inline comment on automation-save-action.ts.
Reviewed changes (since prior review)
isRunnable*read-back helpers —isRunnableAutomationSchedule/isRunnableAutomationCronScheduleparse leniently (no oversized-step refusal), so the strictisValid*gate now means "acceptable as new input" only.acceptsAutomationDraftSchedule— the save gate short-circuits when the custom schedule is byte-identical to the saved rrule, so an edit that never touches the schedule (rename, prompt change) is not re-judged.- Renderer read-back switched to lenient —
buildAutomationEditDraft(Orca + external),HermesCronOutputView, andexternal-automation-schedule-displaynow use the runnable check.
The scheduleRuns/cronScheduleRuns refactor preserves prior semantics (RRULE always runs; cron gates on cronHasPossibleOccurrence), and automation-legacy-schedule-editing.test.ts covers the Orca rename-with-legacy-schedule path well.
ℹ️ Nitpicks
- The editor sidebar still live-validates the loaded draft with strict
isValidAutomationSchedule(AutomationSchedulePicker→customScheduleInvalid), so a legacy oversized-step schedule opens withscheduleWarning === nullyet shows an "invalid schedule" status andaria-invalidon the cron field. Cosmetic only (a rename still saves for Orca rows via the byte-identical skip), but it reads as "unsupported" for a schedule the PR elsewhere calls editable.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No new issues in this delta — both prior review findings are addressed.
Reviewed changes (since prior review)
savedScheduleon the draft —AutomationDraftnow carries the cadence the record was opened with (automation.rrulefor Orca rows, the trimmedrawSchedulefor provider-owned rows,nullfor a new automation), so the gate has a record to compare against without re-deriving it from a live list.- One gate for the picker and the save —
AutomationSchedulePicker's live cron status and theAutomationCustomCronPanelstatus now runacceptsAutomationDraftSchedule, so an untouched legacy oversized-step schedule opens withoutaria-invalidor the "fix this before saving" message, while a changed expression is still judged as new input. - External/Hermes save unblocked —
automation-save-action.tspassesdraft.savedScheduleinstead of derivingsavedRrulefromeditingAutomationId(alwaysnullfor provider-owned rows), closing the gap where a Hermes rename carrying a legacy schedule was refused. - Tests —
automation-legacy-schedule-editing.test.tscovers the cron status label andsavedSchedulepropagation; the picker test drafts gained the new field.
The earlier thread on the Windows DST tests in src/shared/automation-cron-dialect.test.ts is untouched by this delta and remains open, so this is a comment review rather than an approval. It stays latent (that file runs on ubuntu-only CI) and is out of scope for this commit.
openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes (since prior review)
- Schedule drift detector —
describeAutomationScheduleDriftreconstructs the pre-repair reading (toPreRepairFieldcollapses a bareN/stepback toN; the day-restriction flags are re-derived from set cardinality) and compares the days both readings match over a 730-day scan plus minute/hour set equality, so it reports only schedules whose actual firing changed. - Startup report —
reportAutomationScheduleDriftnames each affected record, its expression, and the direction and size of the change fromAutomationService.start(); it stays silent when nothing drifted, and both the RRULE and unreadable-schedule paths returnnull. - Tests —
automation-schedule-drift.test.tspins the drifted/stable corpora recorded from the parent build, the exact5/15run-rate, and the RRULE/unreadable exclusions;schedule-drift-report.test.tscovers the log shape and the silent case.
The reconstruction is a faithful inverse of the removed parser: the only pre-repair divergence for a non-star, non-range term was end = start, which toPreRepairField reverses, and the cardinality-based restriction flags match the deleted code. I confirmed locally that the two new suites pass (7 tests) and oxlint is clean.
One prior Pullfrog thread on the Windows DST tests in automation-cron-dialect.test.ts remains open and is untouched by this delta, so this is a comment review rather than an approval.
openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/automations/service.ts (1)
235-235: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winAdvance
nextRunAtor quarantine the automation after an evaluation failure.When
evaluateAutomationthrows,recordUnevaluableAutomationcallsrepeatSkipbut does not updateautomation.nextRunAt.recordRepeatedAutomationSkipchanges only the run record. The same due automation is therefore evaluated on every scheduler tick, repeating the parser failure and error log. Advance the occurrence with a safe fallback, or quarantine the automation until it is edited.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: c86e5f08-9764-469a-a4c0-126a054f0781
📒 Files selected for processing (5)
src/main/automations/schedule-drift-report.test.tssrc/main/automations/schedule-drift-report.tssrc/main/automations/service.tssrc/shared/automation-schedule-drift.test.tssrc/shared/automation-schedule-drift.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.
0886f96 to
9f01c71
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 82a47570-02a8-49f2-82ac-bf6ee142c924
📒 Files selected for processing (4)
src/main/automations/service.tssrc/shared/automation-cron-field-parsing.tssrc/shared/automation-cron-input-validation.test.tssrc/shared/automation-schedule-parsing.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.
| } else { | ||
| start = parseCronNumber(rangePart, args.names ?? null, args.field) | ||
| end = start | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Expand bare stepped values through the field maximum.
For 5/15, Line 107 sets end to start. The loop therefore produces only 5 instead of 5,20,35,50.
Use args.max as the endpoint when a bare value has a step. Add a regression test for 5/15.
Proposed fix
} else {
start = parseCronNumber(rangePart, args.names ?? null, args.field)
- end = start
+ end = stepPart === undefined ? start : args.max
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| } else { | |
| start = parseCronNumber(rangePart, args.names ?? null, args.field) | |
| end = start | |
| } | |
| } else { | |
| start = parseCronNumber(rangePart, args.names ?? null, args.field) | |
| end = stepPart === undefined ? start : args.max | |
| } |
There was a problem hiding this comment.
Deferred to #20202 by design: this PR keeps end = start byte-identical to main so no persisted schedule changes cadence, and the open-ended 5/15 expansion is the semantic half held for an owner decision.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| dayOfMonthRestricted: daysOfMonth.size !== 31, | ||
| dayOfWeekRestricted: daysOfWeek.size !== 7 |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Determine day-field restriction from the source text.
Set size does not preserve cron syntax. For example, 1-31 is lexically restricted despite containing all days. Conversely, */2 starts with a wildcard and is lexically unrestricted despite producing a partial set.
Use the raw dayOfMonth and dayOfWeek fields to set these flags. Add tests that distinguish full-domain ranges and wildcard steps.
- dayOfMonthRestricted: daysOfMonth.size !== 31,
- dayOfWeekRestricted: daysOfWeek.size !== 7
+ dayOfMonthRestricted: isCronDayFieldRestricted(dayOfMonth),
+ dayOfWeekRestricted: isCronDayFieldRestricted(dayOfWeek)There was a problem hiding this comment.
Deferred to #20202 by design: main's cardinality-based flags are preserved here verbatim so 0 9 */2 * 1 keeps its current cadence, and the lexical isCronDayFieldRestricted switch is the semantic half held for an owner decision.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes (since prior pullfrog review)
- Split the semantic half out to #20191 — the bare-
N/stepopen-ended expansion (#15723), the lexical day-restriction flags (#15896), and the schedule drift detector are removed;parseCronField's bare-value branch is back toend = startand the day-restriction booleans are back to set cardinality, both byte-identical tomain. - Retained the scheduler tick isolation —
evaluateDueRunsstill catches per record and folds oneskipped_unavailablerun viarecordUnevaluableAutomation(#16303), with the poison-cron and poison-RRULE path tests. - Retained the oversized-step input gate —
rejectOversizedStepstill refuses a step above a field's distinct-value count at input time only, whileisRunnable*stay lenient for read-back (#15895). - Retained the input-gate/read-back split and
savedSchedule— the picker's live status andautomation-save-action.tsboth route throughacceptsAutomationDraftSchedule, so an untouched legacy oversized-step cadence is neither blocked nor painted red. - Kept the parsing and usage extractions — cron field parsing lives in the new
automation-cron-field-parsing.ts(a pure move;rejectOversizedStepdefaults off) and run-usage writing inwriteAutomationRunUsage. - Moved the DST and oversized-step cases into
automation-cron-input-validation.test.ts— the oldautomation-cron-dialect.test.tsand the drift suites are gone with no dangling references.
The revert is clean and restores main's parser semantics exactly, so the PR's "no existing schedule changes behaviour" claim holds for this branch. I ran the affected suites locally (shared automation-cron-input-validation + automation-schedules, main service, and the renderer automation-legacy-schedule-editing + picker suites) and all pass.
The earlier thread on the Windows DST tests is anchored to a now-deleted file, but the same tests live on in automation-cron-input-validation.test.ts without a win32 skip. It is unchanged by this delta, so I'm leaving it open and this is a comment review rather than an approval.
openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
9f01c71 to
80837f2
Compare
…n steps Two defects that change nothing about when an existing schedule fires. #16303: evaluateDueRuns awaited each row with no catch, so one unreadable schedule skipped every later due automation in that tick. Each row is isolated now; a poison record writes one folded skipped_unavailable run explaining itself and the tick continues. #15895: step validation only checked integer >= 1, so a step wider than its field degraded silently to a single value and still passed validation. Oversized steps are refused at input time only, bounded by the count of distinct values a field holds, so day of week rejects */8 while */7 stays legal. Runtime parsing stays lenient so rows saved before the gate keep running the cadence they have. isValidAutomationSchedule now answers only "acceptable as new input"; a new isRunnableAutomationSchedule answers "can Orca still run this", and the editor uses it so a legacy row opens intact and can be renamed without re-authoring a schedule that is still firing. Field parsing moves to its own module because the schedule parser was already at the 300-line limit. Fixes #16303 Fixes #15895
|
Addressing the review comments before merge. @pullfrog — DST tests and Windows ( @coderabbitai — advance @coderabbitai — bare stepped values should expand through the field maximum ( @coderabbitai — day restriction should come from the source text ( Both of those are the reason this half exists: it carries only the two fixes that change no existing schedule's behaviour, verified as 34/34 expressions firing identically to @pullfrog — external/Hermes |
|
Verified the author's responses against head The one open actionable thread the response did not cover was CodeRabbit's renderer dispatch-failure finding at Verified locally: Task list (6/6 completed)
|
|
Tip For best results, initiate chat on the files or code changes.
Keeping The bare-step and day-restriction changes are intentionally deferred to The 🐇 ✏️ Learnings added
If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! You are interacting with an AI system. |
80837f2 to
731d28a
Compare
A send that throws after the run reached 'dispatching' escaped to the tick's per-record catch and was written as an unreadable schedule, leaving the dispatching run stranded and adding a bogus skipped_unavailable row. Send through a helper that closes the run out as dispatch_failed with the real error instead.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes (since prior pullfrog review)
- Fold logged only when a run is actually written —
recordUnevaluableAutomationnow callsconsole.errorafterruns.repeatSkip, so a permanently-broken record logs once with its singleskipped_unavailablerow instead of once per tick forever. - Catch log carries the original failure — the write-failure path now reports
automation.idand the evaluation error alongsidewriteError, so a poison record whose run write fails is no longer invisible. dispatch-refusal.test.tsadded — pins the contract both ways: a newly-broken record writes exactly one run and logs once, and an already-folded record writes nothing and logs nothing.- DST tests gated for Windows — the
cron occurrence local-time controlsblock is nowdescribe.skipIf(process.platform === 'win32'), matching the repo idiom, so theTZstub and its precondition assertion no longer hard-fail where Node ignoresprocess.env.TZ.
Both previously open concerns are addressed — the external/Hermes save-path thread was resolved earlier, and this commit adds the win32 skip the DST thread asked for; that thread is now retired. Ran the affected suites locally (dispatch-refusal, automation-cron-input-validation, service = 21/21 green) and oxlint on all three touched files (clean).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
Two fixes to Orca's scheduled automations, neither of which changes when any existing schedule runs.
First: if any one automation had a schedule Orca could not read, it gave up on that whole round of checks — so every other automation due at that moment silently did not run. Now a broken one is skipped on its own, with a run record explaining why, and the rest go ahead.
Second: you could ask for something Orca cannot actually do, like "every 90 minutes" (
*/90 * * * *). Orca told you the schedule was fine and then quietly ran it once an hour at the top of the hour. Now it says up front that it can't do that, so you find out while you're typing instead of weeks later. Schedules already saved with one of these keep running exactly as they have been, and you can still rename or edit them without being made to rewrite the schedule.What this PR does
evaluateDueRunsawaited each row with no catch, so a single unreadable schedule skipped every later due automation in that tick. Each row is isolated now; a poison record writes one foldedskipped_unavailablerun explaining itself and the tick continues.5/90 * * * *runs hourly #15895 — an oversized step degraded silently and still validated. Step validation only checkedinteger >= 1, so*/90on minutes quietly collapsed to a single value at:00while passingisValidAutomationSchedule. Oversized steps are refused at input time only, bounded by the count of distinct values a field holds — so day-of-week, which spans0-7but holds seven days, rejects*/8while*/7stays legal.Input gate vs. read-back
isValidAutomationSchedulenow answers only "is this acceptable as new input?" A newisRunnableAutomationScheduleanswers "can Orca still run a value it did not just receive?" The oversized-step refusal belongs only to the first question.--rrule, theAutomationScheduleRPC param, the schedule picker's live validation, the editor sidebar validator, the save action's advanced-schedule gate.buildAutomationEditDraftfor Orca and external rows, the external provider schedule label, the Hermes output schedule label.The editor's save gate additionally skips a custom schedule byte-identical to the saved one, and the picker's live status runs through that same gate, so a cadence the user never touched is neither blocked nor painted red.
saveOrcaAutomationalready omitsrrulefrom the update payload when unchanged, so the RPC gate is never reached for an untouched legacy schedule.Leniency is scoped precisely to the oversized-step gate: a saved schedule that cannot be parsed at all (say
0 9 32 * *) still raises the unsupported-schedule warning rather than silently round-tripping.automation-cron-field-parsing.tsis a new module becauseautomation-schedule-parsing.tswas already at exactly the 300-line limit on main.Every expression in a 34-expression corpus, including all the shapes that do change under the held semantic half, parses and fires identically to
main:What does change is what can be newly entered:
*/90 * * * *,0 */25 * * *,0 9 */32 * *,0 9 * */13 *and0 9 * * */8are now refused at input. An older client or script that submits one to an updated host gets a validation error where it previously succeeded. Already-saved rows keep running and stay editable.Verification
Safety claim, re-established on this head against current
mainThe whole basis for merging this half ahead of the dialect decision:
The second line confirms those 152 commits never touched the cron parser, so nothing moved under the claim.
Exercised: #16303 tick isolation
The real
AutomationServiceagainst a realStorewith real JSON persistence and real timers, poison row ordered first:The last line covers CodeRabbit's finding that a permanently broken record logged once per tick forever.
Exercised: #15895 oversized-step gate, on the real input paths
And through the running Electron app over the live RPC bridge:
Exercised: legacy
*/90row stays editableA
*/90 * * * *row written straight into persistence to stand in for one saved by an older build, opened in the real app over CDP. Measured, not inferred:The schedule is intact, the field is not flagged, and the status is the descriptive label rather than "Enter a valid five-field cron before saving." Filling the name field works (
fillset it toRENAMED legacy sweepwith the cron unchanged), and the save gate is reached —Save Changesbecomesdisabled(isSaving), which by the ordering inautomation-save-action.ts(setIsSaving(true)at line 84, after the schedule gates at 43 and 57) proves both schedule gates passed.Stated plainly, because it was asked for: I could not drive the full click-Save-and-watch-it-persist loop to completion in the app. The save reaches
isSavingand then stops with no toast and no editor notice, and the rename does not land. A control run settles what that is — renaming the healthy0 * * * *automation through the identical path also fails to persist, so the blocker is environmental to my hand-seeded fixture (rows written via raw RPC/data file whose destination and worktree state the editor cannot resolve in a fresh profile), not schedule-related and not something this PR touches. The rename itself round-trips over the realautomation.updateRPC:updateOk: true, name changed,rrulestill*/90 * * * *.Third commit, added by pullfrog[bot] — reviewed and kept
b114935e61a fix(automations): record renderer send failures as dispatch_failedwas pushed to this branch by the bot, not written by me. I reviewed it on the merits and kept it, because it fixes a real defect that this PR's own #16303 change introduced:this.webContents.send(...)can throw (destroyed WebContents). Before #16303 that throw aborted the tick. With the per-record catch added here, it is instead caught and written asUNEVALUABLE_SCHEDULE— "Orca could not evaluate this automation" — which is simply false: the schedule parsed fine, the send failed. The run row, already atdispatching, is left stranded, and a bogusskipped_unavailablerow is written beside it.The fix routes the send through a helper that closes the run out as
dispatch_failedwith the real error. Its test asserts one row, statusdispatch_failed, the true error text, and noconsole.error— i.e. not mislabelled as unevaluable. It uses theAutomationRendererChannelnarrowing added earlier in this PR, so it needs no type assertion.Verified by me on this head: typecheck, changed-code ratchet, oxlint, type-aware lint all pass; 1442 tests across 169 files pass; and the safety claim is unchanged at
identical=34, DIFFERENT=0, since none of it touches schedule parsing.Split from the semantic half
This was originally one PR covering four defects. The two that change what already-saved schedules do — #15723 (step expansion) and #15896 (day restriction) — are split out to #20202, which is held pending an explicit decision, because they move persisted cadences in both directions.
They cannot be split from each other:
0 9 1/1 * 1matches 124 days under the old parser, 104 under #15723 alone, and 730 under both, because the old cardinality-based day flags react to the corrected expansion. These two, by contrast, have no semantic dependency on either.Known limitation, pre-existing and not fixed here
nextAutomationOccurrenceAftercannot advance past the second repeat of an ambiguous DST fall-back hour. Pre-existing and untouched by this PR; pinned by a test so a later fix has to update it deliberately. Tracked as #20154.Fixes #16303
Fixes #15895