Skip to content

fix(plugin): run cache purge queue writes in transactions - #4305

Merged
riderx merged 2 commits into
mainfrom
fix/purge-rpc-transactions
Dec 1, 2026
Merged

riderx merged 2 commits into
mainfrom
fix/purge-rpc-transactions

Conversation

@riderx

@riderx riderx commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Root cause of the /updates cache purge storm I've been chasing in prod since the #4290 release. #4303 and #4304 were needed, but they couldn't take effect because of this.

The purge queue RPCs were sent as bare SELECTs:

  • claim_updates_cache_purge
  • ack_updates_cache_purge
  • notify_updates_edge_cache_purge

Hyperdrive caches SELECTs and can answer them from its query cache without running them. These functions write (leases, the shared throttle, requeues, pending rows), so a cached answer means the write never happens.

Production evidence (2026-12-01 08:2x UTC, measured together):

  • pg_stat_user_tables.n_tup_upd on updates_cache_purge_state rose by 13 in about 75 s. Every claim that runs updates that row.
  • In the same window, the API worker logged 930 updates cache purged batches.
  • So over 900 batches came from cached claim results. Many drains replayed one cached claim, purged the same 100 apps against Cloudflare, and got 3,000+ 429s every 2 minutes.
  • Cached failed acks never applied fix(plugin): pause every cache purge drain while Cloudflare rate-limits purges #4304's back-off. Enqueues could be dropped the same way.

Fix: the claim, ack and both enqueue calls now run inside withPgTransaction. That's the existing pattern for queue RPCs that write (plugin_state_sync.ts mutate(), with the same comment). A transaction always reaches the database. This doesn't make a read uncacheable to dodge stale data, which AGENTS.md forbids: these calls are writes. They're one round trip per drain batch, not request-path reads.

The same bare-SELECT-of-a-writing-function pattern also exists in:

  • begin_app_storage_cleanup_pass in on_app_delete.ts
  • delta_gc_finish in cron_delta_storage_gc.ts
  • track_onboarding_demo_data in public/app/demo.ts

Not changed here, so this incident fix stays small. They're worth checking next.

Test plan

  • New tests/updates-cache-purge-transaction.unit.test.ts: the drain's claim and the enqueue both run inside a transaction.
  • Existing tests that mock utils/pg.ts get a pass-through withPgTransaction.
  • bun run test:unit (681 files), typecheck:backend, lint:backend, lint:deadcode
  • CI
  • After deploy: real updates_cache_purge_state updates match logged purge batches, 429s drop, and updates_cache_purge_pending drains.

No rendered UI changes, so there are no screenshots.

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

claim_updates_cache_purge, ack_updates_cache_purge and
notify_updates_edge_cache_purge were called as bare SELECTs, which Hyperdrive
can answer from its query cache without running them. In prod the throttle row
was updated 13 times while the worker logged 930 purge batches in 75s: drains
replayed one cached claim and purged the same apps, failed acks never applied
their back-off, and enqueues could be dropped. They now run in a transaction,
like plugin_state_sync's mutate().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@riderx
riderx deployed to deepsec-pr December 1, 2026 08:27 — with GitHub Actions Active
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 5 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 2c792d75-f464-49b5-8050-3ad5e23b5a73
Commits

Reviewing files that changed from the base of the PR and between 71e68c4 and e1c370e.

Files selected for processing: 7

  • supabase/functions/_backend/triggers/on_version_update.ts
  • supabase/functions/_backend/triggers/updates_cache_purge.ts
  • tests/compatibility-events-handler.test.ts
  • tests/on-version-update-cleanup.unit.test.ts
  • tests/purge-updates-cache-triggers.unit.test.ts
  • tests/updates-cache-purge-transaction.unit.test.ts
  • tests/version-notifications.unit.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-01T08:29:32.059403Z 6b2b69b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@riderx
riderx deployed to deepsec-pr December 1, 2026 08:31 — with GitHub Actions Active
@codspeed

codspeed Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing fix/purge-rpc-transactions (e1c370e) with main (71e68c4)

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

sonarqubecloud Bot commented Dec 1, 2026

Copy link
Copy Markdown

@riderx

riderx commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@riderx
riderx merged commit 31cf3d9 into main Dec 1, 2026
80 checks passed
@riderx
riderx deleted the fix/purge-rpc-transactions branch December 1, 2026 08:36

This branch was successfully deployed

1 active deployment
deepsec-pr — e1c370e8 Deployed Dec 1, 2026 by riderx via Scan PR changes #12342
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