#12982: fix(cron): prevent status/list from advancing overdue job nextRunAtMs
stale
Cluster:
Cron Job Management Fixes
## Problem
Read-only cron operations (`status()`, `list()`) call `recomputeNextRuns()` which
silently advances overdue `nextRunAtMs` to the next future occurrence. This prevents
`runMissedJobs()` from catching and executing missed jobs on service restart.
Fixes #12851
## Solution
In `recomputeNextRuns()`, skip advancing recurring jobs that were never executed at
their current slot. The guard checks `lastRunAtMs >= nextRunAtMs` to determine if
the job ran at this slot. One-shot (`at`) jobs are excluded from this guard since
they have different lifecycle semantics.
## Testing
- [ ] `pnpm build` passes
- [ ] `pnpm check` passes
- [ ] Added regression test: overdue recurring job nextRunAtMs is preserved
- [ ] Added control test: executed recurring job IS advanced
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This change updates `recomputeNextRuns()` (`src/cron/service/jobs.ts`) to avoid advancing `nextRunAtMs` for overdue *recurring* jobs that haven’t actually executed at their current slot (determined via `lastRunAtMs >= nextRunAtMs`). This prevents read-only cron operations like `status()`/`list()`—which call `recomputeNextRuns()`—from silently skipping missed executions, allowing `runMissedJobs()` to catch up on restart.
The PR also adds regression coverage in `src/cron/service.issue-regressions.test.ts` to assert that overdue recurring jobs keep their `nextRunAtMs` when recomputed, while jobs that have executed at the overdue slot *do* advance to the next run.
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge with low risk once CI confirms tests/build pass.
- The change is small and localized (a guard in `recomputeNextRuns()`), and the added regression tests directly exercise the intended behavior. I couldn’t execute the test suite locally in this environment (pnpm unavailable), so confidence is slightly reduced pending CI confirmation.
- src/cron/service/jobs.ts; src/cron/service.issue-regressions.test.ts
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#12443: fix(cron): don't advance past-due jobs that haven't been executed
by rummangeminicode · 2026-02-09
91.1%
#13796: fix: skip recomputing nextRunAtMs for running cron jobs (#13739)
by echoVic · 2026-02-11
89.4%
#14667: fix: preserve missed cron runs when updating job schedule
by WalterSumbon · 2026-02-12
88.2%
#12448: fix: prevent cron list/status from silently skipping due jobs
by Yida-Dev · 2026-02-09
87.6%
#11108: fix(cron): prevent missed jobs from being skipped on timer recompute
by Bentlybro · 2026-02-07
87.1%
#12747: fix: catch up missed cron-expression job runs on restart
by obin94-commits · 2026-02-09
86.4%
#17838: fix: prevent cron job spin loop by not recomputing nextRunAtMs for ...
by MisterGuy420 · 2026-02-16
86.0%
#11857: fix: recompute stale cron nextRunAtMs on gateway restart
by Yida-Dev · 2026-02-08
84.0%
#9393: fix(cron): avoid recomputeNextRuns on forceReload
by matthewpapa07 · 2026-02-05
84.0%
#17949: fix: clear stale runningAtMs in cron.run() before already-running c...
by yasumorishima · 2026-02-16
83.8%