Repository navigation
fix(billing): serialize Gmail inbox allowance decisions so racing alias signups can't both keep it - #9431
Conversation
…as signups can't both keep it
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
[Medium impact] The changes since the previous review appear safe to merge. SummaryThe PR puts Gmail allowance decisions inside a transaction with a shared inbox lock. It also removes the allowance from later aliases when the earlier account’s signup finishes last.
|
There was a problem hiding this comment.
All reported issues were addressed across 8 files
This PR changes concurrency-sensitive code such as locks, queues, or retries. Ultrareviews find 2.4x more serious bugs than standard reviews. Comment @cubic-dev-ai ultrareview to run one.
Turn on auto-fix | Re-trigger cubic
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
Summary
user.create.afterruns, so two signups on one Gmail inbox could race: the later account's earlier-account check could run before the earlier row was visible, and both kept the free allowance (follow-up to fix(billing): withhold the free allowance from Gmail aliases of an existing account #9418)handleNewUsernow decides inside one transaction under a per-inbox advisory lock (acquireGmailInboxLock, existingacquireAdvisoryXactLock), inserts the stats row, then withdraws the allowance from any later alias on the inbox that got in first (laterGmailAliasesWithAllowance) — the earliest account keeps it whichever hook runs firstidentityHadFreeAllowancemoves tolib/users/free-allowance.ts; the admin balance grant now uses it, so a stats row it creates applies the Gmail rule too (it previously checked deleted identities only)user_gmail_mailbox_idx; test schema mock gainsgmailMailboxType of Change
Testing
lib/users/gmail-alias.integration.tson real Postgres (INTEGRATION_DB_PROVISION=migrate): 11/11. New guards shown red with the fix disabled: an alias whose signup decided first loses the allowance once the earlier account decides; a held inbox lock blocks a same-inbox signup (pg_blocking_pids); the fallback never withdraws from a later alias. Index test now EXPLAINs the self-join shapelib/billing/core/usage.test.ts,lib/admin/dashboard-credit-grant.test.ts: 30/30bun run lint,check:file-names,check:test-patterns,check:comment-hygiene,check:unused-exports,check:boundaries,check:schema-mock;drizzle-kit generatereports no driftChecklist
test-auditauthoring gate)