← Back to PRs

#5428: fix(Cron): prevent one-shot loop on skip

by imshrishk open 2026-01-31 13:41 View on GitHub →
docs
Fixes #5397 Problem: - One‑shot `at` cron jobs with past `nextRunAtMs` could stay due after a skipped run, causing rapid re-fire loops. Solution: - Treat one‑shot jobs as single-run even when skipped or errored, so they don’t remain due. Changes: - Stop re-scheduling one‑shot jobs after the first run attempt. - Added a test for past-due one‑shot jobs to confirm no loop. <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR adjusts one-shot (`schedule.kind === "at"`) cron job scheduling so jobs only auto-run once, even if the first run attempt is skipped/errored. Specifically, `computeJobNextRunAtMs` now returns `undefined` after any first attempt (`state.lastRunAtMs`), preventing past-due one-shot jobs from remaining due and re-firing in a tight loop. A new Vitest regression test covers the past-due + skipped scenario. The change fits into the cron service by affecting how `recomputeNextRuns` derives `job.state.nextRunAtMs`, which in turn drives `isJobDue` and the scheduler wake-up logic. <h3>Confidence Score: 4/5</h3> - This PR is likely safe to merge and addresses the reported one-shot looping behavior with a small, localized scheduling change plus a regression test. - The core logic change is confined to `computeJobNextRunAtMs` for `at` schedules and aligns with the stated intent (treat one-shot as single-attempt). The added test increases confidence. Remaining risk is mainly around behavioral expectations for one-shot jobs that previously retried until success; if any callers relied on that retry semantics, this change is a behavior shift rather than a pure bugfix. - src/cron/service/jobs.ts (one-shot scheduling semantics), src/cron/service.runs-one-shot-main-job-disables-it.test.ts (regression test robustness). <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> **Context used:** - Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8)) - Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13)) <!-- /greptile_comment -->

Most Similar PRs