openclaw - 💡(How to fix) Fix Cron: missed-run catchup/backfill on gateway startup [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#59302Fetched 2026-04-08 02:26:14
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

Code Example

On startup:
  for each job where nextRunAtMs < now:
    if (now - nextRunAtMs) < gracePeriodMs:
      queue job for immediate execution
      log: "Backfilling missed cron: {job.name}"
    else:
      log: "Skipping stale cron: {job.name} (missed by {delta})"
      advance nextRunAtMs to next occurrence

---

{
  "cron": {
    "backfillGraceMs": 3600000,
    "backfillOnStartup": true
  }
}
RAW_BUFFERClick to expand / collapse

Problem

When the gateway restarts and a cron job's scheduled time has passed, the behavior is inconsistent:

  • Sometimes the job is backfilled (if the gateway starts right after the scheduled time)
  • Sometimes it is skipped entirely (if the previous instance already "claimed" the run but died before completing it)

There is no reliable missed-run catchup mechanism. If a job was scheduled during a gateway outage or restart, it may be silently skipped with no record.

Observed Behavior

Two jobs scheduled close together on the same day:

  • Job A (18:45 Sunday): Gateway restarted at 18:45:32 → backfilled at ~18:50 ✅
  • Job B (19:15 Sunday): Previous gateway instance fired it at 19:15:00, was killed at 19:15:35. New instance started at 19:15:38, saw 19:15 had passed, scheduled next run for 7 days later ❌

Job B was silently lost. No run record exists. openclaw cron runs shows 0 entries.

Expected Behavior

On gateway startup, the cron scheduler should:

  1. Scan all enabled jobs
  2. For each job, check if nextRunAtMs is in the past
  3. If a job's window was missed (within a configurable grace period, e.g., 1 hour), backfill it
  4. If a started record exists without a completed record (see related issue), retry it

This should be opt-in or have a configurable grace window to avoid firing very stale jobs.

Suggested Implementation

On startup:
  for each job where nextRunAtMs < now:
    if (now - nextRunAtMs) < gracePeriodMs:
      queue job for immediate execution
      log: "Backfilling missed cron: {job.name}"
    else:
      log: "Skipping stale cron: {job.name} (missed by {delta})"
      advance nextRunAtMs to next occurrence

Configuration

{
  "cron": {
    "backfillGraceMs": 3600000,
    "backfillOnStartup": true
  }
}

Environment

  • OpenClaw v2026.3.11
  • macOS (arm64)

Related

  • #59301 (gateway restart loop should pause/defer cron jobs)

extent analysis

TL;DR

Implement a backfill mechanism on gateway startup to catch up on missed cron jobs within a configurable grace period.

Guidance

  • Review the suggested implementation and consider adding a backfillOnStartup configuration option to enable or disable this feature.
  • Implement a grace period (backfillGraceMs) to determine which missed jobs to backfill and which to skip.
  • Update the cron scheduler to scan all enabled jobs on startup and check if nextRunAtMs is in the past.
  • Consider adding logging to track backfilled and skipped jobs for monitoring and debugging purposes.

Example

{
  "cron": {
    "backfillGraceMs": 3600000,
    "backfillOnStartup": true
  }
}

This configuration example enables backfilling on startup with a 1-hour grace period.

Notes

The implementation should be opt-in or have a configurable grace window to avoid firing very stale jobs. The suggested implementation provides a basic outline, but additional error handling and edge cases may need to be considered.

Recommendation

Apply the suggested implementation with a configurable backfillGraceMs to ensure that missed cron jobs are properly backfilled or skipped, providing a reliable and consistent behavior.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING