carlos / platform Public

feat/platform-mail-submission

Platform mail submission

An instance of a switched app sends mail by POST /v1/mail on its own control socket instead of holding SMTP credentials. The agent stamps each message with the socket's route and forwards it to a box-local mailer (carlos mailer serve, its own unit and uid). The mailer accepts only the agent's main process and refuses routes not on its box. Before the send it applies the sender's From, pause, daily cap and rate. It then sends through SES with one dedicated IAM user per region. No instance of a switched app holds a sending credential.

Why: Paul, 2026-11-12. Instances of every team environment each held their own IAM user and SMTP key, and exec children share the agent's uid, so per-instance passwords never stopped a sibling on the same box from sending as you. Alta's team runs were blocked on this.

Spec: docs/superpowers/specs/2026-11-12-platform-mail-submission-design.md (rev 5 + §9.0, approved). Plan: docs/superpowers/plans/2026-11-13-platform-mail-submission.md. Runbook: docs/mailer-runbook.md.

What changes

  • Sender record: pause moves onto the sender record (pause), plus a per-app submission switch. Both are additive omitempty fields, and old records parse unchanged.
  • Attribution: SES EmailTags are believed only from the mailer's principal (guard test 8.11). Sends are counted by caller class (mail_caller_sends).
  • Mailer unit: user, socket, .path arm, tmpfiles and sysusers. Tenant units get InaccessiblePaths= for the mailer's paths. The peer rule is the agent's MainPID and uid. Box status reports MailerArmed, and a mailer_unarmed alert fires for a box hosting a switched app.
  • The verb: at both control-socket bind sites. CARLOS_MAIL is agent-owned and set only for a bound, provisioned route of a switched app. An unreadable switch is decided from the instance's own bundle and never read as off.
  • Mailer send pipeline: header hygiene (Bcc, X-SES-*, RFC 2231 parameters refused), From/domain, pause, cap, a rate of 2/s with a burst of 20, and SES v2 raw send with tags.
  • Per-app switch: carlos email submission on|off --app <a>, with its preconditions. One serving judgement (judgeServing) under the app lock gates every serve, create and rebind door. Switch-on and switch-off are ordered so every instance keeps a working mail channel at every step. The app-level user is reaped once its key has been unused for a week.
  • Builds: carlos ship --mail submit declares a build's mail transport.
  • Infra: the mailer IAM user and policy (infra/modules/region-host/mailer.tf), tofu tests, and the runbook.

Tests, simulation, sweeps

  • Full gate green on the tip, including the root-read census and the record-write census (TestPlan9B8RecordWriteCensus).
  • TestSubmissionChannelSimulation drives the doors in random and scripted interleavings, with injected store and AWS faults. After every step it asserts the one-working-channel invariant, including that every SMTP key an instance would use is live in AWS. Its scripted steps cover each ruled case, and each case's fix was mutation-checked (watched to fail when removed).
  • Seed sweeps: - CI runs the default 60 seeds. - Run locally on the final code: seeds 5000–5119 and a fresh 9000–9199. All green.

Reviews

  • Fable whole-branch review of b0aba39b0: APPROVE, no P1. Its P2s are fixed. P2-1 to P2-3 are in the one-working-channel family: the agent marks the switch stale before a flip's restart; an unreadable switch is never off; the week-7 reap takes the switch door's locks.
  • Astra census approvals r1–r3, the last at fd5c1d2cc: every root-read unit, envelope and record-write re-pin accepted, no findings. The merge of main ada520b6d changed no disposition: it re-pinned envelopes for the packages main changed, and the two route tables both sides edited.
  • Copy: Paul approved the 56 strings unedited (f578a857e).
  • Paul's rulings (2026-11-12 to 11-14): - Gaps G1–G10 as listed in the plan. - The RFC 2231 refusal. - "One working channel" as one invariant enforced in one place, plus the simulation. - The 65 MB binary ceiling; main has since raised it to 70 MB. - Fix P2-1 to P2-3 as named. - "Switch-off checks keys". - "Switch-on removes SMTP settings before deleting the user", with the week-7 reap extension kept. - "Replace first" as a standing rule for this family: any case where a working credential or channel is removed before its replacement is in place is fixed replacement-first. Case 1 was seed 5063.

Still to do (Paul's operator steps, docs/mailer-runbook.md and plan "Operator steps")

  1. Release and roll the platform.
  2. IAM user and key per region, with scoped approval: tofu mailer on each region-host that hosts Oficina instances, then create the key (runbook 1–2).
  3. Before the first switch-on: - the tenant backfill / ses:ListTenantResources check; - the one-off tenant-attributed send proof (runbook 2b).
  4. Arm each box that hosts the apps' routes (runbook 3). New or replaced group boxes are named by mailer_unarmed and need arming too (runbook 4).
  5. Before each switch-on: check that every route of the app has an instance record (hand-made routes would have neither channel).
  6. Per app: carlos email submission on --app <a>, watch for 7 days, and abort with off if needed. Each Oficina app needs its own branch shipping --mail submit first (Task 9). The rastrillo submit transport is on its own branch.
  7. After every later platform roll: restart carlos-mailer.service on armed boxes (runbook 5b).
  8. Before rolling the console back past this build: switch every app off (runbook 5c).

Nothing is deployed. This branch made no AWS write, no tofu apply, and no state-changing carlos command. Until an app is switched, everything is inert: no unit starts without a key, and no CARLOS_MAIL is set.

🤖 Generated with Claude Code

Commits 55
Discussions 0 0 open
Tasks 0/0 done

Discussions

  • No discussions on this branch yet.

Tasks

  • No tasks yet.

Activity