Fix scheduled workflows executing multiple times (#506)#667
Open
DevDesai444 wants to merge 2 commits intosuperglue-ai:mainfrom
Open
Fix scheduled workflows executing multiple times (#506)#667DevDesai444 wants to merge 2 commits intosuperglue-ai:mainfrom
DevDesai444 wants to merge 2 commits intosuperglue-ai:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
1 issue found across 7 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/core/datastore/postgres.ts">
<violation number="1" location="packages/core/datastore/postgres.ts:1208">
P2: listDueToolSchedules uses `CURRENT_TIMESTAMP at time zone 'utc'` (timestamp without tz) while the new `updateScheduleNextRun` guard uses `CURRENT_TIMESTAMP` (timestamptz). In Postgres, comparing a timestamp without tz to a timestamptz assumes the session time zone, so if the DB isn’t set to UTC these two “now” values diverge. That can make listDue return schedules that aren’t actually due (or miss due ones), leading to failed claims or delays with the new guard.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Add one-off context when rerunning by tagging
@cubic-dev-aiwith guidance or docs links (includingllms.txt) - Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
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
Problem
Scheduled workflows could run twice in quick succession when concurrent scheduler workers picked up the same due schedule.
Root cause
updateScheduleNextRunupdated by schedule id without checking that the schedule was still due at update time.Fix
enabled = true AND next_run_at <= CURRENT_TIMESTAMPFixes #506
Issue: #506
Summary by cubic
Prevents duplicate scheduled workflow runs by making schedule advancement a single-claim operation on due schedules. Aligns due-schedule selection and claim checks to the same TIMESTAMPTZ semantics to avoid timezone mismatches.
Written for commit b82252c. Summary will update on new commits.