carlos / platform Public

mail: a plan's hourly email limit, held back like the daily one

Summary

Catalog field email_per_hour caps an account's sends in one UTC hour. Send events are counted per app and hour (new mail_hour_sends table, registered with the SQL gate and the app-keyed mail lists, rows over two days old dropped on write). enforceAccountMail, which already holds the account back at twice the daily limit, now also pauses every sender once the hour's sends reach the hourly limit, with a new pause kind plan-hour that lifts on the hour roll (resumePlanMail, the SES path and email status). The day's pause wins when both are due. Billing page, carlos accounts plan and carlos email status name it, with copy pending review.
Agent notes
Reactive like every SES limit here: counted from Send events, so about 5. Held back at 1x the hourly limit (Paul: no more than 5 in any hour); the daily stays at 2x. A box mailer that predates plan-hour treats it as a non-lifting pause with Retry-After 3600, which is correct enough; no box change.
claude agent, operated by paul@keymail.dev 79e6b1205397781a74c4c1168ecc443b4a32b7eb parent d247a34
13 files changed, +273 −18
  • accounts_plan.go +1 −0
  • accounts_plan_copy_pending.go +18 −0
  • internal/console/billingpage.go +7 −0
  • internal/console/mailcounts.go +41 −4
  • internal/console/mailevents.go +9 −2
  • internal/console/planmail.go +48 −12
  • internal/console/planmail_hour_test.go +117 −0
  • internal/console/sesevents.go +2 −0
  • internal/console/store.go +12 −0
  • internal/console/store_gate.go +1 −0
  • internal/mail/mail.go +3 −0
  • internal/mailwire/mailwire.go +12 −0
  • mail_cli.go +2 −0

CI cancelled — superseded by a newer push — run details

diff --git a/accounts_plan.go b/accounts_plan.go
index 30796de9b..666735c99 100644
--- a/accounts_plan.go
+++ b/accounts_plan.go
@@ -222,6 +222,7 @@ func printAccountPlan(w io.Writer, r accountPlanReply) {
{cliPlanCopyLimitDisk, planBytes(l.DiskBytes)},
{cliPlanCopyLimitStorage, storage},
{cliPlanCopyLimitEmail, strconv.Itoa(l.EmailPerDay)},
+ {cliPlanCopyLimitEmailHour, emailPerHour(l.EmailPerHour)},
{cliPlanCopyLimitBandwidth, planBytes(l.BandwidthBytesMonth)},
{cliPlanCopyLimitDomains, allowed(l.CustomDomains)},
{cliPlanCopyLimitFleets, allowed(l.Fleets)},
diff --git a/accounts_plan_copy_pending.go b/accounts_plan_copy_pending.go
new file mode 100644
index 000000000..8cdb016ae
--- /dev/null
+++ b/accounts_plan_copy_pending.go
@@ -0,0 +1,18 @@
+package main
+
+// Copy still in Paul's review (#1076). Each value is replaced by the
+// approved sentence, and moved into the generated copy file it belongs to,
+// before this branch merges.
+const (
+ cliPlanCopyLimitEmailHour = "copy pending review (#1076): cli.plan.email_hour"
+ cliPlanCopyNoHourlyLimit = "copy pending review (#1076): cli.plan.email_hour.none"
+ cliEmailCopyPlanHourPaused = "copy pending review (#1076): cli.email.plan_hour.paused"
+)
+
+// emailPerHour is the hourly email limit as `carlos accounts plan` shows it.
+func emailPerHour(n int) string {
+ if n <= 0 {
+ return cliPlanCopyNoHourlyLimit
+ }
+ return plural(n, "email")
+}
diff --git a/internal/console/billingpage.go b/internal/console/billingpage.go
index 5d03883d6..731fb7a1b 100644
--- a/internal/console/billingpage.go
+++ b/internal/console/billingpage.go
@@ -731,6 +731,13 @@ func planIncludes(l plans.Limits, maxMembers int) []billingInclude {
if l.PDFRendersMonth > 0 {
add(fmt.Sprintf(billingCopy["limit.pdf"], billingCount(int64(l.PDFRendersMonth))))
}
+ if l.EmailPerHour > 0 {
+ // #1076; the sentence is in copy review.
+ add(fmt.Sprintf("%s (%s)", copyPending("billing.limit.email_hour"), billingCount(int64(l.EmailPerHour))))
+ }
+ if l.StorageScanRequired {
+ add(copyPending("billing.limit.storage_scanned"))
+ }
if l.CustomDomains {
add(billingCopy["limit.domains"])
}
diff --git a/internal/console/mailcounts.go b/internal/console/mailcounts.go
index a5a1dd59d..56e8853f5 100644
--- a/internal/console/mailcounts.go
+++ b/internal/console/mailcounts.go
@@ -128,6 +128,34 @@ ON CONFLICT(account, app, sender, day) DO UPDATE SET %s = %s + 1`, col, col, col
})
}
+// mailHour is t's UTC hour as mail_hour_sends keys it.
+func mailHour(t time.Time) string { return t.UTC().Format("2006-01-02T15") }
+
+// RecordMailHourSend counts one Send event for (acct, app) in the UTC hour
+// of at (#1076), and drops that app's rows older than two days: the hourly
+// limit reads the current hour alone.
+func (s *Store) RecordMailHourSend(ctx context.Context, acct, app string, at time.Time) error {
+ return s.withMailAppSQL(ctx, acct, app, "sql.RecordMailHourSend", func(v *Store) error {
+ if _, err := v.db.ExecContext(ctx, `INSERT INTO mail_hour_sends (account, app, hour, sends)
+VALUES (?, ?, ?, 1)
+ON CONFLICT(account, app, hour) DO UPDATE SET sends = sends + 1`, acct, app, mailHour(at)); err != nil {
+ return err
+ }
+ _, err := v.db.ExecContext(ctx, `DELETE FROM mail_hour_sends WHERE account = ? AND app = ? AND hour < ?`,
+ acct, app, mailHour(at.Add(-48*time.Hour)))
+ return err
+ })
+}
+
+// AccountHourSends is the account's sends in one UTC hour over every app:
+// the figure a plan's hourly email limit reads (#1076).
+func (s *Store) AccountHourSends(ctx context.Context, account string, at time.Time) (int64, error) {
+ var n int64
+ err := s.db.QueryRowContext(ctx, `SELECT COALESCE(SUM(sends), 0) FROM mail_hour_sends
+ WHERE account = ? AND hour = ?`, account, mailHour(at)).Scan(&n)
+ return n, err
+}
+
// RecordMailCallerSend counts one Send event for (acct, app, day) under its
// caller class (mail.CallerClass). The class is computed by the caller of
// this function from the event's caller identity alone; this store method
@@ -232,12 +260,17 @@ func (s *Server) resumeStaleCapPause(ctx context.Context, acct, app, sender stri
// untouched. The first two never auto-resume by design; the third must
// not, because resuming reactivates every key including the standalones
// and the app credential every instance still holds.
+ hour := mailHour(now)
stale := func(cur *mail.Sender) bool {
pz := mail.EffectivePause(cur)
+ if pz == nil || cur.PerInstance {
+ return false
+ }
// A pause dated earlier TODAY (or a clock oddity puts it in the
- // future) is not a day roll yet.
- return pz != nil && pz.LiftsAtDayRoll() && !cur.PerInstance &&
- pz.At.UTC().Format("2006-01-02") < today
+ // future) is not a day roll yet; the plan's hourly pause (#1076)
+ // lifts on the hour roll the same way.
+ return (pz.LiftsAtDayRoll() && pz.At.UTC().Format("2006-01-02") < today) ||
+ (pz.LiftsAtHourRoll() && mailHour(pz.At) < hour)
}
if sn == nil || !stale(sn) {
return sn, false, nil
@@ -253,7 +286,11 @@ func (s *Server) resumeStaleCapPause(ctx context.Context, acct, app, sender stri
log.Printf("console: mail resume audit: resolving account %s: %v", acct, err)
jobFailed(ctx, fmt.Errorf("mail resume audit: resolving account %s: %w", acct, err))
} else if a != nil {
- s.audit(a, app, "ses", "mail.resumed", fmt.Sprintf("%s: daily cap pause cleared on the UTC day roll", mailAuditSubject(app, sender)))
+ what := "daily cap pause cleared on the UTC day roll"
+ if mail.EffectivePause(sn).LiftsAtHourRoll() {
+ what = copyPending("mail.plan_hour.resumed")
+ }
+ s.audit(a, app, "ses", "mail.resumed", fmt.Sprintf("%s: %s", mailAuditSubject(app, sender), what))
}
fresh, _, err := mail.GetSender(ctx, s.cfg.Releases, acct, app, sender)
if err != nil {
diff --git a/internal/console/mailevents.go b/internal/console/mailevents.go
index db314757f..19086de4a 100644
--- a/internal/console/mailevents.go
+++ b/internal/console/mailevents.go
@@ -116,7 +116,10 @@ func mailNoticeKey(notice string, ev mail.Event, now time.Time) string {
// rename or a move: the switch's reap asks it whether the app-level user
// sent in the last seven days, and history left under the old name would
// answer "no" for an app whose key is still in use.
-var mailAppTables = []string{"mail_events", "mail_event_hooks", "mail_event_deliveries", "mail_sender_counts", "mail_caller_sends"}
+//
+// mail_hour_sends (#1076) joins too, keyed on a UTC hour string that
+// compares against a day string the way the day tables do.
+var mailAppTables = []string{"mail_events", "mail_event_hooks", "mail_event_deliveries", "mail_sender_counts", "mail_caller_sends", "mail_hour_sends"}
// execer is what carryMailApp and forgetMailApp need from a transaction.
type execer interface {
@@ -203,6 +206,8 @@ func mailAppTimeColumn(table string) string {
return "set_at"
case "mail_sender_counts", "mail_caller_sends":
return "day"
+ case "mail_hour_sends":
+ return "hour"
}
return "created_at"
}
@@ -213,7 +218,9 @@ func mailAppTimeColumn(table string) string {
// string in SQLite is not an error, it is simply always false, so getting
// this wrong would silently carry nothing.
func mailAppTimeSince(table string, createdAt int64) any {
- if mailAppTimeColumn(table) == "day" {
+ // An hour string "YYYY-MM-DDTHH" sorts at or after its own day's
+ // "YYYY-MM-DD", so the day is the right bound for it too.
+ if c := mailAppTimeColumn(table); c == "day" || c == "hour" {
return time.Unix(createdAt, 0).UTC().Format("2006-01-02")
}
return createdAt
diff --git a/internal/console/planmail.go b/internal/console/planmail.go
index e9d661831..d1cb7d87d 100644
--- a/internal/console/planmail.go
+++ b/internal/console/planmail.go
@@ -44,13 +44,33 @@ func (s *Server) enforceAccountMail(ctx context.Context, acct string, now time.T
if err != nil || l == nil {
return false, err
}
- at := planMailPauseAt(l, s.planCeilings(a))
- if at == 0 {
- return false, nil
+ // The day's pause first: it holds until the day rolls, so it is the
+ // one to take when both are due.
+ kind, audit := "", ""
+ if at := planMailPauseAt(l, s.planCeilings(a)); at > 0 {
+ sent, err := s.store.AccountSends(ctx, acct, usage.DayOf(now))
+ if err != nil {
+ return false, err
+ }
+ if sent >= at {
+ kind = mail.PauseKindPlan
+ audit = fmt.Sprintf("plan: %d of %d emails today, paused at twice the limit until the UTC day rolls", sent, l.EmailPerDay)
+ }
}
- sent, err := s.store.AccountSends(ctx, acct, usage.DayOf(now))
- if err != nil || sent < at {
- return false, err
+ // The hour's (#1076): held back once the hour's sends reach the
+ // plan's hourly limit, until the hour rolls (resumePlanMail).
+ if kind == "" && l.EmailPerHour > 0 {
+ sent, err := s.store.AccountHourSends(ctx, acct, now)
+ if err != nil {
+ return false, err
+ }
+ if sent >= int64(l.EmailPerHour) {
+ kind = mail.PauseKindPlanHour
+ audit = fmt.Sprintf("%s (%d of %d)", copyPending("mail.plan_hour.paused"), sent, l.EmailPerHour)
+ }
+ }
+ if kind == "" {
+ return false, nil
}
apps, err := s.store.AppsIn(a.ID)
if err != nil {
@@ -79,23 +99,36 @@ func (s *Server) enforceAccountMail(ctx context.Context, acct string, now time.T
log.Printf("console: plan mail %s: %s/%s is per-instance; left to its own cap", acct, app, sn.ID)
continue
}
- if _, err := mail.SetSenderPausedIf(ctx, s.claimMailStore(), s.cfg.MailProvisioner, acct, app, sn.ID, true, mail.PauseKindPlan, now, eligible); err != nil {
+ if _, err := mail.SetSenderPausedIf(ctx, s.claimMailStore(), s.cfg.MailProvisioner, acct, app, sn.ID, true, kind, now, eligible); err != nil {
if !errors.Is(err, mail.ErrNotEligible) {
errs = append(errs, fmt.Errorf("%s/%s: %w", app, sn.ID, err))
}
continue
}
paused = true
- s.audit(a, app, "ses", "mail.paused", fmt.Sprintf("%s: plan: %d of %d emails today, paused at twice the limit until the UTC day rolls",
- mailAuditSubject(app, sn.ID), sent, l.EmailPerDay))
+ s.audit(a, app, "ses", "mail.paused", fmt.Sprintf("%s: %s", mailAuditSubject(app, sn.ID), audit))
}
}
return paused, errors.Join(errs...)
}
-// resumePlanMail lifts plan and cap pauses from an earlier UTC day on every
-// sender of the account. A paused sender sends nothing, so no SES event
-// would ever resume it; the hourly grace pass does.
+// recordMailHourSend counts a Send event toward the account's hourly
+// email limit (#1076). A failed write is logged and the ingest goes on: the
+// day's counts and limits still run.
+func (s *Server) recordMailHourSend(ctx context.Context, acct, app, evType string, at time.Time) {
+ if evType != mail.EventSend {
+ return
+ }
+ if err := s.store.RecordMailHourSend(ctx, acct, app, at); err != nil {
+ log.Printf("console: ses events: recording an hourly send for %s/%s -> %v", acct, app, err)
+ }
+}
+
+// resumePlanMail lifts plan and cap pauses from an earlier UTC day, and
+// plan pauses from an earlier UTC hour (#1076), on every sender of the
+// account. A paused sender sends nothing, so no SES event would ever resume
+// it; the hourly grace pass does. An account whose day's sends are still at
+// the day's pause is paused again for the day straight after.
func (s *Server) resumePlanMail(ctx context.Context, acct *Account, now time.Time) error {
apps, err := s.store.AppsIn(acct.ID)
if err != nil {
@@ -114,5 +147,8 @@ func (s *Server) resumePlanMail(ctx context.Context, acct *Account, now time.Tim
}
}
}
+ if _, err := s.enforceAccountMail(ctx, acct.Sqid, now); err != nil {
+ errs = append(errs, err)
+ }
return errors.Join(errs...)
}
diff --git a/internal/console/planmail_hour_test.go b/internal/console/planmail_hour_test.go
new file mode 100644
index 000000000..a9185c579
--- /dev/null
+++ b/internal/console/planmail_hour_test.go
@@ -0,0 +1,117 @@
+package console
+
+import (
+ "context"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/mail"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// hourMailFixture is planMailFixture under the #1076 draft: Free sends at
+// most 5 emails an hour beside its 50 a day.
+func hourMailFixture(t *testing.T) *consoleFixture {
+ t.Helper()
+ fx := planMailFixture(t)
+ fx.srv.cfg.PlanCatalog = draftFreeStorageCatalog(t)
+ return fx
+}
+
+func hourSends(t *testing.T, fx *consoleFixture, app string, n int, at time.Time) {
+ t.Helper()
+ sends(t, fx, app, n, at)
+ for i := 0; i < n; i++ {
+ if err := fx.st.RecordMailHourSend(context.Background(), release.OpsAccount, app, at); err != nil {
+ t.Fatal(err)
+ }
+ }
+}
+
+// The account is held back once the hour's sends, over every app, reach
+// the hourly limit, and not before.
+func TestAccountMailPausesAtTheHourlyLimit(t *testing.T) {
+ fx := hourMailFixture(t)
+ ctx := context.Background()
+ hourSends(t, fx, "blog", 3, planMailNow)
+ hourSends(t, fx, "shop", 1, planMailNow)
+ hourSends(t, fx, "shop", 10, planMailNow.Add(-time.Hour)) // last hour's do not count
+ if paused, err := fx.srv.enforceAccountMail(ctx, release.OpsAccount, planMailNow); err != nil || paused {
+ t.Fatalf("4 sends this hour: paused %v, %v; want no pause", paused, err)
+ }
+ hourSends(t, fx, "shop", 1, planMailNow)
+ if paused, err := fx.srv.enforceAccountMail(ctx, release.OpsAccount, planMailNow); err != nil || !paused {
+ t.Fatalf("5 sends this hour: paused %v, %v; want a pause", paused, err)
+ }
+ for _, app := range []string{"blog", "shop"} {
+ if p := senderState(t, fx, app); p.Active || p.PauseKind != mail.PauseKindPlanHour {
+ t.Errorf("%s sender = active %v kind %q, want held back for the hour", app, p.Active, p.PauseKind)
+ }
+ }
+}
+
+// The hourly pause lifts on the hour roll, not before; the day's pause
+// still waits for the day.
+func TestHourlyMailPauseResumesOnTheHourRoll(t *testing.T) {
+ fx := hourMailFixture(t)
+ ctx := context.Background()
+ hourSends(t, fx, "blog", 5, planMailNow)
+ fx.srv.enforceAccountMail(ctx, release.OpsAccount, planMailNow)
+ acct, _ := fx.st.AccountBySqid(fx.sqid)
+ if err := fx.srv.resumePlanMail(ctx, acct, planMailNow.Add(30*time.Minute)); err != nil {
+ t.Fatal(err)
+ }
+ if senderState(t, fx, "blog").Active {
+ t.Fatal("resumed within the same hour")
+ }
+ if err := fx.srv.resumePlanMail(ctx, acct, planMailNow.Add(time.Hour)); err != nil {
+ t.Fatal(err)
+ }
+ if !senderState(t, fx, "blog").Active || !senderState(t, fx, "shop").Active {
+ t.Fatal("hourly pause not lifted on the UTC hour roll")
+ }
+}
+
+// When the day's pause is due too, the account takes the day's: it is the
+// one that holds longer, and an hour roll does not lift it.
+func TestDailyPauseWinsOverHourly(t *testing.T) {
+ fx := hourMailFixture(t)
+ ctx := context.Background()
+ sends(t, fx, "blog", 100, planMailNow)
+ hourSends(t, fx, "blog", 5, planMailNow)
+ fx.srv.enforceAccountMail(ctx, release.OpsAccount, planMailNow)
+ if p := senderState(t, fx, "blog"); p.PauseKind != mail.PauseKindPlan {
+ t.Fatalf("kind %q, want the day's", p.PauseKind)
+ }
+ acct, _ := fx.st.AccountBySqid(fx.sqid)
+ if err := fx.srv.resumePlanMail(ctx, acct, planMailNow.Add(time.Hour)); err != nil {
+ t.Fatal(err)
+ }
+ if senderState(t, fx, "blog").Active {
+ t.Fatal("an hour roll lifted the day's pause")
+ }
+}
+
+// A plan with no hourly limit is never held back by the hour.
+func TestNoHourlyLimitNoHourlyPause(t *testing.T) {
+ fx := planMailFixture(t) // example catalog: no email_per_hour
+ hourSends(t, fx, "blog", 40, planMailNow)
+ if paused, err := fx.srv.enforceAccountMail(context.Background(), release.OpsAccount, planMailNow); err != nil || paused {
+ t.Fatalf("paused %v, %v; want none", paused, err)
+ }
+}
+
+// The hourly rows are pruned as new ones land, and travel with the app.
+func TestMailHourSendsPrunesOldRows(t *testing.T) {
+ fx := planMailFixture(t)
+ ctx := context.Background()
+ hourSends(t, fx, "blog", 2, planMailNow.Add(-72*time.Hour))
+ hourSends(t, fx, "blog", 1, planMailNow)
+ var n int
+ if err := fx.st.db.QueryRow(`SELECT COUNT(*) FROM mail_hour_sends WHERE account = ? AND app = ?`, release.OpsAccount, "blog").Scan(&n); err != nil || n != 1 {
+ t.Fatalf("%d rows, %v; want only this hour's", n, err)
+ }
+ if got, err := fx.st.AccountHourSends(ctx, release.OpsAccount, planMailNow); err != nil || got != 1 {
+ t.Fatalf("hour sends %d, %v", got, err)
+ }
+}
diff --git a/internal/console/sesevents.go b/internal/console/sesevents.go
index 492fc8a54..0f086fa46 100644
--- a/internal/console/sesevents.go
+++ b/internal/console/sesevents.go
@@ -563,6 +563,7 @@ func (s *Server) recordAndEnforceMail(ctx context.Context, ev mail.Event, notice
log.Printf("console: ses events: recording %s for %s/%s/%s -> %v", ev.Type, callerAcct, callerApp, callerSender, err)
return
}
+ s.recordMailHourSend(ctx, callerAcct, callerApp, ev.Type, at)
if _, reason, err := s.enforceMailLimits(ctx, callerAcct, callerApp, callerSender, at); err != nil {
log.Printf("console: ses events: enforcing limits for %s/%s/%s -> %v", callerAcct, callerApp, callerSender, err)
} else if reason != "" {
@@ -611,6 +612,7 @@ func (s *Server) recordAndEnforceMail(ctx context.Context, ev mail.Event, notice
log.Printf("console: ses events: recording %s for %s/%s: %v", ev.Type, a.Sqid, app, err)
continue
}
+ s.recordMailHourSend(ctx, a.Sqid, app, ev.Type, at)
if _, reason, err := s.enforceMailLimits(ctx, a.Sqid, app, mail.SenderAppID, at); err != nil {
log.Printf("console: ses events: enforcing limits for %s/%s: %v", a.Sqid, app, err)
} else if reason != "" {
diff --git a/internal/console/store.go b/internal/console/store.go
index ebaf04747..5a0f91b72 100644
--- a/internal/console/store.go
+++ b/internal/console/store.go
@@ -319,6 +319,18 @@ func (s *Store) migrate() error {
// from a tag (mail.CallerClass). Keyed like mail_sender_counts, by
// the account sqid, with the same day string, and it joins every
// app-keyed mail list beside it (mailAppTables, the store gate).
+ // Send events per app and UTC hour (#1076): what a plan's hourly
+ // email limit reads, summed over the account (planmail.go). Keyed
+ // like mail_sender_counts, by the account sqid, and joins every
+ // app-keyed mail list beside it (mailAppTables, the store gate).
+ // Rows older than two days are dropped as new ones are written.
+ `CREATE TABLE IF NOT EXISTS mail_hour_sends (
+ account TEXT NOT NULL,
+ app TEXT NOT NULL,
+ hour TEXT NOT NULL, -- UTC YYYY-MM-DDTHH
+ sends INTEGER NOT NULL DEFAULT 0,
+ PRIMARY KEY (account, app, hour)
+);`,
`CREATE TABLE IF NOT EXISTS mail_caller_sends (
account TEXT NOT NULL,
app TEXT NOT NULL,
diff --git a/internal/console/store_gate.go b/internal/console/store_gate.go
index b966ed5b9..dfcfbfa82 100644
--- a/internal/console/store_gate.go
+++ b/internal/console/store_gate.go
@@ -233,6 +233,7 @@ var claimSQLTables = map[string]claimSQLTable{
"mail_counts": {Sqid: "account", App: "app"},
"mail_sender_counts": {Sqid: "account", App: "app"},
"mail_caller_sends": {Sqid: "account", App: "app"},
+ "mail_hour_sends": {Sqid: "account", App: "app"},
"mail_events": {Sqid: "account", App: "app"},
"pdf_renders": {Sqid: "account", App: "app"},
"mail_event_hooks": {Sqid: "account", App: "app"},
diff --git a/internal/mail/mail.go b/internal/mail/mail.go
index a3df97e5e..9fe71cde1 100644
--- a/internal/mail/mail.go
+++ b/internal/mail/mail.go
@@ -88,6 +88,9 @@ const (
// PauseKindPlan is the account-wide pause at twice the plan's daily
// email limit (plans 4b). Like a cap pause it lifts on the UTC day roll.
PauseKindPlan = mailwire.PauseKindPlan
+ // PauseKindPlanHour is the account-wide pause at the plan's hourly
+ // email limit (#1076). It lifts on the UTC hour roll.
+ PauseKindPlanHour = mailwire.PauseKindPlanHour
)
// Standalone is a displayed credential for something not running on CARLOS.
diff --git a/internal/mailwire/mailwire.go b/internal/mailwire/mailwire.go
index b85c3308b..15a5ee146 100644
--- a/internal/mailwire/mailwire.go
+++ b/internal/mailwire/mailwire.go
@@ -29,6 +29,12 @@ const (
// (gap G1: the plan keeps today's behaviour rather than spec decision
// 8's wording, which would have been a billing change).
PauseKindPlan = "plan"
+ // PauseKindPlanHour is the account-wide pause once the account's sends
+ // in one UTC hour reach the plan's hourly email limit (#1076). It lifts
+ // on the UTC hour roll (LiftsAtHourRoll). A reader that predates it
+ // treats it as a pause that does not lift on its own, which only ever
+ // holds mail back longer.
+ PauseKindPlanHour = "plan-hour"
// PauseKindPerInstance is the pause an app sender carries once its app
// has moved to per-instance senders. It never lifts on its own.
PauseKindPerInstance = "per-instance"
@@ -52,6 +58,12 @@ func (p *Pause) LiftsAtDayRoll() bool {
return p.Kind == PauseKindCap || p.Kind == PauseKindPlan
}
+// LiftsAtHourRoll reports whether the pause clears itself once the UTC hour
+// it was taken in has passed: the plan's hourly pause, and nothing else.
+func (p *Pause) LiftsAtHourRoll() bool {
+ return p != nil && p.Kind == PauseKindPlanHour
+}
+
// Submission is the per-app switch to the submit transport (decision 10).
// It lives on the app sender record. Nothing writes it until the switch's
// door exists; it is defined here so the agent can read it.
diff --git a/mail_cli.go b/mail_cli.go
index cfd9a3090..3b86a5844 100644
--- a/mail_cli.go
+++ b/mail_cli.go
@@ -1577,6 +1577,8 @@ func printEmailStatus(w io.Writer, res apiEmailReply) {
mutedf(w, " daily cap reached — this clears at the next UTC day roll; running `carlos email status` after that will clear it")
case "rate":
mutedf(w, " bounce/complaint rate over threshold — this does not clear on its own; ask a deployment operator to resume it")
+ case "plan-hour":
+ mutedf(w, " %s", cliEmailCopyPlanHourPaused)
default:
mutedf(w, " paused by a deployment operator — ask them to resume it")
}