-
Notifications
You must be signed in to change notification settings - Fork 0
Code Review Bench PR #25526 - Updated the scaling factors for domain warmup #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: base_pr_25526_20260125_9231
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,7 @@ type LabsService = { | |||||
| }; | ||||||
|
|
||||||
| type EmailModel = { | ||||||
| findOne: (options: {filter: string; order: string}) => Promise<EmailRecord | null>; | ||||||
| findPage: (options: {filter: string; order: string; limit: number}) => Promise<{data: EmailRecord[]}>; | ||||||
| }; | ||||||
|
|
||||||
| type EmailRecord = { | ||||||
|
|
@@ -20,22 +20,48 @@ type WarmupScalingTable = { | |||||
| limit: number; | ||||||
| scale: number; | ||||||
| }[]; | ||||||
| defaultScale: number; | ||||||
| highVolume: { | ||||||
| threshold: number; | ||||||
| maxScale: number; | ||||||
| maxAbsoluteIncrease: number; | ||||||
| }; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Configuration for domain warming email volume scaling. | ||||||
| * | ||||||
| * | Volume Range | Multiplier | | ||||||
| * |--------------|--------------------------------------------------| | ||||||
| * | ≤100 (base) | 200 messages | | ||||||
| * | 101 – 1k | 1.25× (conservative early ramp) | | ||||||
| * | 1k – 5k | 1.5× (moderate increase) | | ||||||
| * | 5k – 100k | 1.75× (faster ramp after proving deliverability) | | ||||||
| * | 100k – 400k | 2× | | ||||||
| * | 400k+ | min(1.2×, +75k) cap | | ||||||
| */ | ||||||
| const WARMUP_SCALING_TABLE: WarmupScalingTable = { | ||||||
| base: { | ||||||
| limit: 100, | ||||||
| value: 200 | ||||||
| }, | ||||||
| thresholds: [{ | ||||||
| limit: 1_000, | ||||||
| scale: 1.25 | ||||||
| }, { | ||||||
| limit: 5_000, | ||||||
| scale: 1.5 | ||||||
| }, { | ||||||
| limit: 100_000, | ||||||
| scale: 2 | ||||||
| scale: 1.75 | ||||||
| }, { | ||||||
| limit: 400_000, | ||||||
| scale: 1.5 | ||||||
| scale: 2 | ||||||
| }], | ||||||
| defaultScale: 1.25 | ||||||
| highVolume: { | ||||||
| threshold: 400_000, | ||||||
| maxScale: 1.2, | ||||||
| maxAbsoluteIncrease: 75_000 | ||||||
| } | ||||||
| }; | ||||||
|
|
||||||
| export class DomainWarmingService { | ||||||
|
|
@@ -72,17 +98,18 @@ export class DomainWarmingService { | |||||
| * @returns The highest number of messages sent from the CSD in a single email (excluding today) | ||||||
| */ | ||||||
| async #getHighestCount(): Promise<number> { | ||||||
| const email = await this.#emailModel.findOne({ | ||||||
| filter: `created_at:<${new Date().toISOString().split('T')[0]}`, | ||||||
| order: 'csd_email_count DESC' | ||||||
| const result = await this.#emailModel.findPage({ | ||||||
| filter: `created_at:<=${new Date().toISOString().split('T')[0]}`, | ||||||
| order: 'csd_email_count DESC', | ||||||
| limit: 1 | ||||||
| }); | ||||||
|
|
||||||
| if (!email) { | ||||||
| if (!result.data.length) { | ||||||
| return 0; | ||||||
| } | ||||||
|
|
||||||
| const count = email.get('csd_email_count'); | ||||||
| return count || 0; | ||||||
| const count = result.data[0].get('csd_email_count'); | ||||||
| return count != null ? count : 0; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
@@ -94,12 +121,20 @@ export class DomainWarmingService { | |||||
| return WARMUP_SCALING_TABLE.base.value; | ||||||
| } | ||||||
|
|
||||||
| // For high volume senders (400k+), cap the increase at 20% or 75k absolute | ||||||
| if (lastCount >= WARMUP_SCALING_TABLE.highVolume.threshold) { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚨 Bug: High volume check
|
||||||
| if (lastCount >= WARMUP_SCALING_TABLE.highVolume.threshold) { | |
| if (lastCount > WARMUP_SCALING_TABLE.highVolume.threshold) { |
- Apply suggested fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚨 Bug: Off-by-one: < should be <= in threshold comparison
The change from <= to < on line 132 causes every threshold boundary value to be assigned to the wrong scaling tier. For example:
lastCount = 1000:1000 < 1000is false, falls through to the 5k bucket → returns1500(1.5×) instead of the expected1250(1.25×)lastCount = 5000:5000 < 5000is false, falls through to 100k bucket → returns8750(1.75×) instead of7500(1.5×)lastCount = 100000: falls through to 400k bucket → returns200000(2×) instead of175000(1.75×)
This contradicts the documented behavior in the comment table (lines 33-40), the test expectations, and the PR's stated scaling tiers. The unit tests for boundary values will fail.
Fix: Change < back to <= on line 132:
if (lastCount <= threshold.limit) {Was this helpful? React with 👍 / 👎
| if (lastCount < threshold.limit) { | |
| if (lastCount <= threshold.limit) { |
- Apply suggested fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<to<=may include today's emailsThe filter was changed from
created_at:<${today}tocreated_at:<=${today}(line 102), but the JSDoc on line 98 still says "excluding today."The original
<operator excluded all records from today. The new<=operator may include today's records depending on how the ORM compares timestamps against date-only strings. If the ORM interprets<=2026-02-15as<= 2026-02-15T00:00:00.000Z, records created at midnight would be included. If it interprets it as<= 2026-02-15T23:59:59.999Z, all of today's records would be included.Including today's emails in the "highest count" query could cause the warmup limit to reflect the current send rather than historical data, defeating the purpose of progressive warming. The test on line 181 also still asserts
created_at:<(without=), so the test won't catch this.Fix: Revert to
<to maintain the documented "excluding today" behavior:Was this helpful? React with 👍 / 👎