Skip to content

[Bug] Cron jobs created after gateway start never execute until restart #11217

@git-tao

Description

@git-tao

Description

Cron jobs added via the cron tool while the gateway is running are persisted to storage but never execute. They remain in an "idle" state (enabled, but lastRun is null) until the gateway is manually restarted.

Environment

  • OpenClaw Version: Latest (installed via npm)
  • Platform: macOS (Darwin 25.2.0, arm64)
  • Node: v22.21.0

Steps to Reproduce

  1. Start the gateway: openclaw gateway start
  2. Wait for it to stabilize
  3. Create a cron job via the agent or CLI:
    {
      "name": "test-job",
      "schedule": {"kind": "every", "everyMs": 60000},
      "sessionTarget": "main",
      "payload": {"kind": "systemEvent", "text": "Hello"}
    }
  4. Wait for the scheduled time to pass
  5. Check job status: cron action=list

Expected Behavior

Job should execute at the scheduled time.

Actual Behavior

Job never executes. Status shows:

  • enabled: true
  • lastRun: null (never ran)
  • nextRunAtMs may be in the past

Only after openclaw gateway restart does the job start executing.

Evidence

Five production jobs created Feb 4-5 all showed this pattern:

Job Name Created Last Run Status
signal-collection Feb 4 null Never executed
content-factory-morning-topics Feb 5 null Never executed
pipeline-trigger Feb 5 null Never executed
content-factory-reaction-scanner Feb 5 null Never executed
Supabase keepalive Feb 5 null Never executed

All jobs were enabled: true with valid schedules.

Root Cause Hypothesis

The cron scheduler loads jobs from storage only at startup. Jobs added afterward are written to persistent storage but not registered with the in-memory scheduler. The scheduler never polls storage for new jobs.

Suggested Fix

Option A (Hot reload):

  • When cron action=add succeeds, emit an event that the scheduler listens to
  • Scheduler adds the new job to its in-memory schedule

Option B (Polling):

  • Scheduler periodically compares in-memory jobs vs storage
  • Syncs any differences

Option C (File watch):

  • Watch the cron storage file for changes
  • Reload when modified

Workaround

After adding new cron jobs, run:

openclaw gateway restart

This forces a full reload of all jobs from storage.

Impact

  • Severity: High — affects anyone adding cron jobs dynamically via agent
  • User experience: Jobs silently fail to run with no error message
  • Discoverability: Hard to debug since jobs appear valid in listings

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