fix(cron): don't skip first-run cron jobs past grace window - #41307
fix(cron): don't skip first-run cron jobs past grace window#41307cmcejas wants to merge 1 commit into
Conversation
Cron jobs with last_run_at=None (never run) were being silently skipped by _get_due_jobs_locked() when the computed next_run_dt fell outside the grace window. The grace-window fast-forward logic is correct for jobs that have already run, but wrong for first-run jobs the user just created or manually triggered. Fix: when kind=='cron' and last_run_at is falsy, bypass the grace-window check and let the job run. Fixes NousResearch#41037
|
Note: this PR is complementary to the other open PRs for #41037 (#41130 by @kyssta-exe and #41269 by @rodboev). Those PRs address the immediate dispatch problem — making This PR addresses a different root cause: even when Both fixes are needed for a complete solution:
The fixes are independent and can merge in any order. |
✅ Verification — cron first-run grace window fixReviewed
Clean fix — no issues found. |
|
Automated hermes-sweeper review: this cron first-run skip fix is now implemented on main by the later merged catch-up behavior. Evidence:
Thanks to @cmcejas for identifying the never-run cron edge case and to the commenters who linked the related #41037 fixes; the current main behavior now covers this PR's requested guarantee. |
Problem
Cron jobs with
last_run_at=None(never run) were being silently skipped by_get_due_jobs_locked()when the computednext_run_dtfell outside the grace window. The grace-window fast-forward logic is correct for jobs that have already run, but wrong for first-run jobs the user just created or manually triggered.Root Cause
In
_get_due_jobs_locked(), when a job'snext_run_dtis past the grace window, the code fast-forwards to the next future occurrence. For cron jobs that have never run (last_run_atis None/empty), this means the first run is silently skipped.Fix
When
kind=='cron'andlast_run_atis falsy, bypass the grace-window check and let the job run. The grace-window logic still applies to cron jobs that have already run at least once.Fixes #41037