-
-
Notifications
You must be signed in to change notification settings - Fork 54.8k
Description
Bug Report: Cron Scheduler Skips Jobs After Mid-Day Gateway Restart
Summary
When the OpenClaw gateway restarts mid-day, cron jobs scheduled for earlier in the day (before the restart time) incorrectly skip to the next occurrence 48 hours later instead of running the next morning.
Environment
- OpenClaw Version: 2026.2.3-1
- Platform: macOS 15.2.1 (Sequoia)
- Gateway Config: Default cron scheduler with
Asia/Kuala_Lumpurtimezone
Reproduction Steps
- Configure daily cron jobs scheduled for early morning (e.g.,
0 6 * * *for 6:00 AM) - Run the gateway and let jobs execute normally on Day 1
- Perform a hard gateway restart mid-afternoon (e.g., 5:20 PM on Day 1)
- Observe job states after restart
Expected Behavior
After a mid-day restart on Day 1 at 5:20 PM:
- Jobs scheduled for 6:00 AM should have
nextRunAtMsset to Day 2 at 6:00 AM (next occurrence)
Actual Behavior
After restart on Day 1 at 5:20 PM:
- Jobs scheduled BEFORE restart time (6:00 AM) have
nextRunAtMsset to Day 3 at 6:00 AM (48 hours later) - Jobs scheduled AFTER restart time (9:00 AM+) correctly set to Day 2
Evidence
Affected Jobs (Early Morning)
| Job | Schedule | Last Run | Next Run | Gap |
|---|---|---|---|---|
| Morning Briefing | 0 6 * * * |
Day 1, 6:00 AM | Day 3, 6:00 AM | 48h |
| Early Morning Email | 55 5 * * * |
Day 1, 5:55 AM | Day 3, 5:55 AM | 48h |
Unaffected Jobs (After Restart Time)
| Job | Schedule | Last Run | Next Run | Gap |
|---|---|---|---|---|
| Crypto Morning | 0 9 * * * |
Day 1, 9:00 AM | Day 2, 9:00 AM | 24h ✅ |
| Security Audit | 30 11 * * * |
Day 1, 11:30 AM | Day 2, 11:30 AM | 24h ✅ |
Gateway restart time: Day 1, ~5:20 PM (1770320400000 ms epoch)
Root Cause Hypothesis
The cron scheduler's next-run calculation logic appears to:
- Check if current time > scheduled time today
- If YES, skip to next occurrence (Day 2)
- If NO, skip to Day 3 (incorrectly treating Day 2 as "already considered")
The logic fails to recognize that for jobs scheduled earlier than the restart time, Day 2's scheduled time is still upcoming and should be the next run.
Impact
- Cron jobs scheduled for early morning hours skip execution on the day after a mid-day gateway restart
- Users lose automated daily tasks (morning briefings, email checks, backups, etc.)
- Pattern self-corrects after the skipped day (resumes normal 24h cadence)
Suggested Fix
Update cron scheduler's next-run calculation to:
function calculateNextRun(schedule, currentTime, lastRun) {
const todayScheduled = getScheduledTimeToday(schedule);
const tomorrowScheduled = getScheduledTimeTomorrow(schedule);
// If today's scheduled time hasn't passed yet, use it
if (currentTime < todayScheduled) {
return todayScheduled;
}
// Otherwise, use tomorrow
return tomorrowScheduled;
}Instead of comparing against lastRun, compare against the scheduled time relative to current day.
Workaround
Manually trigger affected jobs or avoid mid-day gateway restarts when possible. Jobs self-correct and resume normal schedule after one skipped execution.
Additional Context
- This occurred after updating from 2026.2.2-3 to 2026.2.3-1 (hard restart required for npm package reload)
- Related to recent delivery mode migration (
deliver: true→delivery: "announce") - Timezone: Asia/Kuala_Lumpur (GMT+8)
Version Info
$ openclaw --version
2026.2.3-1
$ node --version
v22.22.0
Reporter: rex05ai (via user rene05@pm.me)
Date: 2026-02-06
Session: Direct chat with René Fischer-Bernard