Skip to content

fix(automations): isolate the scheduler tick and refuse oversized cron steps - #20152

Merged
nwparker merged 2 commits into
mainfrom
fix/cron-parser
Sep 13, 2026
Merged

nwparker merged 2 commits into
mainfrom
fix/cron-parser

Conversation

@nwparker

@nwparker nwparker commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​488 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​488
Prod 14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​370 $\color{#cf222e}{\Huge{\mathbf{−}}}$​166 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​204

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

Input gate vs. read-back

isValidAutomationSchedule now answers only "is this acceptable as new input?" A new isRunnableAutomationSchedule answers "can Orca still run a value it did not just receive?" The oversized-step refusal belongs only to the first question.

  • Strict (new input): CLI --rrule, the AutomationSchedule RPC param, the schedule picker's live validation, the editor sidebar validator, the save action's advanced-schedule gate.
  • Lenient (read-back / display): buildAutomationEditDraft for 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. saveOrcaAutomation already omits rrule from 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.ts is a new module because automation-schedule-parsing.ts was already at exactly the 300-line limit on main.

⚠️ This PR changes no existing schedule's behaviour — verified

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:

SAFE HALF vs MAIN: 34 expressions, identical=34, DIFFERENT=0

What does change is what can be newly entered: */90 * * * *, 0 */25 * * *, 0 9 */32 * *, 0 9 * */13 * and 0 9 * * */8 are 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 main

The whole basis for merging this half ahead of the dialect decision:

#20152 HEAD vs current origin/main: 34 expressions, identical=34, DIFFERENT=0
old main vs current main (152 commits):                        differences=0

The second line confirms those 152 commits never touched the cron parser, so nothing moved under the claim.

Exercised: #16303 tick isolation

The real AutomationService against a real Store with real JSON persistence and real timers, poison row ordered first:

REAL AutomationService | REAL Store | REAL JSON persistence | REAL timers

  persisted: A poison cron   rrule=0 9 32 * *   nextRunAt=2026-05-13T09:00:00.000Z
  persisted: B healthy cron  rrule=0 9 * * *    nextRunAt=2026-05-13T09:00:00.000Z

  tick 1 console.error lines: 1
    [automations] failed to evaluate automation: 20a611e4-... Error: Invalid cron day of month.

  IPC dispatches: 1
    -> automations:dispatchRequested  automation="B healthy cron"

  after 4 more ticks: console.error lines went 1 -> 1

  A poison cron: rows=1
      status=skipped_unavailable    error=Orca could not evaluate this automation and skipped the occurrence.
  B healthy cron: rows=1
      status=dispatching            error=<none>

  VERDICT healthy dispatched = true
  VERDICT poison isolated    = true
  VERDICT no log spam        = true

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

REAL CLI flag parser: getScheduleFlag(new Map([["trigger", expr]]))

  --trigger '*/90 * * * *'     REFUSED   Invalid automation trigger: */90 * * * *
  --trigger '0 */25 * * *'     REFUSED   Invalid automation trigger: 0 */25 * * *
  --trigger '0 9 */32 * *'     REFUSED   Invalid automation trigger: 0 9 */32 * *
  --trigger '0 9 * */13 *'     REFUSED   Invalid automation trigger: 0 9 * */13 *
  --trigger '0 9 * * */8'      REFUSED   Invalid automation trigger: 0 9 * * */8
  --trigger '*/15 * * * *'     ACCEPTED
  --trigger '0 */24 * * *'     ACCEPTED
  --trigger '0 9 * * */7'      ACCEPTED
  --trigger '30 9 * * 1-5'     ACCEPTED

REAL RPC param schema: AutomationSchedule.safeParse(expr)  [gates automation.create/update]

  '*/90 * * * *'   REFUSED   Invalid automation trigger
  '0 */25 * * *'   REFUSED   Invalid automation trigger
  '0 9 */32 * *'   REFUSED   Invalid automation trigger
  '0 9 * */13 *'   REFUSED   Invalid automation trigger
  '0 9 * * */8'    REFUSED   Invalid automation trigger
  '*/15 * * * *'   ACCEPTED   (and the other three legal steps)

And through the running Electron app over the live RPC bridge:

Healthy hourly     -> CREATED
Attempt oversized  -> REFUSED: {"code":"invalid_argument","message":"Invalid automation trigger"}

Exercised: legacy */90 row stays editable

A */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:

{ cron: "*/90 * * * *", ariaInvalid: "false", status: "Hourly at :00" }

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 (fill set it to RENAMED legacy sweep with the cron unchanged), and the save gate is reached — Save Changes becomes disabled (isSaving), which by the ordering in automation-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 isSaving and then stops with no toast and no editor notice, and the rename does not land. A control run settles what that is — renaming the healthy 0 * * * * 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 real automation.update RPC: updateOk: true, name changed, rrule still */90 * * * *.

Third commit, added by pullfrog[bot] — reviewed and kept

b114935e61a fix(automations): record renderer send failures as dispatch_failed was 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 as UNEVALUABLE_SCHEDULE — "Orca could not evaluate this automation" — which is simply false: the schedule parsed fine, the send failed. The run row, already at dispatching, is left stranded, and a bogus skipped_unavailable row is written beside it.

The fix routes the send through a helper that closes the run out as dispatch_failed with the real error. Its test asserts one row, status dispatch_failed, the true error text, and no console.error — i.e. not mislabelled as unevaluable. It uses the AutomationRendererChannel narrowing 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 * 1 matches 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

nextAutomationOccurrenceAfter cannot 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

@pullfrog pullfrog Bot 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.

ℹ️ No critical issues — one cross-platform rough edge in the new DST tests.

Reviewed changes

  • Cron step expansion (#15723) — parseCronField now expands a bare N/step as the open-ended N-max/step sequence in every field, while a bare N with no step stays a single value.
  • Oversized-step input validation (#15895) — a rejectOversizedStep option 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/dayOfWeekRestricted now derive from the field text (isCronDayFieldRestricted) rather than set cardinality, matching vixie/robfig (*/2 is a star, so it stays AND).
  • Tick isolation (#16303) — evaluateDueRuns isolates each automation and folds one skipped_unavailable run 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

  • recordUnevaluableAutomation logs console.error before the repeatSkip fold, 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 3a9b480d-df9c-4f94-9324-5ff4500ea2a8

📥 Commits

Reviewing files that changed from the base of the PR and between 9f01c71 and 80837f2fce0298b9241799985b67176ecb6a4a96.

📒 Files selected for processing (2)
  • src/main/automations/service.test.ts
  • src/main/automations/service.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The 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 80837

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)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR satisfies #15895. New-input validation passes rejectOversizedStep: true, while runnable parsing keeps the lenient mode for persisted oversized schedules. The editor preserves an unchanged sav… Run headless dispatch outside the scheduler evaluation gate, or apply a bounded timeout with a recorded terminal failure. Ensure the affected occurrence is finalized and the scheduler advances so later due automations continue.
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 35 functions across 27 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The cron parser, strict versus runnable validation, legacy schedule editing, scheduler error recording, and related tests support #15895 or #16303. No demonstrated unrelated change is present.
Title check ✅ Passed The title clearly identifies both main changes: scheduler tick isolation and rejection of oversized cron steps.
Description check ✅ Passed The description provides a clear ELI5 summary, detailed change scope, rationale, linked issues, extensive verification results, compatibility details, and known limitations. It does not use every temp…
Full details: Linked Issues check

Explanation

The PR satisfies #15895. New-input validation passes rejectOversizedStep: true, while runnable parsing keeps the lenient mode for persisted oversized schedules. The editor preserves an unchanged saved schedule. The PR partially satisfies #16303. evaluateDueRuns catches per-automation evaluation errors, records skipped_unavailable, and continues to later automations. However, evaluateAutomation still awaits runHeadlessAutomationDispatch. A non-resolving dispatch, including its precheck or launch work, can still block later due automations.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: f986042d-7d57-4a01-966d-ead95c250902

📥 Commits

Reviewing files that changed from the base of the PR and between 7294915 and eed23d1.

📒 Files selected for processing (10)
  • src/main/automations/dispatch-refusal.ts
  • src/main/automations/run-usage-collection.ts
  • src/main/automations/service.test.ts
  • src/main/automations/service.ts
  • src/shared/automation-cron-dialect.test.ts
  • src/shared/automation-cron-field-parsing.ts
  • src/shared/automation-cron-occurrence.ts
  • src/shared/automation-schedule-parsing.ts
  • src/shared/automation-schedules.test.ts
  • src/shared/automation-schedules.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.

Comment thread src/main/automations/service.ts Resolved

@pullfrog pullfrog Bot 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.

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/isRunnableAutomationCronSchedule parse leniently (no oversized-step refusal), so the strict isValid* 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, and external-automation-schedule-display now 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 with scheduleWarning === null yet shows an "invalid schedule" status and aria-invalid on 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot 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.

ℹ️ No new issues in this delta — both prior review findings are addressed.

Reviewed changes (since prior review)

  • savedSchedule on the draft — AutomationDraft now carries the cadence the record was opened with (automation.rrule for Orca rows, the trimmed rawSchedule for provider-owned rows, null for 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 the AutomationCustomCronPanel status now run acceptsAutomationDraftSchedule, so an untouched legacy oversized-step schedule opens without aria-invalid or the "fix this before saving" message, while a changed expression is still judged as new input.
  • External/Hermes save unblocked — automation-save-action.ts passes draft.savedSchedule instead of deriving savedRrule from editingAutomationId (always null for provider-owned rows), closing the gap where a Hermes rename carrying a legacy schedule was refused.
  • Tests — automation-legacy-schedule-editing.test.ts covers the cron status label and savedSchedule propagation; 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.

Pullfrog  | Fix it ➔ | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Reviewed changes (since prior review)

  • Schedule drift detector — describeAutomationScheduleDrift reconstructs the pre-repair reading (toPreRepairField collapses a bare N/step back to N; 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 — reportAutomationScheduleDrift names each affected record, its expression, and the direction and size of the change from AutomationService.start(); it stays silent when nothing drifted, and both the RRULE and unreadable-schedule paths return null.
  • Tests — automation-schedule-drift.test.ts pins the drifted/stable corpora recorded from the parent build, the exact 5/15 run-rate, and the RRULE/unreadable exclusions; schedule-drift-report.test.ts covers 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.

Pullfrog  | Fix it ➔ | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai coderabbitai Bot 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.

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 win

Advance nextRunAt or quarantine the automation after an evaluation failure.

When evaluateAutomation throws, recordUnevaluableAutomation calls repeatSkip but does not update automation.nextRunAt. recordRepeatedAutomationSkip changes 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9180295 and 0886f96.

📒 Files selected for processing (5)
  • src/main/automations/schedule-drift-report.test.ts
  • src/main/automations/schedule-drift-report.ts
  • src/main/automations/service.ts
  • src/shared/automation-schedule-drift.test.ts
  • src/shared/automation-schedule-drift.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.

@nwparker nwparker changed the title fix(automations): repair cron step expansion, day restriction and tick isolation fix(automations): isolate the scheduler tick and refuse oversized cron steps Sep 12, 2026

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 82a47570-02a8-49f2-82ac-bf6ee142c924

📥 Commits

Reviewing files that changed from the base of the PR and between 0886f96 and 9f01c71.

📒 Files selected for processing (4)
  • src/main/automations/service.ts
  • src/shared/automation-cron-field-parsing.ts
  • src/shared/automation-cron-input-validation.test.ts
  • src/shared/automation-schedule-parsing.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.

Comment on lines +105 to +108
} else {
start = parseCronNumber(rangePart, args.names ?? null, args.field)
end = start
}

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.

🎯 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.

Suggested change
} 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
}

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.

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.

Pullfrog  | View workflow run | via Pullfrog | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment on lines 116 to 117
dayOfMonthRestricted: daysOfMonth.size !== 31,
dayOfWeekRestricted: daysOfWeek.size !== 7

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.

🎯 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)

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.

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.

Pullfrog  | View workflow run | via Pullfrog | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Reviewed changes (since prior pullfrog review)

  • Split the semantic half out to #20191 — the bare-N/step open-ended expansion (#15723), the lexical day-restriction flags (#15896), and the schedule drift detector are removed; parseCronField's bare-value branch is back to end = start and the day-restriction booleans are back to set cardinality, both byte-identical to main.
  • Retained the scheduler tick isolation — evaluateDueRuns still catches per record and folds one skipped_unavailable run via recordUnevaluableAutomation (#16303), with the poison-cron and poison-RRULE path tests.
  • Retained the oversized-step input gate — rejectOversizedStep still refuses a step above a field's distinct-value count at input time only, while isRunnable* stay lenient for read-back (#15895).
  • Retained the input-gate/read-back split and savedSchedule — the picker's live status and automation-save-action.ts both route through acceptsAutomationDraftSchedule, 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; rejectOversizedStep defaults off) and run-usage writing in writeAutomationRunUsage.
  • Moved the DST and oversized-step cases into automation-cron-input-validation.test.ts — the old automation-cron-dialect.test.ts and 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.

Pullfrog  | Fix it ➔ | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

…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
@nwparker

Copy link
Copy Markdown
Contributor Author

Addressing the review comments before merge.

@pullfrog — DST tests and Windows (automation-cron-dialect.test.ts:176): fixed, good catch. Node reads the OS timezone on Windows and ignores a runtime process.env.TZ change, so the precondition assertion would hard-fail there rather than skip. That describe now lives in automation-cron-input-validation.test.ts after the split and is gated with describe.skipIf(process.platform === 'win32'), matching linux-package-update-recovery.test.ts and zsh-startup-hook-user-config-equivalence.live-shell.test.ts.

@coderabbitai — advance nextRunAt or quarantine after an evaluation failure (service.ts:235): partly taken. Not advancing nextRunAt: leaving the record due is deliberate, so a schedule the user repairs resumes on its own rather than waiting for the next occurrence. But you are right that the failure repeated every tick — console.error ran before the fold check, so a permanently broken record logged once per tick forever. The log now sits after the fold, so a newly broken record reports once and a record already reported stays silent. dispatch-refusal.test.ts pins both halves, and the end-to-end exercise shows console.error lines going 1 -> 1 across five real scheduler ticks.

@coderabbitai — bare stepped values should expand through the field maximum (automation-cron-field-parsing.ts:108): correct, and deliberately not in this PR. That is #15723. It changes what already-saved schedules do (5/15 goes from ~8,760 to ~35,040 runs/year), so it was split out to #20202 and is held pending an owner decision. end = start here is byte-identical to main on purpose.

@coderabbitai — day restriction should come from the source text (automation-schedule-parsing.ts:117): also correct, also deliberately not in this PR. That is #15896, same split, same reason — 0 9 */2 * 1 moves from ~212 to ~27 runs/year. main's cardinality flags are preserved here verbatim. Your suggested isCronDayFieldRestricted implementation is exactly what #20202 lands.

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 main.

@pullfrog — external/Hermes savedRrule (automation-save-action.ts:59): already resolved in 9180295 and re-confirmed by your later review; savedSchedule is carried on the draft (rawSchedule for provider-owned rows) and the gate reads it rather than deriving from editingAutomationId.

@pullfrog

pullfrog Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Verified the author's responses against head 731d28a: all accurate (Windows DST block is describe.skipIf(process.platform === 'win32') at automation-cron-input-validation.test.ts:52; console.error now sits after the repeatSkip fold; end = start and the cardinality day flags are byte-identical to main; savedSchedule is carried on the draft).

The one open actionable thread the response did not cover was CodeRabbit's renderer dispatch-failure finding at service.ts:237. Implemented it in b114935e61: requestDispatch now sends through a new sendRendererDispatch helper in dispatch-refusal.ts, which closes the run out as dispatch_failed with the send's own error rather than letting it reach the tick's catch as an unreadable schedule. Added a regression test where send throws, asserting exactly one run in dispatch_failed with no skipped_unavailable row.

Verified locally: service.test.ts + dispatch-refusal.test.ts 17/17 pass, pnpm tc:node clean, oxlint clean (stayed within the 300-line cap on service.ts), changed-code quality gate clean. Replies posted to the three open threads; the dispatch thread is resolved, and the two deferred-to-#20202 threads are left open as designed.

Task list (6/6 completed)
  • Checkout PR 20152 branch
  • Fetch review comments and read threads
  • Verify each finding against actual code
  • Implement sound fixes if needed
  • Test/commit/push and reply/resolve threads
  • Report progress summary

Pullfrog  | View workflow run | via Pullfrog | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@nwparker Thanks for the detailed resolution.

Keeping nextRunAt due supports automatic recovery after the user repairs a schedule. Moving console.error after the fold prevents repeated logs for the same unavailable occurrence. The added tests and multi-tick verification cover the concern I raised.

The bare-step and day-restriction changes are intentionally deferred to #20202 because they change existing schedule behavior. That separation is consistent with this PR’s compatibility scope.

The savedSchedule handling also preserves the original provider-owned rawSchedule for editor validation.

🐇


✏️ Learnings added
Learnt from: nwparker
URL: https://github.com/stablyai/orca/pull/20152

Timestamp: 2026-09-13T05:35:24.283Z
Learning: In `src/main/automations`, an automation whose schedule cannot be evaluated must keep `nextRunAt` due so that a user repair resumes scheduling without waiting for a later occurrence. Repeated unavailable-schedule failures must be folded before `console.error` so the same occurrence produces one run record and one log entry rather than repeating on every scheduler tick.

Learnt from: nwparker
URL: https://github.com/stablyai/orca/pull/20152

Timestamp: 2026-09-13T05:35:24.283Z
Learning: Cron semantic changes for bare stepped values such as `5/15` and lexical day-field restriction detection are intentionally deferred to GitHub issue `#20202` because they change behavior for persisted schedules. The compatibility-preserving scheduler validation work must retain the existing cardinality behavior.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


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.

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.

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Reviewed changes (since prior pullfrog review)

  • Fold logged only when a run is actually written — recordUnevaluableAutomation now calls console.error after runs.repeatSkip, so a permanently-broken record logs once with its single skipped_unavailable row instead of once per tick forever.
  • Catch log carries the original failure — the write-failure path now reports automation.id and the evaluation error alongside writeError, so a poison record whose run write fails is no longer invisible.
  • dispatch-refusal.test.ts added — 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 controls block is now describe.skipIf(process.platform === 'win32'), matching the repo idiom, so the TZ stub and its precondition assertion no longer hard-fail where Node ignores process.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).

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit 8759b25 into main Sep 13, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant