Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(scheduler): stop cron enumeration when a schedule never fires (#11234)
Thejesh277d934b3e48
diff --git a/server/internal/scheduler/jobs_plugin_hook_test.go b/server/internal/scheduler/jobs_plugin_hook_test.goindex a5dce357e7..785e101d8f 100644--- a/server/internal/scheduler/jobs_plugin_hook_test.go+++ b/server/internal/scheduler/jobs_plugin_hook_test.go@@ -86,6 +86,32 @@ func TestLatestPluginHookOccurrencePagesThroughLongOutage(t *testing.T) {}}+func TestLatestPluginHookOccurrenceNeverFiringCronReturns(t *testing.T) {+ activated := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)+ now := activated.Add(9 * 24 * time.Hour)+ type result struct {+ latest time.Time+ count int+ err error+ }+ done := make(chan result, 1)+ go func() {+ latest, count, err := latestPluginHookOccurrence("0 0 30 2 *", "UTC", activated, now)+ done <- result{latest, count, err}+ }()+ select {+ case got := <-done:+ if got.err != nil {+ t.Fatalf("enumerate occurrences: %v", got.err)+ }+ if got.count != 0 || !got.latest.IsZero() {+ t.Fatalf("latest=%s count=%d, want no due occurrence", got.latest, got.count)+ }+ case <-time.After(10 * time.Second):+ t.Fatal("latestPluginHookOccurrence did not return for a cron that never fires")+ }+}+func TestPluginHookScheduleDeliveryIDIsStablePerOccurrence(t *testing.T) {installation := util.MustParseUUID("11111111-1111-4111-8111-111111111111")generation := util.MustParseUUID("22222222-2222-4222-8222-222222222222")diff --git a/server/internal/service/cron.go b/server/internal/service/cron.goindex 06dc33f339..12247c5cc8 100644--- a/server/internal/service/cron.go+++ b/server/internal/service/cron.go@@ -79,7 +79,9 @@ func NextOccurrencesUTC(cronExpr, timezone string, after, until time.Time) ([]tiuntilLocal := until.In(loc)for len(out) < hardCap {next := sched.Next(cursor)- if next.After(untilLocal) {+ // robfig reports "no further occurrence" (e.g. "0 0 30 2 *") as the+ // zero time, which would otherwise pass the until check.+ if next.IsZero() || next.After(untilLocal) {break}out = append(out, next.UTC())diff --git a/server/internal/service/cron_test.go b/server/internal/service/cron_test.goindex 11354983aa..a5d459d6e8 100644--- a/server/internal/service/cron_test.go+++ b/server/internal/service/cron_test.go@@ -97,6 +97,24 @@ func TestNextOccurrencesUTCExclusiveAfter(t *testing.T) {}}+// TestNextOccurrencesUTCNeverFiringCron covers expressions that parse but+// have no occurrence (Feb 30, Apr 31). robfig reports that as the zero time,+// which must end the enumeration instead of being emitted as a due plan.+func TestNextOccurrencesUTCNeverFiringCron(t *testing.T) {+ after := time.Date(2026, 6, 23, 12, 0, 0, 0, time.UTC)+ until := after.Add(30 * 24 * time.Hour)+ for _, cron := range []string{"0 0 30 2 *", "0 0 31 4 *"} {+ got, err := NextOccurrencesUTC(cron, "UTC", after, until)+ if err != nil {+ t.Fatalf("NextOccurrencesUTC(%q): %v", cron, err)+ }+ if len(got) != 0 {+ t.Fatalf("NextOccurrencesUTC(%q) returned %d occurrences (first %s), want none",+ cron, len(got), got[0].Format(time.RFC3339))+ }+ }+}+// TestNextOccurrencesUTCInvalidInputs surfaces parse errors loudly so// a bad cron expression cannot silently disable a trigger.func TestNextOccurrencesUTCInvalidInputs(t *testing.T) {