Skip to content

Cron scheduler skips jobs after mid-day gateway restart #10021

@rex05ai

Description

@rex05ai

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_Lumpur timezone

Reproduction Steps

  1. Configure daily cron jobs scheduled for early morning (e.g., 0 6 * * * for 6:00 AM)
  2. Run the gateway and let jobs execute normally on Day 1
  3. Perform a hard gateway restart mid-afternoon (e.g., 5:20 PM on Day 1)
  4. 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 nextRunAtMs set 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 nextRunAtMs set 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:

  1. Check if current time > scheduled time today
  2. If YES, skip to next occurrence (Day 2)
  3. 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: truedelivery: "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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions