chore(workflows): add cyclotron index for the reschedule sweep predicate - #71473
Merged
Conversation
Partial composite index (function_id, action_id, scheduled) WHERE status = 'available' on cyclotron_jobs, supporting the timing-edit reschedule sweep queries (#71293). Shipped separately per the migration/service separation rule; the sweep's queries are safe without it (they fall back to the function_id index plus a heap filter), so ordering against the service deploy is not critical - but this should merge first so the sweep never runs unindexed at scale. Generated-By: PostHog Code Task-Id: 7f5083cf-5d17-4f37-8bee-8c43db70cb79
mayteio
added a commit
that referenced
this pull request
Jul 16, 2026
The migrations-separation check forbids sqlx migrations and nodejs service changes in one PR; the index now ships in #71473. Generated-By: PostHog Code Task-Id: 7f5083cf-5d17-4f37-8bee-8c43db70cb79
mayteio
marked this pull request as ready for review
July 16, 2026 10:42
Contributor
|
Reviews (1): Last reviewed commit: "chore(workflows): add cyclotron index fo..." | Re-trigger Greptile |
2 tasks
dmarchuk
approved these changes
Jul 16, 2026
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
#71293 adds a reschedule sweep whose queries filter
cyclotron_jobsbyfunction_id,action_id,status, andscheduled.action_idhas never been indexed, so at the scale the sweep is built for (parked backlogs into the hundreds of thousands) each call would repeat a heap-filtered scan up to ~22 times against the live queue table. Raised as a must-fix by ReviewHog on #71293; the migrations-separation check (correctly) refuses to let the migration ship in the same PR as the service code, hence this standalone PR.Changes
One sqlx migration for the cyclotron-node database:
Partial on
status = 'available'(only parked rows are sweepable, and it keeps the index off the write path of terminal transitions),scheduledas a trailing key column so the sweep's range predicate lands in the Index Cond rather than a heap filter - same reasoning, and sameCREATE INDEX CONCURRENTLY/-- no-transactionpattern, as the email fair-dequeue composite index (20260622000001).team_idis deliberately left out:function_idis a per-workflow UUID and already maximally selective, soteam_idstays a cheap residual filter.Ordering: should merge before #71293's feature is exercised, but nothing breaks without it - the sweep's queries fall back to the existing
function_idindex plus a heap filter, just slower.How did you test this code?
Ran the migration against the local cyclotron-node test database, seeded 50k parked rows (mixed action_ids, one workflow), and confirmed via
EXPLAINthat the planner uses a bitmap index scan with all three columns in the Index Cond and onlyteam_idas a residual filter. The full cyclotron-v2 Jest suite (113 tests) passes against the migrated schema. No new tests: an index has no behavior of its own to pin, and the queries it serves are covered in #71293.Automatic notifications
Docs update
Not needed - the module README note pointing at this index ships with #71293.
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Authored with PostHog Code (Claude). Split out of #71293 after the migrations-separation check flagged the sqlx migration + nodejs service code combination; the index itself was ReviewHog's (valid) must-fix finding there.
Created with PostHog Code