From 186a1398abb680a919df187c53b2faeafaf3f6ec Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 22 Jul 2026 12:35:44 +0000 Subject: [PATCH] fix(webapp): billing alert preview uses current limit instead of stale saved amount After a customer raised their billing limit, the alert-threshold percentage preview kept calculating dollar amounts against the previous limit until they re-saved their alerts. This happened because the preview reused the alert record's snapshotted amount whenever saved percentage levels existed. The preview now returns the snapshot only when it still matches the current effective/plan limit, and otherwise falls back to the current effective limit, so the preview reflects the saved billing limit immediately. Adds a regression test covering the raised-limit scenario. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01TywtuVBcXSNVTV6nJbgLk8 --- .../billing-alert-preview-current-limit.md | 6 ++++++ .../app/components/billing/billingAlertsFormat.ts | 3 --- apps/webapp/test/billingAlertsFormat.test.ts | 12 ++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 .server-changes/billing-alert-preview-current-limit.md diff --git a/.server-changes/billing-alert-preview-current-limit.md b/.server-changes/billing-alert-preview-current-limit.md new file mode 100644 index 00000000000..9ab90e952e7 --- /dev/null +++ b/.server-changes/billing-alert-preview-current-limit.md @@ -0,0 +1,6 @@ +--- +area: webapp +type: fix +--- + +Raising your billing limit now updates the alert threshold preview amounts right away, instead of showing figures based on the previous limit until you save your alerts again. diff --git a/apps/webapp/app/components/billing/billingAlertsFormat.ts b/apps/webapp/app/components/billing/billingAlertsFormat.ts index dc99c49ff1d..27b2fe035cf 100644 --- a/apps/webapp/app/components/billing/billingAlertsFormat.ts +++ b/apps/webapp/app/components/billing/billingAlertsFormat.ts @@ -315,9 +315,6 @@ export function getAlertPreviewLimitCents( planLimitCents: number ): number { const amountCents = getSavedAlertAmountCents(alerts); - if (amountCents > 0 && percentageAlertLevelsToUiThresholds(alerts.alertLevels).length > 0) { - return amountCents; - } if (percentageAlertAmountMatches(amountCents, effectiveLimitCents, planLimitCents)) { return amountCents; } diff --git a/apps/webapp/test/billingAlertsFormat.test.ts b/apps/webapp/test/billingAlertsFormat.test.ts index 7ef84770d7b..275dc5adfbb 100644 --- a/apps/webapp/test/billingAlertsFormat.test.ts +++ b/apps/webapp/test/billingAlertsFormat.test.ts @@ -90,6 +90,18 @@ describe("billingAlertsFormat", () => { ).toBe(10_000); }); + it("previews percentage alerts against the current limit after it is raised", () => { + // Alerts were saved against an old $30 limit; the customer has since raised + // it to $300. The preview should follow the current limit, not the snapshot. + expect( + getAlertPreviewLimitCents( + { amount: 30, emails: [], alertLevels: [0.75, 0.9] }, + 30_000, + 10_000 + ) + ).toBe(30_000); + }); + it("normalizes legacy API alerts with dollar amount field and whole percents", () => { expect( normalizeBillingAlertsFromApi(