iterate.com / cloud

git clone https://git.iterate.com/repos/cloud

cloud / scripts / zone-enrollmentmain at aacbc74

README.md

# A zone that joins or leaves a mind

`iterate deploy --zones a,b` gives a mind its whole list of zones, and the stack
(`core/alchemy/src/stack.ts`, "each zone") makes or deletes eight resources for each. For
iterate's own minds the run is `scripts/deploy-own-minds.ts --zones a,b <domain>`.

`zone-enrollment.test.ts` proves every statement below that says "proven": Alchemy's own CLI
against `fake-cloudflare.ts` on 127.0.0.1, with no account. The fake answers as Cloudflare's
docs say. So the tests prove which calls Alchemy sends, in which order, and what its state then
plans. They do not prove what Cloudflare does with a call.

## There is no rollback of a zone change

Alchemy has no undo. A deploy that fails midway leaves what it made, in the account and in its
state (proven). The runner's rollback returns the five Workers to their versions before, and no
zone resource. Its stop then says "THE ZONE CHANGE IS NOT ROLLED BACK".

From a deploy that stopped there are two ways, and both are runs of the same tool:

| The deploy that stopped | The way on: the same run again                                                      | The way back: the zone list from before                                                                                                                                     |
| ----------------------- | ----------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| A zone joined           | Makes what is missing, and nothing twice (proven: one call for the one that failed) | Deletes what was made, gives the catch-all back, turns Email Routing off, and **deletes the zone's Email Sending domain, also one that was there before the join** (proven) |
| A zone left             | Deletes what is left (proven)                                                       | Makes the eight anew. The Email Sending domain is a **new** one: whether its DKIM key and return-path records equal the old ones is Cloudflare's, and not proven            |

So prefer the way on. The way back from a join is right only when the zone must not stay in the
mind, and then the loss of the sending domain is the price that Jonas accepted for a zone that
leaves (25 Nov 2026, the card `tasks/prepare-pinned-alchemy-zone-enrollment-and-mail-adoption.md`
of the iterate.com mind).

## What no run gives back

- **Email Routing that was on before the join.** Alchemy's resource does not record it. A zone
  that received mail before it joined has routing turned off when it leaves (proven). Its
  catch-all goes back to what it was at the join.
- **The sending domain**, as above.
- **Mail.** A mail that the boundary took is in the mind and stays. A mail that arrives while a
  zone's routing is on and its catch-all is `drop` is lost.
- **DNS answers that resolvers hold.** After a zone leaves, a sender can use the zone's MX
  records until their TTL ends (Cloudflare's "automatic" TTL is 300 s). With routing off,
  Cloudflare refuses that mail, and the sender gets it back. What Cloudflare does in that window
  was not measured.

## When the run must stop, and a person reads the zone

The runner cannot see these. Read the zone (Email Routing's state, the catch-all rule, the
Worker routes, the sending domains) before the next step:

1. **After any stop of a run with `--zones`.** The zone may be half done.
2. **After every leave, also one that ended well.** Alchemy's Email Routing provider drops every
   error of its delete (2.0.0-beta.87, `Email/Routing.ts`). A refused turning-off ends as a
   success, the zone keeps its MX records with a catch-all that is `drop`, disabled, and the
   state has forgotten the zone, so no later run turns it off (proven). Turn it off by hand.
3. **Before a join, when the account may hold an events subscription for the zone's sending
   domain already.** Cloudflare allows one subscription for a source, and the stack makes
   `MailEvents-<zone>` by a plain create. The join then fails at that call, with the zone's
   seven other resources made (proven for a refused create). List the account's event
   subscriptions first.
4. **Before a leave of a zone that had mail or a sending domain before it joined.** The verdict
   of a `--plan-only` run names the loss. It needs a person's yes for that zone.

## What the gate has not seen

The gate lets a zone change through only with the Workers' config lines that go with it, among
them `Auth/SEND_EMAIL update`. That wording is read off Alchemy's source (a binding's line is
`<Worker>/<its env key> <action>`, `alchemy/Cli/LoggingCli.ts`) and off live plans of other env
keys (`Boundary/DEPLOY_CONFIG update`). No live plan with a changed zone list was run. A plan that
words it otherwise is a stop at `--plan-only`, never a pass: then correct `ZONE_LIST_LINES` in
`../lib/own-minds-gate.ts` from that plan.