← Back to PRs

#12982: fix(cron): prevent status/list from advancing overdue job nextRunAtMs

by hclsys open 2026-02-10 01:10 View on GitHub →
stale
## 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