Skip to content

fix: harden cron and wake time boundaries - #308

Merged
ryuzdev merged 1 commit into
mainfrom
fix/292-294-cron-wake-bounds
Nov 27, 2026
Merged

ryuzdev merged 1 commit into
mainfrom
fix/292-294-cron-wake-bounds

Conversation

@ryuzdev

@ryuzdev ryuzdev commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Cron timestamp arithmetic now returns None instead of wrapping past i64::MAX, wake keys round-trip variable-width years, and L-xW month-end matching cannot fire twice. Nine focused and 400-year-cycle regressions cover the boundaries.

Closes #292
Closes #293
Closes #294

Summary by CodeRabbit

  • Bug Fixes
    • Corrected cron matching for schedules based on the last weekday of a month, including cases where the nominal date falls on a weekend.
    • Improved handling of schedules near the maximum representable timestamp, avoiding invalid next-occurrence results.
    • Updated wake-time parsing to support years with four or more digits while continuing to reject invalid dates and times.
    • Preserved expected results for ordinary schedules and valid wake times.

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Cron scheduling now avoids duplicate L-xW matches and returns None when a next occurrence exceeds the timestamp range. Wake-key parsing accepts years longer than four digits and rejects unrepresentable timestamps.

Changes: Cron matching and timestamp bounds

Layer / File(s) Summary
Cron matching and timestamp bounds
crates/logic/cron.rs, crates/logic/tests/cron_wake_bounds.rs
LastOffsetWeekday suppresses the Monday match when the Friday match falls within the month. next_after uses checked arithmetic and returns None on overflow. Tests cover matching, schedule results, and timestamp bounds.

Wake-key parsing bounds

Layer / File(s) Summary
Variable-width wake-key parsing
crates/logic/wake.rs, crates/logic/tests/cron_wake_bounds.rs
parse_minute accepts years with four or more digits, validates date and time fields, and returns None when the resulting timestamp is outside the i64 range. Tests cover round trips, malformed keys, and migration seed keys.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: ry

Merge Risk: Minimal · up to ddc5c

This change makes cron next-occurrence calculation return nothing instead of a wrapped timestamp near the i64 limit, lets wake keys with years of five or more digits round-trip, and stops L-xW month-end schedules from firing twice. No concrete defects remain after review, and regression tests cover the boundary cases. The merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix: harden cron and wake time boundaries" matches the main change. The PR hardens cron next_after arithmetic against i64::MAX overflow, makes wake keys parse variable-width years (such as …
Linked Issues check Passed [#292] cron::next_after (crates/logic/cron.rs) now uses checked_mul/checked_add for the final day-to-minute and minute-to-millisecond conversion. It returns None when the result is unrepresent…
Out of Scope Changes check Passed The source diffs for crates/logic/cron.rs and crates/logic/wake.rs change only the code paths named by #292, #293, and #294. The two_digits helper and the i128 change to days_from_civil support …
Full details: Title check

Explanation

The title "fix: harden cron and wake time boundaries" matches the main change. The PR hardens cron next_after arithmetic against i64::MAX overflow, makes wake keys parse variable-width years (such as year 10000), and stops L-xW month-end matching from firing twice. The title names the cron and wake boundary areas, and the conventional fix: prefix signals a bug fix. It does not name the L-xW double-match fix, but it does not need to cover every detail.

Full details: Linked Issues check

Explanation

[#292] cron::next_after (crates/logic/cron.rs) now uses checked_mul/checked_add for the final day-to-minute and minute-to-millisecond conversion. It returns None when the result is unrepresentable, so next_after(MAX) no longer wraps to a negative timestamp. The ? operator returns None from the function as required.

[#293] parse_minute (crates/logic/wake.rs) no longer requires a fixed 16-character bucket. It splits on T, -, and : and accepts a year of four or more ASCII digits. minute_bucket writes {y:04}, so year 10000 produces 10000-01-01T00:00, and this parser now accepts that form. The round-trip check minute_bucket(ms) == minute still rejects non-canonical input such as February 30th. days_from_civil uses i128, and i64::try_from returns None when the result is out of range.

[#294] In day_of_month_matches, the LastOffsetWeekday Monday arm now requires target - last != 2 || day <= 3. For L-2W in August 2026 (last = 31), the Friday 28th matches through the Friday arm. Monday 31st has target - last == 2 and day = 31 > 3, so it no longer matches. Monday still matches when the Friday falls outside the month (day <= 3). The guard follows from the nominal-date arithmetic: target - last == 2 identifies a Saturday nominal date.

The PR summary reports regression tests in crates/logic/tests/cron_wake_bounds.rs for these boundaries. I assessed those tests from the summary only. I did not run them. Neither issue requires tests explicitly.

Full details: Out of Scope Changes check

Explanation

The source diffs for crates/logic/cron.rs and crates/logic/wake.rs change only the code paths named by #292, #293, and #294. The two_digits helper and the i128 change to days_from_civil support the #293 parser and the #292 overflow checks. The added header comments in both files attribute the changes to the linked issues. The test file (crates/logic/tests/cron_wake_bounds.rs), as described in the summary, covers the same three boundaries. The PR contains no unrelated changes that I could identify. I did not inspect the full test file contents.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3365e5bf-36cb-4b59-88cb-a8d99e7bbb50
Commits

Reviewing files that changed from the base of the PR and between 74a0e3e and ddc5c71.

Files selected for processing: 3

  • crates/logic/cron.rs
  • crates/logic/tests/cron_wake_bounds.rs
  • crates/logic/wake.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@ryuzdev
ryuzdev force-pushed the fix/292-294-cron-wake-bounds branch 3 times, most recently from d264153 to cebfab5 Compare November 27, 2026 08:02
- Stop cron timestamps from wrapping past i64::MAX.
- Round-trip variable-width wake years while retaining strict validation.
- Make L-xW month-end matching mutually exclusive.

Fixes #292
Fixes #293
Fixes #294
@ryuzdev
ryuzdev force-pushed the fix/292-294-cron-wake-bounds branch from cebfab5 to ddc5c71 Compare November 27, 2026 08:16
@ryuzdev
ryuzdev merged commit ec44d2f into main Nov 27, 2026
7 checks passed
@ryuzdev
ryuzdev deleted the fix/292-294-cron-wake-bounds branch November 27, 2026 08:29
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