Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@devkiran
Copy link
Collaborator

@devkiran devkiran commented Oct 17, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved email delivery reliability for partner program summaries by adding per-partner idempotency tracking to batch sends, reducing duplicate emails.

@vercel
Copy link
Contributor

vercel bot commented Oct 17, 2025

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

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Oct 17, 2025 8:43am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 17, 2025

Walkthrough

A partner program summary cron route now includes an Idempotency-Key header in each email batch payload sent via Resend. The header uses the format program.id-partner.id and is added alongside existing fields like subject, to, react, and variant.

Changes

Cohort / File(s) Summary
Partner Program Summary Email Batch
apps/web/app/(ee)/api/cron/partner-program-summary/route.ts
Added Idempotency-Key header to each per-partner batch email payload with format {program.id}-{partner.id} for request idempotency. No other logic or control-flow changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • dubinc/dub#2541: Refactors payout reminder cron route to use Resend batch emails; related to per-partner batch email construction and sending.

Suggested reviewers

  • steven-tey

Poem

🐰 I stitched a key for every send,

program-dot-id with partner-friend.
No echoes hop, no double starts,
Just tidy batches, faithful parts.
Hooray — the inbox peace imparts! 📬

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Add Idempotency header to PartnerProgramSummary" directly and accurately describes the main change in the pull request, which adds an Idempotency-Key header to email batch payloads sent from the PartnerProgramSummary route. The title is concise, clear, and specific enough that a teammate reviewing the commit history would immediately understand the primary change without ambiguity. It avoids vague terminology, file listings, or unnecessary noise, making it an effective summary of the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add-idempotency-key-partner-summary

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a47067c and cf1b20d.

📒 Files selected for processing (1)
  • apps/web/app/(ee)/api/cron/partner-program-summary/route.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/app/(ee)/api/cron/partner-program-summary/route.ts

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 46a8b5a and a47067c.

📒 Files selected for processing (1)
  • apps/web/app/(ee)/api/cron/partner-program-summary/route.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (1)
apps/web/app/(ee)/api/cron/partner-program-summary/route.ts (1)

334-336: The sendBatchEmail function accepts the headers parameter as part of the TypeScript signature.

The Resend API supports a "headers" parameter for custom email headers in batch email payloads, allowing you to add headers per message. However, note that Idempotency-Key is documented as an HTTP request header for deduplicating an entire batch (not per-message). The current implementation adds a unique Idempotency-Key to each individual email item in the batch, which may not align with the documented pattern. Verify that this per-message approach is intentional and produces the desired deduplication behavior.

Comment on lines 334 to 336
headers: {
"Idempotency-Key": `${program.id}-${partner.id}`,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Include reporting period in the idempotency key.

The current idempotency key format (${program.id}-${partner.id}) lacks a temporal component, meaning the same key is reused every month. While email providers typically expire idempotency keys after 24 hours, this creates two concerns:

  1. If the cron job needs to be re-run within the idempotency TTL window (e.g., to fix a bug or update data), the duplicate key will prevent emails from being resent to partners.
  2. The intent isn't explicit—each monthly report is a distinct email and should have a unique key.

Including the reporting period makes the key unique per report cycle and more robust.

Apply this diff to include the reporting period:

+      const reportingMonth = format(currentMonth, "MMM yyyy");
+
       await sendBatchEmail(
         summary.map(({ partner, ...rest }) => ({
           subject: `Your ${reportingMonth} performance report for ${program.name} program`,
           to: partner.email!,
           react: PartnerProgramSummary({
             program,
             partner,
             ...rest,
             reportingPeriod: {
               month: reportingMonth,
               start: currentMonth.toISOString(),
               end: endOfMonth(currentMonth).toISOString(),
             },
           }),
           variant: "notifications",
           headers: {
-            "Idempotency-Key": `${program.id}-${partner.id}`,
+            "Idempotency-Key": `${program.id}-${partner.id}-${format(currentMonth, "yyyy-MM")}`,
           },
         })),
       );

Note: Move the reportingMonth declaration above the sendBatchEmail call as shown, since it's currently declared at line 317 but needs to be accessible here. Alternatively, use format(currentMonth, "yyyy-MM") directly in the idempotency key as suggested above.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In apps/web/app/(ee)/api/cron/partner-program-summary/route.ts around lines 334
to 336, the idempotency key currently uses `${program.id}-${partner.id}` and
must include the reporting period so each monthly report is unique; move the
reportingMonth declaration (currently at ~line 317) above the sendBatchEmail
call and change the header to include it (e.g.
`${program.id}-${partner.id}-${reportingMonth}`) or inline the formatted month
with format(currentMonth, "yyyy-MM") in the Idempotency-Key; ensure the
reportingMonth/format expression is defined before the headers and preserve
existing string interpolation and header structure.

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.

2 participants