fix(coding-agent): accept sparse leap-day schedules - #912
Open
chai1any wants to merge 3 commits into
Open
Conversation
Search a full Gregorian calendar cycle for the next cron date and skip non-matching calendar days efficiently, instead of rejecting valid schedules whose next run is more than one year away.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Problem
nextCronRunAfter()currently stops after 366 days. A valid schedule such as0 0 29 2 *is therefore rejected during creation in most years because its next occurrence can be several years away:Gregorian calendar dates repeat every 400 years, which provides a finite correctness bound. Skipping calendar days that cannot match keeps that bound practical and also rejects impossible dates deterministically.
Verification
npx tsx ../../node_modules/vitest/dist/cli.js --run test/cron-jobs.test.ts(54 tests passed)npm run checkUTC,America/New_York,Europe/Berlin,Pacific/Apia, andAustralia/Lord_Howe0 0 29 2 *from March 2025 to February 29, 2028Note
Fix
nextCronRunAfterto accept leap-day cron schedules beyond one yearnextCronRunAfterwith a 400-year Gregorian window, allowing sparse schedules like0 0 29 2 *(leap day) to resolve correctly.matchesCronCalendarDayhelper that skips non-matching days in whole-day increments instead of iterating minute-by-minute.0 0 31 2 *) now throw'Cron schedule has no matching date: ...'instead of'Cron schedule did not match within one year: ...'.Macroscope summarized d53b62e.