Skip to content

perf(jobs): prune terminal rows on their own hourly clock, index-usable bound - #506

Merged
mortondev merged 1 commit into
mainfrom
perf/job-prune-cadence
Sep 6, 2026
Merged

perf(jobs): prune terminal rows on their own hourly clock, index-usable bound#506
mortondev merged 1 commit into
mainfrom
perf/job-prune-cadence

Conversation

@mortondev

Copy link
Copy Markdown
Member

Summary

  • pruneTerminalJobs ran on every lease-reap tick (JOB_REAP_INTERVAL_MS) although retention is measured in days. It now runs on its own JOB_PRUNE_INTERVAL_MS clock (default 1 hour); lease reaping is unchanged. runMaintenanceTick takes { prune } and defaults to the historical behaviour for callers with a single clock.
  • The prune predicate finished_at < now() - make_interval(secs => COALESCE(overrides -> queue ->> status, default)) depends on the row's own queue/status, so the planner could never use job_queue_terminal_idx and scanned every terminal row per call. The statement now leads with finished_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 again
  • runner.test.ts: runMaintenanceTick(config, { prune: false }) still terminates a dead lease and leaves an aged terminal row alone
  • job-queue.test.ts: a row past the shortest window but inside its own longer override is kept (the floor only narrows the scan)
  • typecheck, lint, prettier

Made with Cursor

…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>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@mortondev
mortondev merged commit f57343d into main Sep 6, 2026
14 checks passed
@mortondev
mortondev deleted the perf/job-prune-cadence branch September 6, 2026 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant