Skip to content

Bug: Cron nextRunAtMs incorrectly skips next occurrence for cross-day schedules #10086

@zjy282

Description

@zjy282

Bug Report: Cron nextRunAtMs Calculation Error for Cross-Day Schedule

Environment

  • OpenClaw Version: 2026.2.3-1
  • Node.js: v22.22.0
  • OS: Linux (OpenCloudOS 9, kernel 6.6.117)
  • Timezone: Asia/Shanghai (UTC+8)

Summary

Cron scheduler incorrectly calculates nextRunAtMs when a job is updated/created in the evening and the next scheduled time is the following morning. It skips the next occurrence and schedules for the day after.

Steps to Reproduce

  1. Create/update a daily cron job at 21:53 (Feb 5, 2026)

    • Schedule: 0 10 * * * (daily at 10:00 AM)
    • Timezone: Asia/Shanghai
  2. Expected: nextRunAtMs should be Feb 6, 2026 10:00 (12 hours later)

  3. Actual: nextRunAtMs was set to Feb 7, 2026 10:00 (36 hours later, skipping Feb 6)

Evidence

Job Configuration:

{
  "id": "d369ad13-b554-4123-aad0-7a5367a76b99",
  "name": "用药提醒-热淋清-早10点",
  "createdAtMs": 1770211095092,
  "updatedAtMs": 1770299625973,  // Feb 5, 2026 21:53:45 CST
  "schedule": {
    "expr": "0 10 * * *",
    "tz": "Asia/Shanghai",
    "kind": "cron"
  },
  "state": {
    "nextRunAtMs": 1770429600000  // Feb 7, 2026 10:00:00 CST (WRONG!)
  },
  "enabled": true
}

Time Calculation:

  • Job updated: 2026-02-05 21:53:45 CST (timestamp: 1770299625973)
  • Next run set to: 2026-02-07 10:00:00 CST (timestamp: 1770429600000)
  • Time difference: 36 hours (should be 12 hours)
  • Skipped occurrence: 2026-02-06 10:00:00 CST

Run History:

  • openclaw cron runs <jobId> returns empty array
  • Confirms Feb 6 10:00 AM was never triggered

Expected Behavior

When a cron job with expression 0 10 * * * is updated at 21:53, the next occurrence should be calculated as the next 10:00 AM, which is:

  • Current time: Feb 5, 21:53
  • Next 10:00: Feb 6, 10:00 (12 hours later)

Actual Behavior

The scheduler incorrectly skips the next occurrence and schedules for:

  • Next 10:00: Feb 7, 10:00 (36 hours later)

Additional Context

  • Gateway started: Feb 5, 2026 21:23:53 CST
  • Job updated: Feb 5, 2026 21:53:45 CST (via openclaw cron update)
  • The issue appears to occur specifically in cross-day scheduling scenarios
  • Similar cron jobs scheduled for 14:00 and 20:00 on the same day have correct nextRunAtMs values for the current day

Possible Root Cause

The cron expression parser may have an issue with:

  1. Date boundary calculations when current time is PM and next occurrence is AM
  2. Timezone conversion between Asia/Shanghai and UTC
  3. Logic that determines "next occurrence" vs "occurrence after next"

Impact

  • Severity: High
  • Scheduled jobs miss their first occurrence after being created/updated in the evening
  • Affects medication reminders, scheduled tasks, and time-sensitive automations
  • Users may not realize jobs didn't run until checking manually

Related Issues

  • Previous version (2026.2.2-3) had issue with nextWakeAtMs: null (fixed in 2026.2.3-1)
  • This may be a related edge case in the cron scheduler

Workaround

Manual trigger using:

openclaw cron run <jobId>

Or wait for the next day's occurrence (jobs will run normally after the first skipped occurrence).

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