From 2dc2298a8490731d303537556ce2c4d68acf6c8c Mon Sep 17 00:00:00 2001 From: Matthew Meszaros Date: Sun, 8 Nov 2026 14:24:50 +0100 Subject: [PATCH 1/2] feat: apply workspace risk after the campaign ramp and graduation in the launch projection as the scheduler does, send ramp numbers from campaign settings only while the schedule is on, label the ramp inputs for screen readers, show the ramp preview's real steady day, accept the full 1 to 5000 ramp range on iOS, drop the unsupported daily-limit advice for a ramp bottleneck and require schema 370 in the graduation live test --- .../campaign_warmup_graduation_live_test.go | 2 +- internal/scheduler/campaign_projection.go | 27 ++++++++-------- internal/scheduler/warmup_graduation_test.go | 6 ++++ .../Campaigns/CampaignSettingsPage.swift | 4 +-- .../app/campaigns/[id]/preferences/page.tsx | 8 ++--- .../components/app/campaigns/RampUpChoice.tsx | 31 +++++++++---------- .../app/campaigns/new/estimateText.ts | 2 -- web/src/components/ui/field.tsx | 7 +++-- 8 files changed, 46 insertions(+), 41 deletions(-) diff --git a/internal/repository/campaign_warmup_graduation_live_test.go b/internal/repository/campaign_warmup_graduation_live_test.go index 475af0b90..1191860b8 100644 --- a/internal/repository/campaign_warmup_graduation_live_test.go +++ b/internal/repository/campaign_warmup_graduation_live_test.go @@ -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() diff --git a/internal/scheduler/campaign_projection.go b/internal/scheduler/campaign_projection.go index ab621a2cd..9feef9377 100644 --- a/internal/scheduler/campaign_projection.go +++ b/internal/scheduler/campaign_projection.go @@ -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 @@ -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 - 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 @@ -229,6 +229,12 @@ func projectSenderDay(p *projectedSender, spans []span, midnight, rampStart time c = g } } + if m := p.risk.CapMultiplier(); m < 1 { + if r := max(1, int(float64(c)*m+0.5)); r < c { + d.risk = c - r + c = r + } + } // 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 +345,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 +355,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 +541,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 diff --git a/internal/scheduler/warmup_graduation_test.go b/internal/scheduler/warmup_graduation_test.go index 7e45820c5..9f3e4e1ce 100644 --- a/internal/scheduler/warmup_graduation_test.go +++ b/internal/scheduler/warmup_graduation_test.go @@ -48,6 +48,12 @@ 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 := max(1, int(10*p.risk.CapMultiplier()+0.5)) + 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) + } } func TestNextRampLevelStartsAtRampStart(t *testing.T) { diff --git a/ios/Warmbly/Features/Campaigns/CampaignSettingsPage.swift b/ios/Warmbly/Features/Campaigns/CampaignSettingsPage.swift index 6cdf06533..a9e49a31e 100644 --- a/ios/Warmbly/Features/Campaigns/CampaignSettingsPage.swift +++ b/ios/Warmbly/Features/Campaigns/CampaignSettingsPage.swift @@ -182,12 +182,12 @@ 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, + value: campaign.rampStart ?? 10, range: 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( diff --git a/web/src/app/app/campaigns/[id]/preferences/page.tsx b/web/src/app/app/campaigns/[id]/preferences/page.tsx index 47fc35780..83ab38ecf 100644 --- a/web/src/app/app/campaigns/[id]/preferences/page.tsx +++ b/web/src/app/app/campaigns/[id]/preferences/page.tsx @@ -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, }), diff --git a/web/src/components/app/campaigns/RampUpChoice.tsx b/web/src/components/app/campaigns/RampUpChoice.tsx index 7b2a77587..a25c40501 100644 --- a/web/src/components/app/campaigns/RampUpChoice.tsx +++ b/web/src/components/app/campaigns/RampUpChoice.tsx @@ -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 (
@@ -63,8 +65,9 @@ export default function RampUpChoice({
- +
- +
- + 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 (
@@ -181,7 +180,7 @@ export function RampPreview({
Day 1 · {start}/day - {more > 0 ? `+${more} more · ` : ""}Day {days.length} · {steady}/day, then steady + {more > 0 ? `+${more} more · ` : ""}Day {steadyDay} · {steady}/day, then steady
diff --git a/web/src/components/app/campaigns/new/estimateText.ts b/web/src/components/app/campaigns/new/estimateText.ts index 2d3e89c0a..711fd9ee9 100644 --- a/web/src/components/app/campaigns/new/estimateText.ts +++ b/web/src/components/app/campaigns/new/estimateText.ts @@ -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; } diff --git a/web/src/components/ui/field.tsx b/web/src/components/ui/field.tsx index f833a3c61..860d09ac3 100644 --- a/web/src/components/ui/field.tsx +++ b/web/src/components/ui/field.tsx @@ -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 ( -