Skip to content

Scheduler fires Monday cron jobs on Tuesday (off-by-one day) #145

Closed

Description

@pandore

Bug Description

Schedules configured with cron day-of-week 1 (Monday) are consistently firing on Tuesday instead. The scheduler correctly computes next_run_at as Monday, but the actual execution happens on Tuesday.

Evidence

Agent: ability-website

Weekly SEO Monitor (5 9 * * 1)

Execution history shows the pattern clearly:

Execution Date Day of Week Expected Status
2026-03-17 09:05 UTC Tuesday Monday success
2026-03-10 09:05 UTC Tuesday Monday failed
2026-03-03 09:05 UTC Tuesday Monday failed

(Mar 16 Monday execution at 17:49 was a manual trigger, not the cron)

Weekly CRO Report (42 9 * * 1)

Execution Date Day of Week Expected
2026-03-17 09:47 UTC Tuesday Monday

Pre-SEO git-sync (55 8 * * 1)

Execution Date Day of Week Expected
2026-03-17 08:55 UTC Tuesday Monday

next_run_at is correct

The scheduler computes future run times correctly:

  • 42 9 * * 1 → next_run_at: 2026-03-23T09:42:00Z (Monday ✓)
  • Tested * * 0: returned next_run_at: 2026-03-22 (Sunday ✓)

So the cron parsing is correct (0=Sun, 1=Mon), but actual execution is shifted +1 day.

Possible Causes

  1. Catch-up execution: If the agent was down on Monday and the scheduler retries missed jobs on the next available window (Tuesday). However, this happened 3 weeks in a row (Mar 3, 10, 17).

  2. Off-by-one in the execution trigger (not the parser): The cron expression is parsed correctly for next_run_at display, but the actual trigger comparison uses a different weekday calculation.

  3. Timezone boundary issue: All schedules use timezone: UTC and fire times are well within the UTC day (08:55-09:47), so this seems unlikely.

Additional Notes

  • The updated_at field on ALL schedules shows the same timestamp (2026-03-17T12:15:47), suggesting a bulk sync or agent restart on Tuesday
  • Container health last_check_at is stale (2026-02-28)
  • Container shows restart_count: 0 but logs show a fresh startup sequence

Expected Behavior

Cron 5 9 * * 1 should fire on Monday at 09:05 UTC, not Tuesday.

Environment

  • Trinity platform (self-hosted)
  • Agent: ability-website
  • Schedules created between 2026-01-30 and 2026-03-16

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions