email: one working mail channel for a switched app (P2-1 to P2-4, ruled)
Ruled by Paul, 2026-11-14 (the one-working-channel family, option 1), recorded in the plan: every instance of a switched app has a working mail channel at every moment, enforced in one place. - P2-1: the switch door takes beginCopiesMutation (the app lock every serve door holds), after the account lock, before the preconditions, and holds it through SwitchOn or SwitchOff. - P2-2: the preconditions judge what each record's pin would serve: a pin to a build without --mail submit refuses the switch (PMS-C43). - P2-3: SwitchOff delivers SMTP to every bundle first, through the Enable and EnableEnvironment walks' new "deliver although switched" path, writes On:false last, then takes the From out; a failure leaves the app on submission, still working. SwitchOn is ordered the same way: the From into every bundle, the switch, then the five out (the environment reap keeps the From). The plan states the per-instance restart gap. - P2-4: a switched app's DeliverMailFromIn failure is returned to the adopt, fork and team config doors, which answer it (PMS-C45); and an instance create or rebind into an owned environment without the From is refused (PMS-C44). - TestSubmissionChannelSimulation drives the doors in seeded random interleavings (switch on and off, promote, rollback, pin, channel moves, instance creation and rebinding, environment fork and adopt, box arm, disarm and adoption, injected store and AWS failures, a promote raced into the switch-on door) after scripted ones for each of P2-1 to P2-4, and checks the invariant after every step. It catches each fix removed (P2-1, P2-2, both P2-3 orders, the reap's kept From, P2-4, the environment gate). Census: the record-write layer re-pins Enable, EnableEnvironment, ReapEnvironment, SwitchOn, SwitchOff and the instance update door.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
17 files changed,
+929
−92
approved_platform_mail_submission_copy_test.go+1 −1docs/superpowers/plans/platform-mail-submission-copy.json+18 −0internal/console/apiconfig.go+5 −2internal/console/apienv.go+12 −2internal/console/apiinstances.go+12 −0internal/console/apisubmission.go+56 −15internal/console/configwrite.go+7 −0internal/console/server.go+13 −9internal/console/submission_sim_test.go+552 −0internal/console/submissioncopy.go+5 −0internal/console/submissiongate.go+48 −0internal/console/teamcreds.go+39 −6internal/console/teamenv.go+5 −3internal/mail/submission.go+96 −34internal/mail/walk.go+14 −6internal/mail/walk_environment.go+25 −12internal/provision/platform_mail_submission_census_test.go+21 −2
CI cancelled — superseded by a newer push — run details
diff --git a/approved_platform_mail_submission_copy_test.go b/approved_platform_mail_submission_copy_test.go| index 05c38f7bb..be454e7e9 100644 |
| --- a/approved_platform_mail_submission_copy_test.go |
| +++ b/approved_platform_mail_submission_copy_test.go |
| @@ -10,7 +10,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-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", |
| } |
| // Every string of the switch's copy record is in the file it names, byte |
diff --git a/docs/superpowers/plans/platform-mail-submission-copy.json b/docs/superpowers/plans/platform-mail-submission-copy.json| index 96260e987..d0ed031ba 100644 |
| --- a/docs/superpowers/plans/platform-mail-submission-copy.json |
| +++ b/docs/superpowers/plans/platform-mail-submission-copy.json |
| @@ -254,6 +254,24 @@ |
| "file": "internal/console/submissioncopy.go", |
| "text": "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.", |
| "note": "ConfigSetUnbuildable" |
| + }, |
| + { |
| + "id": "PMS-C43", |
| + "file": "internal/console/submissioncopy.go", |
| + "text": "Instance %s is pinned to build %s, which doesn't declare --mail submit. Pin a build that does, or unpin it, first.", |
| + "note": "RoutePinUndeclared" |
| + }, |
| + { |
| + "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.", |
| + "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.", |
| + "note": "EnvironmentFromFailed" |
| } |
| ] |
| } |
diff --git a/internal/console/apiconfig.go b/internal/console/apiconfig.go| index 346b33d03..4858986c7 100644 |
| --- a/internal/console/apiconfig.go |
| +++ b/internal/console/apiconfig.go |
| @@ -749,8 +749,11 @@ func (s *Server) teamApplyEnvironment(ctx context.Context, tv *teamView, envName |
| if err == nil && !found { |
| // A bundle this scope just brought into being: the walks mint its |
| // own platform credentials (§3a), under the lock, best-effort — a |
| - // re-enable repairs anything that did not land. |
| - s.mintOwnedEnvironment(ctx, tv.acct, tv.app, envName) |
| + // re-enable repairs anything that did not land — except a switched |
| + // app's From, whose failure the door answers (P2-4). |
| + if mintErr := s.mintOwnedEnvironment(ctx, tv.acct, tv.app, envName); mintErr != nil { |
| + return removed, mintErr |
| + } |
| } |
| return removed, err |
| } |
diff --git a/internal/console/apienv.go b/internal/console/apienv.go| index 6982b5f98..7f1bda353 100644 |
| --- a/internal/console/apienv.go |
| +++ b/internal/console/apienv.go |
| @@ -177,8 +177,13 @@ func (s *Server) handleAPIEnvironmentAdopt(w http.ResponseWriter, r *http.Reques |
| // (fleet secrets key spec §5.2.1). Taken here, after the app lock above |
| // was released, so the lock order holds. |
| unlockAcct := s.lockAccount(acct.Sqid) |
| - s.mintOwnedEnvironment(ctx, acct, app, env) |
| + mintErr := s.mintOwnedEnvironment(ctx, acct, app, env) |
| unlockAcct() |
| + if fe := (*envFromError)(nil); errors.As(mintErr, &fe) { |
| + // Adopted, but a switched app's From did not land (P2-4). |
| + jsonError(w, http.StatusBadGateway, fe.msg()) |
| + return |
| + } |
| writeJSON(w, http.StatusOK, map[string]any{"environment": env, "scope": req.Scope, "stripped": stripped}) |
| } |
| @@ -358,8 +363,13 @@ func (s *Server) handleAPIEnvironmentFork(w http.ResponseWriter, r *http.Request |
| Detail: fmt.Sprintf("forked environment %s into %s for team scope %s, platform-managed keys left out: %s (cli)", from, to, req.Scope, noneOr(stripped)), |
| }) |
| s.bumpSerial(ctx) |
| - s.mintOwnedEnvironment(ctx, acct, app, to) |
| + mintErr := s.mintOwnedEnvironment(ctx, acct, app, to) |
| releaseAcct.Do(unlockAcct) |
| + if fe := (*envFromError)(nil); errors.As(mintErr, &fe) { |
| + // Forked, but a switched app's From did not land (P2-4). |
| + jsonError(w, http.StatusBadGateway, fe.msg()) |
| + return |
| + } |
| writeJSON(w, http.StatusOK, map[string]any{"from": from, "to": to, "scope": req.Scope, "stripped": stripped}) |
| } |
diff --git a/internal/console/apiinstances.go b/internal/console/apiinstances.go| index af23695ef..3f19962df 100644 |
| --- a/internal/console/apiinstances.go |
| +++ b/internal/console/apiinstances.go |
| @@ -2160,6 +2160,12 @@ func (s *Server) handleAPIInstanceCreate(w http.ResponseWriter, r *http.Request) |
| jsonError(w, ref.Status, ref.Msg) |
| return |
| } |
| + // A switched app's owned environment must hold its From (P2-4, |
| + // ruled 2026-11-14). |
| + if ref := s.submissionEnvironmentRefusal(ctx, acct.Sqid, app, strings.TrimSpace(req.Environment)); ref != nil { |
| + jsonError(w, ref.Status, ref.Msg) |
| + return |
| + } |
| } |
| // Managed fleets 1b (rules 1, 7, 8): on a fleet the console labels, the |
| // record names the box that runs it. The fleet's lock is held from this |
| @@ -3140,6 +3146,12 @@ func (s *Server) handleAPIInstanceUpdate(w http.ResponseWriter, r *http.Request) |
| jsonError(w, ref.Status, ref.Msg) |
| return |
| } |
| + // A switched app's owned environment must hold its From |
| + // (P2-4, ruled 2026-11-14). |
| + if ref := s.submissionEnvironmentRefusal(ctx, acct.Sqid, app, rec.Environment); ref != nil { |
| + jsonError(w, ref.Status, ref.Msg) |
| + return |
| + } |
| } |
| } |
| } |
diff --git a/internal/console/apisubmission.go b/internal/console/apisubmission.go| index 0be866dd1..d1b4c080e 100644 |
| --- a/internal/console/apisubmission.go |
| +++ b/internal/console/apisubmission.go |
| @@ -73,24 +73,53 @@ func (s *Server) handleAPIEmailSubmission(w http.ResponseWriter, r *http.Request |
| defer cancel() |
| now := time.Now() |
| - envs, err := s.ownedEnvironmentNames(ctx, acct.Sqid, app) |
| - if err != nil { |
| - log.Printf("console: api email submission %s/%s: owned environments: %v", acct.Sqid, app, err) |
| - jsonError(w, http.StatusBadGateway, submissionCopy.SwitchFailed) |
| - return |
| - } |
| - if *req.On { |
| - if ref := s.submissionPreconditions(ctx, acct.Sqid, app, now); ref != nil { |
| - writeDoorRefusalJSON(w, r, ref) |
| - return |
| + // The app lock every serve door holds (beginCopiesMutation), taken |
| + // after the account lock and held from the preconditions through the |
| + // switch's writes (ruled by Paul, 2026-11-14, P2-1): no promote, |
| + // rollback, pin or channel move can land between the check that every |
| + // route declares --mail submit and the switch itself. Released before |
| + // the restart, which takes it again. |
| + answered := false |
| + err := func() error { |
| + lctx, unlockApp, lockRef := s.beginCopiesMutation(ctx, acct, app) |
| + if lockRef != nil { |
| + writeDoorRefusalJSON(w, r, lockRef) |
| + answered = true |
| + return nil |
| + } |
| + defer unlockApp() |
| + if s.submissionSwitchHook != nil { |
| + s.submissionSwitchHook(*req.On, "locked") |
| + } |
| + envs, err := s.ownedEnvironmentNames(lctx, acct.Sqid, app) |
| + if err != nil { |
| + log.Printf("console: api email submission %s/%s: owned environments: %v", acct.Sqid, app, err) |
| + jsonError(w, http.StatusBadGateway, submissionCopy.SwitchFailed) |
| + answered = true |
| + return nil |
| + } |
| + if *req.On { |
| + if ref := s.submissionPreconditions(lctx, acct.Sqid, app, now); ref != nil { |
| + writeDoorRefusalJSON(w, r, ref) |
| + answered = true |
| + return nil |
| + } |
| + if s.submissionSwitchHook != nil { |
| + s.submissionSwitchHook(true, "checked") |
| + } |
| + _, err = mail.SwitchOn(lctx, s.claimMailStore(), s.cfg.MailProvisioner, acct.Sqid, app, envs, addr, now) |
| + return err |
| } |
| - _, err = mail.SwitchOn(ctx, s.claimMailStore(), s.cfg.MailProvisioner, acct.Sqid, app, envs, addr, now) |
| - } else { |
| - sealer, ok := s.mailSealKey(w, ctx, acct, app) |
| + sealer, ok := s.mailSealKey(w, lctx, acct, app) |
| if !ok { |
| - return |
| + answered = true |
| + return nil |
| } |
| - _, err = mail.SwitchOff(ctx, s.claimMailStore(), s.cfg.MailProvisioner, sealer, s.cfg.MailDeployment, acct.Sqid, app, envs, addr, now) |
| + _, err = mail.SwitchOff(lctx, s.claimMailStore(), s.cfg.MailProvisioner, sealer, s.cfg.MailDeployment, acct.Sqid, app, envs, addr, now) |
| + return err |
| + }() |
| + if answered { |
| + return |
| } |
| switch { |
| case errors.Is(err, mail.ErrNotDeclared): |
| @@ -272,6 +301,18 @@ func (s *Server) submissionPreconditions(ctx context.Context, acct, app string, |
| } |
| } |
| }) |
| + // P2-2 (ruled 2026-11-14): what each record's pin would serve, the pin |
| + // half of submissionRecordRefusal's rule, judged before the switch: a |
| + // box adopts a pin it has not reported yet, so the reports alone do not |
| + // show it. An unpinned record serves its channel's head, judged below. |
| + for _, rec := range recs { |
| + if rec.Pin == "" { |
| + continue |
| + } |
| + if ok, err := isDeclared(rec.Pin); err != nil || !ok { |
| + return conflict(fmt.Sprintf(submissionCopy.RoutePinUndeclared, rec.Host, rec.Pin)) |
| + } |
| + } |
| for _, host := range sorted { |
| vs := versions[host] |
| if len(vs) == 0 { |
diff --git a/internal/console/configwrite.go b/internal/console/configwrite.go| index a2d9a12c4..a942d111e 100644 |
| --- a/internal/console/configwrite.go |
| +++ b/internal/console/configwrite.go |
| @@ -274,6 +274,13 @@ func (s *Server) configWriteStore(ctx context.Context, unlock func(), acct *Acco |
| // environment gets (§3, §4), with no log line. |
| return 0, &configRefusal{Code: configRefusalNotFound, Status: http.StatusNotFound, Msg: notFoundBody} |
| } |
| + var fromErr *envFromError |
| + if errors.As(err, &fromErr) { |
| + // The environment was written; a switched app's From was not |
| + // (P2-4, ruled 2026-11-14): say so, never "ready". |
| + log.Printf("console: api config apply %s/%s (%s): %v", acct.Sqid, app, configBundleName(envName), err) |
| + return removed, &configRefusal{Code: configRefusalStore, Status: http.StatusBadGateway, Msg: fromErr.msg()} |
| + } |
| if err != nil { |
| return 0, configStoreRefusal(fmt.Sprintf("api config apply %s/%s (%s)", acct.Sqid, app, configBundleName(envName)), err) |
| } |
diff --git a/internal/console/server.go b/internal/console/server.go| index 0a22b379a..949068bec 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -1016,15 +1016,19 @@ type Config struct { |
| // Server is the console's http.Handler. |
| type Server struct { |
| // mailCallerGaps holds caller-class sends not yet recorded (apisubmission.go). |
| - mailCallerGaps mailCallerGapSet |
| - sourceDownloads sourceDownloads |
| - haPools map[string][]string |
| - haScopeInvalid bool |
| - capacityStart sync.Once |
| - capacityDone chan struct{} |
| - haCapacityStart sync.Once |
| - haCapacity atomic.Pointer[haObserver] |
| - demoTransport http.RoundTripper |
| + mailCallerGaps mailCallerGapSet |
| + // submissionSwitchHook, when set (tests only), is called by the email |
| + // submission door at its stages: "locked" once it holds the app lock, |
| + // "checked" once switch-on's preconditions pass, before the switch. |
| + submissionSwitchHook func(on bool, stage string) |
| + sourceDownloads sourceDownloads |
| + haPools map[string][]string |
| + haScopeInvalid bool |
| + capacityStart sync.Once |
| + capacityDone chan struct{} |
| + haCapacityStart sync.Once |
| + haCapacity atomic.Pointer[haObserver] |
| + demoTransport http.RoundTripper |
| demoAdmission demoAdmissionCache |
| demoClaimAdmission demoClaimAdmissionCache |
diff --git a/internal/console/submission_sim_test.go b/internal/console/submission_sim_test.go| new file mode 100644 |
| index 000000000..1ae4a12c8 |
| --- /dev/null |
| +++ b/internal/console/submission_sim_test.go |
| @@ -0,0 +1,552 @@ |
| +package console |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "fmt" |
| + "math/rand" |
| + "net/http" |
| + "slices" |
| + "strings" |
| + "sync" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/appconfig" |
| + "github.com/carlosframework/platform/internal/mail" |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/release" |
| + "github.com/carlosframework/platform/internal/status" |
| +) |
| + |
| +// The one-working-channel invariant (ruled by Paul, 2026-11-14): every |
| +// instance of a switched app has a working mail channel at every moment. |
| +// Its build declares --mail submit and its bundle holds <stem>_MAIL_FROM; |
| +// and a switch-off that turns the switch off leaves every instance's bundle |
| +// holding the five <P>_SMTP_* first. |
| +// |
| +// TestSubmissionChannelSimulation drives the console's doors in random |
| +// interleavings, seeded so a failure names its seed and steps: switch on |
| +// and off; promote and rollback; pin; channel moves; instance creation and |
| +// rebinding; environment creation (fork); box arm, disarm and adoption; |
| +// and, before a door, an injected failure at one of its store writes or |
| +// AWS calls. One step races a promote against the switch-on door between |
| +// its preconditions and its switch (P2-1). Scripted interleavings, one for |
| +// each of P2-1 to P2-4, run first, so each is reached on every run. After |
| +// every step the invariant is checked against the store, and a door that |
| +// answered 2xx for an environment of a switched app must have left its |
| +// From there (P2-4). |
| + |
| +// simFaultStore fails the nth write (Put or Delete) to a key under prefix, |
| +// once, when armed; with match set, only keys holding match count. |
| +type simFaultStore struct { |
| + release.Store |
| + mu sync.Mutex |
| + prefix string |
| + match string |
| + failAt int // 0: off |
| + writes int |
| +} |
| + |
| +var errSimFault = errors.New("simulated store failure") |
| + |
| +func (f *simFaultStore) arm(n int) { f.armMatching("", n) } |
| + |
| +func (f *simFaultStore) armMatching(match string, n int) { |
| + f.mu.Lock() |
| + defer f.mu.Unlock() |
| + f.match, f.failAt, f.writes = match, n, 0 |
| +} |
| + |
| +func (f *simFaultStore) hit(key string) bool { |
| + f.mu.Lock() |
| + defer f.mu.Unlock() |
| + if f.failAt == 0 || !strings.HasPrefix(key, f.prefix) || !strings.Contains(key, f.match) { |
| + return false |
| + } |
| + f.writes++ |
| + if f.writes == f.failAt { |
| + f.failAt = 0 |
| + return true |
| + } |
| + return false |
| +} |
| + |
| +func (f *simFaultStore) Put(ctx context.Context, key string, body []byte, ifMatch string) (string, error) { |
| + if f.hit(key) { |
| + return "", errSimFault |
| + } |
| + return f.Store.Put(ctx, key, body, ifMatch) |
| +} |
| + |
| +func (f *simFaultStore) Delete(ctx context.Context, key string) error { |
| + if f.hit(key) { |
| + return errSimFault |
| + } |
| + return f.Store.Delete(ctx, key) |
| +} |
| + |
| +// simProvisionerFaults are the AWS calls a switch or an environment walk |
| +// makes, one of which an armed step fails. |
| +var simProvisionerFaults = []string{"EnsureUser", "MintKey", "ReapKeys", "DeleteUser", "SetKeyActive", "DeleteKey"} |
| + |
| +type channelSim struct { |
| + t *testing.T |
| + w *submissionWorld |
| + rng *rand.Rand |
| + faults *simFaultStore |
| + prov *mail.MemProvisioner |
| + hosts []string |
| + envs []string // owned environments: "team" and the forks |
| + armed bool |
| + nextID int |
| + steps []string |
| +} |
| + |
| +func newChannelSim(t *testing.T, seed int64) *channelSim { |
| + t.Helper() |
| + w := newSubmissionWorld(t, fmt.Sprintf("code-sim-%d", seed)) |
| + ctx := context.Background() |
| + // The world's route follows edge, a channel no passkey guards, so |
| + // every serve door is open to the owner's CLI token. |
| + seedChannel(t, w.fx, "titogo", "edge", "v2") |
| + seedChannel(t, w.fx, "titogo", "beta", "v2") |
| + // v1 promoted once, where no instance follows it, so it can be pinned. |
| + seedChannel(t, w.fx, "titogo", "canary", "v1") |
| + w.fx.srv.cli.write = newRateLimiter(1<<20, time.Minute) |
| + rec, etag, err := provision.GetRecordETag(ctx, w.fx.rel, "bab", "titogo", submissionHost) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + rec.Channel = "edge" |
| + if err := provision.UpdateRecord(ctx, w.fx.rel, *rec, etag); err != nil { |
| + t.Fatal(err) |
| + } |
| + sim := &channelSim{t: t, w: w, rng: rand.New(rand.NewSource(seed)), prov: w.fx.srv.cfg.MailProvisioner.(*mail.MemProvisioner), |
| + hosts: []string{submissionHost}, envs: []string{"team"}, armed: true} |
| + sim.faults = &simFaultStore{Store: w.fx.srv.cfg.Releases, prefix: "apps/bab/titogo/"} |
| + w.fx.srv.cfg.Releases = sim.faults |
| + sim.boxTick(true) |
| + return sim |
| +} |
| + |
| +// step logs one step, for the failure message. |
| +func (sim *channelSim) step(format string, args ...any) { |
| + sim.steps = append(sim.steps, fmt.Sprintf(format, args...)) |
| +} |
| + |
| +func (sim *channelSim) cli(method, path, body string) (int, string) { |
| + sim.t.Helper() |
| + st, _, out := rawReq(sim.t, method, sim.w.fx.ts.URL+"/api/cli/apps/bab/titogo"+path, sim.w.owner, body) |
| + return st, out |
| +} |
| + |
| +// resolved is the build a record would serve: its pin, else its channel's |
| +// head ("" when the channel has none). |
| +func (sim *channelSim) resolved(rec provision.Record) string { |
| + if rec.Pin != "" { |
| + return rec.Pin |
| + } |
| + p, err := release.Channel(context.Background(), sim.w.fx.rel, sim.w.fx.srv.cfg.ReleasePub, "bab", "titogo", rec.Channel) |
| + if err != nil { |
| + return "" |
| + } |
| + return p.Version |
| +} |
| + |
| +func (sim *channelSim) records() []provision.Record { |
| + sim.t.Helper() |
| + recs, _, err := provision.ListRecords(context.Background(), sim.w.fx.rel, "bab", "titogo", 1000) |
| + if err != nil { |
| + sim.t.Fatal(err) |
| + } |
| + return recs |
| +} |
| + |
| +// boxTick writes box-1's report: armed or not, and serving what each |
| +// record resolves to, as a box that has adopted every change would. |
| +func (sim *channelSim) boxTick(armed bool) { |
| + sim.t.Helper() |
| + sim.armed = armed |
| + versions := map[string]string{} |
| + for _, rec := range sim.records() { |
| + if v := sim.resolved(rec); v != "" { |
| + versions[rec.Host] = v |
| + } |
| + } |
| + b := status.CollectBox(nil, status.Probes{MachineID: "box-1"}, time.Now()) |
| + b.Label = "box-1" |
| + b.Metrics = &status.BoxMetrics{RouteVersions: versions, MailerArmed: armed, UpdateSettings: status.UpdateSettingsProtocol} |
| + if err := status.WriteBox(context.Background(), sim.w.fx.rel, b); err != nil { |
| + sim.t.Fatal(err) |
| + } |
| +} |
| + |
| +// armFault arms, sometimes, one failure for the next door: the nth store |
| +// write under the app, or one AWS call. |
| +func (sim *channelSim) armFault() string { |
| + switch sim.rng.Intn(10) { |
| + case 0, 1, 2: |
| + n := 1 + sim.rng.Intn(6) |
| + sim.faults.arm(n) |
| + return fmt.Sprintf(" [store write #%d fails]", n) |
| + case 3, 4: |
| + m := simProvisionerFaults[sim.rng.Intn(len(simProvisionerFaults))] |
| + sim.prov.FailNext = map[string]error{m: errors.New("simulated AWS failure")} |
| + return " [" + m + " fails]" |
| + } |
| + return "" |
| +} |
| + |
| +func (sim *channelSim) disarm() { |
| + sim.faults.arm(0) |
| + sim.prov.FailNext = nil |
| +} |
| + |
| +func (sim *channelSim) pick(xs []string) string { return xs[sim.rng.Intn(len(xs))] } |
| + |
| +// switched reads the app sender's switch. |
| +func (sim *channelSim) switched() bool { |
| + sim.t.Helper() |
| + sn, _, err := mail.GetSender(context.Background(), sim.w.fx.rel, "bab", "titogo", mail.SenderAppID) |
| + if err != nil { |
| + sim.t.Fatal(err) |
| + } |
| + return mail.Switched(sn) |
| +} |
| + |
| +// bundleVars is what an instance bound to env reads: an owned |
| +// environment's bundle alone, else the default bundle under the |
| +// environment's overlay. |
| +func (sim *channelSim) bundleVars(env string) map[string]appconfig.Var { |
| + sim.t.Helper() |
| + ctx := context.Background() |
| + out := map[string]appconfig.Var{} |
| + if env != "" { |
| + m, _, found, err := appconfig.GetEnvironment(ctx, sim.w.fx.rel, "bab", "titogo", env) |
| + if err != nil { |
| + sim.t.Fatal(err) |
| + } |
| + if found && m.Owned() { |
| + return m.Vars |
| + } |
| + if found { |
| + defer func() { |
| + for k, v := range m.Vars { |
| + out[k] = v |
| + } |
| + }() |
| + } |
| + } |
| + def, err := appconfig.Get(ctx, sim.w.fx.rel, "bab", "titogo") |
| + if err != nil { |
| + sim.t.Fatal(err) |
| + } |
| + for k, v := range def.Vars { |
| + out[k] = v |
| + } |
| + return out |
| +} |
| + |
| +// check asserts the invariant after a step. wasSwitched is the switch |
| +// before it: a step that turned it off must leave every instance on SMTP. |
| +func (sim *channelSim) check(wasSwitched bool) { |
| + sim.t.Helper() |
| + ctx := context.Background() |
| + sn, _, err := mail.GetSender(ctx, sim.w.fx.rel, "bab", "titogo", mail.SenderAppID) |
| + if err != nil || sn == nil || sn.Declared == nil { |
| + sim.t.Fatalf("sender: %v", err) |
| + } |
| + switched := mail.Switched(sn) |
| + mf, err := mail.MailFromName(sn.Declared.EnvPrefix) |
| + if err != nil { |
| + sim.t.Fatal(err) |
| + } |
| + host, port, user, pass, from := mail.EnvNames(sn.Declared.EnvPrefix) |
| + var bad []string |
| + for _, rec := range sim.records() { |
| + vars := sim.bundleVars(rec.Environment) |
| + switch { |
| + case switched: |
| + v := sim.resolved(rec) |
| + m, err := release.GetManifest(ctx, sim.w.fx.rel, "bab", "titogo", v) |
| + if v != "" && (err != nil || m.Mail != release.MailSubmit) { |
| + bad = append(bad, fmt.Sprintf("%s serves %s, which does not declare --mail submit", rec.Host, v)) |
| + } |
| + if got := vars[mf]; got.Kind != "env" || got.Value != sn.Declared.From { |
| + bad = append(bad, fmt.Sprintf("%s (environment %q) has no %s", rec.Host, rec.Environment, mf)) |
| + } |
| + case wasSwitched: |
| + for _, k := range []string{host, port, user, pass, from} { |
| + if _, ok := vars[k]; !ok { |
| + bad = append(bad, fmt.Sprintf("%s (environment %q) was switched off without %s", rec.Host, rec.Environment, k)) |
| + } |
| + } |
| + } |
| + } |
| + if len(bad) > 0 { |
| + sim.t.Fatalf("the invariant broke:\n %s\nsteps:\n %s", strings.Join(bad, "\n "), strings.Join(sim.steps, "\n ")) |
| + } |
| +} |
| + |
| +// do runs one door, maybe with a fault armed, and checks the invariant. |
| +func (sim *channelSim) do(name string, fault bool, door func() string) { |
| + sim.t.Helper() |
| + was := sim.switched() |
| + note := "" |
| + if fault { |
| + note = sim.armFault() |
| + } |
| + out := door() |
| + sim.disarm() |
| + sim.step("%s%s -> %s", name, note, out) |
| + sim.check(was) |
| +} |
| + |
| +func short(st int, out string) string { |
| + if len(out) > 120 { |
| + out = out[:120] |
| + } |
| + return fmt.Sprintf("%d %s", st, out) |
| +} |
| + |
| +// The doors. |
| + |
| +func (sim *channelSim) switchOn() string { |
| + st, out := sim.w.submit(sim.t, true) |
| + return short(st, out) |
| +} |
| + |
| +func (sim *channelSim) switchOff() string { |
| + st, out := sim.w.submit(sim.t, false) |
| + return short(st, out) |
| +} |
| + |
| +func (sim *channelSim) promote(channel, version string) string { |
| + return short(sim.cli(http.MethodPost, "/promote", fmt.Sprintf(`{"channel":%q,"version":%q,"hotfix":true}`, channel, version))) |
| +} |
| + |
| +func (sim *channelSim) rollback(channel string) string { |
| + return short(sim.cli(http.MethodPost, "/rollback", fmt.Sprintf(`{"channel":%q}`, channel))) |
| +} |
| + |
| +func (sim *channelSim) pin(host, version string) string { |
| + return short(sim.cli(http.MethodPut, "/instances/"+host+"/updates", fmt.Sprintf(`{"pin":%q}`, version))) |
| +} |
| + |
| +func (sim *channelSim) move(host, channel string) string { |
| + return short(sim.cli(http.MethodPost, "/instances/"+host+"/channel", fmt.Sprintf(`{"channel":%q}`, channel))) |
| +} |
| + |
| +func (sim *channelSim) create(channel, env string) string { |
| + sim.nextID++ |
| + host := fmt.Sprintf("sim%d.go.tito.io", sim.nextID) |
| + st, out := sim.cli(http.MethodPost, "/instances", fmt.Sprintf(`{"host":%q,"region":"ie","channel":%q,"environment":%q,"scope":%q}`, host, channel, env, scopeOf(env))) |
| + if st/100 == 2 { |
| + sim.hosts = append(sim.hosts, host) |
| + } |
| + return short(st, out) |
| +} |
| + |
| +func (sim *channelSim) rebind(host, env string) string { |
| + return short(sim.cli(http.MethodPatch, "/instances/"+host, fmt.Sprintf(`{"environment":%q,"scope":%q}`, env, scopeOf(env)))) |
| +} |
| + |
| +// scopeOf is the scope a person names to bind into env: every owned |
| +// environment here is scope alta's. |
| +func scopeOf(env string) string { |
| + if env == "" { |
| + return "" |
| + } |
| + return "alta" |
| +} |
| + |
| +// fork creates an owned environment, and checks the door's word: a 2xx |
| +// for a switched app means its From is there. |
| +func (sim *channelSim) fork() string { |
| + sim.nextID++ |
| + env := fmt.Sprintf("e%d", sim.nextID) |
| + st, out := sim.cli(http.MethodPost, "/environments/fork", fmt.Sprintf(`{"from":"team","to":%q,"scope":"alta"}`, env)) |
| + ctx := context.Background() |
| + if m, _, found, err := appconfig.GetEnvironment(ctx, sim.w.fx.rel, "bab", "titogo", env); err == nil && found && m.Owned() { |
| + sim.envs = append(sim.envs, env) |
| + if st/100 == 2 && sim.switched() { |
| + sn, _, _ := mail.GetSender(ctx, sim.w.fx.rel, "bab", "titogo", mail.SenderAppID) |
| + mf, _ := mail.MailFromName(sn.Declared.EnvPrefix) |
| + if got := m.Vars[mf]; got.Value != sn.Declared.From { |
| + sim.t.Fatalf("the fork door answered %d for %s, which has no %s\nsteps:\n %s", st, env, mf, strings.Join(sim.steps, "\n ")) |
| + } |
| + } |
| + } |
| + return short(st, out) |
| +} |
| + |
| +// adopt makes a new unowned environment (straight into the store, as an |
| +// earlier config write would have) and adopts it into scope alta through |
| +// the door, which mints its credentials: for a switched app, its From. A |
| +// 2xx for a switched app means the From is there (P2-4). |
| +func (sim *channelSim) adopt() string { |
| + sim.nextID++ |
| + env := fmt.Sprintf("u%d", sim.nextID) |
| + ctx := context.Background() |
| + if _, err := appconfig.ApplyEnvironment(ctx, sim.w.fx.rel, "bab", "titogo", env, |
| + map[string]appconfig.Var{"PLAIN": {Kind: "env", Value: "1"}}, nil); err != nil { |
| + sim.t.Fatal(err) |
| + } |
| + st, out := sim.cli(http.MethodPost, "/environments/"+env+"/adopt", `{"scope":"alta"}`) |
| + if m, _, found, err := appconfig.GetEnvironment(ctx, sim.w.fx.rel, "bab", "titogo", env); err == nil && found && m.Owned() { |
| + sim.envs = append(sim.envs, env) |
| + if st/100 == 2 && sim.switched() { |
| + sn, _, _ := mail.GetSender(ctx, sim.w.fx.rel, "bab", "titogo", mail.SenderAppID) |
| + mf, _ := mail.MailFromName(sn.Declared.EnvPrefix) |
| + if got := m.Vars[mf]; got.Value != sn.Declared.From { |
| + sim.t.Fatalf("the adopt door answered %d for %s, which has no %s\nsteps:\n %s", st, env, mf, strings.Join(sim.steps, "\n ")) |
| + } |
| + } |
| + } |
| + return short(st, out) |
| +} |
| + |
| +// raceSwitchOn is the switch-on door with a promote of an undeclared |
| +// build started between its preconditions and its switch (P2-1). The |
| +// promote is given a moment to land; with the app lock held it cannot, |
| +// and it runs, and is judged, once the switch is in. |
| +func (sim *channelSim) raceSwitchOn(channel string) string { |
| + var wg sync.WaitGroup |
| + var raced string |
| + sim.w.fx.srv.submissionSwitchHook = func(on bool, stage string) { |
| + if !on || stage != "checked" { |
| + return |
| + } |
| + done := make(chan struct{}) |
| + wg.Add(1) |
| + go func() { |
| + defer wg.Done() |
| + defer close(done) |
| + st, _, out := rawReq(sim.t, http.MethodPost, sim.w.fx.ts.URL+"/api/cli/apps/bab/titogo/promote", sim.w.owner, |
| + fmt.Sprintf(`{"channel":%q,"version":"v1","hotfix":true}`, channel)) |
| + raced = short(st, out) |
| + }() |
| + select { |
| + case <-done: |
| + case <-time.After(1500 * time.Millisecond): |
| + } |
| + } |
| + defer func() { sim.w.fx.srv.submissionSwitchHook = nil }() |
| + st, out := sim.w.submit(sim.t, true) |
| + wg.Wait() |
| + return short(st, out) + " | raced promote: " + raced |
| +} |
| + |
| +// The scripted interleavings: each reaches one of P2-1 to P2-4. |
| +func (sim *channelSim) scripted() { |
| + sim.t.Helper() |
| + // P2-2: a pin to an undeclared build no box has adopted yet. |
| + sim.do("pin v1 (no box adopts it)", false, func() string { return sim.pin(submissionHost, "v1") }) |
| + sim.do("switch on", false, sim.switchOn) |
| + sim.do("unpin", false, func() string { return sim.pin(submissionHost, "") }) |
| + sim.boxTick(true) |
| + // P2-1: a promote of an undeclared build between the checks and the |
| + // switch, onto the channel the instance follows (edge is entered by a |
| + // merge only, so beta). |
| + sim.do("move the instance to beta", false, func() string { return sim.move(submissionHost, "beta") }) |
| + sim.boxTick(true) |
| + sim.do("switch on, racing a promote of v1 to beta", false, func() string { return sim.raceSwitchOn("beta") }) |
| + if !sim.switched() { |
| + sim.do("switch on", false, sim.switchOn) |
| + } |
| + // P2-4: an environment created while switched, its From's write |
| + // failing; then an instance created into it. |
| + // An adopted environment's second write is its From (the first marks |
| + // it owned); then a fork's first write. |
| + sim.faults.armMatching(fmt.Sprintf("environments/u%d.json", sim.nextID+1), 2) |
| + sim.do("adopt, its From's write failing", false, sim.adopt) |
| + sim.faults.arm(1) |
| + sim.do("fork, write #1 under the app failing", false, sim.fork) |
| + for _, env := range sim.envs { |
| + sim.do("create an instance on edge in "+env, false, func() string { return sim.create("edge", env) }) |
| + } |
| + sim.boxTick(true) |
| + // P2-3: a switch-off whose SMTP delivery fails part-way. |
| + for _, m := range []string{"MintKey", "EnsureUser"} { |
| + sim.prov.FailNext = map[string]error{m: errors.New("simulated AWS failure")} |
| + sim.do("switch off, "+m+" failing", false, sim.switchOff) |
| + } |
| + for n := 1; n <= 4; n++ { |
| + if !sim.switched() { |
| + break |
| + } |
| + sim.faults.arm(n) |
| + sim.do(fmt.Sprintf("switch off, store write #%d failing", n), false, sim.switchOff) |
| + } |
| + sim.do("switch off", false, sim.switchOff) |
| + // Switch-on's own order: with an instance in team, the From's write to |
| + // team failing, then the write after the reap (which a reap that took |
| + // the From too would need). |
| + sim.do("create an instance on edge in team", false, func() string { return sim.create("edge", "team") }) |
| + sim.boxTick(true) |
| + sim.faults.armMatching("environments/team.json", 1) |
| + sim.do("switch on, team's first write failing", false, sim.switchOn) |
| + sim.faults.armMatching("environments/team.json", 3) |
| + sim.do("switch on, team's third write failing", false, sim.switchOn) |
| + sim.do("switch on", false, sim.switchOn) |
| +} |
| + |
| +// random runs n random steps. |
| +func (sim *channelSim) random(n int) { |
| + sim.t.Helper() |
| + versions, channels := []string{"v1", "v2"}, []string{"edge", "beta"} |
| + for i := 0; i < n; i++ { |
| + switch sim.rng.Intn(14) { |
| + case 0, 1: |
| + sim.do("switch on", true, sim.switchOn) |
| + case 2: |
| + sim.do("switch off", true, sim.switchOff) |
| + case 3: |
| + ch, v := sim.pick(channels), sim.pick(versions) |
| + sim.do("promote "+v+" to "+ch, true, func() string { return sim.promote(ch, v) }) |
| + case 4: |
| + ch := sim.pick(channels) |
| + sim.do("roll back "+ch, true, func() string { return sim.rollback(ch) }) |
| + case 5: |
| + h, v := sim.pick(sim.hosts), sim.pick(append(slices.Clone(versions), "")) |
| + sim.do("pin "+h+" to "+v, true, func() string { return sim.pin(h, v) }) |
| + case 6: |
| + h, ch := sim.pick(sim.hosts), sim.pick(channels) |
| + sim.do("move "+h+" to "+ch, true, func() string { return sim.move(h, ch) }) |
| + case 7: |
| + ch, env := sim.pick(channels), sim.pick(append(slices.Clone(sim.envs), "")) |
| + sim.do("create on "+ch+" in "+env, true, func() string { return sim.create(ch, env) }) |
| + case 8: |
| + sim.do("fork", true, sim.fork) |
| + case 9: |
| + h, env := sim.pick(sim.hosts), sim.pick(append(slices.Clone(sim.envs), "")) |
| + sim.do("rebind "+h+" to "+env, true, func() string { return sim.rebind(h, env) }) |
| + case 10: |
| + armed := sim.rng.Intn(3) > 0 |
| + sim.do(fmt.Sprintf("box tick, armed %v", armed), false, func() string { sim.boxTick(armed); return "" }) |
| + case 11: |
| + sim.do("switch on, racing a promote of v1 to beta", false, func() string { return sim.raceSwitchOn("beta") }) |
| + case 12: |
| + sim.do("box tick, armed", false, func() string { sim.boxTick(true); return "" }) |
| + case 13: |
| + sim.do("adopt", true, sim.adopt) |
| + } |
| + } |
| +} |
| + |
| +func TestSubmissionChannelSimulation(t *testing.T) { |
| + for _, seed := range []int64{1, 2, 3, 4, 5, 6} { |
| + t.Run(fmt.Sprint("seed ", seed), func(t *testing.T) { |
| + sim := newChannelSim(t, seed) |
| + if seed == 1 { |
| + sim.scripted() |
| + } |
| + sim.random(60) |
| + t.Logf("%d steps; switched at the end: %v", len(sim.steps), sim.switched()) |
| + if testing.Verbose() { |
| + t.Logf("steps:\n %s", strings.Join(sim.steps, "\n ")) |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/console/submissioncopy.go b/internal/console/submissioncopy.go| index 75e239e03..62c21d53d 100644 |
| --- a/internal/console/submissioncopy.go |
| +++ b/internal/console/submissioncopy.go |
| @@ -10,6 +10,7 @@ var submissionCopy = struct { |
| NotDeclared, NotEnabled, PrefixNotSMTP, NoEventIngest, DomainNoConfigSet string |
| FromNotSendable, ConfigSetUnbuildable string |
| RouteUnreported, RouteUndeclared, RoutesUnreadable string |
| + RoutePinUndeclared, EnvironmentNoFrom, EnvironmentFromFailed string |
| ChannelUndeclared, ChannelUnreadable string |
| TenantUnassociated, TenantUnconfirmed string |
| BoxUnarmed, BoxesUnreadable string |
| @@ -29,6 +30,10 @@ var submissionCopy = struct { |
| RouteUndeclared: "Instance %s runs build %s, which doesn't declare --mail submit. Ship with --mail submit 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.", |
| + 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.", |
| + |
| ChannelUndeclared: "Channel %s points at build %s, which doesn't declare --mail submit. Ship with --mail submit and promote it first.", |
| ChannelUnreadable: "Can't confirm channel %s: its pointer or build couldn't be read. Try again.", |
diff --git a/internal/console/submissiongate.go b/internal/console/submissiongate.go| index 172237f55..53bcef606 100644 |
| --- a/internal/console/submissiongate.go |
| +++ b/internal/console/submissiongate.go |
| @@ -9,6 +9,8 @@ import ( |
| "net/http" |
| "os" |
| + "github.com/carlosframework/platform/internal/appconfig" |
| + "github.com/carlosframework/platform/internal/mail" |
| "github.com/carlosframework/platform/internal/mailwire" |
| "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/release" |
| @@ -277,3 +279,49 @@ func (s *Server) submissionPolicyRefusal(ctx context.Context, acct, app string, |
| } |
| return nil |
| } |
| + |
| +// submissionEnvironmentRefusal gates a door that puts an instance into |
| +// environment env: creating it there, or rebinding it (ruled by Paul, |
| +// 2026-11-14, P2-4). While acct/app's email submission is on, an owned |
| +// environment's bundle stands alone (it inherits nothing from the default |
| +// bundle), so it must hold the app's From for an instance there to send; |
| +// one created while the From could not be delivered does not, and the |
| +// door refuses with the remedy. The default bundle (env "") and an |
| +// unowned environment, which inherits the default's, get their From from |
| +// the switch itself. A read that fails refuses. |
| +func (s *Server) submissionEnvironmentRefusal(ctx context.Context, acct, app, env string) *doorRefusal { |
| + if env == "" { |
| + return nil |
| + } |
| + switched, ref := s.submissionSwitched(ctx, acct, app) |
| + if ref != nil || !switched { |
| + return ref |
| + } |
| + m, _, found, err := appconfig.GetEnvironment(ctx, s.cfg.Releases, acct, app, env) |
| + if err != nil { |
| + log.Printf("console: submission gate %s/%s: read environment %s: %v", acct, app, env, err) |
| + return submissionEnvironmentUnreadable() |
| + } |
| + if !found || !m.Owned() { |
| + return nil |
| + } |
| + sn, _, err := mail.GetSender(ctx, s.cfg.Releases, acct, app, mail.SenderAppID) |
| + if err != nil || sn == nil || sn.Declared == nil { |
| + log.Printf("console: submission gate %s/%s: read sender: %v", acct, app, err) |
| + return submissionEnvironmentUnreadable() |
| + } |
| + mf, err := mail.MailFromName(sn.Declared.EnvPrefix) |
| + if err != nil { |
| + return submissionEnvironmentUnreadable() |
| + } |
| + if v, ok := m.Vars[mf]; ok && v.Kind == "env" && v.Value == sn.Declared.From { |
| + return nil |
| + } |
| + return &doorRefusal{Status: http.StatusConflict, Msg: fmt.Sprintf(submissionCopy.EnvironmentNoFrom, app, env, app)} |
| +} |
| + |
| +// submissionEnvironmentUnreadable is submissionEnvironmentRefusal'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."} |
| +} |
diff --git a/internal/console/teamcreds.go b/internal/console/teamcreds.go| index 58173c46b..162838b20 100644 |
| --- a/internal/console/teamcreds.go |
| +++ b/internal/console/teamcreds.go |
| @@ -14,6 +14,7 @@ package console |
| import ( |
| "context" |
| + "errors" |
| "fmt" |
| "log" |
| "net/http" |
| @@ -26,17 +27,46 @@ import ( |
| // mintOwnedEnvironmentCredentials mints env's own platform credentials: |
| // the mail walk's, when the app's mail is provisioned, and the relay's, |
| -// when the app's relay is enabled. Best-effort: a walk that fails is |
| -// logged, and the app-level enable or the relay reconcile repairs it, so |
| -// the door that brought the environment into being still answers for the |
| -// write it made. |
| -func (s *Server) mintOwnedEnvironmentCredentials(ctx context.Context, acct *Account, app, env string) { |
| +// when the app's relay is enabled. Best-effort for an app that is not |
| +// switched to email submission: a walk that fails is logged, and the |
| +// app-level enable or the relay reconcile repairs it, so the door that |
| +// brought the environment into being still answers for the write it made. |
| +// |
| +// For a switched app the From delivery is not best-effort (ruled by Paul, |
| +// 2026-11-14, P2-4): its failure is returned as an *envFromError, which |
| +// the door answers, so it never reports an environment ready that no |
| +// instance could send from. The relay half stays best-effort. |
| +func (s *Server) mintOwnedEnvironmentCredentials(ctx context.Context, acct *Account, app, env string) error { |
| + var fromErr error |
| if err := s.mintOwnedEnvironmentMail(ctx, acct, app, env); err != nil { |
| log.Printf("console: team environment %s/%s (%s): mail credential: %v", acct.Sqid, app, env, err) |
| + var fe *envFromError |
| + if errors.As(err, &fe) { |
| + fromErr = fe |
| + } |
| } |
| if err := s.relayEnvironmentHook(ctx, acct.Sqid, app); err != nil { |
| log.Printf("console: team environment %s/%s (%s): relay identity: %v", acct.Sqid, app, env, err) |
| } |
| + return fromErr |
| +} |
| + |
| +// envFromError is a switched app's From delivery that failed for a new or |
| +// adopted environment (P2-4): the door that made the environment answers it. |
| +type envFromError struct { |
| + acct, app, env string |
| + err error |
| +} |
| + |
| +func (e *envFromError) Error() string { |
| + return fmt.Sprintf("deliver the email From to environment %s of %s/%s: %v", e.env, e.acct, e.app, e.err) |
| +} |
| + |
| +func (e *envFromError) Unwrap() error { return e.err } |
| + |
| +// msg is the door's answer for it. |
| +func (e *envFromError) msg() string { |
| + return fmt.Sprintf(submissionCopy.EnvironmentFromFailed, e.env, e.app, e.app) |
| } |
| // mintOwnedEnvironmentMail is the mail half: nothing when the app has no |
| @@ -62,7 +92,10 @@ func (s *Server) mintOwnedEnvironmentMail(ctx context.Context, acct *Account, ap |
| // round 1 P1-1). A bundle does not inherit from the default, so without |
| // this a team environment created after the flip boots with no From. |
| if mail.Switched(sn) { |
| - return mail.DeliverMailFromIn(ctx, s.claimMailStore(), acct.Sqid, app, env) |
| + if err := mail.DeliverMailFromIn(ctx, s.claimMailStore(), acct.Sqid, app, env); err != nil { |
| + return &envFromError{acct: acct.Sqid, app: app, env: env, err: err} |
| + } |
| + return nil |
| } |
| if sn == nil || sn.Provisioned == nil { |
| return nil |
diff --git a/internal/console/teamenv.go b/internal/console/teamenv.go| index b6c6bb857..3d4001b44 100644 |
| --- a/internal/console/teamenv.go |
| +++ b/internal/console/teamenv.go |
| @@ -230,9 +230,11 @@ func (s *Server) teamFilterRecords(ctx context.Context, tv *teamView, recs []pro |
| // mintOwnedEnvironment asks the delivery walks for env's own platform |
| // credentials (§3a): the mail walk's per-environment SMTP user and the |
| // relay's per-environment identity. Best-effort: a walk that fails is |
| -// logged, and the app-level enable or the reconcile repairs it. |
| -func (s *Server) mintOwnedEnvironment(ctx context.Context, acct *Account, app, env string) { |
| - s.mintOwnedEnvironmentCredentials(ctx, acct, app, env) |
| +// logged, and the app-level enable or the reconcile repairs it; except a |
| +// switched app's From delivery, whose failure is returned (*envFromError, |
| +// P2-4) for the door to answer. |
| +func (s *Server) mintOwnedEnvironment(ctx context.Context, acct *Account, app, env string) error { |
| + return s.mintOwnedEnvironmentCredentials(ctx, acct, app, env) |
| } |
| // mintOwnedEnvironmentCredentials and reapOwnedEnvironmentCredentials are |
diff --git a/internal/mail/submission.go b/internal/mail/submission.go| index 1f4c19c39..5ee3054d9 100644 |
| --- a/internal/mail/submission.go |
| +++ b/internal/mail/submission.go |
| @@ -155,6 +155,30 @@ func writeMailFromIn(ctx context.Context, s release.Store, acct, app, env, prefi |
| return nil |
| } |
| +// addMailFromIn puts the From variable into one bundle beside whatever is |
| +// there, the five included: SwitchOn's first step, so a bundle holds the |
| +// From before the switch says to use it. Idempotent. |
| +func addMailFromIn(ctx context.Context, s release.Store, acct, app, env, prefix, from string) error { |
| + mf, err := MailFromName(prefix) |
| + if err != nil { |
| + return err |
| + } |
| + if err := appconfig.ValidVarValue(from); err != nil { |
| + return fmt.Errorf("mail: From for %s is not EnvironmentFile-safe: %w", mf, err) |
| + } |
| + m, err := bundleFor(ctx, s, acct, app, env) |
| + if err != nil { |
| + return err |
| + } |
| + if cur, ok := m.Vars[mf]; ok && cur.Kind == "env" && cur.Value == from { |
| + return nil |
| + } |
| + if err := applyBundle(ctx, s, acct, app, env, map[string]appconfig.Var{mf: {Kind: "env", Value: from}}, nil); err != nil { |
| + return fmt.Errorf("mail: deliver %s to %s/%s%s: %w", mf, acct, app, envLabel(env), err) |
| + } |
| + return nil |
| +} |
| + |
| // removeMailFromIn takes the From variable out of one bundle. A bundle that |
| // does not exist, or does not hold it, is left alone. |
| func removeMailFromIn(ctx context.Context, s release.Store, acct, app, env, prefix string) error { |
| @@ -216,17 +240,20 @@ func ownedEnvironments(rec *Record, envs []string) ([]string, error) { |
| // |
| // It refuses an undeclared app (ErrNotDeclared), an app that was never |
| // enabled (ErrNotProvisioned), and a prefix that cannot name the From |
| -// variable (ErrPrefixNotSMTP), all before writing anything. It then |
| -// records the switch on the app sender, keeping the original At and By on |
| -// a re-run. Recording first means a crash part-way leaves an app Enable |
| -// will not re-deliver to, and a re-run finishes the job. |
| +// variable (ErrPrefixNotSMTP), all before writing anything. |
| // |
| -// Each owned environment that has a mail user is reaped (its keys, user, |
| -// caller index entry and variables). Then the default bundle and every |
| -// owned environment's bundle (envs, with the record's environments) get |
| -// <stem>_MAIL_FROM and lose the five. The reap runs first because it takes |
| -// the From variable out too. An environment in envs whose bundle is |
| -// missing or not owned has nothing to deliver into and is skipped. |
| +// The order keeps a working channel in every bundle at every step (ruled |
| +// by Paul, 2026-11-14, the one-working-channel family): first every bundle |
| +// (the default and each owned environment's, envs with the record's |
| +// environments) gets <stem>_MAIL_FROM beside the five, which a switch that |
| +// is still off ignores; then the switch is recorded on the app sender, |
| +// keeping the original At and By on a re-run; then each owned environment |
| +// that has a mail user is reaped (its keys, user, caller index entry and |
| +// the five, its From kept); and last the five leave every bundle. A |
| +// failure part-way leaves either an app still off with SMTP, or a switched |
| +// app with its From, and a re-run finishes the job. An environment in envs |
| +// whose bundle is missing or not owned has nothing to deliver into and is |
| +// skipped. |
| // |
| // The app-level user and key are kept (Provisioned is untouched): the |
| // overlap week, governed by pause, until ReapAppUserAfterSubmission. |
| @@ -251,6 +278,20 @@ func claimUnserializedSwitchOn(ctx context.Context, s release.Store, p Provision |
| if err != nil { |
| return nil, err |
| } |
| + // 1. The From into every bundle, the five left where they are. |
| + if err := addMailFromIn(ctx, s, acct, app, "", prefix, from); err != nil { |
| + return nil, err |
| + } |
| + for _, env := range owned { |
| + err := addMailFromIn(ctx, s, acct, app, env, prefix, from) |
| + if errors.Is(err, ErrEnvironmentNotOwned) { |
| + continue |
| + } |
| + if err != nil { |
| + return nil, err |
| + } |
| + } |
| + // 2. The switch. |
| if !rec.switched() { |
| // The reap mark is history only while the user it records is still |
| // gone. A switch-off re-mints the app-level user, so a new switch-on |
| @@ -266,11 +307,13 @@ func claimUnserializedSwitchOn(ctx context.Context, s release.Store, p Provision |
| return nil, err |
| } |
| } |
| + // 3. The environments' users, their From kept. |
| for _, env := range sortedEnvironments(rec) { |
| - if _, err := claimUnserializedReapEnvironment(ctx, s, p, acct, app, env); err != nil { |
| + if _, err := claimUnserializedReapEnvironment(ctx, s, p, acct, app, env, true); err != nil { |
| return nil, fmt.Errorf("mail: reap environment %s: %w", env, err) |
| } |
| } |
| + // 4. The five out of every bundle. |
| if err := writeMailFromIn(ctx, s, acct, app, "", prefix, from); err != nil { |
| return nil, err |
| } |
| @@ -287,23 +330,32 @@ func claimUnserializedSwitchOn(ctx context.Context, s release.Store, p Provision |
| return rec, err |
| } |
| -// SwitchOff switches an app back to SMTP (decision 10, §7 item 6). It |
| -// records the switch as off (At and By of this change; AppUserReapedAt is |
| -// kept as history), then runs the Enable walk, which re-creates the |
| -// app-level user if it was reaped, mints, and re-delivers the five into |
| -// the default bundle, and EnableEnvironment for each environment in envs |
| -// (SwitchOn's reaps emptied the record's environments, so envs is the |
| -// list of owned environments the caller knows). Each bundle loses |
| -// <stem>_MAIL_FROM only after it holds the five again, so a walk that |
| -// fails part-way never leaves a bundle with neither. Environments the |
| -// record still names but envs does not lose the From variable too. |
| +// SwitchOff switches an app back to SMTP (decision 10, §7 item 6). |
| +// |
| +// The order keeps a working channel in every bundle at every step (ruled |
| +// by Paul, 2026-11-14, P2-3): first the Enable walk delivers, although the |
| +// switch is still on (re-creating the app-level user if it was reaped, |
| +// minting, and putting the five into the default bundle), and |
| +// EnableEnvironment does the same for each environment in envs (SwitchOn's |
| +// reaps emptied the record's environments, so envs is the list of owned |
| +// environments the caller knows). Only then is the switch recorded as off |
| +// (At and By of this change; AppUserReapedAt is kept as history), and only |
| +// after that does each bundle lose <stem>_MAIL_FROM. A walk that fails |
| +// before the switch leaves the app on submission, still working, with |
| +// some bundles holding the five as well, which a switched app's instances |
| +// ignore. Environments the record still names but envs does not lose the |
| +// From variable too. |
| +// |
| +// The switch reaches an instance when it restarts: until then one started |
| +// with CARLOS_MAIL=submit keeps it, and the mailer refuses it with |
| +// SUBMISSION_OFF, so the door asks every instance to restart. |
| // |
| // Idempotent: a re-run on an app already off re-runs the delivery, which |
| // is what finishes a switch-off that failed part-way. |
| func claimUnserializedSwitchOff(ctx context.Context, s release.Store, p Provisioner, seal appconfig.Sealer, |
| d Deployment, acct, app string, envs []string, actor string, now time.Time) (*Record, error) { |
| - rec, etag, err := Get(ctx, s, acct, app) |
| + rec, _, err := Get(ctx, s, acct, app) |
| if err != nil { |
| return nil, err |
| } |
| @@ -315,28 +367,38 @@ func claimUnserializedSwitchOff(ctx context.Context, s release.Store, p Provisio |
| if err != nil { |
| return nil, err |
| } |
| + want := map[string]bool{} |
| + for _, env := range envs { |
| + want[env] = true |
| + } |
| + // 1. SMTP into every bundle, although the switch may still be on. |
| + if _, err := claimUnserializedEnable(ctx, s, p, seal, d, acct, app, now, true); err != nil { |
| + return nil, err |
| + } |
| + for _, env := range owned { |
| + if !want[env] { |
| + continue |
| + } |
| + if _, err := claimUnserializedEnableEnvironment(ctx, s, p, seal, d, acct, app, env, now, true); err != nil { |
| + return nil, fmt.Errorf("mail: environment %s: %w", env, err) |
| + } |
| + } |
| + // 2. The switch, last of the writes a working channel depends on. |
| + rec, etag, err := Get(ctx, s, acct, app) |
| + if err != nil { |
| + return nil, err |
| + } |
| if rec.switched() { |
| rec.setSubmission(&mailwire.Submission{On: false, At: now, By: actor, AppUserReapedAt: rec.submission().AppUserReapedAt}) |
| if _, err := Put(ctx, s, acct, app, rec, etag); err != nil { |
| return nil, err |
| } |
| } |
| - if _, err := claimUnserializedEnable(ctx, s, p, seal, d, acct, app, now); err != nil { |
| - return nil, err |
| - } |
| + // 3. The From out of every bundle. |
| if err := removeMailFromIn(ctx, s, acct, app, "", prefix); err != nil { |
| return nil, err |
| } |
| - want := map[string]bool{} |
| - for _, env := range envs { |
| - want[env] = true |
| - } |
| for _, env := range owned { |
| - if want[env] { |
| - if _, err := claimUnserializedEnableEnvironment(ctx, s, p, seal, d, acct, app, env, now); err != nil { |
| - return nil, fmt.Errorf("mail: environment %s: %w", env, err) |
| - } |
| - } |
| if err := removeMailFromIn(ctx, s, acct, app, env, prefix); err != nil { |
| return nil, err |
| } |
diff --git a/internal/mail/walk.go b/internal/mail/walk.go| index 2e8e7bb30..33637f5c8 100644 |
| --- a/internal/mail/walk.go |
| +++ b/internal/mail/walk.go |
| @@ -762,8 +762,14 @@ func EnvDeliveredIn(ctx context.Context, s release.Store, acct, app, env, prefix |
| // checked; anything less and the rest of the walk runs too, because a |
| // missing or stale variable means the app cannot send what the record |
| // promises. |
| +// |
| +// delivering is SwitchOff's "deliver although switched" path (ruled by |
| +// Paul, 2026-11-14, the one-working-channel family, P2-3): the walk mints |
| +// and delivers the five as for an app that is off, while the switch is |
| +// still on, so every bundle holds a working SMTP channel before the switch |
| +// is turned off. Every other caller passes false. |
| func claimUnserializedEnable(ctx context.Context, s release.Store, p Provisioner, seal appconfig.Sealer, |
| - d Deployment, acct, app string, now time.Time) (*Record, error) { |
| + d Deployment, acct, app string, now time.Time, delivering bool) (*Record, error) { |
| rec, etag, err := Get(ctx, s, acct, app) |
| if err != nil { |
| @@ -775,7 +781,8 @@ func claimUnserializedEnable(ctx context.Context, s release.Store, p Provisioner |
| // A switched app (decision 10) is delivered nothing. Once its app-level |
| // user is reaped there is nothing to refresh either, and no provisioner |
| // call is made. |
| - if rec.switched() && rec.Provisioned == nil { |
| + switched := rec.switched() && !delivering |
| + if switched && rec.Provisioned == nil { |
| // The From may have been re-declared: deliver it (review P3). |
| if err := writeMailFromIn(ctx, s, acct, app, "", rec.Declared.EnvPrefix, rec.Declared.From); err != nil { |
| return nil, err |
| @@ -839,8 +846,9 @@ func claimUnserializedEnable(ctx context.Context, s release.Store, p Provisioner |
| } |
| // A switched app keeps its app-level user for the overlap week (§7.4): |
| // the policy refresh above still runs, and nothing is minted or |
| - // delivered. SwitchOff turns the switch off before it calls this walk. |
| - if rec.switched() { |
| + // delivered. SwitchOff delivers through this walk (delivering) before |
| + // it turns the switch off. |
| + if switched { |
| // The one thing a switched app is delivered: its From, which a |
| // re-declare may have changed (review P3). |
| if err := writeMailFromIn(ctx, s, acct, app, "", rec.Declared.EnvPrefix, rec.Declared.From); err != nil { |
| @@ -2081,7 +2089,7 @@ func Declare(ctx context.Context, s release.Store, acct, app, envPrefix, from, a |
| func Enable(ctx context.Context, s release.Store, p Provisioner, seal appconfig.Sealer, |
| d Deployment, acct, app string, now time.Time) (*Record, error) { |
| if _, enabled := s.(ClaimMailStore); !enabled { |
| - return claimUnserializedEnable(ctx, s, p, seal, d, acct, app, now) |
| + return claimUnserializedEnable(ctx, s, p, seal, d, acct, app, now, false) |
| } |
| var claimResult0 *Record |
| claimErr := WithClaimMailResource(ctx, s, func(ctx context.Context) error { |
| @@ -2090,7 +2098,7 @@ func Enable(ctx context.Context, s release.Store, p Provisioner, seal appconfig. |
| p = claimMarkedProvisioner{raw: p} |
| } |
| var err error |
| - claimResult0, err = claimUnserializedEnable(ctx, s, p, seal, d, acct, app, now) |
| + claimResult0, err = claimUnserializedEnable(ctx, s, p, seal, d, acct, app, now, false) |
| return err |
| }) |
| }) |
diff --git a/internal/mail/walk_environment.go b/internal/mail/walk_environment.go| index f3b4e275a..75b3c7395 100644 |
| --- a/internal/mail/walk_environment.go |
| +++ b/internal/mail/walk_environment.go |
| @@ -33,8 +33,12 @@ var ErrEnvironmentNotOwned = errors.New("mail: environment is not owned by a tea |
| // bundle. Idempotent the way Enable is: a healthy delivered environment |
| // (its record names a key and the five variables carry it) is a no-op, |
| // and anything less reaps and re-mints. |
| +// |
| +// delivering is SwitchOff's "deliver although switched" path (P2-3, ruled |
| +// 2026-11-14), as for claimUnserializedEnable: the environment gets its own |
| +// credential while the switch is still on. Every other caller passes false. |
| func claimUnserializedEnableEnvironment(ctx context.Context, s release.Store, p Provisioner, seal appconfig.Sealer, |
| - d Deployment, acct, app, env string, now time.Time) (*Record, error) { |
| + d Deployment, acct, app, env string, now time.Time, delivering bool) (*Record, error) { |
| if !appconfig.ValidEnvironmentName(env) { |
| return nil, fmt.Errorf("mail: invalid environment name %q", env) |
| @@ -49,7 +53,7 @@ func claimUnserializedEnableEnvironment(ctx context.Context, s release.Store, p |
| // A switched app's environments get no credential (decision 10); an |
| // owned environment receives the From variable through |
| // DeliverMailFromIn instead. |
| - if rec.switched() { |
| + if rec.switched() && !delivering { |
| return nil, ErrSubmissionOn |
| } |
| if rec.Provisioned == nil { |
| @@ -141,7 +145,11 @@ func claimUnserializedEnableEnvironment(ctx context.Context, s release.Store, p |
| // Idempotent: an environment the record does not name has no IAM user to |
| // reap, and a bundle that no longer exists or holds none of the six is |
| // left alone. |
| -func claimUnserializedReapEnvironment(ctx context.Context, s release.Store, p Provisioner, acct, app, env string) (*Record, error) { |
| +// |
| +// keepFrom is SwitchOn's: the environment's From variable stays, so the |
| +// bundle of a switched app never goes without one (P2-3, ruled 2026-11-14). |
| +// Every other caller passes false and the From goes with the five. |
| +func claimUnserializedReapEnvironment(ctx context.Context, s release.Store, p Provisioner, acct, app, env string, keepFrom bool) (*Record, error) { |
| if !appconfig.ValidEnvironmentName(env) { |
| return nil, fmt.Errorf("mail: invalid environment name %q", env) |
| } |
| @@ -155,7 +163,7 @@ func claimUnserializedReapEnvironment(ctx context.Context, s release.Store, p Pr |
| ep := rec.Environments[env] |
| if ep == nil { |
| if rec.Declared != nil { |
| - if err := unsetSMTPEnvIn(ctx, s, acct, app, env, rec.Declared.EnvPrefix); err != nil { |
| + if err := unsetSMTPEnvIn(ctx, s, acct, app, env, rec.Declared.EnvPrefix, keepFrom); err != nil { |
| return nil, err |
| } |
| } |
| @@ -171,7 +179,7 @@ func claimUnserializedReapEnvironment(ctx context.Context, s release.Store, p Pr |
| return nil, err |
| } |
| if rec.Declared != nil { |
| - if err := unsetSMTPEnvIn(ctx, s, acct, app, env, rec.Declared.EnvPrefix); err != nil { |
| + if err := unsetSMTPEnvIn(ctx, s, acct, app, env, rec.Declared.EnvPrefix, keepFrom); err != nil { |
| return nil, err |
| } |
| } |
| @@ -186,17 +194,22 @@ func claimUnserializedReapEnvironment(ctx context.Context, s release.Store, p Pr |
| } |
| // unsetSMTPEnvIn removes every variable mail delivers from env's bundle: |
| -// the five, and the From variable when the prefix names one. It reads |
| +// the five, and the From variable when the prefix names one, unless |
| +// keepFrom. It reads |
| // first: an unset-only apply against a bundle that does not exist is |
| // refused by appconfig (it would mint an empty bundle), and a bundle that |
| // holds none of them has nothing of ours to remove. |
| -func unsetSMTPEnvIn(ctx context.Context, s release.Store, acct, app, env, prefix string) error { |
| +func unsetSMTPEnvIn(ctx context.Context, s release.Store, acct, app, env, prefix string, keepFrom bool) error { |
| m, _, found, err := appconfig.GetEnvironment(ctx, s, acct, app, env) |
| if err != nil || !found { |
| return err |
| } |
| var unsets []string |
| - for _, k := range mailEnvNames(prefix) { |
| + names := mailEnvNames(prefix) |
| + if keepFrom { |
| + names = smtpEnvNames(prefix) |
| + } |
| + for _, k := range names { |
| if _, ok := m.Vars[k]; ok { |
| unsets = append(unsets, k) |
| } |
| @@ -213,7 +226,7 @@ func unsetSMTPEnvIn(ctx context.Context, s release.Store, acct, app, env, prefix |
| func EnableEnvironment(ctx context.Context, s release.Store, p Provisioner, seal appconfig.Sealer, |
| d Deployment, acct, app, env string, now time.Time) (*Record, error) { |
| if _, enabled := s.(ClaimMailStore); !enabled { |
| - return claimUnserializedEnableEnvironment(ctx, s, p, seal, d, acct, app, env, now) |
| + return claimUnserializedEnableEnvironment(ctx, s, p, seal, d, acct, app, env, now, false) |
| } |
| var claimResult0 *Record |
| claimErr := WithClaimMailResource(ctx, s, func(ctx context.Context) error { |
| @@ -222,7 +235,7 @@ func EnableEnvironment(ctx context.Context, s release.Store, p Provisioner, seal |
| p = claimMarkedProvisioner{raw: p} |
| } |
| var err error |
| - claimResult0, err = claimUnserializedEnableEnvironment(ctx, s, p, seal, d, acct, app, env, now) |
| + claimResult0, err = claimUnserializedEnableEnvironment(ctx, s, p, seal, d, acct, app, env, now, false) |
| return err |
| }) |
| }) |
| @@ -231,7 +244,7 @@ func EnableEnvironment(ctx context.Context, s release.Store, p Provisioner, seal |
| func ReapEnvironment(ctx context.Context, s release.Store, p Provisioner, acct, app, env string) (*Record, error) { |
| if _, enabled := s.(ClaimMailStore); !enabled { |
| - return claimUnserializedReapEnvironment(ctx, s, p, acct, app, env) |
| + return claimUnserializedReapEnvironment(ctx, s, p, acct, app, env, false) |
| } |
| var claimResult0 *Record |
| claimErr := WithClaimMailResource(ctx, s, func(ctx context.Context) error { |
| @@ -240,7 +253,7 @@ func ReapEnvironment(ctx context.Context, s release.Store, p Provisioner, acct, |
| p = claimMarkedProvisioner{raw: p} |
| } |
| var err error |
| - claimResult0, err = claimUnserializedReapEnvironment(ctx, s, p, acct, app, env) |
| + claimResult0, err = claimUnserializedReapEnvironment(ctx, s, p, acct, app, env, false) |
| return err |
| }) |
| }) |
diff --git a/internal/provision/platform_mail_submission_census_test.go b/internal/provision/platform_mail_submission_census_test.go| index e2a1d80fb..76ae9f3c0 100644 |
| --- a/internal/provision/platform_mail_submission_census_test.go |
| +++ b/internal/provision/platform_mail_submission_census_test.go |
| @@ -67,6 +67,21 @@ func platformMailSubmissionWriteCensusInventory() []censusEntry { |
| // POST .../email/submission, as linkedRefuse (a linked app's mail |
| // is managed at home). A route-pattern literal; no store access. |
| {"internal/console/linkedpolicy.go", "var linkedPolicies", "key-site", "lit:instances,lit:sidecars", "2c35594af28a461ba65ef59e9943b3e710d63f458bab0ecd4de729909c1d0cd7"}, |
| + // Ruled by Paul, 2026-11-14 (the one-working-channel family, P2-1 to |
| + // P2-4): re-digested, classification and kinds unchanged, the same |
| + // writes. |
| + // - Enable and EnableEnvironment take a delivering flag: SwitchOff's |
| + // "deliver although switched" path; every other caller passes |
| + // false. The same Put of the app sender. |
| + // - ReapEnvironment takes keepFrom: SwitchOn keeps the |
| + // environment's From while it reaps the user. The same Put. |
| + // - the instance update door also refuses a rebind into an owned |
| + // environment that lacks a switched app's From, before its |
| + // existing UpdateRecord. |
| + {"internal/mail/walk.go", "claimUnserializedEnable", "reference", "id:Put", "486eaaebea7d69d488fd46af7f666b16cee4bf3b577b29c6da3d7a2db2d0dd5f"}, |
| + {"internal/mail/walk_environment.go", "claimUnserializedEnableEnvironment", "reference", "id:Put", "aa676ba9623ffa989da7ed3c7943225d23eae78fe564a9674bd272987f92ed5e"}, |
| + {"internal/mail/walk_environment.go", "claimUnserializedReapEnvironment", "reference", "id:Put", "b2d670d8ef9c26a0847fa966559aa51530760f9a0170df3f9d95523994b2f552"}, |
| + {"internal/console/apiinstances.go", "Server.handleAPIInstanceUpdate", "record-writer", "key:UpdateRecord", "90385e624ddc76606423fbb6723d000c7675a5f9ec61223bd14df653c61d4803"}, |
| } |
| for _, r := range repins { |
| found := false |
| @@ -96,9 +111,13 @@ func platformMailSubmissionWriteCensusInventory() []censusEntry { |
| // Provisioned is nil; the reap also waits out an unrecorded day; and |
| // switchedRecordHosts records each host's account, so a fleet box fires |
| // only for its own account's apps. |
| + // Ruled by Paul, 2026-11-14 (P2-3): SwitchOn and SwitchOff are reordered |
| + // so every bundle keeps a working channel (switch-on: the From first, |
| + // the switch, then the five out; switch-off: SMTP delivered first, the |
| + // switch, then the From out). The same Puts of the app sender. |
| entries = append(entries, |
| - censusEntry{"internal/mail/submission.go", "claimUnserializedSwitchOn", "reference", "id:Put", "ad8d87d4d40b10f23beac8542ca78ab920b6ecd3578de780ef5a6cfd136e376c"}, |
| - censusEntry{"internal/mail/submission.go", "claimUnserializedSwitchOff", "reference", "id:Put", "7d2b913ae9c3f5c82d050d4483f5913cc0aa8d0a8c12cac5a01de27aa4a37f04"}, |
| + censusEntry{"internal/mail/submission.go", "claimUnserializedSwitchOn", "reference", "id:Put", "9a51854db684923d987663cca49b0b0dafe0c52c57f809e5b1f0cab2c2cd6cc7"}, |
| + censusEntry{"internal/mail/submission.go", "claimUnserializedSwitchOff", "reference", "id:Put", "fb3b0cf11f4846eb60aefd09130b0cf0f7e243d79178f1b80446b13d312ae0c8"}, |
| censusEntry{"internal/mail/sweep.go", "claimUnserializedReapAppUserAfterSubmission", "reference", "id:Put", "1e0ec1ef110c5237e3755004103f4c2698ec68bf726f1345bde2ca64fa466acf"}, |
| censusEntry{"internal/console/alertsignals.go", "engineReads.switchedRecordHosts", "key-site", "key:RecordsPrefix", "9d474c76f8e5326bb99c79b03fd4677adbec77564172a66d1b4a625d2e33e294"}, |
| censusEntry{"internal/console/submissiongate.go", "var submissionServeDoors", "key-site", "lit:instances", "ffdd74f701289aca38df6d6c47afa10532ba39acee8260b406c66320c1fc2dad"}, |