> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tuturuuu.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Wave-1 production publication

> How Mail, Calendar, Apps, Finance and Drive publish to production: version upload, 0% staged smoke, traffic switch, health gate and automatic rollback.

`wave1-native-production.yaml` publishes the wave-1 native Workers (Mail,
Calendar, Apps, Finance and Drive). The Production Deployment Planner calls it
through each app's `<app>-cloudflare.yaml` when a production push selects the
app; a dispatch of `wave1-native-production.yaml` from `production` is the only
manual route. A direct dispatch of `<app>-cloudflare.yaml` on `production`
never publishes: its run is not part of the upload history.

## Admission

* `productionPublicationPolicy` in `tuturuuu.ci.ts` admits the app. The caller's
  `production-policy` job, the called workflow's `production-policy` job and
  the publisher itself all check it.
* A called run defaults its `automatic` input to true, so an app with a
  `productionPublicationExemptions` record is held. Calendar has such a record
  until its first staged release by manual dispatch is smoked and serving;
  remove the record to let the planner publish it.
* A Worker that already serves through a Custom Domain or zone route publishes
  only when `productionServingTopology` records exactly that topology. Calendar's
  record is `calendar.tuturuuu.com` with no routes. Every other wave-1 Worker
  must stay route-free.

## Publish sequence

Everything below runs in the publish job. The preflight and verify steps hold
only the read token; the upload step holds only the deploy token and performs
every Cloudflare write.

1. **Read-only preflight.** Exact production SHA, topology, secrets, rollback
   deployment and upload history. The history walks manual dispatches and
   planner runs newest first. It skips attempts that provably never started an
   upload, receipts whose serving deployment was restored and confirmed, and
   superseded attempts. An `uncertain` or unknown attempt blocks. The serving
   SHA must be proven, from the serving version's annotation or from the
   accepted receipt that wrote it. When it is newer than the candidate, the
   attempt records `superseded` and uploads nothing.
2. **Version upload.** `cf workers versions create --prebuilt` creates the
   version with no traffic.
3. **Stage at 0%.** A gradual deployment keeps the serving version at 100% and
   adds the new version at 0%.
4. **Staged smoke.** Signed-out requests carry
   `Cloudflare-Workers-Version-Overrides: <worker>="<version>"`. The smoke
   contract:
   * `GET <public host>/api/build-info` and `GET tuturuuu.com/<mount>/api/build-info`
     answer 200, report the candidate `commitHash` and name the app in
     `appName`, so a gateway or another app answering the same path from the
     same commit cannot pass. Build-info carries no version identity. Retries cover edge
     propagation for about a minute; if either path never reports it, the
     override did not reach the staged version and the smoke fails.
   * Where the app's source emits it (Finance today), `x-tuturuuu-runtime: native`
     must be present. Mail, Calendar, Apps and Drive do not emit it yet; their
     records keep the observed value. A test flips the requirement on when an
     app's `start-bridge.config.ts` starts emitting it.
   * `GET tuturuuu.com/<mount>` answers 307 into `https://tuturuuu.com/login`
     (Apps answers 200: its catalog is public; Drive has no apex mount).
   * Login pages answer without a 5xx, and the release recipe's smoke cases
     match.
   * Any 5xx or timeout fails the stage. Records keep each response's status
     and allowed headers (`cache-control`, `cf-ray`, `content-type`,
     `location`, `server`, `x-tuturuuu-runtime`), never a body.
5. **Abort or switch.** A failed smoke restores the serving deployment alone
   (`smoke-failed`); traffic never moves. Otherwise traffic switches to the
   new version at 100%, but only while the staged deployment is still active.
6. **Health gate.** Public probes without the override, every 10 seconds for
   about a minute: every build-info origin reports the candidate commit, and
   no probe answers 5xx or times out. On failure the upload step restores the
   recorded rollback deployment, confirms it is active, probes the restored
   state, records both outcomes (`rolled-back`) and fails the job. A restore
   that cannot be confirmed marks the receipt `uncertain` and the job fails
   loudly; restore the receipt's rollback deployment by hand.
7. **Verify.** The read-only step confirms the active version, script settings
   and unchanged topology, and records `accepted-private`.

The smoke and the health gate stop at a 17-minute budget from the start of the
upload step, whose timeout is 25 minutes, so a failure always leaves time to
restore the rollback deployment. `WAVE1_UPLOAD_BUDGET_MS` overrides the budget
and must be a positive whole number of milliseconds; any other value refuses.
Before the switch the step also checks that the budget still covers the
switch's own worst case (a guard read, the write and four readbacks, about 96
seconds) plus a full health-gate run (every propagation and healthy round with
its probe timeout);
if not, the smoke counts as failed and traffic never moves, instead of
switching only to stop the gate at once and roll back.

If the step is still killed, cancelled or crashes, the next step (**Restore
the rollback deployment after an interrupted upload**, run on `failure() ||
cancelled()` with only the deploy credential) restores the recorded rollback
deployment when the receipt is `staged`, `switched` or `rolling-back`. It
confirms the restore by reading the active deployment back but runs no public
re-probe, and records `rollbackResult.by: recovery` and
`rollbackHealth: { probed: false, by: 'recovery' }`; the health gate's own
rollback re-probes.
The upload history treats both as confirmed restores.

A step timeout or a manual cancel lets this step run. A job-level timeout
(50 minutes) is a cancellation of the whole job: GitHub documents that a
cancelled run re-evaluates step conditions, so a `cancelled()` step is
expected to run, but it does not document the job-timeout case and the runner
force-terminates a cancelling job after a short grace period. The publisher
does not rely on it. The deployment coordinator's `begin` step waits at most
5 minutes for the lane, and setup steps (checkout, toolchain, install, artifact
download) normally finish within a few minutes; the artifact restore, runtime
recheck and preflight have their own timeouts. The 25-minute upload step and
the 4-minute recovery step therefore fit inside the 50-minute job unless the
steps before the upload take more than about 21 minutes, so the upload step
times out first and recovery runs as an ordinary step after a failure. A job
that times out before the upload step starts has written no deployment. If recovery still never runs, the receipt keeps
`switched` or `rolling-back`, which the upload history never skips: every
later attempt refuses until a release owner restores the receipt's rollback
deployment and reconciles it.

## Concurrent deployments

Every stage, switch, restore and rollback writes only while the active
deployment is exactly a split this attempt wrote, or the one it expects
before staging. When another writer has changed it, for example a hand
hotfix or rollback, the publisher writes nothing, records
`concurrent-change` with the active split, and fails. The upload history then
blocks later attempts until a release owner reconciles the receipt.

Cloudflare offers no compare-and-swap for deployments, so the check and the
write are two API calls. A hand deploy that lands in that single round-trip is
still replaced, and the readback then shows the publisher's split. The window
is accepted: it is about one request long, the receipt records every write,
and writing without the check would overwrite every concurrent change. Release
owners should not deploy by hand while a publish job's upload step runs.

## Recovery

The history skips an attempt that restored and confirmed its serving
deployment (`stage-failed`, `smoke-failed`, `switch-failed`, `rolled-back`)
and carries forward the serving SHA its preflight proved, so the next release
can still prove what serves. `uncertain` and `concurrent-change` block until a
release owner reconciles them.

The planner only republishes an app when a production push selects it. After
a failed staged attempt, a later push that does not touch the app does not
retry it: dispatch `wave1-native-production.yaml` with the app from
`production` to publish it again. A rerun of the failed SHA refuses because
its version is already in the Worker's history; ship the fix on a new SHA.

## Abuse guard coverage

Apps with the `ABUSE_GUARD` service binding are smoked with the real binding
attached, but a staged smoke proves the abuse-guard path only when one of the
smoke endpoints exercises it. Build-info, signed-out page redirects and the
release-recipe cases may not call the guard, so a broken guard binding can
still pass the smoke and surface only in the health gate or later traffic.

The receipt artifact `wave1-<app>-production-publication-<sha>-<run>-<attempt>`
is retained 90 days in every outcome.

## Why a 0% gradual deployment

Cloudflare's version override header selects only among the versions of the
current deployment. Staging the new version at 0% beside the serving one puts
it in the current deployment, so the header reaches it on the app's real
public paths, with the Worker's real bindings and secrets, while no reader is
served by it. It changes no route, Custom Domain, `workers.dev` or preview URL
setting.

A preview-URL window would need `preview_urls` enabled on a production Worker:
a settings write that exposes every version on `workers.dev` until it is
reverted, outside the Access and gateway paths real users take. A failed revert
leaves that exposure open. The 0% deployment avoids both. The header is not
guaranteed to pass through every service binding, so the smoke fails closed
unless build-info on each path proves it reached the staged version.

## Concurrency

Builds of one app and SHA share a queue (`wave1-native-production-<app>-<sha>`);
uploads of one app share another (`wave1-native-upload-<app>`). Neither cancels
a run. Callers use a group per run on `production`, so no planner callee
replaces another.

## Regression coverage

* `scripts/ci/wave1-production-staged.test.mjs`: end-to-end sequence with fakes.
* `scripts/ci/wave1-production-health.test.mjs`: health gate, smoke contract,
  switch guards and serving-SHA proof.
* `scripts/ci/wave1-production-concurrent.test.mjs`: concurrent deployments,
  interrupted-upload recovery and the time budget.
* `scripts/ci/wave1-native-production-history.test.mjs`: upload history.
* `scripts/ci/wave1-production-admission.test.js` and
  `scripts/ci/wave1-production-concurrency.test.js`: workflow conditions and
  groups.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.