Skip to content

Add plan usage warning buckets for emails#902

Merged
tudddorrr merged 2 commits intodevelopfrom
usage-warning-buckets
Mar 27, 2026
Merged

Add plan usage warning buckets for emails#902
tudddorrr merged 2 commits intodevelopfrom
usage-warning-buckets

Conversation

@tudddorrr
Copy link
Copy Markdown
Collaborator

No description provided.

@claude
Copy link
Copy Markdown

claude Bot commented Mar 27, 2026

PR Review: Add plan usage warning buckets for emails


🟡 Potential Bugs

Email fires when usage drops between buckets

The condition currentBucket !== lastUsageWarningThreshold triggers any time the bucket changes — including when usage decreases. For example: usage drops from 90% to 80%, getUsageBucket(80) returns 75, 75 !== 90 is true, so a "75% usage warning" email is sent even though utilization went down.

The test suite covers dropping below all buckets (to null) but not dropping between two non-null buckets (e.g. 90→75).

Fix — only send when advancing to a higher bucket:

const previousThreshold = organisationPricingPlan.lastUsageWarningThreshold
if (currentBucket !== previousThreshold) {
  organisationPricingPlan.lastUsageWarningThreshold = currentBucket
  await em.flush()

  if (currentBucket !== null && (previousThreshold === null || currentBucket > previousThreshold)) {
    await queueEmail(...)
  }
}

🔵 Minor

em.flush() before queueEmail() — missed email on queue failure

If queueEmail throws after the flush, lastUsageWarningThreshold is already persisted. The email is never sent, and since the threshold is recorded, it will never be retried for that bucket. Reversing the order (queue first, then flush) means a failed flush at worst causes a duplicate email — generally the safer tradeoff for a notification system.


No issues found

  • Code quality / best practices
  • Performance
  • Security
  • Migration correctness
  • getUsageBucket unit tests are thorough and well-structured

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.33%. Comparing base (accc1f0) to head (138c654).
⚠️ Report is 3 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #902   +/-   ##
========================================
  Coverage    97.33%   97.33%           
========================================
  Files          405      405           
  Lines         6527     6537   +10     
  Branches       851      856    +5     
========================================
+ Hits          6353     6363   +10     
  Misses          90       90           
  Partials        84       84           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tudddorrr tudddorrr merged commit 54d67a2 into develop Mar 27, 2026
10 checks passed
@tudddorrr tudddorrr deleted the usage-warning-buckets branch March 27, 2026 08:29
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.

1 participant