#12443: fix(cron): don't advance past-due jobs that haven't been executed
stale
Cluster:
Cron Job Enhancements
## Summary
Fixes #12440
When `recomputeNextRuns()` is called (e.g., via `cron list`/`status`), it was advancing past-due jobs to the next occurrence without checking if the job was actually executed for that time slot.
This caused jobs to be skipped entirely if `cron list`/`status` was called after the scheduled time but before the job ran.
## Fix
Only advance `nextRunAtMs` if the job was already executed for the current time slot (`lastRunAtMs >= nextRunAtMs`). Past-due jobs that haven't been executed are left alone so `runMissedJobs` or `findDueJobs` can pick them up.
## Testing
1. Create a cron job scheduled for a time in the near future
2. Wait for that time to pass
3. Run `openclaw cron list` before the job executes
4. Previously: `nextRunAtMs` would advance to the next day, job skipped
5. With fix: `nextRunAtMs` stays at the past-due time, job runs normally
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This change updates `recomputeNextRuns()` in `src/cron/service/jobs.ts` to avoid advancing `nextRunAtMs` for past-due jobs unless the job has already been executed for that scheduled slot (`lastRunAtMs >= nextRunAtMs`). The intent is to prevent `cron list` / `cron status` (which call recomputation) from skipping jobs that are due but not yet executed.
The update integrates with the existing scheduler flow in `src/cron/service/timer.ts`, where `findDueJobs`/`runMissedJobs` rely on `nextRunAtMs` remaining past-due so jobs can be picked up and executed.
<h3>Confidence Score: 4/5</h3>
- This PR is likely safe to merge and fixes the reported job-skipping behavior, but verify next-run recomputation remains correct after schedule changes and other state edits.
- The core change is small and targeted, and it aligns with how `findDueJobs` / `runMissedJobs` detect due work. Main remaining concern is whether any code paths depend on `recomputeNextRuns()` to refresh `nextRunAtMs` for future (non-missing) values; if so, stale `nextRunAtMs` could persist and cause incorrect scheduling.
- src/cron/service/jobs.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#11108: fix(cron): prevent missed jobs from being skipped on timer recompute
by Bentlybro · 2026-02-07
91.8%
#12982: fix(cron): prevent status/list from advancing overdue job nextRunAtMs
by hclsys · 2026-02-10
91.1%
#13796: fix: skip recomputing nextRunAtMs for running cron jobs (#13739)
by echoVic · 2026-02-11
90.0%
#14667: fix: preserve missed cron runs when updating job schedule
by WalterSumbon · 2026-02-12
89.6%
#12448: fix: prevent cron list/status from silently skipping due jobs
by Yida-Dev · 2026-02-09
89.2%
#12747: fix: catch up missed cron-expression job runs on restart
by obin94-commits · 2026-02-09
89.2%
#10918: fix(cron): add tolerance for timer precision and skip due jobs in r...
by Cherwayway · 2026-02-07
87.6%
#12303: fix(cron): correct nextRunAtMs calculation and prevent timer stall
by colddonkey · 2026-02-09
87.1%
#5428: fix(Cron): prevent one-shot loop on skip
by imshrishk · 2026-01-31
86.9%
#17838: fix: prevent cron job spin loop by not recomputing nextRunAtMs for ...
by MisterGuy420 · 2026-02-16
86.8%