Skip to content

Configure Email Usage Alert Logic#278

Merged
KMKoushik merged 2 commits intomainfrom
claude/email-usage-alerts-011CUP5EbPpy7o3ybnxJwB2F
Oct 24, 2025
Merged

Configure Email Usage Alert Logic#278
KMKoushik merged 2 commits intomainfrom
claude/email-usage-alerts-011CUP5EbPpy7o3ybnxJwB2F

Conversation

@KMKoushik
Copy link
Copy Markdown
Member

@KMKoushik KMKoushik commented Oct 24, 2025

  • Teams with inactive subscriptions (isActive=false) now receive the same email usage alerts as FREE plan users
  • Sends 80% warning email at 2,400 emails (80% of 3,000 monthly limit)
  • Sends monthly limit reached email at 3,000 emails
  • Uses FREE plan limits (3,000 emails/month) for all inactive subscriptions
  • Improves user communication when subscriptions become inactive

🤖 Generated with Claude Code


Summary by cubic

Treats inactive teams like FREE plans for monthly email usage alerts. Adds clear thresholds and logging to warn at 80% and notify when the monthly limit is reached.

  • New Features
    • Apply FREE plan monthly limit (3,000 emails) to inactive subscriptions (isActive=false).
    • Send 80% warning at 2,400 emails; send limit-reached email at 3,000.
    • Improve logging with isActive flag and clearer context.

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Updated monthly email limit handling to consistently apply FREE plan limits to inactive subscriptions
    • Improved notification messaging to clarify when monthly email limits apply to free or inactive accounts
    • Enhanced logging to track subscription active status for better visibility into limit enforcement

- Teams with inactive subscriptions (isActive=false) now receive the same
  email usage alerts as FREE plan users
- Sends 80% warning email at 2,400 emails (80% of 3,000 monthly limit)
- Sends monthly limit reached email at 3,000 emails
- Uses FREE plan limits (3,000 emails/month) for all inactive subscriptions
- Improves user communication when subscriptions become inactive

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Oct 24, 2025

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

Project Deployment Preview Comments Updated (UTC)
unsend-marketing Ready Ready Preview Comment Oct 24, 2025 6:02pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Oct 24, 2025

Warning

Rate limit exceeded

@KMKoushik has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 33 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between dec2156 and ff72fa7.

📒 Files selected for processing (1)
  • apps/web/src/server/service/limit-service.ts (10 hunks)

Walkthrough

The change updates email limit checking logic to treat inactive subscriptions similarly to FREE plan accounts for monthly limits. When a subscription is inactive, the system now applies FREE plan monthly limits and generates notifications accordingly, regardless of the actual plan tier. Monthly limit thresholds and notifications now reference "FREE plan or inactive subscription." Logging is enhanced with an isActive flag to track subscription state. Daily limit behavior remains unchanged.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Configure Email Usage Alert Logic" is directly related to the main change in this pull request. The PR modifies how email usage alerts are triggered by reconfiguring the logic for inactive subscriptions to use FREE plan limits and alert thresholds. The title accurately reflects this core modification to the alert system, is concise and clear with no vague terminology, and avoids unnecessary noise. A teammate reviewing the repository history would understand that this commit involves changes to email alert behavior, which is the essence of the changeset.

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
Copy Markdown
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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/src/server/service/limit-service.ts (1)

134-137: Apply daily limit logic consistently for inactive subscriptions.

The daily and monthly limit logic treat inactive subscriptions asymmetrically. While inactive subscriptions use the FREE monthly limit (3,000 emails), the daily limit still uses the original team.dailyEmailLimit (which could be unlimited for BASIC plans).

The suggested fix in the original comment has a logic error. When an inactive BASIC plan uses PLAN_LIMITS[team.plan].emailsPerDay, it evaluates to -1 (unlimited) rather than the FREE daily limit. Instead, use PLAN_LIMITS.FREE.emailsPerDay when inactive:

 const dailyLimit =
-  team.plan !== "FREE"
+  team.plan !== "FREE" && team.isActive
     ? team.dailyEmailLimit
-    : PLAN_LIMITS[team.plan].emailsPerDay;
+    : PLAN_LIMITS.FREE.emailsPerDay;

This ensures inactive subscriptions (regardless of plan) follow the same daily and monthly limits as FREE plans.

🧹 Nitpick comments (1)
apps/web/src/server/service/limit-service.ts (1)

176-193: Consider removing duplicate logging statement.

The logging at lines 176-179 and 190-193 is identical and redundant. The values being logged don't change between these two points, so the second logging statement (lines 190-193) can be safely removed.

Apply this diff to remove the duplicate:

     logger.info(
       { monthlyUsage, monthlyLimit, team, isActive: team.isActive },
       `[LimitService]: Monthly usage and limit (FREE plan or inactive subscription)`
     );

     if (monthlyUsage / monthlyLimit > 0.8 && monthlyUsage < monthlyLimit) {
       await TeamService.sendWarningEmail(
         teamId,
         monthlyUsage,
         monthlyLimit,
         LimitReason.EMAIL_FREE_PLAN_MONTHLY_LIMIT_REACHED
       );
     }

-    logger.info(
-      { monthlyUsage, monthlyLimit, team, isActive: team.isActive },
-      `[LimitService]: Monthly usage and limit (FREE plan or inactive subscription)`
-    );
-
     if (isLimitExceeded(monthlyUsage, monthlyLimit)) {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 77b0239 and dec2156.

📒 Files selected for processing (1)
  • apps/web/src/server/service/limit-service.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Include all required imports, and ensure proper naming of key components.

Files:

  • apps/web/src/server/service/limit-service.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: TypeScript-first: use .ts/.tsx for source code (avoid JavaScript source files)
Use 2-space indentation and semicolons (Prettier 3 enforces these)
Adhere to @usesend/eslint-config; fix all ESLint warnings (CI fails on warnings)
Do not use dynamic imports; always place imports at the top of the module

Files:

  • apps/web/src/server/service/limit-service.ts
**/*.{ts,tsx,md}

📄 CodeRabbit inference engine (AGENTS.md)

Format code with Prettier 3 (run pnpm format)

Files:

  • apps/web/src/server/service/limit-service.ts
apps/web/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

apps/web/**/*.{ts,tsx}: In apps/web, use the / alias for src imports (e.g., import { x } from "/utils/x")
Prefer using tRPC in apps/web unless explicitly asked otherwise

Files:

  • apps/web/src/server/service/limit-service.ts
🧬 Code graph analysis (1)
apps/web/src/server/service/limit-service.ts (1)
apps/web/src/lib/constants/plans.ts (1)
  • PLAN_LIMITS (12-36)
🔇 Additional comments (2)
apps/web/src/server/service/limit-service.ts (2)

103-103: LGTM: Documentation accurately reflects the new behavior.

The comment clearly documents that inactive subscriptions receive FREE plan treatment for monthly limit alerts.


167-174: Monthly limit logic correctly implements the requirement.

The condition properly treats both FREE plans and inactive subscriptions with the same 3,000 email/month limit. The explicit use of PLAN_LIMITS.FREE.emailsPerMonth ensures consistency.

However, this change should be reviewed alongside the daily limit behavior to ensure the overall limit strategy is coherent (see comment on lines 134-137).

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Oct 24, 2025

Deploying usesend with  Cloudflare Pages  Cloudflare Pages

Latest commit: ff72fa7
Status: ✅  Deploy successful!
Preview URL: https://69bf502c.usesend.pages.dev
Branch Preview URL: https://claude-email-usage-alerts-01.usesend.pages.dev

View logs

@KMKoushik KMKoushik merged commit 1c9056b into main Oct 24, 2025
5 checks passed
@KMKoushik KMKoushik deleted the claude/email-usage-alerts-011CUP5EbPpy7o3ybnxJwB2F branch October 24, 2025 18:37
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