-
Notifications
You must be signed in to change notification settings - Fork 0
Updated the scaling factors for domain warmup #27
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: coderabbit_combined_20260121_augment_sentry_coderabbit_1_base_updated_the_scaling_factors_for_domain_warmup_pr242
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) { | ||||||||||||||||||||||||
| const scaledIncrease = Math.ceil(lastCount * WARMUP_SCALING_TABLE.highVolume.maxScale); | ||||||||||||||||||||||||
| const absoluteIncrease = lastCount + WARMUP_SCALING_TABLE.highVolume.maxAbsoluteIncrease; | ||||||||||||||||||||||||
| return Math.min(scaledIncrease, absoluteIncrease); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| for (const threshold of WARMUP_SCALING_TABLE.thresholds.sort((a, b) => a.limit - b.limit)) { | ||||||||||||||||||||||||
| if (lastCount <= threshold.limit) { | ||||||||||||||||||||||||
| if (lastCount < threshold.limit) { | ||||||||||||||||||||||||
| return Math.ceil(lastCount * threshold.scale); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
131
to
135
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. Boundary condition bug: threshold comparison should use The
The same issue affects all boundary values (1000, 5000, 100000, 400000). Additionally, Proposed fix- for (const threshold of WARMUP_SCALING_TABLE.thresholds.sort((a, b) => a.limit - b.limit)) {
- if (lastCount < threshold.limit) {
+ for (const threshold of [...WARMUP_SCALING_TABLE.thresholds].sort((a, b) => a.limit - b.limit)) {
+ if (lastCount <= threshold.limit) {
return Math.ceil(lastCount * threshold.scale);
}
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return Math.ceil(lastCount * WARMUP_SCALING_TABLE.defaultScale); | ||||||||||||||||||||||||
| // This should not be reached given the thresholds cover all cases up to highVolume.threshold | ||||||||||||||||||||||||
| return Math.ceil(lastCount * WARMUP_SCALING_TABLE.highVolume.maxScale); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
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.
Filter may include today's emails contrary to the documented intent.
The comment on line 98 states "excluding today", but the filter on line 102 uses
<=which would include emails created today. If the intent is to exclude today's sends when calculating the next limit, the filter should use<instead.Proposed fix
async `#getHighestCount`(): Promise<number> { const result = await this.#emailModel.findPage({ - filter: `created_at:<=${new Date().toISOString().split('T')[0]}`, + filter: `created_at:<${new Date().toISOString().split('T')[0]}`, order: 'csd_email_count DESC', limit: 1 });📝 Committable suggestion
🤖 Prompt for AI Agents