Skip to content

[Bug]: Cron nextRunAtMs calculated with wrong year (2025 instead of 2026) when job time has passed #10035

@hly3825

Description

@hly3825

Summary

When creating a cron job with a time that has already passed today, the nextRunAtMs is incorrectly calculated as a date one year in the past (2025 instead of 2026), causing the job to never run.

This is a different bug from #10025 (which deals with off-by-one-day after execution). This issue occurs on initial job creation.

Environment

  • OpenClaw version: 2026.2.1 (8650)
  • Node.js: v25.5.0
  • OS: macOS Darwin 24.6.0 (arm64)
  • System time: 2026-02-06 08:20 (confirmed correct via date and Date.now())

Steps to Reproduce

  1. At 08:20 (after 07:30), create a cron job scheduled for 07:30 daily:

    openclaw cron add --name "Test" --cron "30 7 * * *" --tz "Asia/Shanghai" --message "test"
  2. Check the job's nextRunAtMs:

    openclaw cron list | grep nextRunAtMs
  3. Observe that nextRunAtMs is 1770420600000 (2025-02-06 07:30 UTC) instead of 1773960600000 (2026-02-07 07:30 UTC).

Expected Behavior

For a job scheduled at 07:30, if current time is 08:20, nextRunAtMs should be tomorrow (2026-02-07 07:30).

Actual Behavior

nextRunAtMs is set to one year ago (2025-02-06 07:30), so the job never triggers.

Root Cause Analysis

The cron scheduler appears to incorrectly handle "past time" calculations. When the scheduled time has already passed for today, it should increment to the next day, but instead it decrements by approximately 365 days (one year).

Verified timestamps

  • Incorrect: 1770420600000 = 2025-02-06 07:30 UTC
  • Expected: 1773960600000 = 2026-02-07 07:30 UTC
  • Gap: ~365 days (one full year)

Workaround

Manually edit ~/.openclaw/cron/jobs.json to fix nextRunAtMs after stopping Gateway:

pkill -f openclaw-gateway
sed -i '' 's/1770420600000/1773960600000/g' ~/.openclaw/cron/jobs.json
openclaw gateway start

Related Issues

Impact

Any daily cron job created after its scheduled time will never run, causing:

  • Missed daily reports/briefings
  • Missed scheduled tasks
  • Silent failures (no error logs, job just does not fire)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions