Skip to content

Duplicate link conversions on concurrent track/sale requests - #4076

Merged
steven-tey merged 5 commits into
mainfrom
track-sale-conversion-race
Jun 26, 2026
Merged

Duplicate link conversions on concurrent track/sale requests#4076
steven-tey merged 5 commits into
mainfrom
track-sale-conversion-race

Conversation

@pepeladeira

@pepeladeira pepeladeira commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes
    • Prevented duplicate “first conversion” counting when multiple sale events are handled at the same time.
    • Ensures only the successfully recorded first conversion updates conversion counts and timestamps, avoiding inflated revenue and partner metrics.
    • Aligns commission and metrics workflows to use the deduplicated first-conversion result rather than the initial candidate check.

@vercel

vercel Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dub Ready Ready Preview Jun 26, 2026 4:08am

Request Review

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dec390ff-04ca-4d40-bb9f-413d6bf55892

📥 Commits

Reviewing files that changed from the base of the PR and between a87efaa and d6ed9e9.

📒 Files selected for processing (1)
  • apps/web/lib/api/conversions/track-sale.ts

📝 Walkthrough

Walkthrough

_trackSale now claims first-conversion handling through Redis before applying the conversion update, commission creation input, and partner metrics payload.

Changes

First-conversion claim deduplication

Layer / File(s) Summary
Atomic claim and propagation
apps/web/lib/api/conversions/track-sale.ts
firstConversionFlag is derived from isFirstConversion, then updated by an atomic Redis SET NX claim and used to gate conversion, commission, and metrics updates.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • devkiran
  • steven-tey

Poem

(_/)
A bunny hopped through Redis light,
Claimed first conversion, crisp and right.
One flag, one count, no double spree,
Then metrics danced in harmony. 🐰

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: making track-sale conversion handling concurrency-safe to avoid duplicate link conversions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch track-sale-conversion-race

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

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

@devkiran
devkiran marked this pull request as ready for review June 26, 2026 03:49

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/lib/api/conversions/track-sale.ts`:
- Around line 507-516: The first-conversion Redis claim in track-sale should not
expire before the sale is fully durable, because customer.sales is updated later
in the waitUntil pipeline. Update the claim logic around
claimedFirstConversion/redis.set so the key either uses a TTL that safely covers
the entire async sale workflow or is replaced with a more durable claim tied to
the customer/link state, ensuring link.conversions cannot be incremented twice
if the background tasks are delayed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6b7cb0f6-6166-402b-9a7c-2b1353ff04c9

📥 Commits

Reviewing files that changed from the base of the PR and between a87efaa and 793d0ec.

📒 Files selected for processing (1)
  • apps/web/lib/api/conversions/track-sale.ts

Comment thread apps/web/lib/api/conversions/track-sale.ts Outdated
@devkiran

Copy link
Copy Markdown
Collaborator

@coderabbitai full review please

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

@devkiran On it — I’ll run a full review of #4076.

✅ Action performed

Full review finished.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/lib/api/conversions/track-sale.ts`:
- Around line 509-519: The Redis claim in track-sale’s firstConversionFlag path
can throw or time out and currently prevents the sale ingestion flow from
reaching the waitUntil persistence logic. Update the claim handling around
redis.set in track-sale to use try/catch, keep firstConversionFlag false when
the claim check fails, and log the error so dedup failures do not block
recording the sale.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5a26f424-1951-4c33-bc4c-2466e84f0faa

📥 Commits

Reviewing files that changed from the base of the PR and between a87efaa and d6ed9e9.

📒 Files selected for processing (1)
  • apps/web/lib/api/conversions/track-sale.ts

Comment thread apps/web/lib/api/conversions/track-sale.ts
@devkiran

Copy link
Copy Markdown
Collaborator

@coderabbitai final review

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

@devkiran: On it — I’ll do a final pass on #4076.

✅ Action performed

Full review finished.

@steven-tey
steven-tey merged commit 32834f6 into main Jun 26, 2026
11 checks passed
@steven-tey
steven-tey deleted the track-sale-conversion-race branch June 26, 2026 18:00
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.

3 participants