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..ac784e02d 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 @@ -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 diff --git a/internal/scheduler/warmup_graduation_test.go b/internal/scheduler/warmup_graduation_test.go index 7e45820c5..6c9038542 100644 --- a/internal/scheduler/warmup_graduation_test.go +++ b/internal/scheduler/warmup_graduation_test.go @@ -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) { diff --git a/ios/Warmbly/Features/Campaigns/CampaignSettingsPage.swift b/ios/Warmbly/Features/Campaigns/CampaignSettingsPage.swift index 6cdf06533..b5794d063 100644 --- a/ios/Warmbly/Features/Campaigns/CampaignSettingsPage.swift +++ b/ios/Warmbly/Features/Campaigns/CampaignSettingsPage.swift @@ -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( 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 ( -