Skip to content

Cron engine crashes on startup when job has no state field #65916

@guillaumeEmery

Description

@guillaumeEmery

Description

cron.start() crashes with TypeError: Cannot read properties of undefined (reading 'runningAtMs') when any job in jobs.json has a null or missing state field.

This prevents all cron jobs from running — not just the one with the missing state.

Version

OpenClaw 2026.4.1 (da64a97)

Steps to reproduce

  1. Add a job to ~/.openclaw/cron/jobs.json without a state field (or with "state": null)
  2. Restart the gateway
  3. Observe in logs: [cron] failed to start: TypeError: Cannot read properties of undefined (reading 'runningAtMs')

This can happen when jobs are added programmatically or restored from a backup/reference file that doesn't include runtime state.

Root cause

In cron-cli-BBHRXUsj.js:184, the formatStatus function accesses job.state.runningAtMs without null-checking job.state:

const formatStatus = (job) => {
    if (!job.enabled) return "disabled";
    if (job.state.runningAtMs) return "running";  // crashes here
    return job.state.lastStatus ?? "idle";
};

The cron scheduler itself handles this case correctly (line 5786-5787 of gateway-cli):

if (!job.state) {
    job.state = {};

But formatStatus is called during cron.start() before the scheduler gets a chance to initialize the state, so the entire cron system fails to start.

Suggested fix

const formatStatus = (job) => {
    if (!job.enabled) return "disabled";
    if (job.state?.runningAtMs) return "running";
    return job.state?.lastStatus ?? "idle";
};

Workaround

Ensure all jobs have at least "state": {} before the gateway starts.

Impact

When this bug triggers, all cron jobs stop running (not just the affected one), since the entire cron service fails to start. No scheduled tasks, no deliveries, no monitoring — silent failure with only a single log line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions