Skip to content

Cron: 'at' jobs don't fire after being rescheduled #19676

@onEnterFrame

Description

@onEnterFrame

Bug Description

When a kind: 'at' scheduled job is updated with a new atMs timestamp, it doesn't fire if the job previously ran successfully.

Root Cause

In src/cron/service/jobs.ts, the computeJobNextRunAtMs function has this logic:

if (job.schedule.kind === 'at') {
  // One-shot jobs stay due until they successfully finish.
  if (job.state.lastStatus === 'ok' && job.state.lastRunAtMs)
    return undefined;
  return job.schedule.atMs;
}

When rescheduling an 'at' job to a new time, the lastStatus remains 'ok' from the previous run, so the function returns undefined instead of the new schedule.atMs.

Reproduction

  1. Create an 'at' job scheduled for 5 minutes from now
  2. Let it run successfully (lastStatus: 'ok')
  3. Update the job with a new atMs 1 hour in the future
  4. The job never fires because nextRunAtMs is undefined

Expected Behavior

When updating an 'at' job with a new atMs that is greater than lastRunAtMs, the job should be scheduled to run at the new time.

Suggested Fix

Change the condition to also check if the new scheduled time is after the last run:

if (job.schedule.kind === 'at') {
  if (job.state.lastStatus === 'ok' && 
      job.state.lastRunAtMs && 
      job.schedule.atMs <= job.state.lastRunAtMs)
    return undefined;
  return job.schedule.atMs;
}

Environment

  • Clawdbot version: (installed via npm)
  • Node: v22.22.0
  • OS: macOS (Darwin arm64)

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleMarked as stale due to inactivity

    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