Skip to content

fix(db): skip missing pgmq tables in queue cleanup - #2734

Merged
riderx merged 1 commit into
mainfrom
fix/cleanup-queue-skip-missing-tables
Jul 23, 2026
Merged

fix(db): skip missing pgmq tables in queue cleanup#2734
riderx merged 1 commit into
mainfrom
fix/cleanup-queue-skip-missing-tables

Conversation

@riderx

@riderx riderx commented Jul 23, 2026

Copy link
Copy Markdown
Member

Summary (AI generated)

  • Make cleanup_queue_messages skip queues whose pgmq.q_* / pgmq.a_* tables are missing
  • Delete obsolete pgmq.meta row for replicate_data when tables are gone
  • Add regression test for meta-without-tables leftover

Motivation (AI generated)

Capgo-EU reclaim failed with relation "pgmq.a_replicate_data" does not exist. replicate_data is an obsolete meta leftover (documented as omitted in prod baseline) still returned by pgmq.list_queues().

Business Impact (AI generated)

Unblocks Capgo-EU queue archive reclaim and hourly cleanup cron.

Test Plan (AI generated)

  • Local vitest: skips queues whose archive tables are missing
  • Deploy migration, re-run SELECT public.cleanup_queue_messages()
  • Confirm Notices report archived/stuck deletes without error

Generated with AI

Made with Cursor

Review in cubic

Summary by CodeRabbit

  • Bug Fixes

    • Improved queue cleanup reliability when queue or archive tables are missing.
    • Prevented cleanup failures caused by stale queue metadata.
    • Continued removing expired archived messages and stuck queue messages in batches.
  • Tests

    • Added coverage confirming cleanup succeeds when archive tables are unavailable.

pgmq.meta can list obsolete queues like replicate_data with no q_/a_
tables; cleanup_queue_messages must skip those instead of failing.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 13416b4c-fa95-42af-aaf0-2f6cb9636998

📥 Commits

Reviewing files that changed from the base of the PR and between 4f9f2cf and 0bb0ca7.

📒 Files selected for processing (2)
  • supabase/migrations/20260723113511_cleanup_queue_skip_missing_tables.sql
  • tests/cleanup_swap_memory.test.ts

📝 Walkthrough

Walkthrough

The migration hardens public.cleanup_queue_messages() against stale pgmq.meta entries whose queue or archive relations are missing, preserves batched cleanup behavior, updates permissions, removes obsolete metadata conditionally, and adds coverage for missing archive tables.

Changes

Queue cleanup resilience

Layer / File(s) Summary
Safe cleanup execution
supabase/migrations/20260723113511_cleanup_queue_skip_missing_tables.sql, tests/cleanup_swap_memory.test.ts
The cleanup function resolves relations with to_regclass, conditionally deletes eligible rows in batches, and the test verifies successful execution when an archive relation is absent.
Permissions and metadata repair
supabase/migrations/20260723113511_cleanup_queue_skip_missing_tables.sql
Function ownership and privileges are updated, and the obsolete replicate_data metadata row is removed only when both relations are missing.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Vitest
  participant cleanup_queue_messages
  participant pgmq.meta
  participant pgmq_relations
  Vitest->>pgmq.meta: Insert stale queue metadata
  Vitest->>cleanup_queue_messages: Invoke cleanup
  cleanup_queue_messages->>pgmq.meta: Read queue metadata
  cleanup_queue_messages->>pgmq_relations: Resolve queue/archive relations
  cleanup_queue_messages->>pgmq_relations: Delete from existing relations only
  cleanup_queue_messages-->>Vitest: Complete successfully
Loading

Possibly related PRs

Suggested labels: codex

Suggested reviewers: dalanir

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

@riderx
riderx marked this pull request as ready for review July 23, 2026 11:36
@cursor

cursor Bot commented Jul 23, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot 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: serverGenReqId_44df1349-9630-4fe9-b6ab-75fe235c4903)

@riderx
riderx merged commit 4fc5500 into main Jul 23, 2026
37 of 58 checks passed
@riderx
riderx deleted the fix/cleanup-queue-skip-missing-tables branch July 23, 2026 11:36

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Risk: medium. Cursor Bugbot did not complete (usage limit reached), so I am not approving. This PR is already merged; the migration change is narrow and includes a regression test, but Bugbot's incomplete run leaves no automated sign-off.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

@coderabbitai coderabbitai Bot added the codex label Jul 23, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Risk: medium. Cursor Bugbot did not complete (check skipped; usage limit), so automated review is unavailable for this database migration. Not approving; human review would have been required, but this PR is already merged.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver External

@codspeed-hq

codspeed-hq Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing fix/cleanup-queue-skip-missing-tables (0bb0ca7) with main (4f9f2cf)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@sonarqubecloud

Copy link
Copy Markdown

cursor Bot pushed a commit that referenced this pull request Jul 23, 2026
Main #2734 skips missing pgmq tables during cleanup so PGlite/Tinbase
unit/DB tests stop failing with relation "pgmq.meta" does not exist.

Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant