#8744: fix(cron): load persisted cron jobs on gateway startup
stale
Cluster:
Cron Job Fixes
Fixes #7624
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR fixes cron job persistence on gateway startup by clearing the in-memory cron store cache before loading jobs from disk. It introduces a small `clearStoreCache(storePath)` helper in `src/cron/service/store.ts` and calls it from `src/cron/service/ops.ts:start()` prior to `ensureLoaded()`, ensuring jobs created while the gateway was stopped (e.g., via CLI) are visible on the next startup.
The change fits the existing architecture where `ensureLoaded()` populates `state.store` (optionally from a process-local cache) and the rest of the cron service (`jobs`, `timer`, `ops`) operates on that store under `locked()` for concurrency control.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- Changes are small and localized: a new cache eviction helper and a single call on startup to ensure persisted cron jobs are reloaded from disk. No API surface changes beyond the new exported helper, and the behavior aligns with the intended persistence semantics.
- No files require special attention
<!-- greptile_other_comments_section -->
**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
#6827: fix: cron scheduler cleanup orphaned .tmp files on startup
by fatelei · 2026-02-02
84.5%
#8698: fix(cron): default enabled to true for new jobs
by emmick4 · 2026-02-04
82.8%
#9060: Fix: Preserve scheduled cron jobs after gateway restart
by vishaltandale00 · 2026-02-04
81.4%
#13065: fix(cron): Fix "every" schedule not re-arming after gateway restart
by trevorgordon981 · 2026-02-10
80.0%
#9393: fix(cron): avoid recomputeNextRuns on forceReload
by matthewpapa07 · 2026-02-05
79.8%
#11857: fix: recompute stale cron nextRunAtMs on gateway restart
by Yida-Dev · 2026-02-08
78.8%
#10829: fix: prevent cron scheduler permanent death on transient startup/ru...
by meaadore1221-afk · 2026-02-07
78.5%
#12368: fix(cron): respect OPENCLAW_STATE_DIR for cron store path
by ComBba · 2026-02-09
78.1%
#9684: fix: cron race condition - run due jobs before recomputing nextRunA...
by divol89 · 2026-02-05
77.9%
#16888: fix(cron): execute missed jobs outside the lock to unblock list/sta...
by hou-rong · 2026-02-15
77.8%