🐛 fix(claim): resolve concurrency race condition in grantFreeClaimItem#675
🐛 fix(claim): resolve concurrency race condition in grantFreeClaimItem#675ShafinNigamana wants to merge 20 commits into
Conversation
|
@ShafinNigamana is attempting to deploy a commit to the ixotic27-8245's projects Team on Vercel. A member of the Team first needs to authorize it. |
📋 GSSoC Label Validation Report
|
| Category | Valid Labels | Rules |
|---|---|---|
| Approval | gssoc:approved |
Required to score and merge |
| Difficulty | level:beginner / intermediate / advanced / critical |
Exactly one is required |
| Quality | quality:clean / quality:exceptional |
Optional (max one); exceptional requires reviewer comment |
| Type | type:bug, type:feature, type:docs, type:testing, type:refactor, type:design, type:accessibility, type:performance, type:devops, type:security |
At least one is required |
| Blocking | gssoc:invalid, gssoc:spam, gssoc:ai-slop |
Excludes PR from scoring and blocks merge |
|
🚨 Hey @ShafinNigamana, the CI Pipeline is failing on this PR and it has been marked as 🔍 What failed:
📋 Error Details (first 3):
Please fix the issues before this can be reviewed. Here's how: 1. Run checks locally before pushing: npm run lint # Run ESLint
npm run build # Verify production build passes2. Auto-fix common issues: npm run lint -- --fix # Auto-fix lint errors where possible3. Check the full failure log here: Once you push a fix and the CI passes, the |
|
Hi @ShafinNigamana, Thank you for your pull request! We noticed a database execution issue with this implementation. The SQL migration adds a partial unique index: CREATE UNIQUE INDEX IF NOT EXISTS idx_purchases_unique_free
ON purchases (developer_id, item_id)
WHERE provider = 'free';Because this index is partial, performing a Supabase/PostgREST upsert with This causes all free claim calls to fail with a database error. Please update the implementation (e.g. by using a standard |
|
Hi @ShafinNigamana, Thank you for your pull request! We noticed a database execution issue with this implementation. The SQL migration adds a partial unique index: CREATE UNIQUE INDEX IF NOT EXISTS idx_purchases_unique_free
ON purchases (developer_id, item_id)
WHERE provider = 'free';Because this index is partial, performing a Supabase/PostgREST upsert with This causes all free claim calls to fail with a database error. Please update the implementation (e.g. by using a standard |
|
Hi @Ixotic27, Thank you for the review and explanation! I have updated the implementation on the Changes Made:
|
What does this PR do?
Resolves a concurrency race condition in the
grantFreeClaimItemAPI by converting the check-then-insert flow into an atomic operation:purchasestable for free claims (provider = 'free') on(developer_id, item_id).grantFreeClaimIteminsrc/lib/items.tsto perform a single atomicupsertwithignoreDuplicates: trueand conflict targets.provider_tx_idasfree_claim_${developerId}_${FREE_CLAIM_ITEM}to ensure unique transaction identifiers per user and item.src/lib/__tests__/claim-free-item-atomic.test.tsto verify the concurrency and idempotency guard behavior.Related issue
Fixes #669
Screenshots
N/A - This is a backend database constraint and logic change. There are no UI/UX, layout, or rendering modifications.
Checklist
npm run lintpasses