Skip to content

Feature: Cron job catch-up for missed runs after gateway restart #10067

@TeigenZhang

Description

@TeigenZhang

Problem

When the gateway restarts after a cron job's scheduled time has passed, the job is skipped and waits for the next cycle. This causes missed runs if the gateway happens to be down during a job's scheduled time.

Example scenario:

  • Job scheduled for 08:00 daily
  • Gateway restarts at 09:35 (e.g., after an update or system wake)
  • The 08:00 job is skipped, nextRunAtMs jumps to tomorrow
  • User misses their daily digest/report

Proposed Solution

Add an optional catchUp flag to cron schedules. When enabled:

  1. On gateway startup, compare lastRunAtMs with the expected run time
  2. If the job was supposed to run since the last execution but didn't, trigger it immediately
  3. Then resume normal scheduling

Suggested Config

{
  "schedule": {
    "kind": "cron",
    "expr": "0 8 * * *",
    "tz": "Asia/Shanghai",
    "catchUp": true
  }
}

Behavior

Scenario catchUp: false (current) catchUp: true (proposed)
Gateway restarts after scheduled time Skip, wait for next cycle Run immediately, then resume
Gateway restarts before scheduled time Run at scheduled time Run at scheduled time
Multiple missed runs All skipped Run once (most recent)

Alternatives Considered

  • Heartbeat-based workaround: Check cron status in HEARTBEAT.md and manually trigger missed jobs. Works but adds complexity and token cost.
  • Always catch up: Could be surprising for some use cases, hence making it opt-in.

Additional Context

This is especially important for daily digest/report jobs where missing a day means missing that day's content entirely.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions