#6827: fix: cron scheduler cleanup orphaned .tmp files on startup
Cluster:
Cron Job Fixes
fix #6814
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds startup cleanup for orphaned `*.tmp` cron store files (left behind by interrupted `saveCronStore` writes) by introducing `cleanupOrphanedTempFiles(storePath)` in `src/cron/store.ts` and calling it from `ensureLoaded()` before reading the cron jobs store.
The change fits the existing persistence approach in `src/cron/store.ts` where writes are done via a temp file + rename; this adds a best-effort guard to prevent old temp artifacts from accumulating across runs (fixing #6814).
<h3>Confidence Score: 4/5</h3>
- This PR is reasonably safe to merge; it adds best-effort temp-file cleanup with low blast radius.
- Changes are small and localized, but there is a plausible behavioral gap where cleanup is skipped on the in-memory cache fast-path, and the cleanup function fully suppresses errors which could hide operational problems.
- src/cron/service/store.ts (cleanup call placement), src/cron/store.ts (error visibility during cleanup)
<!-- greptile_other_comments_section -->
<sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</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
#8744: fix(cron): load persisted cron jobs on gateway startup
by revenuestack · 2026-02-04
84.5%
#12368: fix(cron): respect OPENCLAW_STATE_DIR for cron store path
by ComBba · 2026-02-09
80.0%
#8698: fix(cron): default enabled to true for new jobs
by emmick4 · 2026-02-04
79.0%
#19484: Fix cron store backup churn
by guirguispierre · 2026-02-17
78.3%
#12303: fix(cron): correct nextRunAtMs calculation and prevent timer stall
by colddonkey · 2026-02-09
77.9%
#6315: fix(cron): persist isolated sessions (fixes #6217) - attempt 2
by ChaitanyaSai-Meka · 2026-02-01
76.7%
#9684: fix: cron race condition - run due jobs before recomputing nextRunA...
by divol89 · 2026-02-05
76.6%
#11813: fix(cron): ensure 'at' schedule type correctly registers nextWakeAt...
by leo-reifying · 2026-02-08
76.5%
#9393: fix(cron): avoid recomputeNextRuns on forceReload
by matthewpapa07 · 2026-02-05
76.5%
#10829: fix: prevent cron scheduler permanent death on transient startup/ru...
by meaadore1221-afk · 2026-02-07
76.4%