cron: fix #10934 - preserve future nextRunAtMs in recomputeNextRuns#10988
cron: fix #10934 - preserve future nextRunAtMs in recomputeNextRuns#10988Saman-dev12 wants to merge 1 commit intoopenclaw:mainfrom
Conversation
Additional Comments (1)
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/cron/service/jobs.ts
Line: 110:112
Comment:
**Preserve-only check skips invalid**
`recomputeNextRuns()` now `continue`s whenever `nextRunAtMs` is a number in the future, but it doesn’t validate that value is finite/non-negative. If the store ever contains `nextRunAtMs: NaN`/`Infinity`/negative (e.g., from a bad migration/manual edit), this will either (a) fall through and compute `newNext` as `undefined`/wrong or (b) preserve a nonsensical far-future value and the job will never run. Consider tightening the guard to `Number.isFinite(existingNext) && existingNext > now` (and maybe `existingNext >= 0`) so only valid timestamps are preserved.
How can I resolve this? If you propose a fix, please make it concise. |
There was a problem hiding this comment.
Pull request overview
Adjusts cron scheduling so recomputeNextRuns() does not overwrite an already-valid nextRunAtMs that is still in the future, addressing the reported “every schedules never execute” behavior in #10934.
Changes:
- Preserve existing future
nextRunAtMsvalues inrecomputeNextRuns()rather than always recomputing. - Add a regression test intended to verify that “every” schedules don’t have
nextRunAtMspushed forward before becoming due.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/cron/service/jobs.ts |
Adds an early-continue guard to keep future nextRunAtMs values intact during recomputation. |
src/cron/service.issue-regressions.test.ts |
Adds a regression test for #10934 around nextRunAtMs stability and execution timing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…xtRuns Cron jobs with 'every' schedules never executed because recomputeNextRuns() unconditionally recalculated all nextRunAtMs values before checking for due jobs. For 'every' schedules without anchorMs, this used current time as anchor, pushing all scheduled times forward before runDueJobs() could execute them. Fix: preserve existing nextRunAtMs if valid and in the future; only recalculate when missing or in the past. Added regression test to verify jobs execute on schedule and times don't drift.
3644cd8 to
2b6ab94
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fixes #10934
Problem
Cron jobs with
schedule.kind: "every"never executed automatically becauserecomputeNextRuns()unconditionally recalculated allnextRunAtMsvalues before checking for due jobs. For "every" schedules withoutanchorMs, this used the current time as anchor, pushing all scheduled times forward beforerunDueJobs()could execute them.Solution
Modified
recomputeNextRuns()insrc/cron/service/jobs.tsto preserve existingnextRunAtMsvalues when they are valid and in the future. Only recalculate when:nextRunAtMsyetnextRunAtMsis in the past (job is due)Changes
nextRunAtMsinrecomputeNextRuns()Testing
Greptile Overview
Greptile Summary
recomputeNextRuns()to keep an already-scheduled futurenextRunAtMsinstead of always recomputing it, addressing “every” schedules without an explicit anchor being pushed forward.nextRunAtMsisn’t continuously rescheduled and the job actually executes when due.src/cron/service/timer.tswhere recomputation happens when no jobs are due and after executions to persist updated state.Confidence Score: 3/5
(2/5) Greptile learns from your feedback when you react with thumbs up/down!