carlos / platform Public

console: reap without a catalog, report a switched app, fix the copy

The hourly pass reaps for every account, with or without a plan
catalog. email status skips the delivery check during the overlap week
and, after the reap, shows the switched state and the pause from its
pause block. email rotate maps ErrSubmissionOn. A part-failed switch-off
of a reaped app re-mints on the next run. Declaring From on a switched
app delivers it every time. Every string is a row of the copy record,
and the record is checked against the code both ways.

Fable P2-5, P2-6, P2-4, P3s.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 99013525d0b461b441dffd5fc6e465b739d08b6a parent 2723f79
18 files changed, +482 −104
  • approved_platform_mail_submission_copy_test.go +111 −1
  • docs/superpowers/plans/platform-mail-submission-copy.json +86 −26
  • internal/console/alertmailer_test.go +1 −1
  • internal/console/alertnotify.go +4 −4
  • internal/console/alertpages.go +1 −1
  • internal/console/apicli.go +2 −2
  • internal/console/apimail.go +19 −6
  • internal/console/apisubmission.go +5 −5
  • internal/console/apisubmission_test.go +65 −3
  • internal/console/plangracepass.go +20 −13
  • internal/console/submissioncopy.go +27 −16
  • internal/console/submissiongate.go +8 −11
  • internal/console/submissiongate_test.go +1 −1
  • internal/mail/sender.go +3 −2
  • internal/mail/submission_test.go +43 −0
  • internal/mail/sweep.go +5 −3
  • mail_cli.go +41 −9
  • mail_cli_test.go +40 −0
diff --git a/approved_platform_mail_submission_copy_test.go b/approved_platform_mail_submission_copy_test.go
index 91b4b4571..2022f68b3 100644
--- a/approved_platform_mail_submission_copy_test.go
+++ b/approved_platform_mail_submission_copy_test.go
@@ -2,7 +2,14 @@ package main
import (
"encoding/json"
+ "fmt"
+ "go/ast"
+ "go/parser"
+ "go/token"
"os"
+ "slices"
+ "strconv"
+ "strings"
"testing"
)
@@ -10,7 +17,7 @@ import (
// submission switch (Task 6 step 0): the door's refusals and answers, the
// serve doors' build refusal, and the CLI's lines.
var platformMailSubmissionCopyIDs = []string{
- "PMS-C1", "PMS-C2", "PMS-C3", "PMS-C4", "PMS-C5", "PMS-C6", "PMS-C7", "PMS-C8", "PMS-C9", "PMS-C10", "PMS-C11", "PMS-C12", "PMS-C13", "PMS-C14", "PMS-C15", "PMS-C16", "PMS-C17", "PMS-C18", "PMS-C19", "PMS-C20", "PMS-C21", "PMS-C22", "PMS-C23", "PMS-C24", "PMS-C25", "PMS-C26", "PMS-C27", "PMS-C28", "PMS-C29", "PMS-C30", "PMS-C31", "PMS-C32", "PMS-C33", "PMS-C34", "PMS-C35", "PMS-C36", "PMS-C37", "PMS-C38", "PMS-C39", "PMS-C40", "PMS-C41", "PMS-C42", "PMS-C43", "PMS-C44", "PMS-C45", "PMS-C46",
+ "PMS-C1", "PMS-C2", "PMS-C3", "PMS-C4", "PMS-C5", "PMS-C6", "PMS-C7", "PMS-C8", "PMS-C9", "PMS-C10", "PMS-C11", "PMS-C12", "PMS-C13", "PMS-C14", "PMS-C15", "PMS-C16", "PMS-C17", "PMS-C18", "PMS-C19", "PMS-C20", "PMS-C21", "PMS-C22", "PMS-C23", "PMS-C24", "PMS-C25", "PMS-C26", "PMS-C27", "PMS-C28", "PMS-C29", "PMS-C30", "PMS-C31", "PMS-C32", "PMS-C33", "PMS-C34", "PMS-C35", "PMS-C36", "PMS-C37", "PMS-C38", "PMS-C39", "PMS-C40", "PMS-C41", "PMS-C42", "PMS-C43", "PMS-C44", "PMS-C45", "PMS-C46", "PMS-C47", "PMS-C48", "PMS-C49", "PMS-C50", "PMS-C51", "PMS-C52", "PMS-C53", "PMS-C54", "PMS-C55", "PMS-C56",
}
// Every string of the switch's copy record is in the file it names, byte
@@ -37,3 +44,106 @@ func TestApprovedPlatformMailSubmissionCopy(t *testing.T) {
}
checkApprovedCopy(t, raw, ".", platformMailSubmissionCopyIDs, nil)
}
+
+// TestPlatformMailSubmissionCopyCoversTheCode is the other direction (Fable
+// P2-4): every string the switch's code says has a row in the record. The
+// door's table (submissionCopy), the CLI's submission and ship constants,
+// and the mailer_unarmed alert's keys each appear as some row's text; and
+// the door and gate files answer only through the table, never with a
+// string literal of their own.
+func TestPlatformMailSubmissionCopyCoversTheCode(t *testing.T) {
+ raw, err := os.ReadFile("docs/superpowers/plans/platform-mail-submission-copy.json")
+ if err != nil {
+ t.Fatal(err)
+ }
+ var rec struct {
+ Entries []struct{ File, Text string } `json:"entries"`
+ }
+ if err := json.Unmarshal(raw, &rec); err != nil {
+ t.Fatal(err)
+ }
+ rows := map[string]bool{}
+ for _, e := range rec.Entries {
+ rows[e.File+"\x00"+e.Text] = true
+ }
+ parse := func(path string) *ast.File {
+ t.Helper()
+ f, err := parser.ParseFile(token.NewFileSet(), path, nil, 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return f
+ }
+ str := func(e ast.Expr) (string, bool) {
+ lit, ok := e.(*ast.BasicLit)
+ if !ok || lit.Kind != token.STRING {
+ return "", false
+ }
+ v, err := strconv.Unquote(lit.Value)
+ return v, err == nil
+ }
+ need := func(file, what, text string) {
+ if !rows[file+"\x00"+text] {
+ t.Errorf("%s %s has no row in the copy record: %q", file, what, text)
+ }
+ }
+ // The door's table.
+ ast.Inspect(parse("internal/console/submissioncopy.go"), func(n ast.Node) bool {
+ if kv, ok := n.(*ast.KeyValueExpr); ok {
+ if v, ok := str(kv.Value); ok {
+ need("internal/console/submissioncopy.go", fmt.Sprint(kv.Key), v)
+ }
+ }
+ return true
+ })
+ // The CLI's constants.
+ for file, prefixes := range map[string][]string{"mail_cli.go": {"submission"}, "ship_mail.go": {"shipMail", "shipBadMail"}} {
+ ast.Inspect(parse(file), func(n ast.Node) bool {
+ vs, ok := n.(*ast.ValueSpec)
+ if !ok {
+ return true
+ }
+ for i, name := range vs.Names {
+ if i < len(vs.Values) && slices.ContainsFunc(prefixes, func(p string) bool { return strings.HasPrefix(name.Name, p) }) {
+ if v, ok := str(vs.Values[i]); ok {
+ need(file, name.Name, v)
+ }
+ }
+ }
+ return true
+ })
+ }
+ // The alert's keys.
+ for file, prefix := range map[string]string{"internal/console/alertnotify.go": "rule.mailer_unarmed.", "internal/console/alertpages.go": "rules.when.mailer_unarmed"} {
+ ast.Inspect(parse(file), func(n ast.Node) bool {
+ if kv, ok := n.(*ast.KeyValueExpr); ok {
+ if k, ok := str(kv.Key); ok && strings.HasPrefix(k, prefix) {
+ if v, ok := str(kv.Value); ok {
+ need(file, k, v)
+ }
+ }
+ }
+ return true
+ })
+ }
+ // No literal answers in the door and the gate.
+ for _, file := range []string{"internal/console/apisubmission.go", "internal/console/submissiongate.go"} {
+ ast.Inspect(parse(file), func(n ast.Node) bool {
+ switch n := n.(type) {
+ case *ast.CallExpr:
+ if id, ok := n.Fun.(*ast.Ident); ok && id.Name == "jsonError" && len(n.Args) == 3 {
+ if v, ok := str(n.Args[2]); ok {
+ t.Errorf("%s answers a literal %q: put it in submissionCopy", file, v)
+ }
+ }
+ case *ast.KeyValueExpr:
+ if k, ok := n.Key.(*ast.Ident); ok && k.Name == "Msg" {
+ if v, ok := str(n.Value); ok {
+ t.Errorf("%s answers a literal %q: put it in submissionCopy", file, v)
+ }
+ }
+ }
+ return true
+ })
+ }
+}
diff --git a/docs/superpowers/plans/platform-mail-submission-copy.json b/docs/superpowers/plans/platform-mail-submission-copy.json
index 8ed9fc5fc..99677e52e 100644
--- a/docs/superpowers/plans/platform-mail-submission-copy.json
+++ b/docs/superpowers/plans/platform-mail-submission-copy.json
@@ -24,7 +24,7 @@
{
"id": "PMS-C4",
"file": "internal/console/submissioncopy.go",
- "text": "This deployment has no SES event destination, so mail sent through the box couldn't be counted or capped. Submission needs event ingest.",
+ "text": "This deployment has no SES event destination, so mail sent through the platform's mailer couldn't be counted or capped. Submission needs event ingest.",
"note": "NoEventIngest"
},
{
@@ -36,13 +36,13 @@
{
"id": "PMS-C6",
"file": "internal/console/submissioncopy.go",
- "text": "Can't confirm instance %s: no box has reported it recently. Wait for it to report, or check it is running.",
+ "text": "Can't confirm instance %s: no server has reported it recently. Wait for it to report, or check it is running.",
"note": "RouteUnreported"
},
{
"id": "PMS-C7",
"file": "internal/console/submissioncopy.go",
- "text": "Instance %s runs build %s, which doesn't declare --mail submit. Ship with --mail submit and promote it first.",
+ "text": "Instance %s runs build %s, which doesn't declare --mail submit. Ship a binary build with --mail submit (a rootfs release can't declare it yet) and promote it first.",
"note": "RouteUndeclared"
},
{
@@ -54,7 +54,7 @@
{
"id": "PMS-C9",
"file": "internal/console/submissioncopy.go",
- "text": "Channel %s points at build %s, which doesn't declare --mail submit. Ship with --mail submit and promote it first.",
+ "text": "Channel %s points at build %s, which doesn't declare --mail submit. Ship a binary build with --mail submit (a rootfs release can't declare it yet) and promote it first.",
"note": "ChannelUndeclared"
},
{
@@ -72,19 +72,19 @@
{
"id": "PMS-C12",
"file": "internal/console/submissioncopy.go",
- "text": "Can't confirm this app's SES tenant associations, so submission stays off. Try again.",
+ "text": "Can't confirm this app's SES tenant associations (the console's role needs ses:ListTenantResources), so submission stays off. Try again.",
"note": "TenantUnconfirmed"
},
{
"id": "PMS-C13",
"file": "internal/console/submissioncopy.go",
- "text": "Box %s hosts this app and its mailer isn't armed. Arm it first (docs/mailer-runbook.md).",
+ "text": "Server %s hosts this app and its mailer isn't armed. Ask the platform operator to arm it, then switch on.",
"note": "BoxUnarmed"
},
{
"id": "PMS-C14",
"file": "internal/console/submissioncopy.go",
- "text": "Can't read the boxes' reports, so submission stays off. Try again.",
+ "text": "Can't read the servers' reports, so submission stays off. Try again.",
"note": "BoxesUnreadable"
},
{
@@ -96,7 +96,7 @@
{
"id": "PMS-C16",
"file": "internal/console/submissioncopy.go",
- "text": "Couldn't change email submission. Nothing unrecorded was left behind; run it again to resume.",
+ "text": "Couldn't change email submission, so it stays as it was; a switch-off may have delivered some SMTP credentials already. Run the same command again to finish.",
"note": "SwitchFailed"
},
{
@@ -114,7 +114,7 @@
{
"id": "PMS-C19",
"file": "mail_cli.go",
- "text": "Its instances restart now and send through the box, with no SMTP credential.",
+ "text": "Its instances send through each server's mailer, with no SMTP credential, once they restart. Its app-level SMTP key stays valid for a week, until the reap.",
"note": "submissionOnDetail"
},
{
@@ -132,7 +132,7 @@
{
"id": "PMS-C22",
"file": "mail_cli.go",
- "text": "Its SMTP credential is delivered again, and its instances restart now.",
+ "text": "Its SMTP credential is delivered again; its instances use it once they restart.",
"note": "submissionOffDetail"
},
{
@@ -150,7 +150,7 @@
{
"id": "PMS-C25",
"file": "mail_cli.go",
- "text": "app-level SMTP user kept until a week without SMTP sends",
+ "text": "app-level SMTP user kept until the reap: a week after the switch, once a send has gone through the mailer and no SMTP send has been seen for a week",
"note": "submissionAppUserKept"
},
{
@@ -168,7 +168,7 @@
{
"id": "PMS-C28",
"file": "mail_cli.go",
- "text": " couldn't read the boxes' reports to check their mailers",
+ "text": " couldn't read the servers' reports to check their mailers",
"note": "submissionBoxesUnknown"
},
{
@@ -180,31 +180,31 @@
{
"id": "PMS-C30",
"file": "internal/console/alertnotify.go",
- "text": "%s hosts an app that sends mail through the box, but its mailer has no key.",
+ "text": "%s hosts an app that sends mail through its mailer, and the mailer isn't working: it has no key, can't load it, is missing its regions, or AWS refuses the key.",
"note": "rule.mailer_unarmed.what"
},
{
"id": "PMS-C31",
"file": "internal/console/alertnotify.go",
- "text": "A box hosting an app that sends mail through the box has no mailer key.",
+ "text": "A server hosting an app that sends mail through its mailer has a mailer that isn't working: no key, a key it can't load, missing regions, or a key AWS refuses.",
"note": "rule.mailer_unarmed.what.none"
},
{
"id": "PMS-C32",
"file": "internal/console/alertnotify.go",
- "text": "That app's mail fails on this box until it is armed.",
+ "text": "That app's mail fails on this server until its mailer works.",
"note": "rule.mailer_unarmed.how_long"
},
{
"id": "PMS-C33",
"file": "internal/console/alertnotify.go",
- "text": "Arm the box's mailer key (docs/mailer-runbook.md, step 3).",
+ "text": "Check the server's mailer: its key file, its regions and its log. The mailer runbook's arming step says how.",
"note": "rule.mailer_unarmed.what_to_do"
},
{
"id": "PMS-C34",
"file": "internal/console/alertpages.go",
- "text": "A box hosts an app switched to mail submission and its mailer is not armed.",
+ "text": "A server hosts an app switched to mail submission and its mailer isn't working.",
"note": "rules.when.mailer_unarmed"
},
{
@@ -227,15 +227,15 @@
},
{
"id": "PMS-C38",
- "file": "internal/console/apicli.go",
+ "file": "internal/console/submissioncopy.go",
"text": "a rootfs release cannot declare --mail yet",
- "note": "ship door: rootfs"
+ "note": "RootfsCannotDeclare"
},
{
"id": "PMS-C39",
- "file": "internal/console/apicli.go",
- "text": "was already shipped with a different mail declaration — versions are immutable; ship under a new version",
- "note": "ship door: re-ship"
+ "file": "internal/console/submissioncopy.go",
+ "text": "version %s was already shipped with a different mail declaration — versions are immutable; ship under a new version",
+ "note": "ReshipMailDiffers"
},
{
"id": "PMS-C40",
@@ -246,7 +246,7 @@
{
"id": "PMS-C41",
"file": "internal/console/submissioncopy.go",
- "text": "This app sends as %s, and the box's mailer would refuse it: %s must be granted to the app, list the app and be verified in %s. Run carlos email enable for the app again.",
+ "text": "This app sends as %s, and the platform's mailer would refuse it: %s must be granted to the app, list the app and be verified in %s. Run carlos email enable for the app again.",
"note": "FromNotSendable"
},
{
@@ -264,20 +264,80 @@
{
"id": "PMS-C44",
"file": "internal/console/submissioncopy.go",
- "text": "Email submission is on for %s, and environment %s has no From address for it yet, so an instance there couldn't send. Run carlos email submission on --app %s again to deliver it.",
+ "text": "Email submission is on for %s, and environment %s has no From address for it yet, so an instance there couldn't send. Run carlos email enable --app %s to deliver it.",
"note": "EnvironmentNoFrom"
},
{
"id": "PMS-C45",
"file": "internal/console/submissioncopy.go",
- "text": "Environment %s was written, but email submission is on for %s and its From address couldn't be delivered, so no instance can use it yet. Run carlos email submission on --app %s again to deliver it.",
+ "text": "Environment %s was written, but email submission is on for %s and its From address couldn't be delivered, so no instance can use it yet. Run carlos email enable --app %s to deliver it.",
"note": "EnvironmentFromFailed"
},
{
"id": "PMS-C46",
"file": "internal/console/submissioncopy.go",
- "text": "Declared, but email submission is on for %s and the new From couldn't reach every environment yet. Run carlos email submission on again to deliver it.",
+ "text": "Declared, but email submission is on for %s and the new From couldn't reach every environment yet. Run carlos email enable --app %s to deliver it.",
"note": "DeclaredFromUndelivered"
+ },
+ {
+ "id": "PMS-C47",
+ "file": "internal/console/submissioncopy.go",
+ "text": "Couldn't confirm this build declares --mail submit, so nothing changed. Try again.",
+ "note": "BuildUnreadable"
+ },
+ {
+ "id": "PMS-C48",
+ "file": "internal/console/submissioncopy.go",
+ "text": "Couldn't confirm this environment can send email while submission is on, so nothing changed. Try again.",
+ "note": "EnvironmentUnreadable"
+ },
+ {
+ "id": "PMS-C49",
+ "file": "internal/console/submissioncopy.go",
+ "text": "This change isn't serialised with the email submission switch, so nothing changed. Try again.",
+ "note": "NotSerialised"
+ },
+ {
+ "id": "PMS-C50",
+ "file": "internal/console/submissioncopy.go",
+ "text": "the restart request couldn't be stored",
+ "note": "RestartWriteFailed"
+ },
+ {
+ "id": "PMS-C51",
+ "file": "internal/console/submissioncopy.go",
+ "text": "Email is not configured on this console.",
+ "note": "NotConfigured"
+ },
+ {
+ "id": "PMS-C52",
+ "file": "internal/console/submissioncopy.go",
+ "text": "Say \"on\": true or \"on\": false.",
+ "note": "SayOnOrOff"
+ },
+ {
+ "id": "PMS-C53",
+ "file": "internal/console/submissioncopy.go",
+ "text": "Email submission is on for %s, so it has no SMTP credential to rotate. Switch submission off first: carlos email submission off --app %s.",
+ "note": "RotateSwitched"
+ },
+ {
+ "id": "PMS-C54",
+ "file": "mail_cli.go",
+ "text": "Its instances are restarting now.",
+ "note": "submissionRestarting"
+ },
+ {
+ "id": "PMS-C55",
+ "file": "mail_cli.go",
+ "text": " sending: %s, through each server's mailer",
+ "note": "submissionSendingActive"
+ },
+ {
+ "id": "PMS-C56",
+ "file": "mail_cli.go",
+ "text": " sending: PAUSED — each server's mailer is refusing this app's mail right now",
+ "note": "submissionSendingPaused"
}
]
}
diff --git a/internal/console/alertmailer_test.go b/internal/console/alertmailer_test.go
index e41863044..9f854b4ba 100644
--- a/internal/console/alertmailer_test.go
+++ b/internal/console/alertmailer_test.go
@@ -190,7 +190,7 @@ func TestEnginePassMailerUnarmed(t *testing.T) {
"GET apps/" + opsSqid + "/shop/instances/shop.example.com.json": 1,
})
fire := ef.mailsTo(opA)
- if len(fire) != 1 || !strings.Contains(fire[0], "box-1 hosts an app that sends mail through the box") {
+ if len(fire) != 1 || !strings.Contains(fire[0], "box-1 hosts an app that sends mail through its mailer") {
t.Fatalf("A got %v, want one mailer_unarmed fire for box-1", fire)
}
if strings.Contains(fire[0], "box-2") {
diff --git a/internal/console/alertnotify.go b/internal/console/alertnotify.go
index 23aa12503..440ab0f93 100644
--- a/internal/console/alertnotify.go
+++ b/internal/console/alertnotify.go
@@ -252,10 +252,10 @@ var alertCopy = map[string]string{
// Task 6 step 0): not yet in an approved record. So is
// rules.when.mailer_unarmed in alertpages.go.
"rule.mailer_unarmed.title": "Mailer not armed",
- "rule.mailer_unarmed.what": "%s hosts an app that sends mail through the box, but its mailer has no key.",
- "rule.mailer_unarmed.what.none": "A box hosting an app that sends mail through the box has no mailer key.",
- "rule.mailer_unarmed.how_long": "That app's mail fails on this box until it is armed.",
- "rule.mailer_unarmed.what_to_do": "Arm the box's mailer key (docs/mailer-runbook.md, step 3).",
+ "rule.mailer_unarmed.what": "%s hosts an app that sends mail through its mailer, and the mailer isn't working: it has no key, can't load it, is missing its regions, or AWS refuses the key.",
+ "rule.mailer_unarmed.what.none": "A server hosting an app that sends mail through its mailer has a mailer that isn't working: no key, a key it can't load, missing regions, or a key AWS refuses.",
+ "rule.mailer_unarmed.how_long": "That app's mail fails on this server until its mailer works.",
+ "rule.mailer_unarmed.what_to_do": "Check the server's mailer: its key file, its regions and its log. The mailer runbook's arming step says how.",
"rule.seal_key.title": "Connector key",
"rule.seal_key.what": "Slack and webhook connectors cannot send because the %s cannot open the key that protects their addresses.",
diff --git a/internal/console/alertpages.go b/internal/console/alertpages.go
index 84bef1b3d..8ed9eea3d 100644
--- a/internal/console/alertpages.go
+++ b/internal/console/alertpages.go
@@ -108,7 +108,7 @@ var alertPageCopy = map[string]string{
"rules.when.cert_expiring": "A served host's certificate expires within the threshold.",
"rules.when.alert_delivery_broken": "A box has no place to send its own alerts.",
"rules.when.seal_key": "The console cannot open the key for Slack and webhook connectors, or a connector needs its URL entered again.",
- "rules.when.mailer_unarmed": "A box hosts an app switched to mail submission and its mailer is not armed.",
+ "rules.when.mailer_unarmed": "A server hosts an app switched to mail submission and its mailer isn't working.",
"rules.th.disk": "Default: 90 percent. Each box can set CARLOS_ALERT_DISK_PCT in its host.env.",
"rules.th.mem": "Default: 90 percent. Each box can set CARLOS_ALERT_MEM_PCT in its host.env.",
"rules.th.cpu": "Default: 95 percent. Each box can set CARLOS_ALERT_CPU_PCT in its host.env.",
diff --git a/internal/console/apicli.go b/internal/console/apicli.go
index b0252a237..aa367b4a3 100644
--- a/internal/console/apicli.go
+++ b/internal/console/apicli.go
@@ -2397,7 +2397,7 @@ func (s *Server) handleAPIShip(w http.ResponseWriter, r *http.Request) {
// dropped: a dropped declaration would ship a build that says it
// can submit as one that cannot.
if meta.Mail != "" {
- refuseUnread(w, http.StatusBadRequest, "a rootfs release cannot declare --mail yet")
+ refuseUnread(w, http.StatusBadRequest, submissionCopy.RootfsCannotDeclare)
return
}
var ref *doorRefusal
@@ -2648,7 +2648,7 @@ func (s *Server) handleAPIShip(w http.ResponseWriter, r *http.Request) {
}
if existing.Mail != meta.Mail {
jsonError(w, http.StatusConflict,
- "version "+ver+" was already shipped with a different mail declaration — versions are immutable; ship under a new version")
+ fmt.Sprintf(submissionCopy.ReshipMailDiffers, ver))
return
}
if refuseSwapConflict(w, existing.Swap, meta.Swap, ver) {
diff --git a/internal/console/apimail.go b/internal/console/apimail.go
index 3991fdc74..8034aad08 100644
--- a/internal/console/apimail.go
+++ b/internal/console/apimail.go
@@ -398,7 +398,20 @@ func (s *Server) emailReply(ctx context.Context, acct *Account, app string, rec
host, port, user, pass, from := mail.EnvNames(prefix)
names := []string{host, port, user, pass, from}
missing := []string{}
- if rec.Provisioned != nil {
+ // The senders, read first: a switched app's bundles carry the From and
+ // not the five, by design, so the overlap week's kept key is not
+ // drift (Fable P2-6).
+ all, err := mail.ListSenders(ctx, s.cfg.Releases, acct.Sqid, app)
+ if err != nil {
+ return nil, err
+ }
+ switched := false
+ for _, sn := range all {
+ if sn.ID == mail.SenderAppID && mail.Switched(sn) {
+ switched = true
+ }
+ }
+ if rec.Provisioned != nil && !switched {
wantKeyID := rec.Provisioned.KeyID
// rec.Declared is guaranteed non-nil here: Provisioned is only ever
// set by Enable, which itself requires Declared != nil — so
@@ -423,10 +436,6 @@ func (s *Server) emailReply(ctx context.Context, acct *Account, app string, rec
// The senders array (senders design §8). The top-level fields above keep
// describing the APP sender and the app's whole day, so an older CLI
// still works; this is the per-sender view beside them.
- all, err := mail.ListSenders(ctx, s.cfg.Releases, acct.Sqid, app)
- if err != nil {
- return nil, err
- }
senders := make([]map[string]any, 0, len(all))
for _, sn := range all {
sc, err := s.store.MailCounts(ctx, acct.Sqid, app, sn.ID, day)
@@ -669,7 +678,7 @@ func (s *Server) handleAPIEmailDeclare(w http.ResponseWriter, r *http.Request) {
}
if err != nil {
log.Printf("console: api email declare %s/%s: deliver the From: %v", acct.Sqid, app, err)
- jsonError(w, http.StatusBadGateway, fmt.Sprintf(submissionCopy.DeclaredFromUndelivered, app))
+ jsonError(w, http.StatusBadGateway, fmt.Sprintf(submissionCopy.DeclaredFromUndelivered, app, app))
return
}
s.bumpSerial(ctx)
@@ -1411,6 +1420,10 @@ func (s *Server) handleAPIEmailRotate(w http.ResponseWriter, r *http.Request) {
case errors.Is(err, mail.ErrNotProvisioned):
jsonError(w, http.StatusConflict, "no provisioned email credential to rotate — enable email first")
return
+ case errors.Is(err, mail.ErrSubmissionOn):
+ // A switched app has no SMTP credential to rotate (Fable P3).
+ jsonError(w, http.StatusConflict, fmt.Sprintf(submissionCopy.RotateSwitched, app, app))
+ return
case err != nil:
log.Printf("console: api email rotate %s/%s: %v", acct.Sqid, app, err)
jsonError(w, http.StatusBadGateway,
diff --git a/internal/console/apisubmission.go b/internal/console/apisubmission.go
index f98192ef4..7df76c774 100644
--- a/internal/console/apisubmission.go
+++ b/internal/console/apisubmission.go
@@ -8,8 +8,8 @@
// `--mail submit`, every box hosting the app has its mailer armed (gap G6),
// and the deployment can count what is sent (an SES event destination and a
// configuration set per sending domain). While it is on, every door that
-// changes what a route serves refuses an undeclared build
-// (submissionBuildRefusal, submissiongate.go). A route with no instance
+// changes what a route serves refuses an undeclared build (judgeServing,
+// submissiongate.go, under the app lock). A route with no instance
// record cannot submit (gap G10, ruled: accepted, with the operator check).
package console
@@ -63,7 +63,7 @@ func (s *Server) handleAPIEmailSubmission(w http.ResponseWriter, r *http.Request
return
}
if req.On == nil {
- jsonError(w, http.StatusBadRequest, `say "on": true or "on": false`)
+ jsonError(w, http.StatusBadRequest, submissionCopy.SayOnOrOff)
return
}
// The account lock before any app lock (fleet secrets key spec §5.2.1),
@@ -157,7 +157,7 @@ func (s *Server) handleAPIEmailSubmission(w http.ResponseWriter, r *http.Request
} else {
if err := s.requestAppRestart(rctx, acct.Sqid, app); err != nil {
log.Printf("console: api email submission %s/%s: restart: %v", acct.Sqid, app, err)
- reply.Warning = fmt.Sprintf(submissionCopy.RestartNotRequested, "the bucket write failed", app)
+ reply.Warning = fmt.Sprintf(submissionCopy.RestartNotRequested, submissionCopy.RestartWriteFailed, app)
} else {
reply.RestartRequested = true
s.bumpSerial(rctx)
@@ -183,7 +183,7 @@ func (s *Server) submissionPreconditions(ctx context.Context, acct, app string,
return &doorRefusal{Status: http.StatusConflict, Msg: msg}
}
if s.cfg.Releases == nil || s.cfg.MailProvisioner == nil {
- return &doorRefusal{Status: http.StatusServiceUnavailable, Msg: "email is not configured on this console"}
+ return &doorRefusal{Status: http.StatusServiceUnavailable, Msg: submissionCopy.NotConfigured}
}
// 1. Declared and enabled, with a prefix the transport can name.
diff --git a/internal/console/apisubmission_test.go b/internal/console/apisubmission_test.go
index 0dde0be8e..d6e695c61 100644
--- a/internal/console/apisubmission_test.go
+++ b/internal/console/apisubmission_test.go
@@ -106,7 +106,7 @@ func TestSubmissionDoorPreconditions(t *testing.T) {
refused("the channel heads an undeclared build", "Channel stable points at build v1")
w.promote(t, "v2")
w.box(t, "box-1", "v2", false)
- refused("the box's mailer is not armed", "Box box-1 hosts this app")
+ refused("the box's mailer is not armed", "Server box-1 hosts this app")
w.box(t, "box-1", "v2", true)
// No event ingest on the deployment.
@@ -453,11 +453,11 @@ func TestSubmissionDoorMoreRefusals(t *testing.T) {
})
refused("an identity ARN no set can be named from", "Can't name the configuration set")
edit(func(raw map[string]any) { raw["apps"] = []string{"sheets"} })
- refused("a domain record that does not list the app", "the box's mailer would refuse it")
+ refused("a domain record that does not list the app", "the platform's mailer would refuse it")
edit(func(raw map[string]any) {
raw["regions"].(map[string]any)["eu-west-1"].(map[string]any)["status"] = mail.StatusPending
})
- refused("a domain not verified", "the box's mailer would refuse it")
+ refused("a domain not verified", "the platform's mailer would refuse it")
edit(func(map[string]any) {})
if status, out := w.submit(t, true); status != http.StatusOK {
t.Fatalf("restored: %d %s", status, out)
@@ -602,3 +602,65 @@ func TestTeamConfigDoorAnswersAFailedFrom(t *testing.T) {
t.Fatalf("crew holds a From after its write failed: %v", vars)
}
}
+
+// Fable P2-5: the reap runs from the hourly pass whatever governs the
+// account. With no plan catalog (as here) planGracePass measures nothing,
+// and still reaps a switched app's app-level user after the week.
+func TestReapRunsThroughTheGracePassWithoutACatalog(t *testing.T) {
+ w := newSubmissionWorld(t, "code-submission-reap-pass")
+ if w.fx.srv.cfg.PlanCatalog != nil {
+ t.Fatal("the fixture has a plan catalog; this test needs none")
+ }
+ w.promote(t, "v2")
+ w.box(t, "box-1", "v2", true)
+ if status, out := w.submit(t, true); status != http.StatusOK {
+ t.Fatalf("switch on: %d %s", status, out)
+ }
+ ctx := context.Background()
+ now := time.Now().UTC().AddDate(0, 0, 8)
+ if err := w.fx.st.RecordMailCallerSend(ctx, "bab", "titogo", now.AddDate(0, 0, -1).Format("2006-01-02"), mail.CallerClassMailer); err != nil {
+ t.Fatal(err)
+ }
+ w.fx.srv.planGracePass(ctx, now)
+ sn, _, err := mail.GetSender(ctx, w.fx.rel, "bab", "titogo", mail.SenderAppID)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if sn.Provisioned != nil {
+ t.Fatal("the grace pass with no catalog did not reap the app-level user")
+ }
+}
+
+// Fable P2-6: during the overlap week a switched app's bundles hold the
+// From and not the five, by design: the status reply reports no drift.
+func TestEmailStatusSwitchedReportsNoDrift(t *testing.T) {
+ w := newSubmissionWorld(t, "code-submission-status-drift")
+ w.switchOn(t)
+ if w.sender(t).Provisioned == nil {
+ t.Fatal("the overlap week's app-level user is gone already")
+ }
+ status, _, out := rawReq(t, http.MethodGet, w.fx.ts.URL+"/api/cli/apps/bab/titogo/email", w.owner, "")
+ if status != http.StatusOK {
+ t.Fatalf("status: %d %s", status, out)
+ }
+ var reply struct {
+ MissingVars []string `json:"missing_vars"`
+ }
+ if err := json.Unmarshal([]byte(out), &reply); err != nil {
+ t.Fatal(err)
+ }
+ if len(reply.MissingVars) != 0 {
+ t.Fatalf("a switched app reports drift: %v", reply.MissingVars)
+ }
+}
+
+// Fable P3: rotating a switched app's credential is a 409 that says why,
+// not a 502.
+func TestRotateRefusesASwitchedApp(t *testing.T) {
+ w := newSubmissionWorld(t, "code-submission-rotate")
+ w.switchOn(t)
+ status, _, out := rawReq(t, http.MethodPost, w.fx.ts.URL+"/api/cli/apps/bab/titogo/email/rotate", w.owner, `{}`)
+ if status != http.StatusConflict || !strings.Contains(out, "no SMTP credential to rotate") {
+ t.Fatalf("rotate while switched: %d %s, want 409 naming the switch", status, out)
+ }
+}
diff --git a/internal/console/plangracepass.go b/internal/console/plangracepass.go
index 7b27e285d..ea9d999e7 100644
--- a/internal/console/plangracepass.go
+++ b/internal/console/plangracepass.go
@@ -21,9 +21,10 @@ const planNoticeDeliveryTimeout = 15 * time.Second
// StartPlanGracePass measures every plan-governed account against its
// effective limits, keeps each cap's grace clock and warns owners (plans
-// 4a, spec §6): now, then hourly. With no catalog it does nothing at all.
+// 4a, spec §6): now, then hourly. With no catalog it measures nothing, but
+// still runs the email submission reap for every account (Fable P2-5).
func (s *Server) StartPlanGracePass(ctx context.Context) {
- if s.cfg.Releases == nil || s.cfg.PlanCatalog == nil {
+ if s.cfg.Releases == nil {
return
}
t := time.NewTicker(planGracePassInterval)
@@ -39,9 +40,12 @@ func (s *Server) StartPlanGracePass(ctx context.Context) {
}
// planGracePass is one pass at the given clock. One account's failure
-// never stops the others; a cap that cannot be measured keeps its row.
+// never stops the others; a cap that cannot be measured keeps its row. The
+// email submission reap (gap G4, ruled 2026-11-13) runs for every account,
+// whether or not a catalog governs it or the account is exempt from plans
+// (Fable P2-5): it is not a plan measure.
func (s *Server) planGracePass(ctx context.Context, now time.Time) {
- if s.cfg.Releases == nil || s.cfg.PlanCatalog == nil {
+ if s.cfg.Releases == nil {
return
}
accts, err := s.store.Accounts()
@@ -54,9 +58,18 @@ func (s *Server) planGracePass(ctx context.Context, now time.Time) {
if ctx.Err() != nil {
return
}
- if err := s.planGraceAccount(ctx, &accts[i], now); err != nil {
- log.Printf("console: plan grace %s: %v", accts[i].Sqid, err)
- jobFailed(ctx, fmt.Errorf("plan grace %s: %w", accts[i].Sqid, err))
+ if s.cfg.PlanCatalog != nil {
+ if err := s.planGraceAccount(ctx, &accts[i], now); err != nil {
+ log.Printf("console: plan grace %s: %v", accts[i].Sqid, err)
+ jobFailed(ctx, fmt.Errorf("plan grace %s: %w", accts[i].Sqid, err))
+ }
+ }
+ // The app-level user of an app switched to submission goes once
+ // its SMTP key has gone unused for a week (gap G4, ruled
+ // 2026-11-13).
+ if err := s.reapSubmittedAppUsers(ctx, &accts[i], now); err != nil {
+ log.Printf("console: plan grace %s: submission reap: %v", accts[i].Sqid, err)
+ jobFailed(ctx, fmt.Errorf("plan grace %s: submission reap: %w", accts[i].Sqid, err))
}
}
}
@@ -181,12 +194,6 @@ func (s *Server) planGraceAccountLocked(ctx context.Context, acct *Account, now
log.Printf("console: plan grace %s: mail resume: %v", acct.Sqid, err)
jobFailed(ctx, fmt.Errorf("plan grace %s: mail resume: %w", acct.Sqid, err))
}
- // The app-level user of an app switched to submission goes once its
- // SMTP key has gone unused for a week (gap G4, ruled 2026-11-13).
- if err := s.reapSubmittedAppUsers(ctx, acct, now); err != nil {
- log.Printf("console: plan grace %s: submission reap: %v", acct.Sqid, err)
- jobFailed(ctx, fmt.Errorf("plan grace %s: submission reap: %w", acct.Sqid, err))
- }
}
return s.notifyPlanOwners(ctx, acct, states, now)
}
diff --git a/internal/console/submissioncopy.go b/internal/console/submissioncopy.go
index dc669f904..3d68d3655 100644
--- a/internal/console/submissioncopy.go
+++ b/internal/console/submissioncopy.go
@@ -11,42 +11,53 @@ var submissionCopy = struct {
FromNotSendable, ConfigSetUnbuildable string
RouteUnreported, RouteUndeclared, RoutesUnreadable string
RoutePinUndeclared, EnvironmentNoFrom, EnvironmentFromFailed string
- DeclaredFromUndelivered string
+ DeclaredFromUndelivered, RotateSwitched string
ChannelUndeclared, ChannelUnreadable string
TenantUnassociated, TenantUnconfirmed string
BoxUnarmed, BoxesUnreadable string
- BuildUndeclared string
- SwitchFailed, RestartNotRequested string
+ BuildUndeclared, BuildUnreadable, EnvironmentUnreadable, NotSerialised string
+ SwitchFailed, RestartNotRequested, RestartWriteFailed string
+ NotConfigured, SayOnOrOff, ReshipMailDiffers, RootfsCannotDeclare string
}{
NotDeclared: "No email is declared for this app. Declare and enable it first.",
NotEnabled: "Email is not enabled for this app. Run carlos email enable --app %s first.",
PrefixNotSMTP: "This app's mail variables use the prefix %s, which does not end in _SMTP, so the submit transport can't find its From address. Declare it again with a prefix ending in _SMTP.",
- NoEventIngest: "This deployment has no SES event destination, so mail sent through the box couldn't be counted or capped. Submission needs event ingest.",
+ NoEventIngest: "This deployment has no SES event destination, so mail sent through the platform's mailer couldn't be counted or capped. Submission needs event ingest.",
DomainNoConfigSet: "Sending domain %s has no configuration set in %s, so its mail couldn't be counted or capped. Submission needs one.",
- FromNotSendable: "This app sends as %s, and the box's mailer would refuse it: %s must be granted to the app, list the app and be verified in %s. Run carlos email enable for the app again.",
+ FromNotSendable: "This app sends as %s, and the platform's mailer would refuse it: %s must be granted to the app, list the app and be verified in %s. Run carlos email enable for the app again.",
ConfigSetUnbuildable: "Can't name the configuration set of %s from its identity, so its tenant can't be checked. Run carlos email domains add for it again.",
- RouteUnreported: "Can't confirm instance %s: no box has reported it recently. Wait for it to report, or check it is running.",
- RouteUndeclared: "Instance %s runs build %s, which doesn't declare --mail submit. Ship with --mail submit and promote it first.",
+ RouteUnreported: "Can't confirm instance %s: no server has reported it recently. Wait for it to report, or check it is running.",
+ RouteUndeclared: "Instance %s runs build %s, which doesn't declare --mail submit. Ship a binary build with --mail submit (a rootfs release can't declare it yet) and promote it first.",
RoutesUnreadable: "Can't read this app's instances, so submission stays off. Try again.",
RoutePinUndeclared: "Instance %s is pinned to build %s, which doesn't declare --mail submit. Pin a build that does, or unpin it, first.",
- EnvironmentNoFrom: "Email submission is on for %s, and environment %s has no From address for it yet, so an instance there couldn't send. Run carlos email submission on --app %s again to deliver it.",
- DeclaredFromUndelivered: "Declared, but email submission is on for %s and the new From couldn't reach every environment yet. Run carlos email submission on again to deliver it.",
- EnvironmentFromFailed: "Environment %s was written, but email submission is on for %s and its From address couldn't be delivered, so no instance can use it yet. Run carlos email submission on --app %s again to deliver it.",
+ EnvironmentNoFrom: "Email submission is on for %s, and environment %s has no From address for it yet, so an instance there couldn't send. Run carlos email enable --app %s to deliver it.",
+ RotateSwitched: "Email submission is on for %s, so it has no SMTP credential to rotate. Switch submission off first: carlos email submission off --app %s.",
+ DeclaredFromUndelivered: "Declared, but email submission is on for %s and the new From couldn't reach every environment yet. Run carlos email enable --app %s to deliver it.",
+ EnvironmentFromFailed: "Environment %s was written, but email submission is on for %s and its From address couldn't be delivered, so no instance can use it yet. Run carlos email enable --app %s to deliver it.",
- ChannelUndeclared: "Channel %s points at build %s, which doesn't declare --mail submit. Ship with --mail submit and promote it first.",
+ ChannelUndeclared: "Channel %s points at build %s, which doesn't declare --mail submit. Ship a binary build with --mail submit (a rootfs release can't declare it yet) and promote it first.",
ChannelUnreadable: "Can't confirm channel %s: its pointer or build couldn't be read. Try again.",
TenantUnassociated: "This app's sender sends as tenant %s, and %s isn't associated with it. Associate it first.",
- TenantUnconfirmed: "Can't confirm this app's SES tenant associations, so submission stays off. Try again.",
+ TenantUnconfirmed: "Can't confirm this app's SES tenant associations (the console's role needs ses:ListTenantResources), so submission stays off. Try again.",
- BoxUnarmed: "Box %s hosts this app and its mailer isn't armed. Arm it first (docs/mailer-runbook.md).",
- BoxesUnreadable: "Can't read the boxes' reports, so submission stays off. Try again.",
+ BoxUnarmed: "Server %s hosts this app and its mailer isn't armed. Ask the platform operator to arm it, then switch on.",
+ BoxesUnreadable: "Can't read the servers' reports, so submission stays off. Try again.",
- BuildUndeclared: "This build doesn't declare --mail submit, and email submission is on for %s. Switch submission off first (carlos email submission off --app %s), or ship with --mail submit.",
+ BuildUndeclared: "This build doesn't declare --mail submit, and email submission is on for %s. Switch submission off first (carlos email submission off --app %s), or ship with --mail submit.",
+ BuildUnreadable: "Couldn't confirm this build declares --mail submit, so nothing changed. Try again.",
+ EnvironmentUnreadable: "Couldn't confirm this environment can send email while submission is on, so nothing changed. Try again.",
+ NotSerialised: "This change isn't serialised with the email submission switch, so nothing changed. Try again.",
- SwitchFailed: "Couldn't change email submission. Nothing unrecorded was left behind; run it again to resume.",
+ SwitchFailed: "Couldn't change email submission, so it stays as it was; a switch-off may have delivered some SMTP credentials already. Run the same command again to finish.",
RestartNotRequested: "Submission changed, but the restart couldn't be requested (%s). Run carlos restart --app %s.",
+ RestartWriteFailed: "the restart request couldn't be stored",
+
+ NotConfigured: "Email is not configured on this console.",
+ SayOnOrOff: `Say "on": true or "on": false.`,
+ ReshipMailDiffers: "version %s was already shipped with a different mail declaration — versions are immutable; ship under a new version",
+ RootfsCannotDeclare: "a rootfs release cannot declare --mail yet",
}
diff --git a/internal/console/submissiongate.go b/internal/console/submissiongate.go
index 51d6dff34..08840cc34 100644
--- a/internal/console/submissiongate.go
+++ b/internal/console/submissiongate.go
@@ -22,10 +22,11 @@ import (
// declare --mail submit. Such a build has no SMTP credential to fall back on
// (the switch removed it), so it would boot unable to send.
//
-// Waking is never refused: a box that wakes an undeclared build logs loudly
-// and raises an event instead (the activator and the adopt pass). A
-// direct-bucket promote with the root key bypasses every console door by
-// design; the adopt pass's loud log is the answer there too (gap G7).
+// Waking is never refused: a box that starts an undeclared build of a
+// switched app logs loudly and raises an event instead, at spawn, on every
+// launch path (the activator, gap G7 as built; the adopt pass itself does
+// not log). A direct-bucket promote with the root key bypasses every
+// console door by design; that spawn-time log is the answer there too.
// submissionServeDoors is every console route that changes which build a
// route serves: it writes a channel pointer, an instance's channel, or an
@@ -104,12 +105,8 @@ var submissionUngatedServeDoors = map[string]string{
// - the demo publish and claim jobs promote demo apps from a background
// job, not a route; a demo app has no declared mail.
-// submissionBuildUnreadableMsg answers a gate that could not read what it
-// needs to judge: an unconfirmed build is never let through.
-const submissionBuildUnreadableMsg = "Couldn't confirm this build declares --mail submit, so nothing changed. Try again."
-
func submissionUnreadable() *doorRefusal {
- return &doorRefusal{Status: http.StatusBadGateway, Msg: submissionBuildUnreadableMsg}
+ return &doorRefusal{Status: http.StatusBadGateway, Msg: submissionCopy.BuildUnreadable}
}
// submissionSwitched reads whether acct/app's email submission is on. A
@@ -195,7 +192,7 @@ type servingPolicy struct {
func (s *Server) judgeServing(ctx context.Context, acct, app string, c servingChange) *doorRefusal {
if !s.appLocks.held(acct + "/" + app) {
log.Printf("console: submission gate %s/%s: judged without the app lock", acct, app)
- return &doorRefusal{Status: http.StatusInternalServerError, Msg: "This change isn't serialised with the email submission switch, so nothing changed. Try again."}
+ return &doorRefusal{Status: http.StatusInternalServerError, Msg: submissionCopy.NotSerialised}
}
if s.servingJudged != nil {
s.servingJudged(acct, app)
@@ -384,5 +381,5 @@ func (s *Server) servingEnvironment(ctx context.Context, acct, app, env string)
// submissionEnvironmentUnreadable is servingEnvironment's answer when it
// could not read what it judges.
func submissionEnvironmentUnreadable() *doorRefusal {
- return &doorRefusal{Status: http.StatusBadGateway, Msg: "Couldn't confirm this environment can send email while submission is on, so nothing changed. Try again."}
+ return &doorRefusal{Status: http.StatusBadGateway, Msg: submissionCopy.EnvironmentUnreadable}
}
diff --git a/internal/console/submissiongate_test.go b/internal/console/submissiongate_test.go
index 35e41ecbf..257ffe318 100644
--- a/internal/console/submissiongate_test.go
+++ b/internal/console/submissiongate_test.go
@@ -350,7 +350,7 @@ func TestSubmissionGateCoversEveryServeDoor(t *testing.T) {
case listed[p] && len(gated) == 0:
t.Errorf("%s is a listed serve door but reaches no submission gate (it reaches %s)", p, strings.Join(writes, ", "))
case !listed[p] && !ungated:
- t.Errorf("%s reaches %s, which changes the build a route serves, and is in neither submissionServeDoors nor submissionUngatedServeDoors: gate it with submissionBuildRefusal (or a sibling) and list it, or say why not", p, strings.Join(writes, ", "))
+ t.Errorf("%s reaches %s, which changes the build a route serves, and is in neither submissionServeDoors nor submissionUngatedServeDoors: judge it with judgeServing under the app lock and list it, or say why not", p, strings.Join(writes, ", "))
}
}
// The lists name only routes that exist and still reach a writer, so
diff --git a/internal/mail/sender.go b/internal/mail/sender.go
index 2cda3f708..163ade925 100644
--- a/internal/mail/sender.go
+++ b/internal/mail/sender.go
@@ -99,7 +99,8 @@ type Sender struct {
// verb writes both. Additive: an older reader ignores it.
Pause *mailwire.Pause `json:"pause,omitempty"`
// Submission is the app sender's switch to the submit transport
- // (decision 10). Nothing writes it yet. Additive.
+ // (decision 10), written by SwitchOn and SwitchOff (submission.go) and
+ // by the reap (sweep.go). Additive.
Submission *mailwire.Submission `json:"submission,omitempty"`
// Salt disambiguates a slug collision. The slug is 40 bits of a hash, so
@@ -130,7 +131,7 @@ func EffectivePause(sn *Sender) *mailwire.Pause {
}
// Switched reports whether the sender's app has switched to the submit
-// transport (decision 10). Nothing sets it yet.
+// transport (decision 10): its Submission is on.
func Switched(sn *Sender) bool {
return sn != nil && sn.Submission != nil && sn.Submission.On
}
diff --git a/internal/mail/submission_test.go b/internal/mail/submission_test.go
index abc6ccc59..8a60521e1 100644
--- a/internal/mail/submission_test.go
+++ b/internal/mail/submission_test.go
@@ -610,6 +610,49 @@ func TestReapAgainAfterSwitchOffAndOn(t *testing.T) {
}
}
+// Fable P3: a switch-off of a reaped app that re-mints the app-level user
+// and fails before it turns the switch off leaves a switched app with a
+// user again. The reap mark is history, not a bar: that user is reaped in
+// its turn.
+func TestReapAfterAPartFailedSwitchOffOfAReapedApp(t *testing.T) {
+ ctx, s, mem, seal, t0 := switchFixture(t)
+ mailer := map[string]map[string]int64{utcDay(t0): {CallerClassMailer: 3}}
+ if _, err := SwitchOn(ctx, s, mem, subAcct, subApp, []string{"team"}, "o", t0); err != nil {
+ t.Fatal(err)
+ }
+ reap1 := t0.Add(8 * 24 * time.Hour)
+ if ok, err := ReapAppUserAfterSubmission(ctx, s, mem, subAcct, subApp, fakeCounts(mailer, nil), reap1); !ok || err != nil {
+ t.Fatalf("first reap = %v, %v", ok, err)
+ }
+ // The switch-off re-mints the app-level user, then its write to the
+ // team environment fails: the switch stays on.
+ failing := &failTeamStore{Store: s}
+ if _, err := SwitchOff(ctx, failing, mem, seal, testDeployment(), subAcct, subApp, []string{"team"}, "o", reap1.Add(time.Hour)); err == nil {
+ t.Fatal("the switch-off did not fail")
+ }
+ sn, _, _ := GetSender(ctx, s, subAcct, subApp, SenderAppID)
+ if !Switched(sn) || sn.Provisioned == nil || sn.Submission.AppUserReapedAt == nil {
+ t.Fatalf("after the part-failed switch-off: switched %v, provisioned %v, reaped mark %v", Switched(sn), sn.Provisioned, sn.Submission.AppUserReapedAt)
+ }
+ later := reap1.Add(2 * time.Hour)
+ if ok, err := ReapAppUserAfterSubmission(ctx, s, mem, subAcct, subApp, fakeCounts(mailer, nil), later); !ok || err != nil {
+ t.Fatalf("the re-minted user of a switched app was not reaped: %v, %v", ok, err)
+ }
+ if _, ok := mem.Users[UserName(subAcct, subApp)]; ok {
+ t.Fatal("the re-minted app-level user survived")
+ }
+}
+
+// failTeamStore fails every write to the team environment's bundle.
+type failTeamStore struct{ release.Store }
+
+func (f *failTeamStore) Put(ctx context.Context, key string, body []byte, ifMatch string) (string, error) {
+ if strings.Contains(key, "environments/team.json") {
+ return "", errors.New("simulated store failure")
+ }
+ return f.Store.Put(ctx, key, body, ifMatch)
+}
+
// Review P3s: while switched the env prefix stays locked even once the
// app-level user is reaped, and Enable delivers a re-declared From to the
// default bundle (before and after the reap).
diff --git a/internal/mail/sweep.go b/internal/mail/sweep.go
index 322cd476b..cfb208f24 100644
--- a/internal/mail/sweep.go
+++ b/internal/mail/sweep.go
@@ -124,10 +124,12 @@ func claimUnserializedReapAppUserAfterSubmission(ctx context.Context, s release.
if rec == nil || !rec.switched() || rec.Provisioned == nil {
return false, nil
}
+ // A reap mark does not stop a reap while an app-level user exists: a
+ // switch-off that re-minted the user and failed before it turned the
+ // switch off leaves a switched app with a user again, whose key no
+ // instance uses (Fable P3). The mark is history; Provisioned is the
+ // fact, checked above.
sub := rec.submission()
- if sub.AppUserReapedAt != nil {
- return false, nil
- }
if now.Sub(sub.At) < SubmissionOverlap {
return false, nil
}
diff --git a/mail_cli.go b/mail_cli.go
index c446e9973..cfd9a3090 100644
--- a/mail_cli.go
+++ b/mail_cli.go
@@ -389,16 +389,21 @@ func (s *apiSession) emailSubmission(ctx context.Context, a apiAcct, app string,
// The switch's words (draft PMS-C20..; docs/superpowers/plans/platform-mail-submission-copy.json).
const (
submissionOnLine = "Email submission is on for %s."
- submissionOnDetail = "Its instances restart now and send through the box, with no SMTP credential."
+ submissionOnDetail = "Its instances send through each server's mailer, with no SMTP credential, once they restart. Its app-level SMTP key stays valid for a week, until the reap."
submissionOnOutage = "A route with no instance record can't send mail now, and its app will refuse to start. Check carlos instances --app %s."
submissionOffLine = "Email submission is off for %s."
- submissionOffDetail = "Its SMTP credential is delivered again, and its instances restart now."
+ submissionOffDetail = "Its SMTP credential is delivered again; its instances use it once they restart."
+ submissionRestarting = "Its instances are restarting now."
submissionStatusOn = " submission: on since %s, by %s (%s)"
submissionStatusOff = " submission: off since %s"
- submissionAppUserKept = "app-level SMTP user kept until a week without SMTP sends"
+ submissionAppUserKept = "app-level SMTP user kept until the reap: a week after the switch, once a send has gone through the mailer and no SMTP send has been seen for a week"
submissionAppUserGone = "app-level SMTP user removed %s"
submissionUnarmedBoxes = " mailer not armed on %s: mail from this app fails there until it is"
- submissionBoxesUnknown = " couldn't read the boxes' reports to check their mailers"
+ submissionBoxesUnknown = " couldn't read the servers' reports to check their mailers"
+ // The sending line of a switched app (Fable P2-6): mail goes through
+ // each server's mailer, under the app sender's pause.
+ submissionSendingActive = " sending: %s, through each server's mailer"
+ submissionSendingPaused = " sending: PAUSED — each server's mailer is refusing this app's mail right now"
)
// runEmailSubmission is `carlos email submission on|off`.
@@ -440,6 +445,11 @@ func printEmailSubmission(w io.Writer, res apiSubmissionReply) {
fmt.Fprintf(w, submissionOffLine+"\n", res.App)
fmt.Fprintln(w, submissionOffDetail)
}
+ // The restart is claimed only when the console requested it (Fable
+ // P2-4); otherwise its warning says why not.
+ if res.RestartRequested {
+ fmt.Fprintln(w, submissionRestarting)
+ }
if res.Warning != "" {
warnf(w, "%s", res.Warning)
}
@@ -1514,12 +1524,34 @@ func printEmailStatus(w io.Writer, res apiEmailReply) {
}
}
- if res.Provisioned != nil {
- paused, kind := emailPauseOf(res.Pause, res.Active, res.Provisioned.PauseKind)
- if !paused {
- fmt.Fprintf(w, " sending: %s (key %s)\n", c.ok("active"), res.Provisioned.KeyID)
+ // A switched app sends through each server's mailer, whatever its
+ // app-level user (kept the overlap week, then reaped): its state and
+ // pause come from the sender's pause block alone, never "active",
+ // which reads a reaped user as paused (Fable P2-6).
+ switched := res.Submission != nil && res.Submission.On
+ if res.Provisioned != nil || switched {
+ var paused bool
+ var kind string
+ if switched {
+ paused = res.Pause != nil
+ if paused {
+ kind = res.Pause.Kind
+ }
} else {
- warnf(w, " sending: PAUSED — SMTP auth is failing for this app right now")
+ paused, kind = emailPauseOf(res.Pause, res.Active, res.Provisioned.PauseKind)
+ }
+ switch {
+ case !paused && switched:
+ fmt.Fprintf(w, submissionSendingActive+"\n", c.ok("active"))
+ case !paused:
+ fmt.Fprintf(w, " sending: %s (key %s)\n", c.ok("active"), res.Provisioned.KeyID)
+ }
+ if paused {
+ if switched {
+ warnf(w, "%s", submissionSendingPaused)
+ } else {
+ warnf(w, " sending: PAUSED — SMTP auth is failing for this app right now")
+ }
// The record does not carry a causal reason beyond PauseKind
// (mail.Provisioned has no free-text Reason field) — the
// honest thing to print is the evidence a member CAN see
diff --git a/mail_cli_test.go b/mail_cli_test.go
index b744f5889..167929e0f 100644
--- a/mail_cli_test.go
+++ b/mail_cli_test.go
@@ -1452,3 +1452,43 @@ func TestPrintEmailStatusReadsThePauseBlock(t *testing.T) {
}
}
}
+
+// Fable P2-6: a switched app's status. During the overlap week (its
+// app-level user kept) and after the reap (none left), it sends through
+// each server's mailer, and its pause is the sender's pause block: never
+// "not enabled", never PAUSED because a reaped user reads inactive.
+func TestPrintEmailStatusSwitched(t *testing.T) {
+ at := time.Date(2026, 11, 14, 9, 0, 0, 0, time.UTC)
+ reaped := at.AddDate(0, 0, 8)
+ for name, c := range map[string]struct {
+ res apiEmailReply
+ want []string
+ mustNot []string
+ }{
+ "overlap week": {apiEmailReply{App: "docs", DailyCap: 50, Active: true,
+ Provisioned: &apiEmailProvisioned{KeyID: "AKIA1"},
+ Submission: &apiEmailSubmission{On: true, At: at, By: "paul@keymail.dev"}},
+ []string{"sending: active, through each server's mailer", submissionAppUserKept}, []string{"PAUSED", "not enabled", "key AKIA1"}},
+ "after the reap": {apiEmailReply{App: "docs", DailyCap: 50, Active: false,
+ Submission: &apiEmailSubmission{On: true, At: at, By: "paul@keymail.dev", AppUserReapedAt: &reaped}},
+ []string{"sending: active, through each server's mailer", "app-level SMTP user removed"}, []string{"PAUSED", "not enabled"}},
+ "after the reap, paused at the cap": {apiEmailReply{App: "docs", DailyCap: 50, Active: false,
+ Pause: &apiEmailPause{Kind: "cap"},
+ Submission: &apiEmailSubmission{On: true, At: at, AppUserReapedAt: &reaped}},
+ []string{"PAUSED", "each server's mailer is refusing", "next UTC day roll"}, []string{"not enabled", "SMTP auth"}},
+ } {
+ var buf bytes.Buffer
+ printEmailStatus(&buf, c.res)
+ out := buf.String()
+ for _, w := range c.want {
+ if !strings.Contains(out, w) {
+ t.Errorf("%s: no %q in:\n%s", name, w, out)
+ }
+ }
+ for _, w := range c.mustNot {
+ if strings.Contains(out, w) {
+ t.Errorf("%s: %q in:\n%s", name, w, out)
+ }
+ }
+ }
+}