perf(jobs): prune terminal rows on their own hourly clock, index-usable bound - #506
Merged
Conversation
…le bound Pruning ran on every lease-reap tick even though retention is measured in days, and its per-row retention predicate could never use job_queue_terminal_idx, so every tick was a full scan of each workspace's terminal rows. Split the prune onto JOB_PRUNE_INTERVAL_MS (default 1h) and lead the predicate with the shortest retention as a constant bound so the partial index applies; lease reaping keeps its fast cadence. Co-authored-by: Cursor <cursoragent@cursor.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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
pruneTerminalJobsran on every lease-reap tick (JOB_REAP_INTERVAL_MS) although retention is measured in days. It now runs on its ownJOB_PRUNE_INTERVAL_MSclock (default 1 hour); lease reaping is unchanged.runMaintenanceTicktakes{ prune }and defaults to the historical behaviour for callers with a single clock.finished_at < now() - make_interval(secs => COALESCE(overrides -> queue ->> status, default))depends on the row's ownqueue/status, so the planner could never usejob_queue_terminal_idxand scanned every terminal row per call. The statement now leads withfinished_at < now() - <shortest retention anywhere>as a constant, index-usable bound; the precise per-row test still decides the outcome, so semantics are unchanged.JOBS.md§8 documents the new variable.Test plan
worker.test.ts: first maintenance tick prunes, subsequent ticks within the prune window do not, the next window prunes againrunner.test.ts:runMaintenanceTick(config, { prune: false })still terminates a dead lease and leaves an aged terminal row alonejob-queue.test.ts: a row past the shortest window but inside its own longer override is kept (the floor only narrows the scan)Made with Cursor