Merge pull request #1206 from warmbly/t3/2f91cde5-ramp-followup

feat: align the launch projection's risk order with the scheduler and fix ramp-up review findings from #1202
This commit is contained in:
Matthew Meszaros
2026-11-08 13:50:24 +00:00
committed by GitHub
8 changed files with 58 additions and 43 deletions
@@ -15,7 +15,7 @@ import (
// go test ./internal/repository/ -run LiveCampaignWarmupGraduation -v
func TestLiveCampaignWarmupGraduation(t *testing.T) {
handle, pool := liveContactDB(t)
requireSchemaVersion(t, pool, 368)
requireSchemaVersion(t, pool, 370)
f := newSharedOrgFixture(t, pool)
repo := NewCampaignRepostory(handle)
ctx := context.Background()
+19 -15
View File
@@ -127,9 +127,9 @@ type projectedSender struct {
state string
held bool
heldTill *time.Time
cap int // mailbox cap after the campaign limit and workspace risk
capLoss int // sends the campaign limit took from the mailbox cap
riskLoss int
cap int // mailbox cap after the campaign limit
capLoss int // sends the campaign limit took from the mailbox cap
risk models.OrgRiskState // workspace risk, applied after the ramp and graduation as stagedCap does
cold repository.ColdRampState
hasCold bool
health models.WarmupHealthState
@@ -139,10 +139,18 @@ type projectedSender struct {
sentAll int
}
// riskCut is what workspace risk takes from a cap, as stagedCap rounds it.
func (p *projectedSender) riskCut(c int) int {
if m := p.risk.CapMultiplier(); m < 1 {
return max(0, c-max(1, int(float64(c)*m+0.5)))
}
return 0
}
// senderDay is one mailbox's day with the clamps that shaped it.
type senderDay struct {
sends, warmup int
ramp, graduation, other, health, spacing, behaviorLoss, held int
sends, warmup int
ramp, graduation, risk, other, health, spacing, behaviorLoss, held int
}
// warmupOnDay is the warmup mail a mailbox sends on its local day, while it
@@ -206,7 +214,8 @@ func projectSenderDay(p *projectedSender, spans []span, midnight, rampStart time
c := p.cap
if p.held {
if p.heldTill == nil || !p.heldTill.Before(spans[len(spans)-1].to) {
d.held = c
d.risk = p.riskCut(c)
d.held = c - d.risk
return d
}
spans = clipSpans(spans, *p.heldTill)
@@ -229,6 +238,8 @@ func projectSenderDay(p *projectedSender, spans []span, midnight, rampStart time
c = g
}
}
d.risk = p.riskCut(c)
c -= d.risk
// The mailbox's own clock: a behaviour profile's workday, or the 8am-8pm
// band in its own timezone when that differs from the campaign's.
@@ -339,7 +350,6 @@ func (s *schedulerService) ProjectCampaign(ctx context.Context, in CampaignProje
}
}
riskMul := pass.risk.CapMultiplier()
senders := make([]*projectedSender, 0, len(in.Accounts))
otherPerDay := 0.0
for _, acct := range in.Accounts {
@@ -350,13 +360,7 @@ func (s *schedulerService) ProjectCampaign(ctx context.Context, in CampaignProje
p.capLoss = p.cap - campaign.DailyLimit
p.cap = campaign.DailyLimit
}
if riskMul < 1 {
r := max(1, int(float64(p.cap)*riskMul+0.5))
if r < p.cap {
p.riskLoss = p.cap - r
p.cap = r
}
}
p.risk = pass.risk
p.cold = pass.coldRamp[acct.ID].WithKnownWarmup(acct.Warmup)
p.hasCold = campaign.WarmupGraduation && p.cold.CeilingApplies()
h := s.healthFor(ctx, pass, acct.ID)
@@ -542,7 +546,7 @@ func (s *schedulerService) ProjectCampaign(ctx context.Context, in CampaignProje
first = d.sends
losses[models.EstimateBottleneckCampaignLimit] += p.capLoss
losses[models.EstimateBottleneckCampaignRamp] += d.ramp
losses[models.EstimateBottleneckWorkspaceRisk] += p.riskLoss
losses[models.EstimateBottleneckWorkspaceRisk] += d.risk
losses[models.EstimateBottleneckGraduation] += d.graduation
losses[models.EstimateBottleneckOtherCampaigns] += d.other
losses[models.EstimateBottleneckHealth] += d.health
@@ -48,6 +48,17 @@ func TestProjectSenderDayAppliesTheCampaignRamp(t *testing.T) {
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)
}
// Workspace risk cuts what the ramp left, as stagedCap does.
p.risk = models.OrgRiskRestricted
want := 3
if d := projectSenderDay(p, spans, mid, day, false, 10); d.sends != want || d.ramp != 40 || d.risk != 10-want {
t.Fatalf("restricted: got %+v, want %d sends after the ramp", d, want)
}
// A held day still reports what risk would have taken.
p.cap, p.held = 40, true
if d := projectSenderDay(p, spans, mid, day, false, -1); d.sends != 0 || d.risk != 30 || d.held != 10 {
t.Fatalf("held and restricted: got %+v, want 30 to risk and 10 held", d)
}
}
func TestNextRampLevelStartsAtRampStart(t *testing.T) {
@@ -181,13 +181,13 @@ struct CampaignSettingsPage: View {
)
if campaign.rampEnabled == true {
stepperRow(
"Start", subtitle: "emails/day on day one", icon: "1.circle.fill", tone: .orange,
value: campaign.rampStart ?? 10, range: 1...100,
"Start", subtitle: "emails/day on day one, up to the ceiling", icon: "1.circle.fill", tone: .orange,
value: campaign.rampStart ?? 10, range: 1...min(max(campaign.rampCeiling ?? 50, 1), 5000),
body: { CampaignUpdateBody(rampStart: $0) }, mutate: { $0.rampStart = $1 }
)
stepperRow(
"Ceiling", subtitle: "the most it ramps to", icon: "arrow.up.to.line", tone: .orange,
value: campaign.rampCeiling ?? 50, range: max(campaign.rampStart ?? 1, 1)...100,
value: campaign.rampCeiling ?? 50, range: min(max(campaign.rampStart ?? 1, 1), 5000)...5000,
body: { CampaignUpdateBody(rampCeiling: $0) }, mutate: { $0.rampCeiling = $1 }
)
stepperRow(
@@ -233,11 +233,11 @@ export default function CampaignPreferences() {
follow_up_sender: newData.follow_up_sender,
}),
// Ramp-up
// Ramp-up: the numbers only while the schedule is on, so hidden stale ones are never refused.
...(newData.ramp_enabled !== campaign.ramp_enabled && { ramp_enabled: newData.ramp_enabled }),
...(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.ramp_enabled && newData.ramp_start !== campaign.ramp_start && { ramp_start: newData.ramp_start }),
...(newData.ramp_enabled && newData.ramp_increment !== campaign.ramp_increment && { ramp_increment: newData.ramp_increment }),
...(newData.ramp_enabled && 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,
}),
@@ -1,6 +1,7 @@
// 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 React from "react";
import { AnimatePresence, motion } from "framer-motion";
import { AlertCircleIcon, GaugeIcon, MessageSquareReplyIcon, TrendingUpIcon } from "lucide-react";
import { Label, NumberInput } from "@/components/ui/field";
@@ -25,6 +26,7 @@ export default function RampUpChoice({
}) {
const mode = rampUpMode(value);
const invalid = rampUpInvalid(value);
const id = React.useId();
return (
<div>
<div role="radiogroup" aria-label="Ramp-up" className="grid grid-cols-1 sm:grid-cols-3 gap-2">
@@ -63,8 +65,9 @@ export default function RampUpChoice({
<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>
<Label htmlFor={`${id}-start`}>Start</Label>
<NumberInput
id={`${id}-start`}
value={value.ramp_start}
min={1}
max={5000}
@@ -74,8 +77,9 @@ export default function RampUpChoice({
/>
</div>
<div>
<Label>Increase by</Label>
<Label htmlFor={`${id}-increment`}>Increase by</Label>
<NumberInput
id={`${id}-increment`}
value={value.ramp_increment}
min={0}
max={100}
@@ -85,8 +89,9 @@ export default function RampUpChoice({
/>
</div>
<div>
<Label>Ceiling</Label>
<Label htmlFor={`${id}-ceiling`}>Ceiling</Label>
<NumberInput
id={`${id}-ceiling`}
value={value.ramp_ceiling}
min={1}
max={5000}
@@ -152,19 +157,13 @@ export function RampPreview({
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;
}
// The climb reaches its ceiling on steadyDay; the chart shows its first MAX_BARS days.
const steadyDay = increment > 0 ? 1 + Math.ceil((ceiling - start) / increment) : 1;
const steady = increment > 0 ? ceiling : start;
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];
const shown = Array.from({ length: Math.min(steadyDay, MAX_BARS) }, (_, i) => Math.min(ceiling, start + i * increment));
const more = steadyDay - shown.length;
const todayIdx = level > 0 ? shown.findIndex((d) => d >= level) : -1;
return (
<div>
@@ -181,7 +180,7 @@ export function RampPreview({
<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
{more > 0 ? `+${more} more · ` : ""}Day {steadyDay} · {steady}/day, then steady
</span>
</div>
</div>
@@ -119,8 +119,6 @@ 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;
}
+5 -2
View File
@@ -128,9 +128,9 @@ export function SearchInput({
);
}
export function Label({ children, className }: { children: React.ReactNode; className?: string }) {
export function Label({ children, className, htmlFor }: { children: React.ReactNode; className?: string; htmlFor?: string }) {
return (
<label className={cn(
<label htmlFor={htmlFor} className={cn(
"text-[10px] uppercase tracking-[0.14em] text-slate-400 font-medium block mb-1.5",
className,
)}>
@@ -165,6 +165,7 @@ export function FieldRow({ children, className }: { children: React.ReactNode; c
// inside the field, before the steppers.
export function NumberInput({
value,
id,
onChange,
onCommit,
min,
@@ -192,6 +193,7 @@ export function NumberInput({
suffix?: React.ReactNode;
align?: "left" | "right" | "center";
className?: string;
id?: string;
}) {
const clamp = (n: number) => {
if (Number.isNaN(n)) return min ?? 0;
@@ -217,6 +219,7 @@ export function NumberInput({
)}
>
<input
id={id}
type="number"
inputMode="numeric"
value={Number.isFinite(value) ? value : ""}