Skip to content

Deploy a change

A change reaches gomoe.dev in one of two ways. Once following is on, the follower on the server host deploys main’s head by itself whenever it finds a new one, and an operator can deploy a checkout’s head by hand. Both run the same lines on the host under the same lock, keep a commit only once the same health check passes, and name it in the SSM parameter /agents/deployed (ops/aws-deploy/release.ts).

agents-follow.timer on the host runs ops/aws-deploy/follow.ts 2 minutes after its last run ended. A run reads /agents/follow, asks GitHub for the head of the branch it names with the credential at /agents/github/follow-credential, and when the head is new does these things.

  1. Deploys it, as deploy.ts does.
  2. Keeps it once GET /v1/me answers 401, the API’s answer to a caller with no session, through the load balancer six times in a row, 5 seconds apart, within two minutes. Any other answer starts the count again. It then writes the commit to /agents/deployed.
  3. When the install or the health check fails, writes the commit to /agents/deploy-failed and deploys the commit /agents/deployed names again, which must pass the same health check. With nothing in /agents/deployed, as before the first deploy that passed, there is nothing to roll back to. A failed commit is not tried again until the branch moves.
  4. After a deploy that passed, builds and pushes that commit’s computer image, and writes it to /agents/imaged, or to /agents/image-failed when the build fails, and that commit’s image is not built again. A run that finds the head deployed but not imaged builds its image.

gomoe.tfvars sets follow_branch = "main", from which Terraform makes /agents/follow. AGENTS.md says the apply of that setting waits on a practice failure, as of 2026-11-25. Until it is applied, /agents/follow is missing and each run says nothing is followed.

A merge that lands while a deploy or an image build runs waits for that run to end and 2 more minutes. A run deploys the head it finds, so when two merges land between runs, only the later one is deployed. Once /agents/follow exists, each run that finishes tells Watchtower it ran, once /agents/watchtower and /agents/watchtower/follow-token are in SSM. Watchtower emails the watchtower_notify list when a deploy fails or rolls back or the image build after it fails (deploy-failed), when a rollback fails too (deploy-rollback-failed), and when no run has told it so for 15 minutes (follower-silent).

To see what the next run would do, run node ops/aws-deploy/follow.ts --dry-run on the host. It reads the same settings, credential, branch head and parameters, prints the step, and installs and writes nothing.

Run these from a laptop with AWS_PROFILE=gomoe and the region us-east-1. To pause, put the parameter with the reason as its value.

Terminal window
aws ssm put-parameter --name /agents/follow-paused --type String --value <why>

While /agents/follow-paused exists, a run deploys nothing and builds no image. A deploy by hand still works. To resume, delete it.

Terminal window
aws ssm delete-parameter --name /agents/follow-paused
  1. From a checkout with AWS_PROFILE=gomoe and TF_DATA_DIR=~/.agents-app/terraform/gomoe set, check out the commit to deploy and run this. Uncommitted changes are not deployed, and the command warns when a tracked file has any.

    Terminal window
    node ops/aws-deploy/deploy.ts

    It uploads the commit as a git bundle to the objects bucket, then has the host check it out in /srv/agents and run ops/aws-deploy/host.ts as root. The host waits up to 30 minutes for the deploy lock, /var/lock/agents-deploy, when another deploy or image build holds it.

  2. Read the last lines. <commit> is live at https://gomoe.dev means the deploy was kept. rolling back to <commit>, the last commit that passed means the host’s lines or the health check failed, and rolled back: <commit> is live again that the rollback passed. no earlier commit passed, so there is nothing to roll back to means /agents/deployed is empty, as before the first deploy that passed, or names the commit just deployed, as when the live commit is deployed again. The command exits 1 for a failed deploy, rolled back or not.

  3. Build the computer image of the commit the server now runs.

    Terminal window
    node ops/aws-deploy/deploy.ts --image

    It refuses unless /agents/deployed, the last commit that passed, names that commit, so the image’s daemon matches the server it talks to.

When SSM holds /agents/watchtower and /agents/watchtower/deploy-token, each deploy of the server opens a Watchtower deployment window and closes it with the outcome (ops/aws-deploy/window.ts). An image build opens none. Inside a window, a computer’s keeper holds its daemon’s calls once the API stops answering, until the API answers the keeper’s probe again, the deploy marks the window live or closes it, the keeper’s last good listing of windows is 2 minutes old, or a minute after the window’s deadline passes, whichever comes first. Calls already sent are not held.

A deploy of the server changes no image, so a running computer keeps the daemon it started with. Once an image build puts a newer image in the registry, the runner’s pass each minute moves running computers onto it (moveToNewestImage in server/boxes.ts). A computer moves only with nothing in hand and no run, pass or attempt holding it. The move makes a new container from the newest image on the computer’s home and its team’s folder, with a new machine token, and keeps nothing else the old container held, as Tayler decided on 2026-11-28. At most two computers move a minute. A busy computer moves at a later minute once its work ends, and one asleep or stopped starts on the newest image when it next starts.

Migrations are the .sql files in server/migrations. The API applies each one that has not run, in name order, before it listens. It runs each in its own transaction and records it in the schema_migrations table, so a migration never runs twice. A lock keeps two processes from applying migrations at once. A deploy has no separate migration step.

A migration that fails stops the API, and the log names the file and its SQLSTATE but not the database’s message, which can quote a row. The failed migration is rolled back, and the migrations before it stay applied. The stopped API fails the health check, so the deploy rolls back to the last good commit, when one has passed before. Going back to older code does not undo a migration. The older code runs against the newer schema.

Neither deploy.ts nor follow.ts rehearses migrations. On the developer’s Mac, bin/agentsctl db rehearse --dump <file> restores a pg_dump --format=custom dump into a postgres:17 container of its own, applies the new code’s pending migrations there, and prints each migration it applied and each table’s row count before and after, or the migration Postgres refused with its SQLSTATE. Run it in the new code’s checkout. Nothing touches the database the dump came from, and the container goes when the run ends.

The nightly backup writes a dump in that format to backups/<date>/record.dump in the objects bucket. The copy needs room on Docker’s disk, about 11 times the dump and 2 GiB more, and the command refuses with less. The first rehearsal of a dump of the live database is Tayler’s to run, since no agent makes or reads one. ops/aws-deploy/restore-rehearsal.ts restores with the same --no-owner --no-privileges, and on 2026-11-11 it restored, with no error, a dump the nightly backup made when it was run once by hand on the AWS stack. No db rehearse run of a gomoe.dev dump is recorded.