fix(plugin): run cache purge queue writes in transactions
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_purgeack_updates_cache_purgenotify_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_updonupdates_cache_purge_staterose by 13 in about 75 s. Every claim that runs updates that row.- In the same window, the API worker logged 930
updates cache purgedbatches. - 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 #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_passinon_app_delete.tsdelta_gc_finishincron_delta_storage_gc.tstrack_onboarding_demo_datainpublic/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.tsget a pass-throughwithPgTransaction. -
bun run test:unit(681 files),typecheck:backend,lint:backend,lint:deadcode - CI
- After deploy: real
updates_cache_purge_stateupdates match logged purge batches, 429s drop, andupdates_cache_purge_pendingdrains.
No rendered UI changes, so there are no screenshots.
š¤ Generated with Claude Code