fix(scheduler): prevent NULL next_run_at from permanently dropping schedules - #728
Merged
Merged
Conversation
…hedules (#722) Three bugs caused enabled schedules to silently disappear from the fire query (which requires next_run_at IS NOT NULL AND next_run_at <= now()): Bug 1 - fireSchedule() and recordSkipped(): when ComputeNextRun returned an error, nextRunPtr stayed nil and UPDATE SET next_run_at = $2 wrote NULL. Fix: change to COALESCE($2, next_run_at) so the existing DB value is preserved when $2 is NULL, and log the error explicitly. Bug 2 - org importer (handlers/org.go): nextRun, _ := ComputeNextRun(...) silently discarded the error. A bad cron expression would pass time.Time{} (zero value) to the INSERT. Fix: surface the error, log it, and skip the schedule INSERT via continue. Bug 3 - no startup repair: schedules already NULL'd by the pre-fix binary would never recover. Fix: Start() now calls repairNullNextRunAt() once on boot, recomputing next_run_at for every enabled schedule with a NULL value. Tests: TestFireSchedule_ComputeNextRunError, TestRecordSkipped_ComputeNextRunError, TestRepairNullNextRunAt_RepairsRows, TestRepairNullNextRunAt_DBError_NoPanic, TestOrgImport_ScheduleComputeError (all pass). Fixes #722 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This was referenced Apr 17, 2026
molecule-ai Bot
pushed a commit
that referenced
this pull request
Apr 21, 2026
…-next-run fix(scheduler): prevent NULL next_run_at from permanently dropping schedules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #722 — three bugs in the scheduler that caused enabled schedules to silently disappear from the fire query (
WHERE next_run_at IS NOT NULL AND next_run_at <= now()).Bug 1 —
fireSchedule()+recordSkipped()write NULL onComputeNextRunerrorRoot cause: when
ComputeNextRunfails (bad cron/tz),nextRunPtrstays nil →UPDATE SET next_run_at = $2writes NULL → schedule excluded from every future tick.Fix (
scheduler.go): replacenext_run_at = $2withnext_run_at = COALESCE($2, next_run_at). When$2is NULL (error case), the existing DB value is preserved. Error is now logged explicitly.Bug 2 — org importer silently discards
ComputeNextRunerrorRoot cause:
nextRun, _ := scheduler.ComputeNextRun(sched.CronExpr, tz, time.Now())— error discarded,time.Time{}(zero) passed to INSERT.Fix (
handlers/org.go): surface the error, log it, andcontinue(skip the INSERT) — consistent with how prompt resolution errors are handled in the same loop.Bug 3 — no startup repair for already-NULL'd schedules
Root cause: schedules broken by the pre-fix binary stay broken forever even after patching.
Fix (
scheduler.go):Start()callsrepairNullNextRunAt()once on boot — queriesenabled = true AND next_run_at IS NULL, recomputes viaComputeNextRun, and UPDATEs each row. Logs count of repaired/skipped schedules.Tests added (all pass)
TestFireSchedule_ComputeNextRunErrorTestRecordSkipped_ComputeNextRunErrorTestRepairNullNextRunAt_RepairsRowsTestRepairNullNextRunAt_DBError_NoPanicTestOrgImport_ScheduleComputeErrorTest output
Test plan
go build ./...— cleango test ./... -count=1— all packages pass🤖 Generated with Claude Code