fix(cron): run due jobs before recomputing next run times#9755
Closed
AI-Chef wants to merge 1 commit intoopenclaw:mainfrom
Closed
fix(cron): run due jobs before recomputing next run times#9755AI-Chef wants to merge 1 commit intoopenclaw:mainfrom
AI-Chef wants to merge 1 commit intoopenclaw:mainfrom
Conversation
The cron scheduler was not executing due jobs because ensureLoaded() with forceReload would call recomputeNextRuns() before runDueJobs(), pushing all overdue job times into the future. Fix by adding skipRecompute option to ensureLoaded() and restructuring onTimer() to: 1. Load jobs without recomputing 2. Run due jobs first 3. Then recompute next run times for the next cycle
4 tasks
Member
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.
Problem
The cron scheduler was not executing due jobs because
ensureLoaded()withforceReloadwould callrecomputeNextRuns()beforerunDueJobs(), pushing all overdue job times into the future.This caused cron jobs to never execute - every time the timer fired, the due jobs would have their
nextRunAtMsrecalculated to a future time before they could be run.Solution
skipRecomputeoption toensureLoaded()onTimer()to:Testing
Verified that cron jobs now execute correctly at their scheduled times.
Greptile Overview
Greptile Summary
This PR fixes a logic bug in the cron scheduler where a forced reload (
ensureLoaded({ forceReload: true })) recomputednextRunAtMsbefore executing overdue jobs, effectively pushing all “due” jobs into the future and preventing them from ever running.Changes:
src/cron/service/store.ts: extendsensureLoaded()with an optionalskipRecomputeflag to allow callers to load the store without immediately recalculating next run times.src/cron/service/timer.ts: restructuresonTimer()to (1) reload the store without recomputing next runs, (2) run due jobs, and then (3) recompute next runs and persist, ensuring overdue jobs execute before their schedule is advanced.This fits with existing behavior where job state (including
state.nextRunAtMs) is persisted in the cron store and recomputation is used to keep schedules accurate across restarts and long-running processes.Confidence Score: 5/5
(2/5) Greptile learns from your feedback when you react with thumbs up/down!