Skip to content

feat(core): in-tree cron and @every schedule parser (#578) - #604

Merged
ajianaz merged 1 commit into
developfrom
feat/ledger-cron
Nov 11, 2026
Merged

ajianaz merged 1 commit into
developfrom
feat/ledger-cron

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What

First half of the automation ledger core (#578): a small in-tree schedule parser in tole-core — 5-field cron, the @hourly/@daily/… macros and @every <duration> — with next-occurrence math. Pure and UTC-only: times are Unix seconds passed in by the caller, nothing reads a clock. The ledger (claim, fold, recovery, catch-up) follows in a second PR on the same issue, stacked on this one.

Why

Part of #578 (epic #577). The scheduler must validate a schedule on save and never "just not run" (design docs/automation-design.md §2 P5, §4). The issue and design ask for an in-tree parser over a crate: Cargo.lock has no cron crate, and the widely used cron crate pulls chrono and nom into tole-core, which embedders build --no-default-features. No new dependency here.

The PR is split to stay reviewable (the full #578 change is ~2.5k lines with tests); this part is ~740 lines and self-contained.

Changes

  • crates/tole-core/src/cron.rs (new): Schedule::parse / next_after / span, Hinnant civil-date helpers.
    • Fields: *, N, A-B, */S, A-B/S, comma lists; month and weekday names (case-insensitive); weekday 0 and 7 are Sunday. N/S is rejected as ambiguous (implementations disagree) with a hint to write N-MAX/S.
    • Day rule (documented and tested): Vixie cron / cronie. A day-of-month or day-of-week field whose text starts with * (so * and */2) is unrestricted; if either day field is unrestricted, both must match (AND); if both are restricted, either may match (OR): 0 0 13 * 5 = every 13th and every Friday.
    • Malformed input fails with a precise reason naming the field and value (e.g. "minute field 60: value 60 out of range 0-59", "range 5-2 is reversed", "step 0 out of range"). An expression that can never fire (0 0 30 2 *) is rejected at parse time; a search over one 400-year Gregorian cycle (146 097 days, a whole number of weeks) is a complete check.
    • @every / every: units d h m s (1h30m), at least 60 s, at most 366 days; occurrences are anchor + k·period, k ≥ 1.
    • span(after, until, anchor) returns first/last/count of owed occurrences (O(1) for @every), which the ledger uses to record every skipped occurrence.
    • Time zones (feat(cron): explicit per-job time zones with pluggable sources #580) will add a zone argument to next_after; the expression text and the log format do not change.
  • crates/tole-core/src/lib.rs: pub mod cron;.
  • docs/epics.md: Track E status — feat(core): append-only ledger core — claim, fold, recovery and cron parser #578 in progress, parser landed (the README status line is updated with the ledger PR, which is the first user-relevant piece).
  • crates/tole-core/tests/cron_schedule.rs (new): parser tables, dom/dow semantics, month ends and leap years (2024, 2000, 2100, 2096→2104), span, and a property test (below).

Testing

  • Property test: 400 random expressions (seeded xorshift, no new dependency) from random and edge start times (leap days, century years, month and year ends); next_after must equal a brute-force minute walker that keeps its own calendar counters (independent of the civil-date code under test) over a 120-day window, plus three chained occurrences each. Teeth: with the month-skip deliberately broken (m >= 11 instead of m == 12), the oracle test and the month-end test go red; restored, green.
  • cargo fmt --all — clean
  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • cargo test --workspace — 1326 passed, 0 failed
  • cargo build -p tole-core --no-default-features and cargo test -p tole-core --no-default-features — pass (434 passed, 0 failed)
  • cora review --no-llm --base origin/develop (cora 0.20.0, deterministic rules) — no issues found
  • Binary size (cargo build --release -p tole-cli): measured in the ledger PR, see there

Part of the automation ledger core: 5-field cron with the Vixie/cronie
day-of-month/day-of-week rule, macros and @every durations, with
next-occurrence math and owed-occurrence spans. UTC only; zones follow
in #580. Malformed and never-firing expressions are rejected with a
precise reason. Property-tested against a minute-walking oracle.
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 0911ba7 into develop Nov 11, 2026
19 of 20 checks passed
@ajianaz
ajianaz deleted the feat/ledger-cron branch November 20, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants