Skip to content

feat(infra): the deploy workflow, the fleet promote entrypoint and production runbooks - #521

Merged
allisonmahmood merged 1 commit into
mainfrom
infra/415-deploy
Oct 4, 2026
Merged

allisonmahmood merged 1 commit into
mainfrom
infra/415-deploy

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner

What changed

Nothing could deploy the CDK stacks. The spike promoted the fleet with an inline node -e script, and the docs still said production was unbuilt.

.github/workflows/deploy.yml runs on workflow_dispatch from main only. It is gated by the production environment's reviewer and runs one at a time (concurrency group). It:

  1. refuses commits that are not on main, and assumes the deploy role through OIDC;
  2. stops any promote task a cancelled run left behind;
  3. decides, from the release record, the secret slot this release reads and the release it rolls out beside, and records it as pending;
  4. builds the reproducible server image (the server-image.yml steps);
  5. deploys the base stack;
  6. pushes the image to ECR with crane, tagged with the commit. On a rollback the tag already exists, and the run checks the rebuilt digest matches it;
  7. deploys the app stack, pinned to the digest, with the promoted release as its previous revision. CloudFormation waits for ECS; a host that can't start trips the circuit breaker, and the update rolls back;
  8. runs node dist/fleet.js promote <revision> as a one-off task from the host task definition, after ECS has settled, and records the release as promoted;
  9. confirms the service's primary deployment is on the new task definition.

The release record. The SSM parameter /patchy/production/promoted-release is written only by the workflow, never by CloudFormation. It holds the promoted release and, while one is unfinished, the release being promoted, each with the management secret slot it reads and the previous release it was deployed beside. A release is pending from before anything deploys until its promotion. A release is marked pending before promotion and promoted after. Each release takes its previous settings from this record, not from the deployed stack: a run that deployed hosts but didn't promote leaves the fleet on the release before it. A re-run reuses its release's recorded settings. While a promotion is unfinished (failed, timed out or cancelled), the workflow refuses any other release until that run is re-run or the promoted commit is released again.

Fleet promote. Fleet.promote (in packages/execution) stages the revision, waits up to five minutes for its hosts to warm spares, and promotes it. It only moves rollout rows, so it needs no task provider (the spike's script built a whole ECS provider with hand-fed callback URLs). It refuses a revision no host has registered, and returns at once for one already promoted. apps/server/src/fleet.ts is the dist/fleet.js entrypoint; the image build now requires it.

Docs. docs/OPERATIONS.md gains Production: setup, deploy, rollback, restore and secret-rotation runbooks, and names the host log group. ADR-0012 gains the production topology. README, AGENTS, product, ADR-0004/0010 and the API docs now say production is written but not yet deployed.

Choices worth checking

  • Rotation. The management secret stays constant across releases, as the issue decided. It has two slots, and a release reads one. Rotation writes the new secret into the idle slot, where no running host looks. The overlap deploy moves to that slot and reaches the old release's tasks through the old one, and the seal stays on the new slot. So a failure or rollback at any step leaves both slots readable, and no step writes back an old value. Each rotation deploy needs a revision different from the running one, or the ECS provider refuses to start, so the rotation input (release / overlap / seal) names those runs <commit>-overlap-<run> and <commit>-seal-<run>. Rotation needs no new commits.
  • Public run logs. The account id, certificate ARN and alert addresses are environment secrets, not variables. None is secret, but GitHub prints each step's environment in this public repo's logs and masks only secrets. CDK's stack outputs and resource ids are filtered out of the log, and the promote task's output stays in CloudWatch.

What a restore can't do. Neon's branch restore does not revert Object Storage (Neon), so the runbook says which bytes a restore can't bring back. It also says that fleet rows for tasks ECS has forgotten keep holding fleet budget: the controller never treats a missing task as stopped, and nothing clears such rows yet.

Third of three stacked PRs. Based on #520 (infra/415-cdk): the workflow deploys its stacks and reads their outputs. Closes #415.

How it was verified

  • pnpm check and pnpm verify pass locally; actionlint and shellcheck pass on the workflow
  • Added a Fleet.promote case to packages/execution/src/Fleet.test.ts: it refuses an unregistered revision, promotes once spares are warm, and returns at once on a rerun

Nothing has been deployed: the workflow can't run until #416's setup is done.

Release impact

  • Breaking
  • Not breaking — a new workflow and entrypoint; nothing runs until someone dispatches it

Made by Claude Opus 5.5 (1M context) via Claude Code, in T3 Code.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Codex review (GPT 6.1 Sol, xhigh), two rounds before the first push.

Round one:

  1. Blocker: newline injection through the free-text rotation inputs and the newline-delimited context file. Fixed. The free-text inputs are gone; the only inputs are a commit checked to be 40 hex digits and on main, and a choice. CDK context is built inline per step.
  2. Major: no deployment-branch restriction. Fixed. The setup runbook requires the production environment to allow only main, and the job runs only on refs/heads/main.
  3. Major: plain releases had no previous mapping, so housekeeping could reserve tasks the provider can never start or stop. Fixed (see feat(infra): production stacks in AWS CDK #520): every release after the first carries the promoted release as previous.
  4. Major: promotion can deadlock when bound tasks and old spares fill the fleet budget of 15. Not fixed here. This is pre-existing fleet-controller behaviour, not something this stack introduces. The Deploying runbook documents it as a known limit, and the owner is told.
  5. Major: a restore brings back fleet rows for tasks ECS has forgotten, and those rows hold budget. Documented. The runbook stops every exec task first, brings the hosts back within the hour, and says plainly that no operation clears such rows yet. Flagged to the owner as follow-up work.
  6. Major: Neon's branch restore does not revert Object Storage. Documented. Confirmed in Neon's docs. The runbook says which bytes a restore can't bring back. Flagged to the owner: the issue assumed restore covers the content store.
  7. Major: a failed overlap deploy leaves the secret changed. Fixed in the runbook, with recovery for each phase.
  8. Minor: CDK prints stack outputs, resource ids among them, into the public log. Fixed. Output lines and the stack ARN are filtered out, resource-id outputs are masked before later steps see them, and the promote task's own output stays in CloudWatch.
  9. Minor: Fleet.promote re-staged a revision that was already promoted. Fixed. It returns at once, and the test covers a re-run after the spares are gone.
  10. Minor: the trailer's address. Dismissed. This is the repo's attribution convention, carried by every commit on main.

Round two (on those fixes):

  1. Re-running a release, or the next release after a failed promotion, would take "previous" from the deployed stack and lose the revision the fleet still runs. Fixed. The workflow records the promoted release in /patchy/production/promoted-release right after each promotion and reads "previous" from there. The workflow owns the parameter, so no stack update can reset it.
  2. The overlap recovery could delete a key the serving overlap hosts need. Fixed. The runbook now separates a failure before the app deploy finished (write the old value back) from a failure at promotion (leave the secret and re-run).
  3. The restore runbook started before hosts and exec tasks had stopped. Fixed. It now waits for the service to drain and for every exec task to reach STOPPED.

@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area size:l 501-1,000 changed lines labels Oct 4, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Codex review, round three (on the round-two fixes). Four findings, all fixed in the force-pushed commit:

  1. A promotion that succeeds but whose record write fails (or a run cancelled while it waits) leaves the record stale, and the next release rolls out beside the wrong revision. Fixed. The record now holds a pending release, written before promotion, beside the promoted one. Each entry carries the previous release it was deployed beside. While a promotion is unfinished, only re-running that run (which reuses its settings, and whose promote returns at once if it already happened) or releasing the promoted commit is allowed. Any other release is refused. I simulated the record through first release, release, re-run, failed promotion, refusal, re-run, overlap, re-run, seal, failed promotion and rollback against a stub aws.
  2. The restore runbook didn't make sure every host and exec task had stopped. Fixed. It lists host and exec tasks with both desired statuses, scales hosts to zero and waits for each host task to reach STOPPED, then stops every exec task and waits for those too.
  3. A failed or cancelled overlap run doesn't prove the old hosts came back. Fixed. The runbook keeps both keys until the stack has finished rolling back and the service's primary deployment is on the old task definition.
  4. Re-running an overlap that was already promoted (say, after a failed confirmation) refused to start. Fixed. A re-run reuses the promoted release's recorded previous settings, including the overlap's secret key, so its stack deploy is a no-op and promotion returns at once.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Codex review, round four (blocker and major only, on the round-three fixes). Five findings, all fixed in the force-pushed commits on #520 and #521:

  1. A first release's hosts promote themselves, so cancelling before the record write left no record, and the next release would roll out beside nothing. Fixed. A first release is recorded as pending before its app stack deploys.
  2. Rolling back away from a pending overlap pointed both secret mappings at the new key, so the promoted release's exec tasks rejected management. Fixed by redesign. The management secret has two slots, and each release records the slot it reads. Rotation writes the new secret into the idle slot, the overlap moves to it, and the seal stays on it. A rollback away from a pending overlap reads the old slot and reaches the overlap's tasks through the new one. The simulation covers this case.
  3. A cancelled run's promote task could still start and stage a superseded revision. Fixed. Each run first stops any deploy-promote task left in the cluster and waits for it to stop. The deploy role may list and stop tasks in the cluster.
  4. A CloudFormation rollback mid-overlap started hosts that read the rewritten secret. Fixed by the slots. No running host's slot ever changes value, so hosts restarted by a rollback read what they read before.
  5. The documented rollback ("release the promoted commit") couldn't reach a promoted rotation revision, which carries a suffix. Fixed. The runbook rolls back by re-running the run that released the revision, which keeps its revision and recorded settings. The refusal message says the same.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Codex review, round five (a confirmation pass on the slot redesign, blocker and major only). One finding, fixed in 9091571:

  • Rolling back to a release from before a rotation while its exec tasks are still draining would put its hosts on the new slot, which those tasks reject. Re-running an old overlap run after the seal would flip back to a removed slot. Fixed.
    • While a rotation is under way (the promoted release and its previous read different slots), the workflow accepts only a seal run, or an overlap run, which undoes the rotation on whatever commit is chosen and so reaches both slots.
    • Re-running an overlap or seal run whose revision is no longer pending or promoted is refused; the runbook says to start a new run on its commit instead.
    • The record simulation covers both of the reviewer's sequences, an undo, and a plain release of a rotation step's commit afterwards.

@allisonmahmood
allisonmahmood force-pushed the infra/415-deploy branch 2 times, most recently from 9326f0d to 9445ac1 Compare October 4, 2026 15:50
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Codex review, last check (on round five's guards). One finding, fixed in 9445ac1:

  • Re-running an overlap, seal or undo run that failed or was cancelled before it recorded itself was refused, because its revision was in neither record entry. That broke the documented "re-run it" recovery. Fixed. A release is now recorded as pending before anything deploys: the AWS credentials and the decision step run ahead of the image build. An interrupted run's re-run always finds its own entry. A rotation run that is in neither entry has been superseded by a later release, and is still refused. Rolling back away from a pending release that never reached its app deploy redeploys the promoted release as it was. The record simulation covers interrupted overlap and seal re-runs, rollbacks away from pending releases that did and didn't reach their app deploy, and the stale re-run refusal.

The reviewer found nothing else across first release, plain release, re-run, rollback, unfinished promotion, overlap, undo and seal.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Codex review, final narrow check (on recording the release before deploying). One finding, handled in 094bf5e:

  • A rotation run that fails before it can record its release (for example, AWS sign-in fails) deployed nothing, but its re-run is refused as superseded. Documented, as the reviewer offered. The refusal is safe: nothing deployed, and starting a new run is the correct recovery. A durable per-run marker would only change which way it is refused. The refusal message now names both causes (a later release superseded the run, or it failed before recording its release), and step 2 of the rotation runbook says to start a new run in that case.

The reviewer found nothing else in this change: no stranded budget, no hosts unable to manage the fleet's tasks, and no leaks into the public log.

Base automatically changed from infra/415-cdk to main October 4, 2026 19:31
…oduction runbooks

Nothing could deploy the CDK stacks, the spike promoted the fleet with
an inline `node -e` script, and the docs said production was unbuilt.

.github/workflows/deploy.yml runs on workflow_dispatch from main only,
behind the `production` environment's reviewer, one run at a time. It
assumes the deploy role through OIDC, stops promote tasks a cancelled
run left behind, records the release as pending, builds the
reproducible image, deploys the base stack, pushes the image with crane
(a rollback finds its tag and must match its digest), deploys the app
stack pinned to the digest with the promoted release as its previous
revision, promotes the fleet, and confirms the service's primary
deployment. Only merged commits deploy.

An SSM parameter only the workflow writes records the promoted release
and, while one is unfinished, the release being promoted, each with the
management secret slot it reads and the previous release it was
deployed beside. A release is pending from before anything deploys
until its promotion. Releases take their previous settings from the
record, never from the deployed stack, so a run that deployed but did
not promote cannot drop the revision the fleet still runs. A re-run
reuses its release's settings, and while a promotion is unfinished only
re-running it or rolling back to the promoted release may deploy.

Run logs are public: the account id, certificate and alert addresses
are environment secrets so they are masked, stack outputs and resource
ids are filtered out, and the promote task's output stays in CloudWatch.

`node dist/fleet.js promote <revision>` runs Fleet.promote as a one-off
host task after ECS settles: it stages the revision, waits up to five
minutes for its hosts to warm spares, and promotes it. It moves rollout
rows only, so it needs no task provider; it refuses a revision no host
has registered and returns at once for one already promoted.

A release's deployment revision is its commit. Rotating the management
secret writes the new secret into the secret's idle slot, where no
running host looks, then takes an overlap deploy that moves to that slot
and a sealing deploy. Each needs a revision distinct from the running one
or the ECS provider refuses to start, so the workflow's rotation input
suffixes them (<commit>-overlap-<run>, <commit>-seal-<run>). A failure
or rollback at any step leaves both slots readable. While a rotation is
under way, only its seal or an overlap that undoes it may deploy, and a
superseded rotation run cannot be re-run.

docs/OPERATIONS.md gains setup, deploy, rollback, restore and rotation
runbooks and names the host log group. The restore runbook says what
Neon's branch restore does not cover: Object Storage, and fleet rows
for tasks ECS has forgotten. ADR-0012 records the production topology;
the "not built" notes now say written but not yet deployed.

Part of #415.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@allisonmahmood
allisonmahmood merged commit 6b2a7c9 into main Oct 4, 2026
13 checks passed
@allisonmahmood
allisonmahmood deleted the infra/415-deploy branch October 4, 2026 19:43
@allisonmahmood allisonmahmood mentioned this pull request Oct 31, 2026
1 of 2 tasks
allisonmahmood added a commit that referenced this pull request Nov 1, 2026
## What changed

The server, its company exec tasks and fleet promotion now run on Bun
1.4.4 in production, the version the root `package.json` pins. People
notice nothing: patch code still runs in workerd and the CLI stays on
Node. CI now tests what production runs: the offline suite on Bun, every
CI lane's server on Bun, and the built image itself.

Closes #1040

Stacked on #1122 (`bun/seams`), which sits on #1120 (`bun/fmt`). #1122
fixes the stale-stop Supervisor test that failed only on Bun. This PR's
`test (bun)` runs it, and every other server test, without skipping.

## Look at

**1. How Bun gets into the image.** The runner stage is
`oven/bun:1.4.4-slim`, pinned by digest. Its `bun` is byte-identical to
the binary `pnpm-lock.yaml` pins (sha256 `10702245…`), which is the one
CI's tests run on. `scripts/build-server-image.mjs` refuses a runner
whose tag names another version than `"bun": "runtime:<version>"`, or
whose binary isn't the lockfile's. Users stay as #1040 describes: the
image's `bun` user is uid 1000 for hosts, and exec tasks run as root and
drop each workerd to its own uid. Node 24 stays as the builder stage.

**2. Rolling back across the runtime change.** Three places hardcoded
`node`, and each would have broken a deploy or a rollback:

| Seam | Before | Now |
|---|---|---|
| The host's ECS provider overrode every exec task's command with `node
dist/exec.js` | A Bun host would start the previous release's Node
spares with Bun, or the reverse | No override: each release's task
definition names its own runtime |
| `deploy.yml` promoted with `node dist/fleet.js` | A Bun-only image
couldn't promote | Promotes with the `fleetCommand` the image build
recorded (present since #521), so a rollback to a Node release promotes
with `node` |
| Older hosts still send `node dist/exec.js` | — | In the Bun image,
`node` falls back to Bun (the base image's `bun-node-fallback-bin`), so
a rolled-back Node host still starts this release's spares |

A scratch run (not in the repo) of a mixed fleet on one TLS+SCRAM
database:
- host A on the **Node** image from `main`, host B on the **Bun** image,
sharing tasks;
- `bun dist/fleet.js promote` promoted B;
- the Node image's own `node dist/fleet.js promote` rolled back to A;
- both hosts exited on SIGTERM.

**3. The two images, built locally and booted the same way.** Each
image's rootfs ran under bwrap as uid 1000, with the server as PID 1,
against a local Postgres that takes only TLS (verify-full, scratch CA)
and SCRAM. The machine was shared and loaded, so treat the numbers as
relative.

| | Node image (`main`) | Bun image (this PR) |
|---|---|---|
| Compressed layers (what ECR stores and Fargate pulls) | 187.0 MB |
190.0 MB |
| Unpacked | 526 MB | 488 MB |
| Boot, process start to `/healthz` 200, median of 7 | 1,228 ms | 996 ms
|
| RSS once ready, idle, median | 208 MiB | 167 MiB |
| SIGTERM to exit, idle, median | 18 ms (exit 130) | 16 ms (exit 130) |

**4. Which runtime each commit's server runs on in the rollback
rehearsal.** The rehearsal harness stays on Node, as #1121 left it. Each
checkout's server runs on the runtime its own `apps/server/package.json`
`start` script names: the same file that says how that commit runs,
`node dist/start.js` before this PR and `bun dist/start.js` from it. So
this PR rehearses live (Node) → this PR (Bun) → live (Node) → this PR
(Bun); once a Bun release is live it is Bun throughout. Reading it from
each checkout, not from the harness, keeps a later rehearsal across this
PR honest in either direction.

## How it was verified

**CI, new or changed:**
- `test (bun)` runs `pnpm test:bun`: the offline suite under `bun --bun
vitest`. `vitest.bun.config.ts` names the 15 Node-only files and says
why: 13 CLI process and dev-loop tests,
`packages/sdk/src/install.test.ts` and `lint/rules.test.ts`. `test
(22)`, `test (24)` and `test (26)` are unchanged and still run every
file. Nothing else is skipped: #1122 fixed the one real Bun-only
failure, and the other (`RequestEvents`) was a local port probe that CI
doesn't have.
- `image` (server-image.yml) now loads the built image and runs
`scripts/server-image-smoke.mjs` with Docker:
- two hosts on two revisions boot from the default command, as uid 1000,
against a TLS-only, SCRAM-only Postgres; connecting by IP (not in the
certificate) and without TLS are refused;
- `bun dist/fleet.js promote` promotes the staged revision, then rolls
back;
  - both hosts and the exec task exit on SIGTERM, not SIGKILL;
- the exec supervisor runs as root with AppStack's dropped capabilities,
and its standby workerd runs as its own uid;
  - `node` in the image runs Bun 1.4.4.
- `browser` (tier 1 and 2 pages), `cli-smoke`, `tier2-smoke` and
`clerk-live` (live Clerk) now start their server on the pinned Bun; the
CLI stays on Node.
- `rollback-rehearsal` starts each build's server on the runtime its
`apps/server/package.json` start script names, so this PR rehearses live
(Node) → this PR (Bun) → live (Node) → this PR. It runs here because the
rehearsal script changed.
- `NodeCryptography.test.ts` gains a credential and an agent retry copy
sealed on Bun 1.4.4. Node's lanes open them, which is the rollback
direction; the Bun lane opens the Node-sealed fixtures already there.

**Locally:**
- `pnpm lint`, `pnpm typecheck`, infra tests, `EcsTaskProvider.test.ts`,
and the crypto fixtures on both runtimes.
- `pnpm test:packed-tier2-e2e` with the server on Bun: PASS (packed
init, both dev mounts, publish, two-viewer sync, keyed retry, sharing,
files, members, CSV).
- The `browser` lane with the server on Bun: 53 tests passed across
`tier1`, `stream`, `server-subscriptions` and `starting` (local fleet,
idle release, host restart, HTTP/2 ingress). One `tier1` test failed
only on a stray `GET /` to its foreign-origin harness port. That's T3
Code's local port probe, which CI doesn't have, and that server is the
harness's own, on Node.
- The image smoke, end to end, through a scratch stand-in for Docker
(bwrap and unshare; Docker isn't usable on the build machine), plus the
mixed Node/Bun fleet above.
- TLS and SCRAM through Effect's sql-pg, on both built images. Each
connects only with the scratch CA, and refuses an unknown CA ("unable to
verify the first certificate"), an IP the certificate doesn't name, a
wrong SCRAM password, and plaintext.
- The real `@aws-sdk/client-ecs` against a loopback endpoint on Bun:
SigV4-signed, and the response parsed, the same as on Node. The S3
client already runs on Bun in the content-store contract tests.
- Process identity and reap: the image's exec entrypoint as root in a
user namespace with a uid range. The supervisor stays root; workerd runs
as uid 60000 and is gone within ~200 ms of SIGTERM. Started as `node
dist/exec.js`, the process is `/usr/local/bin/bun`.

**Shown only in production:**
- Neon itself: the local Postgres stands in for its TLS and SCRAM.
- The task role's credentials through ECS's container credentials
endpoint, and the Clerk production instance.
- Fargate's CPUs: no AVX2 risk. Bun 1.4's x64 releases are
baseline-only, and the pinned `oven/bun:1.4.4-slim` image ships the
`x64-baseline` binary, byte-identical to pnpm's pin. That was checked in
review against Bun's v1.4.4 slim Dockerfile.
- Memory over several hours.
- Not done here, as #1040 scopes it: `BunHttpServer` stays a separate,
measured follow-up (`Bun.serve` closes silent connections after 10 s
unless streams set `idleTimeout: 0`). The server keeps
`@effect/platform-node` through node:http compat, as the 2026-10-28
trial ran it.

## Release impact

- [ ] **Breaking** — requires action from anyone already running this
- [x] **Not breaking** — no action required

The runtime under the server changes; nothing anyone runs or calls does.
The CLI, the API and the schema are unchanged.

- **What does a revert leave behind?** No data in a new shape: no
migration, and rows are written by the same code on either runtime.
Credentials sealed on Bun open on Node (the new fixture runs on every
Node lane). In ECR, the Bun image stays tagged with its commit. Exec
task definitions from the Bun release stay registered (as every
release's do) and name `bun dist/exec.js`.
- **Does the release before it still work with that?** Yes. A rollback
runs the Node release's own task definitions and promotes with its own
`node dist/fleet.js`. While its hosts still replenish this release's
spares, they start them with `node dist/exec.js`, which the Bun image
runs on Bun. The rollback rehearsal and the mixed-fleet run above
exercise that path. Not `one-way`.

Built by Claude Opus 5.5 (xhigh effort) in T3 Code, via Claude Code.

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area area:server Touches the server area size:l 501-1,000 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(infra): production infrastructure in AWS CDK and the deploy workflow

1 participant