Atlas and Metal upgrade ops: metald rollout plan

This is the plan for frappe/atlas#262. It is a proposal that waits for approval. Nothing in it is implemented yet.

Last updated 13 October 2026

1. Situation

metald is the daemon on each Metal host. It runs the Firecracker VMs, their network, and their consoles. Atlas builds it from the monorepo and gives it to the hosts. These are the problems with that process today:

2. Scope

In this change setLater, as separate work
  1. The operator can set a build version. Without one, the version is a development timestamp.
  2. Each host reports its metald and wg-mesh versions, and Atlas shows them.
  3. A new Operations module with the Metald Update doctype: batches, wait and watch, health gate, pause, resume and cancel.
  4. A safer upgrade on each host: a readiness check, a VM unit check, and self-rollback after a late crash.
  5. No refused connections during a restart: the listening sockets stay in the systemd file descriptor store.
  6. wg-mesh ships in the same update, with a CI check for BPF map compatibility.
  • An Atlas maintenance mode (writes return 503 with Retry-After), and a deploy that does not restart socket.io. This needs the production process layout first.
  • The console page reconnects after a metald restart.
  • A Metal API breaking-change check in CI (oasdiff), and feature flags so a new Atlas can call an old metald.
  • An idempotent patch runner in metald for state on the host. No current change needs it.
  • A phased http-proxy rollout that uses the same rollout code.
  • An end-to-end test on bare metal (#194), a release branch, and release reports.

tableflip is not needed. Section 7 explains why.

3. Build version

There is no release system yet. So the version is optional input to the build:

pilot --site atlas.localhost build-metald --version 1.4.0   # metald 1.4.0
pilot --site atlas.localhost build-metald                   # metald dev-20261013T101500Z
pilot --site atlas.localhost build-wg-mesh --version 1.4.0  # same rule for wg-mesh

4. Version on each host

5. Metald Update doctype

An operator uses one Metald Update record to move a set of hosts to one pinned build. The record upgrades the hosts in batches. After each batch it waits, checks the health of the hosts, and then continues. On any failure it pauses.

Structure

The pinned build is copied once, when the record is created. Later builds do not change a record in progress.

Fields

Metald Update (module Operations, name METALD-UPDATE-.#####)

FieldTypeOwner and rule
statusSelect: Draft, Running, Paused, Completed, CancelledChanged by the rollout job and the Desk actions
versionData, read onlyCopied from Atlas Settings when the record is created
metald_binary_file, metald_binary_hashLink File, Data, read onlyCopied when the record is created
wg_mesh_binary_file, wg_mesh_binary_hashLink File, Data, read onlyCopied when the record is created
canary_sizeInt, default 1Number of hosts in the first batch. Edit only in Draft.
batch_sizeInt, default 5Number of hosts in each later batch. Edit in Draft or Paused.
wait_minutesInt, default 10Time to watch a batch before the health gate. Edit in Draft or Paused.
current_batchInt, read onlySet by the rollout job
wait_untilDatetime, read onlyThe end of the watch time for the current batch
failure_messageSmall Text, read onlyWhy the update paused
serversTable: Metald Update ServerRows can be added, removed and reordered only in Draft

Metald Update Server (child table)

FieldTypeOwner and rule
serverLink Metal ServerUnique in the table
batchInt, read onlySet on Start from the row order
statusSelect: Pending, Upgrading, Upgraded, Failed, SkippedThe rollout job sets Upgrading. The host job sets Upgraded or Failed.
previous_versionData, read onlyThe version that the host reported before its upgrade
ssh_taskLink SSH Task, read onlyThe script output
failure_messageSmall Text, read onlyWhy this host failed

The update does not store counts, because the rows give them. The Metal Server gets two read-only fields: metald_version and wg_mesh_version. They go next to metald_tls_expires_on.

Form mockup

METALD-UPDATE-00003 Running
PauseCancel

Build

1.4.0
Running

Rollout

1
5
10
2 of 3
13-10-2026 11:42

Servers

ServerBatchStatusPrevious VersionSSH Task
metal-waw-11Upgradeddev-20261002T0814ZSSH-TASK-0412
metal-waw-22Upgradeddev-20261002T0814ZSSH-TASK-0418
metal-waw-32Upgradingdev-20261002T0814Z
metal-waw-43Pending

The buttons depend on the status. Draft shows Start. Running shows Pause and Cancel. Paused shows Resume and Cancel. Cancel asks for confirmation.

States

Rollout example

Twelve hosts, with a canary size of 1, a batch size of 5 and a wait of 10 minutes:

Each host upgrade takes about one minute. The wait time controls the total time.

How it works

  1. Create. The record copies the version, the files and the hashes from Atlas Settings. It adds each Running Metal Server whose metald_version is different. The operator can remove or reorder rows. The Metal Server list action "Upgrade Metald" changes to "Create Metald Update", which uses the selected servers.
  2. Start. This assigns batch numbers from the row order. It fails when another update is Running or Paused, or when a server is in another open update.
  3. Rollout job. It runs every minute with one job ID, so only one copy runs. For the current batch, it locks the record and sets each Pending row to Upgrading. It commits, and then it queues one host job for each row. A server that is not Running gets the Skipped status, which does not count as a failure.
  4. Host job. It uses the Metal Server metald_job_id, so it never runs next to another metald operation on that host. It runs upgrade-metald.sh with the pinned URLs and hashes. Then it writes only its own row: Upgraded or Failed, the SSH Task, and the message.
  5. Watch. When all rows in the batch are done, any Failed row pauses the update. If no row failed, the job sets wait_until to now plus wait_minutes.
  6. Health gate. After the wait, each upgraded host must meet two conditions. It must report the target version, and its last sync must be less than 2 minutes old. If a host fails the gate, its row becomes Failed and the update pauses.
  7. Next batch or, when no rows are left, Completed.
  8. Pause stops new batches. Host jobs that are running finish. Resume sets Failed rows back to Pending and continues. Cancel is final.
  9. Stale row. If a row is Upgrading for longer than the script timeout plus 5 minutes, and its job is gone, the row becomes Failed with the message "upgrade job stopped".
  10. Roll back the fleet. Duplicate an older Metald Update. A duplicate keeps its pinned files. The cleanup of unlinked files, which runs every 15 minutes, keeps every file that a Metald Update links.

The "Upgrade Metald" button on a single Metal Server form stays. It is the quick path for one host, and it uses the latest build.

6. Upgrade on one host

These steps are added to upgrade-metald.sh. The download, the hash check, the version smoke test and the backup already exist.

Why STATUS and not Type=notify: with Type=notify, a rollback to an old binary that never sends READY=1 would hang until the start timeout, and then fail. STATUS works with the current unit, which already has NotifyAccess=main. If a very old unit does not have that setting, the script checks only is-active and prints a warning.

7. Restart without refused connections

Why not tableflip

tableflip runs the old and new processes at the same time and passes the listeners from one to the other. metald owns resources that only one process can own at a time: PTY readers, VM units through D-Bus, BPF attachments, reconcilers and migration records. The old process must release all of them before the new one starts. So the overlap gives nothing that the descriptor store does not already give. tableflip would also add a dependency. The descriptor store is already in use.

8. BPF maps

A BPF map is kernel memory that a BPF program reads and writes. A map is "pinned" when a file under /sys/fs/bpf keeps it alive after the process that made it exits. Two components use BPF, and they follow different rules.

metald traffic monitor (not pinned)

wg-mesh datapath (pinned)

The mesh programs stay attached when no process runs. So packets continue to flow during a metald restart. An upgrade replaces the programs in this sequence (this logic already exists in services/wg-mesh/cli):

  1. The new atlas-wg-mesh opens each pinned map that has a name in its object file. It checks the type, key size, value size, maximum entries and flags with MapSpec.Compatible.
  2. It reuses the compatible maps, creates the new maps, and pins its programs under releases/<build hash>.
  3. It fills new maps from the VM interfaces on the host.
  4. tc filter replace swaps each hook atomically. If a step fails, the hooks go back to the old release.
  5. It writes build_hash, and removes the old release and the maps that no program uses.

If a map layout changed, step 1 fails with "reset is required". EnsureHost fails, so metald does not start. The script restores both old binaries. The old programs stay attached the whole time, so packets do not stop. The rollout pauses at the canary.

Rules

9. Compatibility

SurfaceEffect
POST /v1/syncTwo optional response fields. An old Atlas ignores them, and an old metald does not send them.
Metal Server, Atlas SettingsNew read-only fields. They are empty until the next build or sync. No patch is needed.
Metal Server list actionThe bulk "Upgrade Metald" changes to "Create Metald Update". This is a Desk change only, with no API change.
systemd unitA drop-in only. The base unit does not change. Without a descriptor store, metald listens as it does today.
BPFNo map change.
FilesFiles that a Metald Update links stay. Other unlinked files are deleted as today.

10. Failure cases

CaseBehavior
The rollout job runs twiceIts job ID prevents a second copy. A Pending row becomes Upgrading only under the record lock.
A worker is killed during a host jobThe script on the host finishes or rolls back by itself. The row becomes stale, then Failed, and the update pauses.
Atlas is down during a rolloutHost scripts finish. The rollout job continues on the next tick, and the health gate uses the sync time.
A bad binary passes the canary and crashes laterSelf-rollback inside 30 minutes. Sync shows the old version, so the gate fails and the update pauses.
The metald restart stops VMsThe VM count check fails on the canary, and the rollout stops.
BPF map layout changedmetald does not start. The script rolls back, and the datapath has no gap. CI catches this before merge.
200 hostsThe batch size limits how many hosts upgrade at once. Each host job is one SSH job on the long queue.
Who writes whatThe rollout job owns the update status, the batch fields, and the change from Pending to Upgrading. A host job owns its row result. Desk actions change the status under the record lock. The rollout job reads the status again under that lock before each change.
Operator viewThe status, current batch, wait end time, row status, SSH Task and failure message, without SQL.

11. Verification

12. Commits

  1. build(metal): Default the build version to a development timestamp: the Makefiles, --version, and the Atlas Settings version fields.
  2. feat(metal): Report the metald and wg-mesh versions in host sync: the sync response, and the Metal Server fields and list column.
  3. feat(metal): Keep the listening sockets across a metald restart: listeners in the descriptor store, and the readiness status.
  4. feat(atlas): Check readiness and roll back a failed metald upgrade: the script, the rollback drop-in, and the wg-mesh install.
  5. feat(atlas): Add the Metald Update rollout: the Operations module, the doctypes, the rollout job, and the list action.
  6. build(wg-mesh): Check BPF map compatibility in CI
  7. docs(atlas): Document the metald rollout: the operator runbook and the SPEC.md updates.

13. Decisions needed

  1. Is the doctype structure and form layout above good?
  2. Are the defaults good: a canary of 1, a batch size of 5, and a wait of 10 minutes?
  3. Does wg-mesh ship in the same Metald Update as metald? I recommend yes.
  4. Is a self-rollback window of 30 minutes good?
  5. Do we replace the bulk "Upgrade Metald" list action with "Create Metald Update"? I recommend yes, so there is only one way to roll out to the fleet.