Repository navigation
Conversation
… short statements EnqueueSearchTimeCrossings read the whole jobs heap in one statement (41 min on average on prod) and DeleteIneligibleEnrichmentOutbox probed jobs_pkey for every queue row (up to 102 min), each holding its snapshot the whole time. - Age crossings become EnqueueSearchAgeCrossings: range scans on jobs_open_created_idx and jobs_open_enrich_freshness_idx, one call. - Unseen-window crossings become EnqueueSearchUnseenCrossings: job_activity walked in 1M-row primary-key chunks, pre-cut to the distinct window bands. - The enrichment reaper walks the queue in 100k job_id chunks, probing jobs_sitemap_idx; the per-run bound of 20k deletions is unchanged. On the prod replica the old and new enqueue select the same 37,958 jobs for one window; each new statement runs in seconds there.
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: d93f7764-4443-46e8-88d1-1b6250ce2a0f) |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Why
Two housekeeping statements ran for tens of minutes on prod and held one snapshot the whole time, which stops autovacuum and makes
CONCURRENTLYoperations wait:EnqueueSearchTimeCrossings(reindex marker-only, 3×/day)DeleteIneligibleEnrichmentOutbox(start of each hourly enrich run)(pg_stat_statements on core since 2026-11-04.)
What
EnqueueSearchAgeCrossings: oneUNIONof range scans,created_atonjobs_open_created_idx,posted_atonjobs_open_enrich_freshness_idx(written asposted_at IS NOT NULL+COALESCErange, which is exact; a bareposted_atrange made the planner skip-scanjobs_company_slug_idxfor 185 s).EnqueueSearchUnseenCrossings: walksjob_activityin 1M-row primary-key chunks (last_seen_atstays unindexed on purpose). Each chunk is first cut to the bands of the distinct windows (4 of them, not one per source), so only the rows that may cross reach thejobslookup.cmd/reindexloops the chunks and moves its cursor only after all of them succeed, as before.job_idorder (index-only on the(job_id, target_version)key) and anti-joinsjobs_sitemap_idx, the open-and-canonical partial index, which is the claim's own filter. Every live entry of a doomed job is deleted, including a version past the chunk edge.cmd/enrichloops until it has deleted 20k (same bound as before) or reached the end.All three keep
ON CONFLICT DO NOTHING/ id order and the dead-letter exemption.Measurements (prod replica on operator, which other jobs were loading)
jobs(5.2M blocks)jobs_pkeyprobes)Equivalence on real data: for the same
(since, until], the old query and the two new ones selected the same 37,958 jobs (0 only-old, 0 only-new). CoreEXPLAIN(no ANALYZE) shows the same index plans, including the reaper's generic plan.Tests
search_time_reach_integration_test: walksjob_activityone row per chunk; adds a job with nojob_activityrow, a closed crossing and a repost crossing.enrichment_reaper_integration_test: chunk size 1 with a job whose two versions straddle a chunk edge; the bound test goes through the loop.cmd/reindexunit tests: cursor passing between chunks, and a failed chunk keeps the pass cursor.Note
Medium Risk
Touches scheduled reindex and hourly enrich housekeeping SQL with cursor semantics; equivalence was validated on prod replica but incorrect chunking could miss queues or over-delete in edge cases.
Overview
Replaces two long-running DB housekeeping statements with chunked, cursor-driven passes so each statement finishes in seconds instead of holding a snapshot for tens of minutes (blocking autovacuum and concurrent index work).
Time-crossings enqueue (
cmd/reindex):EnqueueSearchTimeCrossingssplits intoEnqueueSearchAgeCrossings(index-backedUNIONofcreated_at/posted_atage bands) andEnqueueSearchUnseenCrossings(1M-row walks overjob_activitywithafter_idcursors). The reindex worker loops unseen chunks before advancing the pass cursor; failures still block cursor movement.Enrichment reaper (
cmd/enrich):DeleteIneligibleEnrichmentOutboxnow takesafter_job_id/chunk_size/max_rows, scans the queue in 100kjob_idchunks via the outbox index, and returnslast_job_id+deleted.Reaploops until the same 20k bound or end of queue.Tests cover chunk boundaries (multi-version doomed jobs, unseen cursor walks, failed chunks), integration paths mirror production loops, and worker docs reference the new query names.
Reviewed by Cursor Bugbot for commit bc0e49a. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit