mirror of
https://github.com/warmbly/warmbly.git
synced 2026-11-21 00:06:38 +00:00
Merge pull request #1202 from warmbly/t3/2f91cde5
feat: per-campaign ramp-up choice (replies, schedule, full volume) in the wizard, settings and API
This commit is contained in:
@@ -67,6 +67,7 @@ A `data` plus `pagination` envelope. `next_cursor` is the campaign id to resume
|
||||
"ramp_increment": 0,
|
||||
"ramp_ceiling": 0,
|
||||
"ramp_level": 0,
|
||||
"warmup_graduation": true,
|
||||
"esp_match_mode": "off",
|
||||
"max_new_leads_per_day": 0,
|
||||
"prioritize_new_leads": false,
|
||||
@@ -116,7 +117,7 @@ Status-bucket counts plus per-folder totals for the organization, used to drive
|
||||
|
||||
`POST /campaigns-estimate`
|
||||
|
||||
Project an audience against a sender pool before a campaign exists. The campaign is simulated day by day under the scheduler's own rules: each mailbox's cap and the campaign limit, the warmup graduation ceiling as it climbs, the workspace's risk band, health bands and holds, domain authentication, cold rotation, sending behaviour profiles, the plan's daily allowance, what other campaigns already send from the same mailboxes, and the sending window with its spacing. The warmup mail each warming mailbox keeps sending shares that spacing, so it is counted too. For a sequence, due follow-ups go out before new contacts start, and the totals assume nobody replies. Nothing is written, so it needs no `Idempotency-Key`. The dashboard's new-campaign flow shows this as its launch plan. **Scope** `READ_CAMPAIGNS` · **Org permission** `view_campaigns`.
|
||||
Project an audience against a sender pool before a campaign exists. The campaign is simulated day by day under the scheduler's own rules: each mailbox's cap and the campaign limit, the campaign's ramp-up (its schedule as it climbs, or the warmup graduation ceiling when it ramps as replies come in), the workspace's risk band, health bands and holds, domain authentication, cold rotation, sending behaviour profiles, the plan's daily allowance, what other campaigns already send from the same mailboxes, and the sending window with its spacing. The warmup mail each warming mailbox keeps sending shares that spacing, so it is counted too. For a sequence, due follow-ups go out before new contacts start, and the totals assume nobody replies. Nothing is written, so it needs no `Idempotency-Key`. The dashboard's new-campaign flow shows this as its launch plan. **Scope** `READ_CAMPAIGNS` · **Org permission** `view_campaigns`.
|
||||
|
||||
### Request body
|
||||
|
||||
@@ -131,6 +132,8 @@ Project an audience against a sender pool before a campaign exists. The campaign
|
||||
| `start_time` | string | no | Daily window start (`HH:MM`). Defaults to `08:00`, the window a new campaign gets. |
|
||||
| `end_time` | string | no | Daily window end (`HH:MM`). Defaults to `18:00`. An end at or before the start returns `400`. |
|
||||
| `step_waits` | integer[] | no | Each follow-up's `wait_after` in days (0 to 365), in order. Omit for a single email. At most 30. |
|
||||
| `warmup_graduation` | boolean | no | As on create. Defaults to the saved campaign's, else `true`. |
|
||||
| `ramp_enabled`, `ramp_start`, `ramp_increment`, `ramp_ceiling` | boolean, integers | no | The ramp schedule to project, as on create. Unsent fields come from the saved campaign, else a new campaign's defaults. A saved campaign's ramp keeps the level it has reached unless one of the numbers changes. |
|
||||
| `campaign_id` | string | no | Project a saved campaign of this workspace. Its leads that no linked segment enrolled count toward `recipients` together with `segment_ids` (each contact once; leads a segment link enrolled count only while that segment is in `segment_ids`, since unlinking it withdraws them). Anything not sent (`daily_limit`, `days`, `timezone`, the window, including per-day windows) is taken from the campaign, and one that sends from mailboxes picked one by one uses those. A campaign from another workspace returns `404`. |
|
||||
|
||||
### Response
|
||||
@@ -141,10 +144,10 @@ Project an audience against a sender pool before a campaign exists. The campaign
|
||||
| --- | --- |
|
||||
| `steps`, `total_sends` | Emails per contact, and `recipients` times `steps`. |
|
||||
| `first_touch_finish_at` | The day the last contact gets their first email. |
|
||||
| `ramping`, `held` | Mailboxes still climbing their graduation ceiling, and mailboxes that send nothing today. |
|
||||
| `ramping`, `held` | Mailboxes still climbing their warmup graduation ceiling, and mailboxes that send nothing today. A campaign that ramps on a schedule shows its climb in `first_day_cap`, `steady_cap` and `full_capacity_at` instead. |
|
||||
| `warmup` | `{mailboxes, per_day, per_day_without, reply_rate}`: the warmup mail running alongside the campaign, what the same mailboxes warm at with no live campaign, and the least chance (in percent) that a pool partner with reply share left answers it on arrival while the campaign runs. Partners answer this warmup before other warmup mail, within their own reply rate. |
|
||||
| `other_campaigns_per_day` | What the pool's mailboxes sent for other campaigns on an average day over the last week. |
|
||||
| `bottleneck` | The clamp that costs the most sends on the first full sending day: `campaign_limit`, `warmup_graduation`, `spacing`, `other_campaigns`, `health`, `held`, `workspace_risk`, `org_daily_limit` or `sending_behavior`. Empty when the mailboxes' own caps are the limit. |
|
||||
| `bottleneck` | The clamp that costs the most sends on the first full sending day: `campaign_limit`, `campaign_ramp`, `warmup_graduation`, `spacing`, `other_campaigns`, `health`, `held`, `workspace_risk`, `org_daily_limit` or `sending_behavior`. Empty when the mailboxes' own caps are the limit. |
|
||||
| `timeline` | Up to 120 days from the start: `date`, `sending_day`, `capacity`, `sends`, `first_emails`, `follow_ups`, `warmup`. |
|
||||
| `senders` | Up to 200 mailboxes: `id`, `email`, `provider`, `state` (`ready`, `ramping`, `throttled`, `health_hold`, `domain_auth`, `resting`, `no_worker`), `first_day_cap`, `steady_cap`, `warmup_per_day`, `warmup_without`, `full_cap_at`. |
|
||||
| `scenarios` | Changes that would finish sooner, each simulated the same way and listed only when it beats `estimated_finish_at`: `kind` (`replies`: the given percent of leads reply, `more_mailboxes`: that many more mailboxes like these, `every_day`: the same hours on every day of the week), `value`, `finish_at`. |
|
||||
@@ -220,10 +223,11 @@ Create a campaign. Only `name` is required, every other field is optional and ap
|
||||
| `rotation_mode` | string | no | How volume spreads across the chosen mailboxes. |
|
||||
| `follow_up_sender` | string | no | Which mailbox sends a lead's follow-ups: `same` (default, the mailbox that sent the first email), `same_domain` (rotate among mailboxes on that domain) or `rotate` (rotate across the pool). Any other value is `400`. |
|
||||
| `senders` | object[] | no | Explicit-strategy mailbox pool (see sender input below). |
|
||||
| `ramp_enabled` | boolean | no | Enable per-campaign daily ramp-up. |
|
||||
| `ramp_start` | integer | no | Ramp starting volume. |
|
||||
| `ramp_increment` | integer | no | Daily ramp increment. |
|
||||
| `ramp_ceiling` | integer | no | Ramp ceiling (never raises above the per-mailbox cap). |
|
||||
| `ramp_enabled` | boolean | no | Ramp each mailbox's volume on a schedule: `ramp_start` on the first sending day, plus `ramp_increment` each sending day, up to `ramp_ceiling`. Default `false`. |
|
||||
| `ramp_start` | integer | no | Ramp starting volume, `1` to `5000` (default `10`). |
|
||||
| `ramp_increment` | integer | no | Daily ramp increment, `0` to `100` (default `5`). |
|
||||
| `ramp_ceiling` | integer | no | Ramp ceiling, `1` to `5000` and at least `ramp_start` (default `50`). It never raises a mailbox above its own cap. |
|
||||
| `warmup_graduation` | boolean | no | Hold mailboxes whose warmup is running or paused to the reply-earned ceiling in this campaign: `5` a day, plus one a day for each lead who replied in the last seven days. Default `true`. `false` leaves each mailbox's daily cap, `daily_limit` and the ramp. The dashboard sets `false` with `ramp_enabled: true` for **On a schedule**, and both `false` for **Full volume**. See [ramp-up](/guides/campaigns/#ramp-up). |
|
||||
| `esp_match_mode` | string | no | `off`, `prefer`, or `strict`. |
|
||||
| `max_new_leads_per_day` | integer | no | New-lead throttle, `0` is unlimited. |
|
||||
| `prioritize_new_leads` | boolean | no | Prefer new leads in each send window. |
|
||||
@@ -290,7 +294,7 @@ Patch any subset of campaign fields. Omitted fields are left unchanged. The expl
|
||||
|
||||
### Request body
|
||||
|
||||
Every field is optional. Scalar fields use nullable pointers, so any field you send is applied. `timezone` accepts `""` to make the campaign follow the workspace timezone. `start_date` and `end_date` additionally accept an explicit `null` to clear the stored date: a null `start_date` means "start now" and a null `end_date` means "run open-ended". Changing any schedule field (`start_date`, `end_date`, `timezone`, `timezone_mode`, `days`, `start_time`, `end_time`, `schedule_windows`, `entry_delay_minutes`) on an active campaign reschedules its next send immediately, so clearing a future start date or shortening the entry delay takes effect right away. Notable fields: `name`, `description`, `status`, `stop_on_reply`, `stop_on_meeting`, `open_tracking`, `link_tracking`, `text_only`, `daily_limit`, `unsubscribe_header`, `risky_emails`, `cc`, `bcc`, `start_date`, `end_date`, `timezone`, `timezone_mode`, `days`, `start_time`, `end_time`, `schedule_windows`, `email_tags`, `folders`, `contact_order_by`, `contact_order_dir`, `contact_order_field`, `sender_strategy`, `rotation_mode`, `follow_up_sender`, `ramp_enabled`, `ramp_start`, `ramp_increment`, `ramp_ceiling`, `esp_match_mode`, `max_new_leads_per_day`, `prioritize_new_leads`, `entry_delay_minutes`, `continuous`, `tracking_domain`, `utm_tracking`, `utm_source`, `utm_medium`, `utm_campaign`.
|
||||
Every field is optional. Scalar fields use nullable pointers, so any field you send is applied. `timezone` accepts `""` to make the campaign follow the workspace timezone. `start_date` and `end_date` additionally accept an explicit `null` to clear the stored date: a null `start_date` means "start now" and a null `end_date` means "run open-ended". Changing any schedule field (`start_date`, `end_date`, `timezone`, `timezone_mode`, `days`, `start_time`, `end_time`, `schedule_windows`, `entry_delay_minutes`) on an active campaign reschedules its next send immediately, so clearing a future start date or shortening the entry delay takes effect right away. Notable fields: `name`, `description`, `status`, `stop_on_reply`, `stop_on_meeting`, `open_tracking`, `link_tracking`, `text_only`, `daily_limit`, `unsubscribe_header`, `risky_emails`, `cc`, `bcc`, `start_date`, `end_date`, `timezone`, `timezone_mode`, `days`, `start_time`, `end_time`, `schedule_windows`, `email_tags`, `folders`, `contact_order_by`, `contact_order_dir`, `contact_order_field`, `sender_strategy`, `rotation_mode`, `follow_up_sender`, `ramp_enabled`, `ramp_start`, `ramp_increment`, `ramp_ceiling`, `warmup_graduation`, `esp_match_mode`, `max_new_leads_per_day`, `prioritize_new_leads`, `entry_delay_minutes`, `continuous`, `tracking_domain`, `utm_tracking`, `utm_source`, `utm_medium`, `utm_campaign`.
|
||||
|
||||
`entry_delay_minutes` is anchored on when each contact entered the campaign, not on when the campaign started, so a contact enrolled by a linked segment next week waits the same amount from their own arrival. Leads that were in the campaign before the field existed count from the campaign's `created_at`, so turning a delay on never re-delays leads that have been enrolled for weeks.
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ Campaign names take priority over descriptions in the list. Descriptions use the
|
||||
|
||||
1. **Leads**: name the campaign at the top (left blank, it is named after its first list, or "Campaign" and the date; rename it any time), then pick one or more lead lists. Lists are your [segments](/guides/segments/), shown with how many leads each holds; someone on several lists is emailed once, and the total below counts each lead once. **Import new leads** takes you to Contacts to bring in a CSV and keeps the draft for when you return. Picking no list is fine: **Continue without leads** creates the campaign so you can add leads afterwards.
|
||||
2. **Emails**: the same editor as the Steps tab, with templates, **Write with AI**, variables, a preview rendered through the send engine and the content score. Selecting a template applies both its saved subject and its body. A template without a subject keeps the email's existing subject. Add follow-ups here, each sent a number of days after the previous email (and stopping for anyone who replies or books a meeting, when **Stop on reply** or **Stop on meeting booked** is on). **Add the usual two follow-ups** adds two at 3 and 7 days. A follow-up with no subject replies in the same thread. The emails can also be left for the Steps tab, where you can branch them and add A/B variants.
|
||||
3. **Schedule**: start at launch or on a date, the timezone, sending days and hours, the mailbox tags to send from, and the daily limit per mailbox. Every mailbox in the pool is listed with what it can send: **Ramping up** while it is still graduating from warmup, **Reduced volume** in a watch or throttled health band, **On hold**, **DNS failing** or **Resting** when it will not send. Tracking, UTM parameters, the unsubscribe header, stop on reply and stop on meeting booked are under **Tracking and replies**.
|
||||
3. **Schedule**: start at launch or on a date, the timezone, sending days and hours, the mailbox tags to send from, the daily limit per mailbox, and the [ramp-up](#ramp-up). Every mailbox in the pool is listed with what it can send: **Ramping up** while it is still graduating from warmup, **Reduced volume** in a watch or throttled health band, **On hold**, **DNS failing** or **Resting** when it will not send. Tracking, UTM parameters, the unsubscribe header, stop on reply and stop on meeting booked are under **Tracking and replies**.
|
||||
4. **Review**: the finish date with the arithmetic behind it and what sets the pace, a chart of first emails, follow-ups and warmup against what the pool can send for the campaign, what would finish it sooner, what each mailbox sends with and without the campaign, and a summary with a link back to each step.
|
||||
|
||||
While you work, a **Launch plan** beside the Leads and Schedule steps keeps the estimate current. See [How the estimate works](#how-the-estimate-works).
|
||||
@@ -244,8 +244,8 @@ The number is the sends already out plus what is still expected, and the list un
|
||||
| Limit | What it means |
|
||||
| --- | --- |
|
||||
| Campaign daily limit | The campaign caps each mailbox below the mailbox's own cap |
|
||||
| Campaign ramp-up | Daily ramp-up is still climbing toward its ceiling |
|
||||
| Easing out of warmup | A mailbox whose warmup is running or paused starts cold at `5` a day and adds at most `5` per clean day, never more than its confirmed replies (see [easing out of warmup](#easing-out-of-warmup)) |
|
||||
| Campaign ramp-up | The campaign ramps **on a schedule** and has not reached its ceiling yet |
|
||||
| Easing out of warmup | The campaign ramps **as replies come in**, and a mailbox whose warmup is running or paused starts cold at `5` a day and adds at most `5` per clean day, never more than its confirmed replies (see [easing out of warmup](#easing-out-of-warmup)) |
|
||||
| Workspace sending posture | A restricted workspace sends a fraction of every cap (see [workspace sending posture](/guides/deliverability/#workspace-sending-posture)) |
|
||||
| Domain authentication failing, Resting or in reserve, Held by warmup health | A mailbox that sends nothing cold today, and why |
|
||||
| Waiting for Warmbly Cloud status | [Warmbly Cloud](/guides/warmbly-cloud/#safety-and-enforcement) has not reported a current status for a mailbox it warms. Cold sends from it wait until one arrives; it is not a Cloud quarantine or block |
|
||||
@@ -266,7 +266,19 @@ The sidebar's **sent today** meter reads its denominator the same way: what the
|
||||
Anything above `50`/day per cold mailbox needs positive reputation signals and a low complaint rate behind it. Adding mailboxes is safer than forcing a few to send more.
|
||||
</Callout>
|
||||
|
||||
**Daily ramp-up** grows volume gradually instead of starting at full limit: **ramp start** (default `10`), **ramp increment** (default `5`), and **ramp ceiling** (default `50`). It applies as another minimum, so it only lowers today's volume while ramping. This is separate from mailbox warmup; the two work together.
|
||||
### Ramp-up
|
||||
|
||||
**Ramp-up** decides how each mailbox's daily volume grows in this campaign. Pick it in the wizard's **Schedule** step or in the campaign's preferences under **Rotation & ramp-up**:
|
||||
|
||||
| Option | What each mailbox sends |
|
||||
| --- | --- |
|
||||
| **As replies come in** (the default) | A mailbox whose warmup is running or paused starts at `5` a day and gains one a day for each lead who replied to it in the last seven days, at most `5` more per clean day (see [easing out of warmup](#easing-out-of-warmup)). A mailbox that never warmed, or whose warmup is stopped, sends at its own limit. With a typical cold reply rate this stays close to `5` a day |
|
||||
| **On a schedule** | Starts at the **start** volume (default `10`) on the first sending day and adds the **increase** (default `5`) every sending day until the **ceiling** (default `50`), whatever the replies |
|
||||
| **Full volume** | Up to its daily limit from the first day |
|
||||
|
||||
Every option applies as another minimum against the mailbox's own daily cap, the campaign's daily limit and the minimum gap between sends, so none of them raises a mailbox above its cap. The schedule does not pause on a bounce or a spam placement, and full volume does not climb at all, so watch the campaign's health while volume rises. Warmup keeps running alongside in all three. The launch plan and the estimate in the wizard follow the option you pick.
|
||||
|
||||
Changing the option on an active campaign takes effect from its next send. Setting the schedule's numbers again keeps the level it has reached; it never goes back below the start.
|
||||
|
||||
**Lead flow** throttles new contacts with **Max new leads per day** (`0` for unlimited, up to `1000`). At the cap, follow-ups to in-flight contacts continue and new leads resume tomorrow. You can prioritize new leads over follow-ups, and choose whether to attempt addresses verification flagged risky.
|
||||
|
||||
@@ -588,6 +600,8 @@ A diagnostic-history mailbox starts cold sending at a conservative ceiling of fi
|
||||
|
||||
Confirmed human replies to actual campaign recipients in the last seven days permit bounded increases: at most five per clean day, and never more than the confirmed reply count. Complaints clear positive progression. Without reply evidence, the ceiling stays five/day.
|
||||
|
||||
This applies to campaigns whose [ramp-up](#ramp-up) is **As replies come in**, the default. A campaign set to ramp **on a schedule** or send at **full volume** does not hold its mailboxes to this ceiling.
|
||||
|
||||
Configured campaign/mailbox caps, shared daily/rolling recipient limits and negative-feedback holds still bind. This is product pacing, not a universal provider-approved safe volume or proven reputation benefit. Missing evidence leaves full-cap dates unknown rather than projecting synthetic age into readiness. If the feedback lookup fails or omits a known warmed mailbox, its execution, projection and displayed explanation retain the conservative ceiling. A missing lookup does not mean the mailbox never warmed.
|
||||
|
||||
Stopping warmup on a mailbox ends this ceiling for it: from then on its own daily cap (default `50`/day), the campaign's daily limit and its minimum gap between sends decide its cold volume, as for a mailbox that never warmed. Pausing warmup does not; a paused mailbox stays on the ceiling. Starting warmup again puts the ceiling back where the mailbox's recent reply evidence places it, so a stop and restart does not reset the climb to day one, and does not skip it either. Stopping warmup is a choice to send without this pacing, not a sign that the mailbox is ready for more volume.
|
||||
|
||||
@@ -423,7 +423,7 @@ The standing follows the address, not the connection. Removing a mailbox from th
|
||||
|
||||
## Graduating to cold sending
|
||||
|
||||
Diagnostic-history mailboxes start cold sending at a conservative ceiling of five/day. Synthetic age never increases it. Recent confirmed human replies to actual campaign recipients permit bounded increases, subject to calendar days and negative feedback. Missing evidence leaves readiness/full-cap dates unknown. This product policy is not a provider-approved safe volume. The ceiling applies while warmup is running or paused. Stopping warmup removes it, leaving the mailbox's own daily cap and minimum gap, and starting warmup again restores it from the recent reply evidence. See [easing out of warmup](/guides/campaigns/#easing-out-of-warmup).
|
||||
Diagnostic-history mailboxes start cold sending at a conservative ceiling of five/day. Synthetic age never increases it. Recent confirmed human replies to actual campaign recipients permit bounded increases, subject to calendar days and negative feedback. Missing evidence leaves readiness/full-cap dates unknown. This product policy is not a provider-approved safe volume. The ceiling applies in campaigns whose ramp-up is **As replies come in**, the default; a campaign can instead ramp on a schedule or send at full volume (see [ramp-up](/guides/campaigns/#ramp-up)). The ceiling applies while warmup is running or paused. Stopping warmup removes it, leaving the mailbox's own daily cap and minimum gap, and starting warmup again restores it from the recent reply evidence. See [easing out of warmup](/guides/campaigns/#easing-out-of-warmup).
|
||||
|
||||
</Fold>
|
||||
|
||||
|
||||
@@ -49783,6 +49783,10 @@
|
||||
"ramp_ceiling": {
|
||||
"type": "integer"
|
||||
},
|
||||
"warmup_graduation": {
|
||||
"type": "boolean",
|
||||
"description": "Hold mailboxes whose warmup is running or paused to the reply-earned ceiling in this campaign: 5 a day, plus one a day for each lead who replied in the last seven days. Default true. false leaves each mailbox's daily cap, daily_limit and the ramp."
|
||||
},
|
||||
"ramp_level": {
|
||||
"type": "integer",
|
||||
"description": "Server-managed current ramp level."
|
||||
@@ -49982,6 +49986,10 @@
|
||||
"ramp_ceiling": {
|
||||
"type": "integer"
|
||||
},
|
||||
"warmup_graduation": {
|
||||
"type": "boolean",
|
||||
"description": "Hold mailboxes whose warmup is running or paused to the reply-earned ceiling in this campaign: 5 a day, plus one a day for each lead who replied in the last seven days. Default true. false leaves each mailbox's daily cap, daily_limit and the ramp."
|
||||
},
|
||||
"esp_match_mode": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
@@ -50159,6 +50167,10 @@
|
||||
"ramp_ceiling": {
|
||||
"type": "integer"
|
||||
},
|
||||
"warmup_graduation": {
|
||||
"type": "boolean",
|
||||
"description": "Hold mailboxes whose warmup is running or paused to the reply-earned ceiling in this campaign: 5 a day, plus one a day for each lead who replied in the last seven days. Default true. false leaves each mailbox's daily cap, daily_limit and the ramp."
|
||||
},
|
||||
"esp_match_mode": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
|
||||
@@ -138,6 +138,7 @@ func (d Deps) registerCampaignTools(r *Registry) {
|
||||
"ramp_start": intProp("Ramp starting volume."),
|
||||
"ramp_increment": intProp("Ramp daily increment."),
|
||||
"ramp_ceiling": intProp("Ramp ceiling."),
|
||||
"warmup_graduation": boolProp("Start mailboxes leaving warmup at 5 a day and raise them as campaign recipients reply. Off sends up to each mailbox's daily limit, or the ramp when it is on."),
|
||||
"entry_delay_minutes": intProp(
|
||||
"Minutes to wait before a contact's FIRST email, counted from when they entered the campaign. 0 sends it as soon as the schedule allows; max 129600 (90 days)."),
|
||||
}, "campaign_id"),
|
||||
@@ -253,6 +254,7 @@ func (d Deps) updateCampaign(ctx context.Context, inv Invocation, args json.RawM
|
||||
RampStart *int `json:"ramp_start"`
|
||||
RampIncrement *int `json:"ramp_increment"`
|
||||
RampCeiling *int `json:"ramp_ceiling"`
|
||||
WarmupGraduation *bool `json:"warmup_graduation"`
|
||||
EntryDelayMinutes *int `json:"entry_delay_minutes"`
|
||||
}](args)
|
||||
if err != nil {
|
||||
@@ -281,6 +283,7 @@ func (d Deps) updateCampaign(ctx context.Context, inv Invocation, args json.RawM
|
||||
RampStart: in.RampStart,
|
||||
RampIncrement: in.RampIncrement,
|
||||
RampCeiling: in.RampCeiling,
|
||||
WarmupGraduation: in.WarmupGraduation,
|
||||
EntryDelayMinutes: in.EntryDelayMinutes,
|
||||
}
|
||||
camp, xerr := d.Campaigns.Update(ctx, inv.OrgID.String(), in.CampaignID, upd)
|
||||
|
||||
@@ -1109,6 +1109,44 @@ const estimateHorizonDays = 2 * 366
|
||||
// wired it simulates the campaign day by day under the send path's clamps and
|
||||
// the warmup mail running alongside; without it, it applies only the cap rule
|
||||
// and the result is the earliest the last send can land.
|
||||
// estimateRampUp gives the draft the ramp-up the wizard has: what was sent,
|
||||
// else the saved campaign's, else a new campaign's defaults.
|
||||
func estimateRampUp(draft, saved *models.Campaign, in *models.CampaignEstimate) *errx.Error {
|
||||
draft.WarmupGraduation = true
|
||||
draft.RampStart, draft.RampIncrement, draft.RampCeiling = config.CampaignRampStartDefault, config.CampaignRampIncrementDefault, config.CampaignRampCeilingDefault
|
||||
if saved != nil {
|
||||
draft.WarmupGraduation, draft.RampEnabled = saved.WarmupGraduation, saved.RampEnabled
|
||||
draft.RampStart, draft.RampIncrement, draft.RampCeiling = saved.RampStart, saved.RampIncrement, saved.RampCeiling
|
||||
draft.RampLevel, draft.RampLevelDate = saved.RampLevel, saved.RampLevelDate
|
||||
}
|
||||
if in.WarmupGraduation != nil {
|
||||
draft.WarmupGraduation = *in.WarmupGraduation
|
||||
}
|
||||
if in.RampEnabled != nil {
|
||||
draft.RampEnabled = *in.RampEnabled
|
||||
}
|
||||
edited := false
|
||||
for _, f := range []struct {
|
||||
v *int
|
||||
dst *int
|
||||
}{{in.RampStart, &draft.RampStart}, {in.RampIncrement, &draft.RampIncrement}, {in.RampCeiling, &draft.RampCeiling}} {
|
||||
if f.v != nil && *f.v != *f.dst {
|
||||
*f.dst, edited = *f.v, true
|
||||
}
|
||||
}
|
||||
if !draft.RampEnabled {
|
||||
return nil
|
||||
}
|
||||
if xerr := validate.CampaignRamp(draft.RampStart, draft.RampIncrement, draft.RampCeiling); xerr != nil {
|
||||
return xerr
|
||||
}
|
||||
// A ramp edited in the wizard is drawn from its first day.
|
||||
if edited || saved == nil || !saved.RampEnabled {
|
||||
draft.RampLevel, draft.RampLevelDate = 0, nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *campaignService) Estimate(ctx context.Context, orgID uuid.UUID, in *models.CampaignEstimate) (*models.CampaignEstimateResult, *errx.Error) {
|
||||
out := &models.CampaignEstimateResult{}
|
||||
|
||||
@@ -1225,6 +1263,9 @@ func (s *campaignService) Estimate(ctx context.Context, orgID uuid.UUID, in *mod
|
||||
zone = *in.Timezone
|
||||
}
|
||||
draft := &models.Campaign{OrganizationID: &orgID, DailyLimit: dailyLimit, Days: days, Timezone: zone, StartDate: in.StartDate, StartTime: startTime, EndTime: endTime}
|
||||
if xerr := estimateRampUp(draft, saved, in); xerr != nil {
|
||||
return nil, xerr
|
||||
}
|
||||
// A saved campaign's own per-day windows stand unless a window is sent.
|
||||
if saved != nil && !timesSent && !saved.ScheduleWindows.IsEmpty() {
|
||||
draft.ScheduleWindows = saved.ScheduleWindows
|
||||
@@ -1235,7 +1276,11 @@ func (s *campaignService) Estimate(ctx context.Context, orgID uuid.UUID, in *mod
|
||||
// domain authentication, cold rotation), so the wizard promises what the
|
||||
// send path will honour rather than the caps added up.
|
||||
if planner, ok := s.planner(); ok {
|
||||
capacity, err := planner.PoolCapacityToday(ctx, &models.Campaign{OrganizationID: &orgID, DailyLimit: dailyLimit}, accounts)
|
||||
capacity, err := planner.PoolCapacityToday(ctx, &models.Campaign{
|
||||
OrganizationID: &orgID, DailyLimit: dailyLimit, WarmupGraduation: draft.WarmupGraduation,
|
||||
RampEnabled: draft.RampEnabled, RampStart: draft.RampStart, RampIncrement: draft.RampIncrement,
|
||||
RampCeiling: draft.RampCeiling, RampLevel: draft.RampLevel,
|
||||
}, accounts)
|
||||
if err != nil {
|
||||
errs.CaptureException(err)
|
||||
return nil, errx.InternalError()
|
||||
@@ -1535,7 +1580,7 @@ func (s *campaignService) WorkspaceCapacity(ctx context.Context, orgID uuid.UUID
|
||||
if xerr != nil {
|
||||
return nil, xerr
|
||||
}
|
||||
out, err := planner.PoolCapacityToday(ctx, &models.Campaign{OrganizationID: &orgID}, accounts)
|
||||
out, err := planner.PoolCapacityToday(ctx, &models.Campaign{OrganizationID: &orgID, WarmupGraduation: true}, accounts)
|
||||
if err != nil {
|
||||
errs.CaptureException(err)
|
||||
return nil, errx.InternalError()
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE campaigns DROP COLUMN IF EXISTS warmup_graduation;
|
||||
@@ -0,0 +1,5 @@
|
||||
-- A campaign may opt out of the reply-earned graduation ceiling; existing campaigns keep it.
|
||||
ALTER TABLE campaigns ADD COLUMN IF NOT EXISTS warmup_graduation boolean NOT NULL DEFAULT true;
|
||||
|
||||
COMMENT ON COLUMN public.campaigns.warmup_graduation IS
|
||||
'Hold mailboxes leaving warmup to the reply-earned cold ceiling in this campaign. Off leaves the mailbox cap, the campaign limit and the campaign ramp.';
|
||||
@@ -154,6 +154,11 @@ type Campaign struct {
|
||||
RampLevel int `json:"ramp_level"`
|
||||
RampLevelDate *time.Time `json:"ramp_level_date,omitempty"`
|
||||
|
||||
// WarmupGraduation holds a mailbox leaving warmup to the reply-earned cold
|
||||
// ceiling in this campaign. Off leaves the mailbox cap, the campaign limit
|
||||
// and the campaign ramp as its only volume limits.
|
||||
WarmupGraduation bool `json:"warmup_graduation"`
|
||||
|
||||
// ESP/provider matching: off | prefer | strict.
|
||||
ESPMatchMode string `json:"esp_match_mode"`
|
||||
|
||||
@@ -273,6 +278,13 @@ type CampaignEstimate struct {
|
||||
// StepWaits is each follow-up's wait_after in days, in order. Empty is a
|
||||
// single email.
|
||||
StepWaits []int `json:"step_waits,omitempty"`
|
||||
// The campaign's ramp-up as the wizard has it; unsent fields come from the
|
||||
// saved campaign, else a new campaign's defaults.
|
||||
WarmupGraduation *bool `json:"warmup_graduation,omitempty"`
|
||||
RampEnabled *bool `json:"ramp_enabled,omitempty"`
|
||||
RampStart *int `json:"ramp_start,omitempty"`
|
||||
RampIncrement *int `json:"ramp_increment,omitempty"`
|
||||
RampCeiling *int `json:"ramp_ceiling,omitempty"`
|
||||
// CampaignID projects a saved campaign, filling anything not sent from it.
|
||||
CampaignID *string `json:"campaign_id,omitempty"`
|
||||
}
|
||||
@@ -349,6 +361,7 @@ const (
|
||||
// Bottleneck values of a campaign estimate.
|
||||
const (
|
||||
EstimateBottleneckCampaignLimit = "campaign_limit"
|
||||
EstimateBottleneckCampaignRamp = "campaign_ramp"
|
||||
EstimateBottleneckGraduation = "warmup_graduation"
|
||||
EstimateBottleneckSpacing = "spacing"
|
||||
EstimateBottleneckOtherCampaigns = "other_campaigns"
|
||||
@@ -465,6 +478,8 @@ type UpdateCampaign struct {
|
||||
RampIncrement *int `json:"ramp_increment,omitempty"`
|
||||
RampCeiling *int `json:"ramp_ceiling,omitempty"`
|
||||
|
||||
WarmupGraduation *bool `json:"warmup_graduation,omitempty"`
|
||||
|
||||
ESPMatchMode *string `json:"esp_match_mode,omitempty"`
|
||||
MaxNewLeadsPerDay *int `json:"max_new_leads_per_day,omitempty"`
|
||||
PrioritizeNewLeads *bool `json:"prioritize_new_leads,omitempty"`
|
||||
@@ -499,7 +514,7 @@ func (u *UpdateCampaign) TouchesSchedule() bool {
|
||||
// TouchesPacing reports whether the patch changes how much the campaign may send or from which mailboxes, which a parked wakeup was placed under too.
|
||||
func (u *UpdateCampaign) TouchesPacing() bool {
|
||||
return u.DailyLimit != nil || u.EmailTags != nil || u.SenderStrategy != nil || u.RotationMode != nil || u.FollowUpSender != nil ||
|
||||
u.RampEnabled != nil || u.RampStart != nil || u.RampIncrement != nil || u.RampCeiling != nil ||
|
||||
u.RampEnabled != nil || u.RampStart != nil || u.RampIncrement != nil || u.RampCeiling != nil || u.WarmupGraduation != nil ||
|
||||
u.MaxNewLeadsPerDay != nil || u.ESPMatchMode != nil
|
||||
}
|
||||
|
||||
@@ -552,6 +567,8 @@ type CreateCampaign struct {
|
||||
RampStart *int `json:"ramp_start,omitempty"`
|
||||
RampIncrement *int `json:"ramp_increment,omitempty"`
|
||||
RampCeiling *int `json:"ramp_ceiling,omitempty"`
|
||||
// WarmupGraduation defaults to true: mailboxes leaving warmup earn volume with replies.
|
||||
WarmupGraduation *bool `json:"warmup_graduation,omitempty"`
|
||||
|
||||
// ESP/provider matching + new-lead throttle + tracking-domain override.
|
||||
ESPMatchMode *string `json:"esp_match_mode,omitempty"`
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/warmbly/warmbly/internal/models"
|
||||
)
|
||||
|
||||
// Run against the dev stack:
|
||||
//
|
||||
// WARMBLY_TEST_DB=postgres://warmbly:warmbly@localhost:15432/warmbly_dev?sslmode=disable \
|
||||
// go test ./internal/repository/ -run LiveCampaignWarmupGraduation -v
|
||||
func TestLiveCampaignWarmupGraduation(t *testing.T) {
|
||||
handle, pool := liveContactDB(t)
|
||||
requireSchemaVersion(t, pool, 368)
|
||||
f := newSharedOrgFixture(t, pool)
|
||||
repo := NewCampaignRepostory(handle)
|
||||
ctx := context.Background()
|
||||
|
||||
plain, xerr := repo.Create(ctx, f.owner.String(), &f.org, &models.CreateCampaign{Name: "Graduation default"})
|
||||
if xerr != nil {
|
||||
t.Fatalf("create: %v", xerr)
|
||||
}
|
||||
if !plain.WarmupGraduation {
|
||||
t.Fatal("a new campaign must default to the reply-earned ceiling")
|
||||
}
|
||||
|
||||
off := false
|
||||
start, inc, ceiling, on := 10, 5, 30, true
|
||||
scheduled, xerr := repo.Create(ctx, f.owner.String(), &f.org, &models.CreateCampaign{
|
||||
Name: "Graduation off", WarmupGraduation: &off, RampEnabled: &on, RampStart: &start, RampIncrement: &inc, RampCeiling: &ceiling,
|
||||
})
|
||||
if xerr != nil {
|
||||
t.Fatalf("create off: %v", xerr)
|
||||
}
|
||||
if scheduled.WarmupGraduation || !scheduled.RampEnabled {
|
||||
t.Fatalf("create returned graduation=%v ramp=%v, want false and true", scheduled.WarmupGraduation, scheduled.RampEnabled)
|
||||
}
|
||||
byID, err := repo.GetByID(ctx, scheduled.ID)
|
||||
if err != nil || byID.WarmupGraduation {
|
||||
t.Fatalf("GetByID: %v, graduation=%v", err, byID != nil && byID.WarmupGraduation)
|
||||
}
|
||||
got, err := repo.Get(ctx, f.org.String(), scheduled.ID.String())
|
||||
if err != nil || got.WarmupGraduation || got.RampCeiling != 30 {
|
||||
t.Fatalf("Get: %v, %+v", err, got)
|
||||
}
|
||||
|
||||
// The first sending day sends ramp_start, then it adds the increment.
|
||||
if err := repo.AdvanceRampLevel(ctx, scheduled.ID); err != nil {
|
||||
t.Fatalf("advance: %v", err)
|
||||
}
|
||||
if c, _ := repo.GetByID(ctx, scheduled.ID); c.RampLevel != 10 {
|
||||
t.Fatalf("day 1 level = %d, want 10", c.RampLevel)
|
||||
}
|
||||
if _, err := pool.Exec(ctx, `UPDATE campaigns SET ramp_level_date = CURRENT_DATE - 1 WHERE id = $1`, scheduled.ID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := repo.AdvanceRampLevel(ctx, scheduled.ID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c, _ := repo.GetByID(ctx, scheduled.ID); c.RampLevel != 15 {
|
||||
t.Fatalf("day 2 level = %d, want 15", c.RampLevel)
|
||||
}
|
||||
|
||||
dup, err := repo.Duplicate(ctx, DuplicateCampaignInput{SourceID: scheduled.ID, NewID: uuid.New(), UserID: f.owner, Name: "Graduation off (copy)"})
|
||||
if err != nil || dup.WarmupGraduation {
|
||||
t.Fatalf("duplicate: %v, graduation=%v", err, dup != nil && dup.WarmupGraduation)
|
||||
}
|
||||
|
||||
updated, xerr := repo.Update(ctx, f.org.String(), plain.ID.String(), &models.UpdateCampaign{WarmupGraduation: &off})
|
||||
if xerr != nil || updated.WarmupGraduation {
|
||||
t.Fatalf("update: %v, %+v", xerr, updated)
|
||||
}
|
||||
}
|
||||
@@ -178,7 +178,7 @@ const CAMPAIGN_SELECT = `id, name, description, status,
|
||||
utm_tracking, utm_source, utm_medium, utm_campaign,
|
||||
unsubscribe_mode,
|
||||
continuous, idle_since, stop_on_meeting,
|
||||
follow_up_sender, timezone_mode`
|
||||
follow_up_sender, timezone_mode, warmup_graduation`
|
||||
|
||||
func getCampaign(rows db.Scannable, campaign *models.Campaign, extra ...any) error {
|
||||
var dest []any = []any{
|
||||
@@ -200,7 +200,7 @@ func getCampaign(rows db.Scannable, campaign *models.Campaign, extra ...any) err
|
||||
&campaign.UTMTracking, &campaign.UTMSource, &campaign.UTMMedium, &campaign.UTMCampaign,
|
||||
&campaign.UnsubscribeMode,
|
||||
&campaign.Continuous, &campaign.IdleSince, &campaign.StopOnMeeting,
|
||||
&campaign.FollowUpSender, &campaign.TimezoneMode,
|
||||
&campaign.FollowUpSender, &campaign.TimezoneMode, &campaign.WarmupGraduation,
|
||||
}
|
||||
dest = append(dest, extra...)
|
||||
return rows.Scan(
|
||||
@@ -227,7 +227,7 @@ const CAMPAIGN_SELECT_FULL = `
|
||||
c.utm_tracking, c.utm_source, c.utm_medium, c.utm_campaign,
|
||||
c.unsubscribe_mode,
|
||||
c.continuous, c.idle_since, c.stop_on_meeting,
|
||||
c.follow_up_sender, c.timezone_mode,
|
||||
c.follow_up_sender, c.timezone_mode, c.warmup_graduation,
|
||||
COALESCE(array_agg(cet.tag_id) FILTER (WHERE cet.tag_id IS NOT NULL), '{}') AS email_tag_ids,
|
||||
COALESCE(array_agg(cec.folder_id) FILTER (WHERE cec.folder_id IS NOT NULL), '{}') AS email_folder_ids
|
||||
`
|
||||
@@ -457,6 +457,10 @@ func (r *campaignRepository) Create(ctx context.Context, userID string, orgID *u
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
warmupGraduation := true
|
||||
if data.WarmupGraduation != nil {
|
||||
warmupGraduation = *data.WarmupGraduation
|
||||
}
|
||||
espMatchMode := "off"
|
||||
if data.ESPMatchMode != nil {
|
||||
if err := validate.CampaignESPMatchMode(*data.ESPMatchMode); err != nil {
|
||||
@@ -529,7 +533,7 @@ func (r *campaignRepository) Create(ctx context.Context, userID string, orgID *u
|
||||
tracking_domain,
|
||||
utm_tracking, utm_source, utm_medium, utm_campaign,
|
||||
unsubscribe_mode, continuous, entry_delay_minutes,
|
||||
stop_on_meeting, follow_up_sender, timezone_mode,
|
||||
stop_on_meeting, follow_up_sender, timezone_mode, warmup_graduation,
|
||||
created_at, updated_at
|
||||
) VALUES (
|
||||
gen_random_uuid(), $1, $2, $3, $4,
|
||||
@@ -543,7 +547,7 @@ func (r *campaignRepository) Create(ctx context.Context, userID string, orgID *u
|
||||
$30,
|
||||
$31, $32, $33, $34,
|
||||
$35, $36, $37,
|
||||
$38, $39, $40,
|
||||
$38, $39, $40, $41,
|
||||
NOW(), NOW()
|
||||
)
|
||||
RETURNING %s
|
||||
@@ -590,6 +594,7 @@ func (r *campaignRepository) Create(ctx context.Context, userID string, orgID *u
|
||||
stopOnMeeting, // $38
|
||||
followUpSender, // $39
|
||||
timezoneMode, // $40
|
||||
warmupGraduation, // $41
|
||||
}
|
||||
|
||||
row := tx.QueryRow(ctx, insertSQL, params...)
|
||||
@@ -1259,6 +1264,11 @@ func (r *campaignRepository) Update(ctx context.Context, orgID, campaignID strin
|
||||
return nil, errx.New(errx.BadRequest, "ramp start cannot exceed ramp ceiling")
|
||||
}
|
||||
}
|
||||
if data.WarmupGraduation != nil {
|
||||
setClauses = append(setClauses, fmt.Sprintf("%s = $%d", "warmup_graduation", argPos))
|
||||
args = append(args, *data.WarmupGraduation)
|
||||
argPos++
|
||||
}
|
||||
if data.ESPMatchMode != nil {
|
||||
if err := validate.CampaignESPMatchMode(*data.ESPMatchMode); err != nil {
|
||||
return nil, err
|
||||
@@ -1507,7 +1517,7 @@ func (r *campaignRepository) GetByID(ctx context.Context, campaignID uuid.UUID)
|
||||
&campaign.UTMTracking, &campaign.UTMSource, &campaign.UTMMedium, &campaign.UTMCampaign,
|
||||
&campaign.UnsubscribeMode,
|
||||
&campaign.Continuous, &campaign.IdleSince, &campaign.StopOnMeeting,
|
||||
&campaign.FollowUpSender, &campaign.TimezoneMode,
|
||||
&campaign.FollowUpSender, &campaign.TimezoneMode, &campaign.WarmupGraduation,
|
||||
&campaign.EmailTags, &campaign.Folders,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -2308,7 +2318,7 @@ func (r *campaignRepository) AdvanceCampaignSender(ctx context.Context, campaign
|
||||
func (r *campaignRepository) AdvanceRampLevel(ctx context.Context, campaignID uuid.UUID) error {
|
||||
_, err := resultDB(ctx, r.DB).Exec(ctx, `
|
||||
UPDATE campaigns
|
||||
SET ramp_level = LEAST(ramp_ceiling, GREATEST(ramp_level, ramp_start) + ramp_increment),
|
||||
SET ramp_level = LEAST(ramp_ceiling, CASE WHEN ramp_level < ramp_start THEN ramp_start ELSE ramp_level + ramp_increment END),
|
||||
ramp_level_date = CURRENT_DATE
|
||||
WHERE id = $1
|
||||
AND ramp_enabled
|
||||
|
||||
@@ -116,7 +116,7 @@ func (r *campaignRepository) Duplicate(ctx context.Context, in DuplicateCampaign
|
||||
cc_addr, bcc_addr,
|
||||
start_date, end_date, timezone, timezone_mode, days, start_time, end_time, schedule_windows,
|
||||
contact_order_by, contact_order_dir, contact_order_field,
|
||||
sender_strategy, rotation_mode, follow_up_sender,
|
||||
sender_strategy, rotation_mode, follow_up_sender, warmup_graduation,
|
||||
ramp_enabled, ramp_start, ramp_increment, ramp_ceiling, ramp_level, ramp_level_date,
|
||||
esp_match_mode, max_new_leads_per_day, prioritize_new_leads, continuous, entry_delay_minutes,
|
||||
tracking_domain, tracking_domain_verified, tracking_domain_verified_at,
|
||||
@@ -135,7 +135,7 @@ func (r *campaignRepository) Duplicate(ctx context.Context, in DuplicateCampaign
|
||||
CASE WHEN end_date > NOW() THEN end_date END,
|
||||
timezone, timezone_mode, days, start_time, end_time, schedule_windows,
|
||||
contact_order_by, contact_order_dir, contact_order_field,
|
||||
sender_strategy, rotation_mode, follow_up_sender,
|
||||
sender_strategy, rotation_mode, follow_up_sender, warmup_graduation,
|
||||
ramp_enabled, ramp_start, ramp_increment, ramp_ceiling, 0, NULL,
|
||||
esp_match_mode, max_new_leads_per_day, prioritize_new_leads, continuous, entry_delay_minutes,
|
||||
tracking_domain, tracking_domain_verified, tracking_domain_verified_at,
|
||||
|
||||
@@ -141,8 +141,8 @@ type projectedSender struct {
|
||||
|
||||
// senderDay is one mailbox's day with the clamps that shaped it.
|
||||
type senderDay struct {
|
||||
sends, warmup int
|
||||
graduation, other, health, spacing, behaviorLoss, held int
|
||||
sends, warmup int
|
||||
ramp, graduation, other, health, spacing, behaviorLoss, held int
|
||||
}
|
||||
|
||||
// warmupOnDay is the warmup mail a mailbox sends on its local day, while it
|
||||
@@ -191,8 +191,9 @@ func warmupOnDay(p *projectedSender, localNoon time.Time, inCampaign bool) (int,
|
||||
// projectSenderDay walks one mailbox through one campaign day. spans is the
|
||||
// campaign's sending time that day, already clipped to the start; rampStart is
|
||||
// when the mailbox's cold ramp starts climbing if it has not yet; today marks
|
||||
// the day that already has sends on the ledger.
|
||||
func projectSenderDay(p *projectedSender, spans []span, midnight, rampStart time.Time, today bool) senderDay {
|
||||
// the day that already has sends on the ledger; rampCap is the campaign ramp's
|
||||
// level that day, negative when the campaign has no ramp.
|
||||
func projectSenderDay(p *projectedSender, spans []span, midnight, rampStart time.Time, today bool, rampCap int) senderDay {
|
||||
var d senderDay
|
||||
noon := midnight.Add(12 * time.Hour)
|
||||
// Warmup keeps running on the side, on every warmup day, on the same
|
||||
@@ -211,6 +212,11 @@ func projectSenderDay(p *projectedSender, spans []span, midnight, rampStart time
|
||||
spans = clipSpans(spans, *p.heldTill)
|
||||
}
|
||||
|
||||
if rampCap >= 0 && rampCap < c {
|
||||
d.ramp = c - rampCap
|
||||
c = rampCap
|
||||
}
|
||||
|
||||
// Graduation: a warmed mailbox climbs from its starting volume.
|
||||
if p.hasCold && p.cold.CeilingApplies() {
|
||||
start := rampStart
|
||||
@@ -307,7 +313,7 @@ func projectSenderDay(p *projectedSender, spans []span, midnight, rampStart time
|
||||
func (s *schedulerService) ProjectCampaign(ctx context.Context, in CampaignProjectionInput) (*models.CampaignEstimateResult, error) {
|
||||
campaign := in.Campaign
|
||||
if campaign == nil {
|
||||
campaign = &models.Campaign{}
|
||||
campaign = &models.Campaign{WarmupGraduation: true}
|
||||
}
|
||||
now := time.Now()
|
||||
out := &models.CampaignEstimateResult{
|
||||
@@ -352,7 +358,7 @@ func (s *schedulerService) ProjectCampaign(ctx context.Context, in CampaignProje
|
||||
}
|
||||
}
|
||||
p.cold = pass.coldRamp[acct.ID].WithKnownWarmup(acct.Warmup)
|
||||
p.hasCold = p.cold.CeilingApplies()
|
||||
p.hasCold = campaign.WarmupGraduation && p.cold.CeilingApplies()
|
||||
h := s.healthFor(ctx, pass, acct.ID)
|
||||
if h.known {
|
||||
p.health = h.state
|
||||
@@ -443,6 +449,9 @@ func (s *schedulerService) ProjectCampaign(ctx context.Context, in CampaignProje
|
||||
}
|
||||
return total
|
||||
}
|
||||
// The campaign ramp advances once per sending day from its persisted level.
|
||||
rampLevel := campaign.RampLevel
|
||||
rampAdvancedToday := campaign.RampLevelDate != nil && !campaign.RampLevelDate.UTC().Truncate(24*time.Hour).Before(now.UTC().Truncate(24*time.Hour))
|
||||
firstFull := -1
|
||||
var lossOrg int
|
||||
for i := 0; i < projectionExactDays; i++ {
|
||||
@@ -460,21 +469,28 @@ func (s *schedulerService) ProjectCampaign(ctx context.Context, in CampaignProje
|
||||
everySpans = clipSpans(everySpans, start)
|
||||
}
|
||||
}
|
||||
rampCap := -1
|
||||
if campaign.RampEnabled {
|
||||
if sendingExact[i] && !(isToday && rampAdvancedToday) {
|
||||
rampLevel = nextRampLevel(rampLevel, campaign.RampStart, campaign.RampIncrement, campaign.RampCeiling)
|
||||
}
|
||||
rampCap = campaignRampCeiling(true, campaign.RampStart, campaign.RampIncrement, campaign.RampCeiling, rampLevel)
|
||||
}
|
||||
row := make([]senderDay, len(senders))
|
||||
total, open, every := 0, 0, 0
|
||||
for j, p := range senders {
|
||||
row[j] = projectSenderDay(p, spans, mid, startDay, isToday)
|
||||
row[j] = projectSenderDay(p, spans, mid, startDay, isToday, rampCap)
|
||||
total += row[j].sends
|
||||
warmupExact[i] += row[j].warmup
|
||||
if p.hasCold {
|
||||
unramped := *p
|
||||
unramped.hasCold = false
|
||||
open += projectSenderDay(&unramped, spans, mid, startDay, isToday).sends
|
||||
open += projectSenderDay(&unramped, spans, mid, startDay, isToday, rampCap).sends
|
||||
} else {
|
||||
open += row[j].sends
|
||||
}
|
||||
if len(everySpans) > 0 {
|
||||
every += projectSenderDay(p, everySpans, mid, startDay, isToday).sends
|
||||
every += projectSenderDay(p, everySpans, mid, startDay, isToday, rampCap).sends
|
||||
}
|
||||
}
|
||||
if room := roomOn(i); !pass.risk.BlocksSending() && room >= 0 && total > room && firstFull < 0 && !isToday && sendingExact[i] {
|
||||
@@ -525,6 +541,7 @@ func (s *schedulerService) ProjectCampaign(ctx context.Context, in CampaignProje
|
||||
d := exact[firstFull][j]
|
||||
first = d.sends
|
||||
losses[models.EstimateBottleneckCampaignLimit] += p.capLoss
|
||||
losses[models.EstimateBottleneckCampaignRamp] += d.ramp
|
||||
losses[models.EstimateBottleneckWorkspaceRisk] += p.riskLoss
|
||||
losses[models.EstimateBottleneckGraduation] += d.graduation
|
||||
losses[models.EstimateBottleneckOtherCampaigns] += d.other
|
||||
@@ -575,7 +592,7 @@ func (s *schedulerService) ProjectCampaign(ctx context.Context, in CampaignProje
|
||||
biggest := 0
|
||||
for _, kind := range []string{
|
||||
models.EstimateBottleneckWorkspaceRisk, models.EstimateBottleneckHeld, models.EstimateBottleneckCampaignLimit,
|
||||
models.EstimateBottleneckGraduation, models.EstimateBottleneckOtherCampaigns, models.EstimateBottleneckHealth,
|
||||
models.EstimateBottleneckCampaignRamp, models.EstimateBottleneckGraduation, models.EstimateBottleneckOtherCampaigns, models.EstimateBottleneckHealth,
|
||||
models.EstimateBottleneckSendingBehavior, models.EstimateBottleneckSpacing, models.EstimateBottleneckOrgDailyLimit,
|
||||
} {
|
||||
if losses[kind] > biggest {
|
||||
|
||||
@@ -101,7 +101,7 @@ func TestProjectSenderDayGraduationRequiresConfirmedReplies(t *testing.T) {
|
||||
}
|
||||
for i, day := range []int{0, 2, 10} {
|
||||
mid, spans := workday(loc, start.AddDate(0, 0, day))
|
||||
if d := projectSenderDay(p, spans, mid, start, false); d.sends != tc.caps[i] || d.graduation != 50-tc.caps[i] {
|
||||
if d := projectSenderDay(p, spans, mid, start, false, -1); d.sends != tc.caps[i] || d.graduation != 50-tc.caps[i] {
|
||||
t.Fatalf("day %d: %+v, want %d sends and %d withheld", day, d, tc.caps[i], 50-tc.caps[i])
|
||||
}
|
||||
}
|
||||
@@ -122,7 +122,7 @@ func TestProjectSenderDayWarmupTakesSpacingSlots(t *testing.T) {
|
||||
cap: 100, loc: loc,
|
||||
}
|
||||
mid, spans := workday(loc, day)
|
||||
d := projectSenderDay(p, spans, mid, day, false)
|
||||
d := projectSenderDay(p, spans, mid, day, false, -1)
|
||||
// Ten hours at a 20 minute gap is 31 slots; the 5 warmup emails a
|
||||
// mailbox in a live campaign keeps sending take 5 of them.
|
||||
if d.warmup != warmupramp.ActiveCampaignCap || d.sends != 31-warmupramp.ActiveCampaignCap {
|
||||
@@ -135,7 +135,7 @@ func TestProjectSenderDayOtherCampaignsShareTheCap(t *testing.T) {
|
||||
day := time.Date(2026, 3, 2, 0, 0, 0, 0, loc)
|
||||
p := &projectedSender{acct: models.Email{CampaignLimit: 50, MinWaitTime: 60}, cap: 50, loc: loc, other: 20}
|
||||
mid, spans := workday(loc, day)
|
||||
if d := projectSenderDay(p, spans, mid, day, false); d.sends != 30 || d.other != 20 {
|
||||
if d := projectSenderDay(p, spans, mid, day, false, -1); d.sends != 30 || d.other != 20 {
|
||||
t.Fatalf("got %+v, want 30 sends and 20 taken by other campaigns", d)
|
||||
}
|
||||
}
|
||||
@@ -147,11 +147,11 @@ func TestProjectSenderDayHealthHoldLapses(t *testing.T) {
|
||||
p := &projectedSender{acct: models.Email{CampaignLimit: 50, MinWaitTime: 600}, cap: 50, loc: loc, held: true, heldTill: &until}
|
||||
mid, spans := workday(loc, day)
|
||||
// Five hours left after the hold at a 10 minute gap: 31 slots.
|
||||
if d := projectSenderDay(p, spans, mid, day, false); d.sends != 31 {
|
||||
if d := projectSenderDay(p, spans, mid, day, false, -1); d.sends != 31 {
|
||||
t.Fatalf("got %d sends after the hold lapsed, want 31", d.sends)
|
||||
}
|
||||
p.heldTill = nil
|
||||
if d := projectSenderDay(p, spans, mid, day, false); d.sends != 0 || d.held != 50 {
|
||||
if d := projectSenderDay(p, spans, mid, day, false, -1); d.sends != 0 || d.held != 50 {
|
||||
t.Fatalf("an open-ended hold sends nothing: %+v", d)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ func TestExplainCapNamesTheClampThatDecided(t *testing.T) {
|
||||
warmed := time.Now().Add(-2 * 24 * time.Hour)
|
||||
base := func() *campaignPass {
|
||||
return &campaignPass{
|
||||
campaign: &models.Campaign{DailyLimit: 50},
|
||||
campaign: &models.Campaign{DailyLimit: 50, WarmupGraduation: true},
|
||||
coldRamp: map[uuid.UUID]repository.ColdRampState{},
|
||||
risk: models.OrgRiskTrusted,
|
||||
sentToday: map[uuid.UUID]int{},
|
||||
@@ -67,7 +67,7 @@ func TestPoolBudgetReportsEveryMailbox(t *testing.T) {
|
||||
open, shut := uuid.New(), uuid.New()
|
||||
warmed := time.Now().Add(-24 * time.Hour)
|
||||
pass := &campaignPass{
|
||||
campaign: &models.Campaign{DailyLimit: 50},
|
||||
campaign: &models.Campaign{DailyLimit: 50, WarmupGraduation: true},
|
||||
coldRamp: map[uuid.UUID]repository.ColdRampState{shut: {WarmupStartedAt: &warmed}},
|
||||
risk: models.OrgRiskTrusted,
|
||||
sentToday: map[uuid.UUID]int{open: 0, shut: 5},
|
||||
@@ -102,7 +102,7 @@ func TestPoolBudgetCountsTheSendInFlight(t *testing.T) {
|
||||
id := uuid.New()
|
||||
warmed := time.Now().Add(-24 * time.Hour)
|
||||
pass := &campaignPass{
|
||||
campaign: &models.Campaign{DailyLimit: 50},
|
||||
campaign: &models.Campaign{DailyLimit: 50, WarmupGraduation: true},
|
||||
coldRamp: map[uuid.UUID]repository.ColdRampState{id: {WarmupStartedAt: &warmed}},
|
||||
risk: models.OrgRiskRestricted,
|
||||
sentToday: map[uuid.UUID]int{id: 0},
|
||||
|
||||
@@ -49,7 +49,7 @@ func TestStoppedWarmupLiftsColdCeilingForEveryReader(t *testing.T) {
|
||||
account.ID: {WarmupStartedAt: &warmed, WarmupStoppedAt: &stopped},
|
||||
}}}
|
||||
states := s.coldRampStates(t.Context(), []models.Email{account})
|
||||
pass := &campaignPass{campaign: &models.Campaign{DailyLimit: 50}, coldRamp: states, risk: models.OrgRiskTrusted,
|
||||
pass := &campaignPass{campaign: &models.Campaign{DailyLimit: 50, WarmupGraduation: true}, coldRamp: states, risk: models.OrgRiskTrusted,
|
||||
health: map[uuid.UUID]healthRead{account.ID: {}}}
|
||||
if cap := pass.explainCap(account); cap.Cap != 50 || cap.LimitedBy == capByGraduation {
|
||||
t.Fatal("execution kept the ceiling on a stopped mailbox", cap)
|
||||
@@ -60,7 +60,7 @@ func TestStoppedWarmupLiftsColdCeilingForEveryReader(t *testing.T) {
|
||||
}
|
||||
p := &projectedSender{acct: account, cap: 50, loc: time.UTC, cold: states[account.ID], hasCold: true}
|
||||
mid, spans := workday(time.UTC, now.AddDate(0, 0, 10))
|
||||
if day := projectSenderDay(p, spans, mid, now, false); day.graduation != 0 {
|
||||
if day := projectSenderDay(p, spans, mid, now, false, -1); day.graduation != 0 {
|
||||
t.Fatal("projection kept the ceiling on a stopped mailbox", day)
|
||||
}
|
||||
if !fullCapacityEvidenceKnown([]*projectedSender{p}) {
|
||||
|
||||
@@ -47,7 +47,7 @@ func TestColdRampUnknownFeedbackPreservesKnownWarmupInExecutionAndProjection(t *
|
||||
if state := states[account.ID]; state.WarmupStartedAt == nil || !state.WarmupStartedAt.Equal(warmed) || state.ConfirmedReplies != 0 {
|
||||
t.Fatal("unknown feedback erased history or manufactured replies", state)
|
||||
}
|
||||
pass := &campaignPass{campaign: &models.Campaign{DailyLimit: 50}, coldRamp: states, risk: models.OrgRiskTrusted,
|
||||
pass := &campaignPass{campaign: &models.Campaign{DailyLimit: 50, WarmupGraduation: true}, coldRamp: states, risk: models.OrgRiskTrusted,
|
||||
health: map[uuid.UUID]healthRead{account.ID: {}}}
|
||||
if cap := pass.explainCap(account); cap.Cap != 5 || cap.LimitedBy != capByGraduation {
|
||||
t.Fatal("execution lifted unknown evidence to full cap", cap)
|
||||
@@ -61,7 +61,7 @@ func TestColdRampUnknownFeedbackPreservesKnownWarmupInExecutionAndProjection(t *
|
||||
}
|
||||
p := &projectedSender{acct: account, cap: 50, loc: time.UTC, cold: states[account.ID], hasCold: true}
|
||||
mid, spans := workday(time.UTC, now.AddDate(0, 0, 10))
|
||||
if day := projectSenderDay(p, spans, mid, now, false); day.sends != 5 || day.graduation != 45 {
|
||||
if day := projectSenderDay(p, spans, mid, now, false, -1); day.sends != 5 || day.graduation != 45 {
|
||||
t.Fatal("projection turned unknown feedback into readiness", day)
|
||||
}
|
||||
if fullCapacityEvidenceKnown([]*projectedSender{p}) {
|
||||
@@ -69,7 +69,7 @@ func TestColdRampUnknownFeedbackPreservesKnownWarmupInExecutionAndProjection(t *
|
||||
}
|
||||
})
|
||||
}
|
||||
pass := &campaignPass{campaign: &models.Campaign{DailyLimit: 50}, risk: models.OrgRiskTrusted}
|
||||
pass := &campaignPass{campaign: &models.Campaign{DailyLimit: 50, WarmupGraduation: true}, risk: models.OrgRiskTrusted}
|
||||
if cap := pass.explainCap(account); cap.Cap != 5 {
|
||||
t.Fatal("missing pass entry bypassed known warmup", cap)
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ func projectRampLevel(c *models.Campaign, now time.Time) {
|
||||
if c.RampLevelDate != nil && !c.RampLevelDate.UTC().Truncate(24*time.Hour).Before(today) {
|
||||
return
|
||||
}
|
||||
c.RampLevel = min(c.RampCeiling, max(c.RampLevel, c.RampStart)+c.RampIncrement)
|
||||
c.RampLevel = nextRampLevel(c.RampLevel, c.RampStart, c.RampIncrement, c.RampCeiling)
|
||||
c.RampLevelDate = &today
|
||||
}
|
||||
|
||||
|
||||
@@ -21,10 +21,16 @@ func TestProjectRampLevelMatchesDailyAdvance(t *testing.T) {
|
||||
t.Fatalf("already advanced today must not advance again: got %d", c.RampLevel)
|
||||
}
|
||||
|
||||
c = &models.Campaign{RampEnabled: true, RampStart: 10, RampIncrement: 5, RampCeiling: 12}
|
||||
c = &models.Campaign{RampEnabled: true, RampStart: 10, RampIncrement: 5, RampCeiling: 50}
|
||||
projectRampLevel(c, now)
|
||||
if c.RampLevel != 12 {
|
||||
t.Fatalf("first advance starts from ramp_start and clamps to the ceiling: got %d", c.RampLevel)
|
||||
if c.RampLevel != 10 {
|
||||
t.Fatalf("the first sending day sends ramp_start: got %d", c.RampLevel)
|
||||
}
|
||||
|
||||
c = &models.Campaign{RampEnabled: true, RampStart: 10, RampIncrement: 5, RampCeiling: 8}
|
||||
projectRampLevel(c, now)
|
||||
if c.RampLevel != 8 {
|
||||
t.Fatalf("the first advance clamps to the ceiling: got %d", c.RampLevel)
|
||||
}
|
||||
|
||||
c = &models.Campaign{RampEnabled: false, RampLevel: 3}
|
||||
|
||||
@@ -424,6 +424,15 @@ func poolRemainingOn(pool []AccountCandidate, at time.Time) int {
|
||||
return total
|
||||
}
|
||||
|
||||
// nextRampLevel is the ramp level after one day's advance, mirroring
|
||||
// campaignRepo.AdvanceRampLevel: the first sending day is ramp_start.
|
||||
func nextRampLevel(level, start, increment, ceiling int) int {
|
||||
if level < start {
|
||||
return min(ceiling, start)
|
||||
}
|
||||
return min(ceiling, level+increment)
|
||||
}
|
||||
|
||||
// campaignRampCeiling returns the day's effective ramp ceiling. When ramp is
|
||||
// disabled it returns the campaign ceiling unchanged (the caller still min()s
|
||||
// against the per-mailbox cap). When enabled it returns the already-advanced
|
||||
|
||||
@@ -80,8 +80,12 @@ func stagedCap(p *campaignPass, acct models.Email) (stages [5]int, limitedBy str
|
||||
stages[2] = cur
|
||||
}
|
||||
// Graduation ceiling: a mailbox at its warmup ceiling must not reach the
|
||||
// full cold cap the day it joins a campaign.
|
||||
clamp(3, coldCeilingFor(p.coldRamp[acct.ID].WithKnownWarmup(acct.Warmup), cur), capByGraduation)
|
||||
// full cold cap the day it joins a campaign, unless the campaign opted out.
|
||||
if c.WarmupGraduation {
|
||||
clamp(3, coldCeilingFor(p.coldRamp[acct.ID].WithKnownWarmup(acct.Warmup), cur), capByGraduation)
|
||||
} else {
|
||||
stages[3] = cur
|
||||
}
|
||||
if m := p.risk.CapMultiplier(); m < 1 {
|
||||
risked := int(float64(cur)*m + 0.5)
|
||||
// A restricted organization still sends, just far less. Zeroing it
|
||||
@@ -647,7 +651,7 @@ func (s *schedulerService) PlanCampaignDay(ctx context.Context, campaignID uuid.
|
||||
// PoolCapacityToday implements CampaignSendPlanner.
|
||||
func (s *schedulerService) PoolCapacityToday(ctx context.Context, campaign *models.Campaign, accounts []models.Email) (*models.WorkspaceSendCapacity, error) {
|
||||
if campaign == nil {
|
||||
campaign = &models.Campaign{}
|
||||
campaign = &models.Campaign{WarmupGraduation: true}
|
||||
}
|
||||
pass := s.newCampaignPass(ctx, campaign, accounts)
|
||||
// One read for the whole pool. A miss is not an error here: a mailbox
|
||||
|
||||
@@ -23,9 +23,9 @@ func TestStagedCapAgreesWithExplainCap(t *testing.T) {
|
||||
{"plain", &campaignPass{campaign: &models.Campaign{DailyLimit: 50}, risk: models.OrgRiskTrusted}, models.Email{ID: id, CampaignLimit: 50}},
|
||||
{"campaign limit", &campaignPass{campaign: &models.Campaign{DailyLimit: 20}, risk: models.OrgRiskTrusted}, models.Email{ID: id, CampaignLimit: 50}},
|
||||
{"ramp", &campaignPass{campaign: &models.Campaign{DailyLimit: 50, RampEnabled: true, RampStart: 10, RampCeiling: 50, RampLevel: 15}, risk: models.OrgRiskTrusted}, models.Email{ID: id, CampaignLimit: 50}},
|
||||
{"graduation", &campaignPass{campaign: &models.Campaign{DailyLimit: 50}, coldRamp: map[uuid.UUID]repository.ColdRampState{id: {WarmupStartedAt: &warmed}}, risk: models.OrgRiskTrusted}, models.Email{ID: id, CampaignLimit: 50}},
|
||||
{"graduation", &campaignPass{campaign: &models.Campaign{DailyLimit: 50, WarmupGraduation: true}, coldRamp: map[uuid.UUID]repository.ColdRampState{id: {WarmupStartedAt: &warmed}}, risk: models.OrgRiskTrusted}, models.Email{ID: id, CampaignLimit: 50}},
|
||||
{"restricted", &campaignPass{campaign: &models.Campaign{DailyLimit: 50}, risk: models.OrgRiskRestricted}, models.Email{ID: id, CampaignLimit: 50}},
|
||||
{"everything", &campaignPass{campaign: &models.Campaign{DailyLimit: 30, RampEnabled: true, RampStart: 10, RampCeiling: 50, RampLevel: 25}, coldRamp: map[uuid.UUID]repository.ColdRampState{id: {WarmupStartedAt: &warmed}}, risk: models.OrgRiskRestricted}, models.Email{ID: id, CampaignLimit: 80}},
|
||||
{"everything", &campaignPass{campaign: &models.Campaign{DailyLimit: 30, WarmupGraduation: true, RampEnabled: true, RampStart: 10, RampCeiling: 50, RampLevel: 25}, coldRamp: map[uuid.UUID]repository.ColdRampState{id: {WarmupStartedAt: &warmed}}, risk: models.OrgRiskRestricted}, models.Email{ID: id, CampaignLimit: 80}},
|
||||
} {
|
||||
stages, by := stagedCap(tc.pass, tc.acct)
|
||||
want := tc.pass.explainCap(tc.acct)
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package scheduler
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/warmbly/warmbly/internal/models"
|
||||
"github.com/warmbly/warmbly/internal/repository"
|
||||
)
|
||||
|
||||
func TestCampaignWithoutGraduationSendsAtTheMailboxCap(t *testing.T) {
|
||||
now := time.Now()
|
||||
warmed := now.Add(-60 * 24 * time.Hour)
|
||||
acct := models.Email{ID: uuid.New(), CampaignLimit: 50, MinWaitTime: 60, Warmup: &warmed}
|
||||
states := map[uuid.UUID]repository.ColdRampState{acct.ID: {WarmupStartedAt: &warmed}}
|
||||
|
||||
on := &campaignPass{campaign: &models.Campaign{DailyLimit: 50, WarmupGraduation: true}, coldRamp: states, risk: models.OrgRiskTrusted}
|
||||
if c := on.explainCap(acct); c.Cap != 5 || c.LimitedBy != capByGraduation {
|
||||
t.Fatalf("graduating campaign: got %+v, want 5 by %s", c, capByGraduation)
|
||||
}
|
||||
off := &campaignPass{campaign: &models.Campaign{DailyLimit: 50}, coldRamp: states, risk: models.OrgRiskTrusted,
|
||||
health: map[uuid.UUID]healthRead{acct.ID: {}}}
|
||||
if c := off.explainCap(acct); c.Cap != 50 || c.LimitedBy != capByMailbox {
|
||||
t.Fatalf("campaign without graduation: got %+v, want the mailbox cap", c)
|
||||
}
|
||||
s := &schedulerService{}
|
||||
if plan := s.planMailbox(t.Context(), off, acct, 0, 0, nil, now, 10*3600, now.Add(10*time.Hour)); plan.byGraduation != 0 || plan.graduation != nil {
|
||||
t.Fatalf("plan still explains a graduation ceiling: %+v", plan)
|
||||
}
|
||||
// The campaign's own ramp still applies when graduation is off.
|
||||
ramped := &campaignPass{campaign: &models.Campaign{DailyLimit: 50, RampEnabled: true, RampStart: 10, RampIncrement: 5, RampCeiling: 40, RampLevel: 15},
|
||||
coldRamp: states, risk: models.OrgRiskTrusted}
|
||||
if c := ramped.explainCap(acct); c.Cap != 15 || c.LimitedBy != capByRamp {
|
||||
t.Fatalf("ramped campaign: got %+v, want 15 by %s", c, capByRamp)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProjectSenderDayAppliesTheCampaignRamp(t *testing.T) {
|
||||
loc := time.UTC
|
||||
day := time.Date(2026, 3, 2, 0, 0, 0, 0, loc)
|
||||
p := &projectedSender{acct: models.Email{CampaignLimit: 50, MinWaitTime: 60}, cap: 50, loc: loc}
|
||||
mid, spans := workday(loc, day)
|
||||
if d := projectSenderDay(p, spans, mid, day, false, 12); d.sends != 12 || d.ramp != 38 {
|
||||
t.Fatalf("got %+v, want 12 sends and 38 held by the ramp", d)
|
||||
}
|
||||
if d := projectSenderDay(p, spans, mid, day, false, -1); d.sends != 50 || d.ramp != 0 {
|
||||
t.Fatalf("no ramp: got %+v, want the full cap", d)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNextRampLevelStartsAtRampStart(t *testing.T) {
|
||||
level, got := 0, []int{}
|
||||
for range 6 {
|
||||
level = nextRampLevel(level, 10, 5, 30)
|
||||
got = append(got, level)
|
||||
}
|
||||
want := []int{10, 15, 20, 25, 30, 30}
|
||||
for i := range want {
|
||||
if got[i] != want[i] {
|
||||
t.Fatalf("levels %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,7 @@ struct Campaign: Codable, Identifiable, Hashable, Sendable {
|
||||
var rampIncrement: Int?
|
||||
var rampCeiling: Int?
|
||||
var rampLevel: Int?
|
||||
var warmupGraduation: Bool?
|
||||
var espMatchMode: String?
|
||||
var maxNewLeadsPerDay: Int?
|
||||
var prioritizeNewLeads: Bool?
|
||||
@@ -77,6 +78,7 @@ struct Campaign: Codable, Identifiable, Hashable, Sendable {
|
||||
case rampIncrement = "ramp_increment"
|
||||
case rampCeiling = "ramp_ceiling"
|
||||
case rampLevel = "ramp_level"
|
||||
case warmupGraduation = "warmup_graduation"
|
||||
case espMatchMode = "esp_match_mode"
|
||||
case maxNewLeadsPerDay = "max_new_leads_per_day"
|
||||
case prioritizeNewLeads = "prioritize_new_leads"
|
||||
@@ -165,6 +167,7 @@ struct CampaignUpdateBody: Encodable {
|
||||
var rampStart: Int? = nil
|
||||
var rampIncrement: Int? = nil
|
||||
var rampCeiling: Int? = nil
|
||||
var warmupGraduation: Bool? = nil
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case name, description, timezone
|
||||
@@ -186,6 +189,7 @@ struct CampaignUpdateBody: Encodable {
|
||||
case rampStart = "ramp_start"
|
||||
case rampIncrement = "ramp_increment"
|
||||
case rampCeiling = "ramp_ceiling"
|
||||
case warmupGraduation = "warmup_graduation"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -169,6 +169,11 @@ struct CampaignSettingsPage: View {
|
||||
|
||||
private var rampSection: some View {
|
||||
Section {
|
||||
toggleRow(
|
||||
"Wait for replies", subtitle: "Mailboxes leaving warmup start at 5/day", icon: "arrowshape.turn.up.left.fill", tone: .orange,
|
||||
value: campaign.warmupGraduation ?? true,
|
||||
body: { CampaignUpdateBody(warmupGraduation: $0) }, mutate: { $0.warmupGraduation = $1 }
|
||||
)
|
||||
toggleRow(
|
||||
"Gradual ramp-up", subtitle: "Raise the daily send slowly over time", icon: "chart.line.uptrend.xyaxis", tone: .orange,
|
||||
value: campaign.rampEnabled ?? false,
|
||||
@@ -194,7 +199,7 @@ struct CampaignSettingsPage: View {
|
||||
} header: {
|
||||
Text("Ramp-up")
|
||||
} footer: {
|
||||
Text("Ramp only ever lowers volume against the daily limit, never raises it above your cap.")
|
||||
Text("Wait for replies raises a mailbox leaving warmup by one a day for each lead who replied this week. Turn both off to send at each mailbox's daily limit. Ramp only ever lowers volume, never above your cap.")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import { expect, test } from "../lib/proof.ts";
|
||||
|
||||
// Requires ../fixtures/campaign-estimate.sql applied to this worktree's rich-seed database.
|
||||
const FIXTURES = process.env.QA_CAMPAIGN_ESTIMATE_FIXTURES === "1";
|
||||
|
||||
test.describe("campaign ramp-up", () => {
|
||||
test.skip(!FIXTURES, "Apply qa/fixtures/campaign-estimate.sql to this stack's database and set QA_CAMPAIGN_ESTIMATE_FIXTURES=1.");
|
||||
|
||||
test("choose how a new campaign's mailboxes ramp up and see the launch plan follow", async ({ page, proof }) => {
|
||||
await page.goto("/app/campaigns");
|
||||
await page.getByRole("button", { name: "New campaign" }).first().click();
|
||||
const dialog = page.getByRole("dialog", { name: "New campaign" });
|
||||
await expect(dialog).toBeVisible();
|
||||
await proof.chapter("Ramp-up", "Pick how each mailbox's daily volume grows in a new campaign");
|
||||
|
||||
await dialog.getByText("Agencies", { exact: true }).click();
|
||||
await dialog.getByRole("button", { name: /^Continue/ }).click();
|
||||
|
||||
await expect(dialog.getByText("What will they receive?")).toBeVisible();
|
||||
await dialog.getByRole("textbox").first().fill("There's room to grow");
|
||||
await dialog.getByText("Hi {{.FirstName}}, …", { exact: true }).click({ force: true });
|
||||
await page.keyboard.type("A quick idea for your agency.");
|
||||
await dialog.getByRole("button", { name: /^Continue/ }).click();
|
||||
|
||||
const ramp = dialog.getByRole("radiogroup", { name: "Ramp-up" });
|
||||
await expect(ramp).toBeVisible();
|
||||
await ramp.scrollIntoViewIfNeeded();
|
||||
await expect(ramp.getByRole("radio", { name: /^As replies come in/ })).toHaveAttribute("aria-checked", "true");
|
||||
await proof.dwell();
|
||||
await proof.shot("ramp-up-replies", { caption: "The default: mailboxes leaving warmup earn volume from replies" });
|
||||
|
||||
await ramp.getByRole("radio", { name: /^On a schedule/ }).click();
|
||||
await expect(dialog.getByText(/then steady/)).toBeVisible();
|
||||
await dialog.getByText(/then steady/).scrollIntoViewIfNeeded();
|
||||
await proof.dwell();
|
||||
await proof.shot("ramp-up-schedule", { caption: "On a schedule: start, daily increase and ceiling, with the day-by-day climb" });
|
||||
|
||||
await ramp.getByRole("radio", { name: /^Full volume/ }).click();
|
||||
await expect(dialog.getByText(/fastest and the riskiest/)).toBeVisible();
|
||||
await proof.dwell();
|
||||
await proof.shot("ramp-up-full", { caption: "Full volume: every mailbox sends up to its own daily limit from day one" });
|
||||
|
||||
await dialog.getByRole("button", { name: /^Continue/ }).click();
|
||||
await expect(dialog.getByText("Review and launch")).toBeVisible();
|
||||
await expect(dialog.getByText(/from day one/)).toBeVisible();
|
||||
await proof.dwell();
|
||||
await proof.shot("ramp-up-review-full", { caption: "The launch plan at full volume" });
|
||||
|
||||
await dialog.getByRole("button", { name: /^Senders/ }).click();
|
||||
await ramp.getByRole("radio", { name: /^As replies come in/ }).click();
|
||||
await dialog.getByRole("button", { name: /^Continue/ }).click();
|
||||
await expect(dialog.getByText("Review and launch")).toBeVisible();
|
||||
await expect(dialog.getByRole("button", { name: /^Senders .*as leads reply/ })).toBeVisible();
|
||||
await proof.dwell();
|
||||
await proof.shot("ramp-up-review-replies", { caption: "The same campaign paced by replies" });
|
||||
});
|
||||
|
||||
test("change a running campaign's ramp-up in its settings", async ({ page, proof }) => {
|
||||
await page.goto("/app/campaigns/dddd0d00-0000-0000-0000-000000000001/preferences");
|
||||
const ramp = page.getByRole("radiogroup", { name: "Ramp-up" });
|
||||
await expect(ramp).toBeVisible();
|
||||
await ramp.scrollIntoViewIfNeeded();
|
||||
await proof.chapter("Campaign settings", "The same choice on an existing campaign");
|
||||
await proof.shot("settings-ramp-up", { caption: "Ramp-up in campaign settings" });
|
||||
|
||||
await ramp.getByRole("radio", { name: /^On a schedule/ }).click();
|
||||
await expect(page.getByText(/then steady/)).toBeVisible();
|
||||
await page.getByText(/then steady/).scrollIntoViewIfNeeded();
|
||||
await proof.dwell();
|
||||
await proof.shot("settings-ramp-up-schedule", { caption: "Switching it to a schedule" });
|
||||
});
|
||||
});
|
||||
@@ -238,6 +238,9 @@ export default function CampaignPreferences() {
|
||||
...(newData.ramp_start !== campaign.ramp_start && { ramp_start: newData.ramp_start }),
|
||||
...(newData.ramp_increment !== campaign.ramp_increment && { ramp_increment: newData.ramp_increment }),
|
||||
...(newData.ramp_ceiling !== campaign.ramp_ceiling && { ramp_ceiling: newData.ramp_ceiling }),
|
||||
...((newData.warmup_graduation !== false) !== (campaign.warmup_graduation !== false) && {
|
||||
warmup_graduation: newData.warmup_graduation !== false,
|
||||
}),
|
||||
|
||||
// First email timing
|
||||
...(newData.entry_delay_minutes !== campaign.entry_delay_minutes && {
|
||||
|
||||
@@ -54,6 +54,7 @@ import {
|
||||
import { draftSignature, freshMeta, loadServerDraft, saveServerDraft, type DraftMeta } from "./new/serverDraft";
|
||||
import { EmailsStep, LeadsStep, LaunchPlanRail, ReviewStep, ScheduleStep, type EstimateState } from "./new/steps";
|
||||
import type { Patch } from "./new/fields";
|
||||
import { rampUpInvalid, rampUpPayload } from "./rampUp";
|
||||
|
||||
interface Props {
|
||||
open: boolean;
|
||||
@@ -186,6 +187,8 @@ export function NewCampaignDialog({ open, onClose, draftId = null }: Props) {
|
||||
start_time: !meta?.customWindows && draft.startTime < draft.endTime ? draft.startTime : undefined,
|
||||
end_time: !meta?.customWindows && draft.startTime < draft.endTime ? draft.endTime : undefined,
|
||||
start_date: at && at.getTime() > Date.now() ? at.toISOString() : undefined,
|
||||
// An invalid ramp is refused by the server; the step explains it instead.
|
||||
...(rampUpInvalid(draft.rampUp) ? {} : rampUpPayload(draft.rampUp)),
|
||||
campaign_id: existing?.id,
|
||||
step_waits: lockedEmails ? lockedEmails.slice(1).map((s) => Math.max(0, s.wait_after)) : stepWaits(draft),
|
||||
},
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
// How a campaign's per-mailbox volume grows: the one picker the new-campaign
|
||||
// wizard and the campaign settings share, over the two server fields it maps to.
|
||||
|
||||
import { AnimatePresence, motion } from "framer-motion";
|
||||
import { AlertCircleIcon, GaugeIcon, MessageSquareReplyIcon, TrendingUpIcon } from "lucide-react";
|
||||
import { Label, NumberInput } from "@/components/ui/field";
|
||||
import { ChoiceCard } from "./new/fields";
|
||||
import { rampUpInvalid, rampUpMode, type RampUp } from "./rampUp";
|
||||
|
||||
const MODE_FIELDS = {
|
||||
replies: { warmup_graduation: true, ramp_enabled: false },
|
||||
schedule: { warmup_graduation: false, ramp_enabled: true },
|
||||
full: { warmup_graduation: false, ramp_enabled: false },
|
||||
} as const satisfies Record<ReturnType<typeof rampUpMode>, Pick<RampUp, "warmup_graduation" | "ramp_enabled">>;
|
||||
|
||||
export default function RampUpChoice({
|
||||
value,
|
||||
onChange,
|
||||
level,
|
||||
}: {
|
||||
value: RampUp;
|
||||
onChange: (patch: Partial<RampUp>) => void;
|
||||
// Today's persisted ramp level on a saved campaign.
|
||||
level?: number;
|
||||
}) {
|
||||
const mode = rampUpMode(value);
|
||||
const invalid = rampUpInvalid(value);
|
||||
return (
|
||||
<div>
|
||||
<div role="radiogroup" aria-label="Ramp-up" className="grid grid-cols-1 sm:grid-cols-3 gap-2">
|
||||
<ChoiceCard
|
||||
selected={mode === "replies"}
|
||||
icon={MessageSquareReplyIcon}
|
||||
title="As replies come in"
|
||||
description="Mailboxes leaving warmup start at 5 a day and gain one a day per lead who replied this week."
|
||||
onSelect={() => onChange(MODE_FIELDS.replies)}
|
||||
/>
|
||||
<ChoiceCard
|
||||
selected={mode === "schedule"}
|
||||
icon={TrendingUpIcon}
|
||||
title="On a schedule"
|
||||
description="Start low and add a fixed amount each sending day, up to a ceiling you pick."
|
||||
onSelect={() => onChange(MODE_FIELDS.schedule)}
|
||||
/>
|
||||
<ChoiceCard
|
||||
selected={mode === "full"}
|
||||
icon={GaugeIcon}
|
||||
title="Full volume"
|
||||
description="Every mailbox sends up to its daily limit from the first day."
|
||||
onSelect={() => onChange(MODE_FIELDS.full)}
|
||||
/>
|
||||
</div>
|
||||
<AnimatePresence initial={false} mode="wait">
|
||||
<motion.div
|
||||
key={mode}
|
||||
initial={{ opacity: 0, height: 0 }}
|
||||
animate={{ opacity: 1, height: "auto" }}
|
||||
exit={{ opacity: 0, height: 0 }}
|
||||
transition={{ duration: 0.16 }}
|
||||
className="overflow-hidden"
|
||||
>
|
||||
{mode === "schedule" ? (
|
||||
<div className="mt-3 rounded-md border border-slate-200 bg-slate-50/40 p-3.5 space-y-3.5">
|
||||
<div className="flex flex-wrap items-end gap-4">
|
||||
<div>
|
||||
<Label>Start</Label>
|
||||
<NumberInput
|
||||
value={value.ramp_start}
|
||||
min={1}
|
||||
max={5000}
|
||||
onChange={(v) => onChange({ ramp_start: v })}
|
||||
suffix="/ day"
|
||||
className="w-32"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Increase by</Label>
|
||||
<NumberInput
|
||||
value={value.ramp_increment}
|
||||
min={0}
|
||||
max={100}
|
||||
onChange={(v) => onChange({ ramp_increment: v })}
|
||||
suffix="/ day"
|
||||
className="w-32"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Ceiling</Label>
|
||||
<NumberInput
|
||||
value={value.ramp_ceiling}
|
||||
min={1}
|
||||
max={5000}
|
||||
onChange={(v) => onChange({ ramp_ceiling: v })}
|
||||
suffix="/ day"
|
||||
className="w-32"
|
||||
/>
|
||||
</div>
|
||||
{level !== undefined && level > 0 && (
|
||||
<span className="inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md bg-sky-50 text-sky-700 text-[11.5px] font-medium">
|
||||
Today's cap
|
||||
<span className="font-mono tabular-nums">{level}</span>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{invalid ? (
|
||||
<p className="flex items-center gap-1.5 text-[11px] text-rose-500">
|
||||
<AlertCircleIcon className="w-3.5 h-3.5 shrink-0" />
|
||||
{invalid}
|
||||
</p>
|
||||
) : (
|
||||
<RampPreview
|
||||
start={value.ramp_start}
|
||||
increment={value.ramp_increment}
|
||||
ceiling={value.ramp_ceiling}
|
||||
level={level ?? 0}
|
||||
/>
|
||||
)}
|
||||
<p className="text-[11px] text-slate-500 leading-relaxed">
|
||||
Per mailbox. The daily limit and each mailbox's own cap still apply, and the climb
|
||||
does not pause on a bounce or a spam placement, so watch the campaign's health while it rises.
|
||||
</p>
|
||||
{value.warmup_graduation && (
|
||||
<p className="text-[11px] text-amber-700 leading-relaxed">
|
||||
Mailboxes leaving warmup also wait for replies in this campaign. Choose On a schedule
|
||||
again to send them on this schedule only.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<p className="mt-2 text-[11px] text-slate-500 leading-relaxed">
|
||||
{mode === "replies"
|
||||
? "A bounce pauses the climb and a spam complaint resets it. With a typical reply rate this stays close to 5 a day, so pick On a schedule if you want a predictable climb. Mailboxes that never warmed, or whose warmup is stopped, send at their own limit."
|
||||
: "Each mailbox's daily limit and minimum gap still apply. Going straight to full volume is the fastest and the riskiest choice for mailboxes that have not sent cold mail before."}
|
||||
</p>
|
||||
)}
|
||||
</motion.div>
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** A day-by-day bar chart of the per-mailbox ramp; the bar at today's level is highlighted. */
|
||||
export function RampPreview({
|
||||
start,
|
||||
increment,
|
||||
ceiling,
|
||||
level,
|
||||
}: {
|
||||
start: number;
|
||||
increment: number;
|
||||
ceiling: number;
|
||||
level: number;
|
||||
}) {
|
||||
if (start <= 0 || ceiling <= 0 || start > ceiling) return null;
|
||||
const days: number[] = [];
|
||||
let v = start;
|
||||
for (let guard = 0; guard < 60; guard++) {
|
||||
const capped = Math.min(v, ceiling);
|
||||
days.push(capped);
|
||||
if (capped >= ceiling || increment <= 0) break;
|
||||
v += increment;
|
||||
}
|
||||
const MAX_BARS = 14;
|
||||
const shown = days.slice(0, MAX_BARS);
|
||||
const more = days.length - shown.length;
|
||||
const todayIdx = level > 0 ? days.findIndex((d) => d >= level) : -1;
|
||||
const steady = days[days.length - 1];
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="flex items-end gap-1 h-14">
|
||||
{shown.map((val, i) => (
|
||||
<div
|
||||
key={i}
|
||||
title={`Day ${i + 1}: ${val}/day`}
|
||||
className={`flex-1 min-w-[4px] rounded-t-sm ${i === todayIdx ? "bg-sky-500" : "bg-sky-200"}`}
|
||||
style={{ height: `${Math.max(10, (val / ceiling) * 100)}%` }}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<div className="flex items-center justify-between mt-1.5 text-[10px] text-slate-400">
|
||||
<span>Day 1 · {start}/day</span>
|
||||
<span>
|
||||
{more > 0 ? `+${more} more · ` : ""}Day {days.length} · {steady}/day, then steady
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
import type { CreateCampaignInput } from "@/lib/api/client/app/campaigns/createCampaign";
|
||||
import { htmlToPlain } from "@/components/app/campaigns/sequences/emailPreview";
|
||||
import { rampUpInvalid, rampUpPayload, type RampUp } from "@/components/app/campaigns/rampUp";
|
||||
|
||||
export type EmailDraft = {
|
||||
id: string;
|
||||
@@ -37,6 +38,7 @@ export type Draft = {
|
||||
scheduledAt: string;
|
||||
emailTagIds: string[];
|
||||
dailyLimit: number;
|
||||
rampUp: RampUp;
|
||||
stopOnReply: boolean;
|
||||
stopOnMeeting: boolean;
|
||||
openTracking: boolean;
|
||||
@@ -86,6 +88,7 @@ export const initialDraft = (timezone: string): Draft => ({
|
||||
scheduledAt: "",
|
||||
emailTagIds: [],
|
||||
dailyLimit: 50,
|
||||
rampUp: { warmup_graduation: true, ramp_enabled: false, ramp_start: 10, ramp_increment: 5, ramp_ceiling: 50 },
|
||||
stopOnReply: true,
|
||||
stopOnMeeting: true,
|
||||
openTracking: true,
|
||||
@@ -172,6 +175,8 @@ export function stepIssue(key: StepKey, d: Draft): string | null {
|
||||
if (at.getTime() < Date.now()) return "The start time has already passed";
|
||||
}
|
||||
if (d.dailyLimit < 3 || d.dailyLimit > 5000) return "Daily limit must be between 3 and 5,000";
|
||||
const ramp = rampUpInvalid(d.rampUp);
|
||||
if (ramp) return `Ramp-up: ${ramp.charAt(0).toLowerCase()}${ramp.slice(1)}`;
|
||||
return null;
|
||||
}
|
||||
default:
|
||||
@@ -213,6 +218,7 @@ export function toCreateInput(d: Draft, name: string): CreateCampaignInput {
|
||||
start_time: d.startTime,
|
||||
end_time: d.endTime,
|
||||
daily_limit: d.dailyLimit,
|
||||
...rampUpPayload(d.rampUp),
|
||||
open_tracking: d.openTracking,
|
||||
link_tracking: d.linkTracking,
|
||||
utm_tracking: d.utmTracking,
|
||||
|
||||
@@ -75,6 +75,8 @@ export function paceLabel(e: CampaignEstimateResult | undefined): string | null
|
||||
return "Paced by the sending window";
|
||||
case "campaign_limit":
|
||||
return "Paced by the daily limit";
|
||||
case "campaign_ramp":
|
||||
return "Paced by the ramp-up";
|
||||
case "other_campaigns":
|
||||
return "Shared with other campaigns";
|
||||
case "health":
|
||||
@@ -117,6 +119,8 @@ export function wontHelpText(e: CampaignEstimateResult): string | null {
|
||||
return "Raising the daily limit would not change the date: replies set the pace, not the limit.";
|
||||
case "spacing":
|
||||
return "Raising the daily limit would not change the date: mailboxes run out of hours first.";
|
||||
case "campaign_ramp":
|
||||
return "Raising the daily limit would not change the date: the ramp-up sets the pace until it reaches its ceiling.";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -145,6 +149,8 @@ export function bottleneckText(e: CampaignEstimateResult, limit?: number): strin
|
||||
}
|
||||
case "spacing":
|
||||
return "The sending window is the limit: with the gap between sends, and warmup sharing the same clock, mailboxes run out of hours before they reach their cap. A wider window goes faster.";
|
||||
case "campaign_ramp":
|
||||
return "The ramp-up schedule is the limit: every mailbox starts at its first-day volume and adds the same amount each sending day until the ceiling. A higher start or a faster increase goes sooner.";
|
||||
case "campaign_limit":
|
||||
return "The configured daily limit per mailbox is the constraint. Raising it is not proof that a higher volume is safe; consider provider policies, recipient permission and observed feedback.";
|
||||
case "other_campaigns":
|
||||
|
||||
@@ -15,6 +15,7 @@ import deleteSequence from "@/lib/api/client/app/campaigns/sequences/deleteSeque
|
||||
import { listCampaignSegments, setCampaignSegments } from "@/lib/api/client/app/segments";
|
||||
import estimateCampaign from "@/lib/api/client/app/campaigns/estimateCampaign";
|
||||
import { htmlToPlain } from "@/components/app/campaigns/sequences/emailPreview";
|
||||
import { rampUpPayload } from "@/components/app/campaigns/rampUp";
|
||||
import { hasContent, initialDraft, scheduledDate, toCreateInput, writtenEmails, type Draft, type EmailDraft } from "./draft";
|
||||
|
||||
export type DraftMeta = {
|
||||
@@ -112,6 +113,13 @@ export async function loadServerDraft(id: string): Promise<LoadedDraft> {
|
||||
scheduledAt: start && start.getTime() > Date.now() ? localInput(start) : "",
|
||||
emailTagIds: campaign.email_tags ?? [],
|
||||
dailyLimit: campaign.daily_limit || base.dailyLimit,
|
||||
rampUp: {
|
||||
warmup_graduation: campaign.warmup_graduation !== false,
|
||||
ramp_enabled: campaign.ramp_enabled,
|
||||
ramp_start: campaign.ramp_start || base.rampUp.ramp_start,
|
||||
ramp_increment: campaign.ramp_increment ?? base.rampUp.ramp_increment,
|
||||
ramp_ceiling: campaign.ramp_ceiling || base.rampUp.ramp_ceiling,
|
||||
},
|
||||
stopOnReply: campaign.stop_on_reply,
|
||||
stopOnMeeting: campaign.stop_on_meeting ?? base.stopOnMeeting,
|
||||
openTracking: campaign.open_tracking,
|
||||
@@ -160,6 +168,7 @@ export async function saveServerDraft(
|
||||
utm_tracking: d.utmTracking,
|
||||
unsubscribe_header: d.unsubHeader,
|
||||
daily_limit: d.dailyLimit,
|
||||
...rampUpPayload(d.rampUp),
|
||||
timezone: d.timezone,
|
||||
timezone_mode: d.recipientTime ? "recipient" : "campaign",
|
||||
start_date: at ?? null,
|
||||
|
||||
@@ -51,6 +51,8 @@ import EstimateTimeline from "./EstimateTimeline";
|
||||
import { BottleneckNote, FinishSooner, MailboxMix, SenderList, WarmupNote } from "./EstimateInsights";
|
||||
import { estimateHeadline, paceLabel, rampStart } from "./estimateText";
|
||||
import { htmlToPlain } from "@/components/app/campaigns/sequences/emailPreview";
|
||||
import RampUpChoice from "@/components/app/campaigns/RampUpChoice";
|
||||
import { rampUpMode, rampUpSummary } from "@/components/app/campaigns/rampUp";
|
||||
|
||||
export type EstimateState = {
|
||||
data: CampaignEstimateResult | undefined;
|
||||
@@ -572,6 +574,16 @@ export function ScheduleStep({
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<SectionLabel right={<span className="text-[11px] text-slate-500">{rampUpSummary(draft.rampUp)}</span>}>
|
||||
Ramp-up
|
||||
</SectionLabel>
|
||||
<RampUpChoice
|
||||
value={draft.rampUp}
|
||||
onChange={(p) => patch((d) => ({ rampUp: { ...d.rampUp, ...p } }))}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button
|
||||
type="button"
|
||||
@@ -642,6 +654,22 @@ export function ScheduleStep({
|
||||
|
||||
// Review -------------------------------------------------------------------
|
||||
|
||||
// How the senders' daily volume grows, for the review's Senders row.
|
||||
function senderPace(draft: Draft, replyStart: number | null): string {
|
||||
const r = draft.rampUp;
|
||||
switch (rampUpMode(r)) {
|
||||
case "schedule": {
|
||||
const top = Math.min(r.ramp_ceiling, draft.dailyLimit);
|
||||
return r.ramp_start < top ? `${r.ramp_start}/day each to start, +${r.ramp_increment} a day up to ${top}` : `up to ${top}/day each`;
|
||||
}
|
||||
case "replies":
|
||||
if (replyStart !== null && replyStart < draft.dailyLimit) return `${replyStart}/day each to start, up to ${draft.dailyLimit} as leads reply`;
|
||||
return `up to ${draft.dailyLimit}/day each`;
|
||||
default:
|
||||
return `up to ${draft.dailyLimit}/day each from day one`;
|
||||
}
|
||||
}
|
||||
|
||||
export type LaunchBlock = string | null;
|
||||
|
||||
export function ReviewStep({
|
||||
@@ -715,7 +743,7 @@ export function ReviewStep({
|
||||
value: e
|
||||
? e.mailboxes === 0
|
||||
? "No active mailbox"
|
||||
: `${plural(e.mailboxes, "mailbox", "mailboxes")}, ${start !== null && start < draft.dailyLimit ? `${start}/day each to start, up to ${draft.dailyLimit} as leads reply` : `up to ${draft.dailyLimit}/day each`}${e.held > 0 ? ` (${e.held} held)` : ""}`
|
||||
: `${plural(e.mailboxes, "mailbox", "mailboxes")}, ${senderPace(draft, start)}${e.held > 0 ? ` (${e.held} held)` : ""}`
|
||||
: "…",
|
||||
warn: !!e && (e.mailboxes === 0 || e.held > 0),
|
||||
},
|
||||
|
||||
@@ -11,66 +11,10 @@ import type Campaign from "@/lib/api/models/app/campaigns/Campaign";
|
||||
import { Label, NumberInput } from "@/components/ui/field";
|
||||
import { EmailListInput, OptionSelect, SettingRow, Toggle } from "./components/CampaignPreferenceBoolBox";
|
||||
import EspCoveragePanel from "./EspCoveragePanel";
|
||||
import RampUpChoice from "@/components/app/campaigns/RampUpChoice";
|
||||
|
||||
type SetCampaign = React.Dispatch<React.SetStateAction<Campaign>>;
|
||||
|
||||
/** RampPreview — a small day-by-day projection of the per-mailbox ramp curve
|
||||
* (Day 1 = start, +increment each day, capped at the ceiling). Highlights the
|
||||
* bar nearest today's live cap (ramp_level). */
|
||||
function RampPreview({
|
||||
start,
|
||||
increment,
|
||||
ceiling,
|
||||
level,
|
||||
}: {
|
||||
start: number;
|
||||
increment: number;
|
||||
ceiling: number;
|
||||
level: number;
|
||||
}) {
|
||||
if (start <= 0 || ceiling <= 0 || start > ceiling) return null;
|
||||
const days: number[] = [];
|
||||
let v = start;
|
||||
let guard = 0;
|
||||
while (guard < 60) {
|
||||
const capped = Math.min(v, ceiling);
|
||||
days.push(capped);
|
||||
if (capped >= ceiling) break;
|
||||
v += Math.max(1, increment);
|
||||
guard++;
|
||||
}
|
||||
const MAX_BARS = 14;
|
||||
const shown = days.slice(0, MAX_BARS);
|
||||
const more = days.length - shown.length;
|
||||
const todayIdx = days.findIndex((d) => d >= level);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="flex items-end gap-1 h-14">
|
||||
{shown.map((val, i) => {
|
||||
const today = i === todayIdx;
|
||||
return (
|
||||
<div
|
||||
key={i}
|
||||
title={`Day ${i + 1}: ${val}/day`}
|
||||
className={`flex-1 min-w-[4px] rounded-t-sm ${today ? "bg-sky-500" : "bg-sky-200"}`}
|
||||
style={{ height: `${Math.max(10, (val / ceiling) * 100)}%` }}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<div className="flex items-center justify-between mt-1.5 text-[10px] text-slate-400">
|
||||
<span>
|
||||
Day 1 · {start}/day
|
||||
</span>
|
||||
<span>
|
||||
{more > 0 ? `+${more} more · ` : ""}Day {days.length} · {ceiling}/day, then steady
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Which mailbox a lead's follow-ups leave from, with the tradeoff spelled out
|
||||
* whenever follow-ups stop being pinned to one address. */
|
||||
function FollowUpSenderSetting({
|
||||
@@ -134,7 +78,7 @@ function FollowUpSenderSetting({
|
||||
);
|
||||
}
|
||||
|
||||
/** Inbox rotation — distribution mode + per-mailbox daily ramp-up. */
|
||||
/** Inbox rotation — distribution mode + how per-mailbox volume ramps up. */
|
||||
export function RotationRampSection({
|
||||
newCampaign,
|
||||
setNewCampaign,
|
||||
@@ -142,7 +86,6 @@ export function RotationRampSection({
|
||||
newCampaign: Campaign;
|
||||
setNewCampaign: SetCampaign;
|
||||
}) {
|
||||
const rampInvalid = newCampaign.ramp_enabled && newCampaign.ramp_start > newCampaign.ramp_ceiling;
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
{/* Inbox rotation */}
|
||||
@@ -187,74 +130,25 @@ export function RotationRampSection({
|
||||
|
||||
<FollowUpSenderSetting newCampaign={newCampaign} setNewCampaign={setNewCampaign} />
|
||||
|
||||
{/* Daily ramp-up */}
|
||||
{/* Ramp-up */}
|
||||
<SettingRow
|
||||
title="Daily ramp-up"
|
||||
description="Gradually raise each mailbox's daily volume instead of starting at full limit — a smooth growth curve protects deliverability. (Separate from warmup.)"
|
||||
title="Ramp-up"
|
||||
description="How each mailbox's daily volume grows in this campaign. Separate from warmup, which keeps running alongside."
|
||||
stack
|
||||
control={
|
||||
<Toggle
|
||||
id="campaign-pref-ramp"
|
||||
value={newCampaign.ramp_enabled}
|
||||
onChange={(v) => setNewCampaign((bef) => ({ ...bef, ramp_enabled: v }))}
|
||||
<RampUpChoice
|
||||
value={{
|
||||
warmup_graduation: newCampaign.warmup_graduation !== false,
|
||||
ramp_enabled: newCampaign.ramp_enabled,
|
||||
ramp_start: newCampaign.ramp_start,
|
||||
ramp_increment: newCampaign.ramp_increment,
|
||||
ramp_ceiling: newCampaign.ramp_ceiling,
|
||||
}}
|
||||
onChange={(p) => setNewCampaign((bef) => ({ ...bef, ...p }))}
|
||||
level={newCampaign.ramp_level}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
{newCampaign.ramp_enabled && (
|
||||
<div className="rounded-md border border-slate-200 bg-slate-50/40 p-3.5 space-y-3.5">
|
||||
<div className="flex flex-wrap items-end gap-4">
|
||||
<div>
|
||||
<Label>Start</Label>
|
||||
<NumberInput
|
||||
value={newCampaign.ramp_start}
|
||||
min={1}
|
||||
max={5000}
|
||||
onChange={(v) => setNewCampaign((bef) => ({ ...bef, ramp_start: v }))}
|
||||
suffix="/ day"
|
||||
className="w-36"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Increase by</Label>
|
||||
<NumberInput
|
||||
value={newCampaign.ramp_increment}
|
||||
min={1}
|
||||
max={100}
|
||||
onChange={(v) => setNewCampaign((bef) => ({ ...bef, ramp_increment: v }))}
|
||||
suffix="/ day"
|
||||
className="w-36"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label>Ceiling</Label>
|
||||
<NumberInput
|
||||
value={newCampaign.ramp_ceiling}
|
||||
min={1}
|
||||
max={5000}
|
||||
onChange={(v) => setNewCampaign((bef) => ({ ...bef, ramp_ceiling: v }))}
|
||||
suffix="/ day"
|
||||
className="w-36"
|
||||
/>
|
||||
</div>
|
||||
<span className="inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md bg-sky-50 text-sky-700 text-[11.5px] font-medium">
|
||||
Today's cap
|
||||
<span className="font-mono tabular-nums">{newCampaign.ramp_level}</span>
|
||||
</span>
|
||||
</div>
|
||||
{rampInvalid ? (
|
||||
<p className="flex items-center gap-1.5 text-[11px] text-rose-500">
|
||||
<AlertCircleIcon className="w-3.5 h-3.5 shrink-0" />
|
||||
Start must be less than or equal to the ceiling.
|
||||
</p>
|
||||
) : (
|
||||
<RampPreview
|
||||
start={newCampaign.ramp_start}
|
||||
increment={newCampaign.ramp_increment}
|
||||
ceiling={newCampaign.ramp_ceiling}
|
||||
level={newCampaign.ramp_level}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { rampUpInvalid, rampUpMode, rampUpPayload, type RampUp } from "./rampUp";
|
||||
|
||||
const base: RampUp = { warmup_graduation: true, ramp_enabled: false, ramp_start: 10, ramp_increment: 5, ramp_ceiling: 50 };
|
||||
|
||||
describe("ramp-up", () => {
|
||||
it("reads the mode off the two server fields", () => {
|
||||
expect(rampUpMode(base)).toBe("replies");
|
||||
expect(rampUpMode({ ...base, warmup_graduation: false })).toBe("full");
|
||||
expect(rampUpMode({ ...base, warmup_graduation: false, ramp_enabled: true })).toBe("schedule");
|
||||
// A campaign with both on shows its schedule; the picker notes the reply hold.
|
||||
expect(rampUpMode({ ...base, ramp_enabled: true })).toBe("schedule");
|
||||
});
|
||||
|
||||
it("sends the schedule numbers only while the schedule is on", () => {
|
||||
const stale = { ...base, ramp_start: 80, ramp_ceiling: 20 };
|
||||
expect(rampUpPayload(stale)).toEqual({ warmup_graduation: true, ramp_enabled: false });
|
||||
expect(rampUpInvalid(stale)).toBeNull();
|
||||
const on = { ...stale, ramp_enabled: true, warmup_graduation: false };
|
||||
expect(rampUpPayload(on)).toEqual(on);
|
||||
expect(rampUpInvalid(on)).not.toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
// The ramp-up a campaign uses, over the two server fields it maps to: kept free
|
||||
// of React so the wizard's draft model can import it without a cycle.
|
||||
|
||||
export type RampUp = {
|
||||
warmup_graduation: boolean;
|
||||
ramp_enabled: boolean;
|
||||
ramp_start: number;
|
||||
ramp_increment: number;
|
||||
ramp_ceiling: number;
|
||||
};
|
||||
|
||||
export type RampUpMode = "replies" | "schedule" | "full";
|
||||
|
||||
export function rampUpMode(r: Pick<RampUp, "warmup_graduation" | "ramp_enabled">): RampUpMode {
|
||||
if (r.ramp_enabled) return "schedule";
|
||||
return r.warmup_graduation ? "replies" : "full";
|
||||
}
|
||||
|
||||
export function rampUpInvalid(r: RampUp): string | null {
|
||||
if (r.ramp_enabled && r.ramp_start > r.ramp_ceiling) return "Start must be less than or equal to the ceiling.";
|
||||
return null;
|
||||
}
|
||||
|
||||
// The fields a save or an estimate sends: the numbers only while the schedule is on, so stale ones are never refused.
|
||||
export function rampUpPayload(r: RampUp): Partial<RampUp> {
|
||||
const { warmup_graduation, ramp_enabled } = r;
|
||||
if (!ramp_enabled) return { warmup_graduation, ramp_enabled };
|
||||
return { ...r };
|
||||
}
|
||||
|
||||
// One phrase for summaries: the review step and the campaign overview.
|
||||
export function rampUpSummary(r: RampUp): string {
|
||||
switch (rampUpMode(r)) {
|
||||
case "schedule":
|
||||
return `${r.ramp_start}/day, +${r.ramp_increment} a day up to ${r.ramp_ceiling}`;
|
||||
case "full":
|
||||
return "Full volume from day one";
|
||||
default:
|
||||
return "As replies come in";
|
||||
}
|
||||
}
|
||||
@@ -272,8 +272,8 @@ function ColdRampNotice({ ramp }: { ramp: import("@/lib/api/models/app/analytics
|
||||
</p>
|
||||
<p className="text-[11.5px] text-sky-800/90 leading-relaxed mt-0.5">
|
||||
{ramp.held ? "Recent negative feedback is holding the pacing policy. " : ""}
|
||||
Automated test history does not prove real-recipient readiness. This conservative policy
|
||||
requires recent human campaign replies before increasing volume. No full-speed date or safe volume is guaranteed.
|
||||
In campaigns that ramp up as replies come in, this mailbox starts low and gains volume as recipients reply.
|
||||
Campaigns set to ramp on a schedule or send at full volume are not held to this. No full-speed date or safe volume is guaranteed.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -46,6 +46,7 @@ export interface CreateCampaignInput {
|
||||
ramp_start?: number;
|
||||
ramp_increment?: number;
|
||||
ramp_ceiling?: number;
|
||||
warmup_graduation?: boolean;
|
||||
esp_match_mode?: 'off' | 'prefer' | 'strict';
|
||||
max_new_leads_per_day?: number;
|
||||
prioritize_new_leads?: boolean;
|
||||
|
||||
@@ -17,6 +17,12 @@ export interface CampaignEstimateInput {
|
||||
end_time?: string;
|
||||
// Each follow-up's wait in days, in order. Empty is a single email.
|
||||
step_waits?: number[];
|
||||
// The ramp-up the wizard has; unsent fields come from the saved draft.
|
||||
warmup_graduation?: boolean;
|
||||
ramp_enabled?: boolean;
|
||||
ramp_start?: number;
|
||||
ramp_increment?: number;
|
||||
ramp_ceiling?: number;
|
||||
// A saved draft: its leads count too, and its own senders and windows apply.
|
||||
campaign_id?: string;
|
||||
}
|
||||
@@ -24,6 +30,7 @@ export interface CampaignEstimateInput {
|
||||
export type EstimateBottleneck =
|
||||
| ""
|
||||
| "campaign_limit"
|
||||
| "campaign_ramp"
|
||||
| "warmup_graduation"
|
||||
| "spacing"
|
||||
| "other_campaigns"
|
||||
|
||||
@@ -74,6 +74,8 @@ export default interface Campaign {
|
||||
ramp_ceiling: number;
|
||||
ramp_level: number;
|
||||
ramp_level_date?: Date | null;
|
||||
// Mailboxes leaving warmup earn volume from replies. Absent from an older backend, which means on.
|
||||
warmup_graduation?: boolean;
|
||||
|
||||
// Match the sending mailbox provider to the recipient's provider.
|
||||
esp_match_mode: 'off' | 'prefer' | 'strict';
|
||||
|
||||
Reference in New Issue
Block a user