Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ADR 0048 — Updates, restore points and backups from Studio

Status: proposed (2026-11-13, owner request). Design: canvas row Updates, restore points, backups (LinkUpdate*, BrokerUpdate*, Backup*, LinkBackup); Studio side: studio/docs/design/specs/updates-backups.md.

Context

What exists today:

  • Packages (ADR 0011, 0043). Installing a newer version of a package (from the repository, a zip, a URL or git) replaces the old one: install_package unpacks the new version, restarts every link that runs it (upgrade_links; a WASM app gets a hot start) and deletes the old version’s directory. There is no way back and no check that a link came back with its nodes. The repository index is read every hour, but nothing says that an installed package has a newer version.
  • Link state. A framework link keeps its runtime edits and secrets sealed in data_dir/links/<id>/data (framework.tree, ADR 0004); a portable app keeps its sealed store there (ADR 0023). Framework links export and import their settings as JSON (wyrm-driver-branch/1); there is no export of a link as a whole (settings, private data, package, grants, net).
  • The broker. wyrmd is updated by hand: replace the binary, restart under systemd (docs/operations.md §2). No release index, no signature, no way back once the registry SCHEMA moved (today 19).
  • Backups are offline copies of data_dir with the broker stopped (docs/operations.md §3), plus wyrmd keys export for the keys. The standby (ADR 0036) already knows how to copy every store consistently while the broker runs: WAL records, sealed files in parts, the storage journal and history rows (control/replication.rs, sys/replication/**).

The owner asks (2026-11-13): update links and the broker from Studio by a remote command, with a way back that restores the state; official links update from the repository, custom ones by bringing a new archive, and the nodes and state of the previous version are kept; export a link as one zip; back up the broker from Studio with checkboxes per section (history, storage, dataflows, links, …).

Decision

1. Package updates with restore points

  1. sys/packages/<name> shows version, latest (from the repository index; empty for custom packages), update_available (bool), previous (the version kept for a rollback, with keep_until) and last_update (a map: from, to, at, result = ok | rolled_back | failed, kept, new, gone counts and up to 200 keys of new and gone). sys/links gains updates_available (count) so Studio can badge it.
  2. Action sys/packages/<name>/~act/update {version?, accept, restore_point = true, auto_rollback_s = 120} (config, audited): installs version (default latest) from the repository with its SHA-256, the same flow as install_repo. A custom package is updated by the existing install_zip / install_url / install_git with the same package name; they take the same three new arguments.
  3. Before anything stops, for every link that runs the package: a restore point, which is a link backup (§3.5) without history, written to data_dir/restore/<link>/<UTC>.wyrm-link, and the link’s current key list (~meta?view=keys of its root). Restore points are listed at sys/links/<id>/restore_points (at, version, size) and pruned after packages.keep_previous_days (default 7).
  4. The previous version’s directory is kept (no remove_dir_all) until keep_until; the registry’s PackageDef keeps previous.
  5. Health after the restart: every link of the package must say hello and declare at least every key it had, within auto_rollback_s. Keys that do not come back are gone; new ones are new. With auto_rollback_s > 0 and anything gone (or a link that never says hello), the broker rolls back by itself (§1.6) and audits update_rollback with the reason. With 0, it keeps the new version and reports.
  6. sys/packages/<name>/~act/rollback {to?} (config): reinstalls previous from its kept directory, stops the links, restores each link’s private data from its newest restore point taken before that update, starts them. A rollback is itself recorded in last_update.
  7. Store format: the package manifest gains state (integer, default 1) and reads_state (list, default [state]). An update whose reads_state does not contain the installed state is shown as changes the store format (Studio’s review says so); the rollback then needs the restore point and Studio does not let the person untick it.
  8. One version per package stays the rule: every link of a package is updated together (Studio lists them).

Rules fixed when §1 was built (2026-11-13; the guide is docs/links.md §5a):

  • Values. version, latest, update_available, previous, last_update are value nodes of sys/packages/<name> (they move while an update runs), beside state and changes_state (the update to latest changes the store format). previous is {version, keep_until, changes_state}; times are unix seconds. last_update carries the counts kept, new, gone, the lists new_keys and gone_keys (<link>/<path>, ≤ 200 each), reason, links, changes_state, restore_point. Its result has a fourth, passing value: checking, while the health check runs. updates_available is an attribute of sys/links, beside catalog (a child node there would read as a link to whoever lists the links: Studio’s Links page does), and counts links (the rows of Studio’s tab).
  • Custom. A package is custom when the repository index does not list its name for this host. update_available compares versions (dotted numbers as numbers, a release over its pre-release); update {version} takes only the index’s version (an index names one), and a version that is not newer only when it is named.
  • The update answers at once. The admin serves one action at a time and a link’s hello is one of its actions, so the health check runs after the action answered ({success, message}, like an install); Studio follows last_update. Until it ends, installs of the package, its Remove and its links’ Start/Stop/Remove answer busy; rollback stops it and rolls back.
  • Health. A link is back when it answers ~meta?view=keys of its root, read without a token (restricted subtrees are not counted). The check ends early when every link is back with every key and nothing changed for 3 s (12 s after a hot start: the old code’s nodes are swept 10 s after it). auto_rollback_s is 0 to 600. With 0 the report is made when every link answers and its keys are stable for 3 s (ok, with gone and a reason), or failed after 120 s without an answer. A link without a key list (stopped before, or over 10 000 keys) only has to answer.
  • Rebuilds. A rebuild of the router waits for the update up to the restart of the links, and for a rollback, as it waits for an install. It does not wait for the polling of the health check: a link may need that rebuild to say hello (one installed a moment before, a grant the update added), and waiting would hold every ACL change for the window. The check steps aside and goes on with the new router with the time it had left (at least 30 s). A broker process that ends during the check leaves failed at the next start; the new version stays.
  • Rights. accept covers grants and net entries the new version asks for and a link lacks; they are added to each link and stay after a rollback.
  • Restore points. data_dir/restore/<link>/<UTC>.wyrm-link and <UTC>.meta (CBOR: time, package, version, size, the key list for the health check, entries skipped). The archive is the link backup of §3.5, made by Control::link_backup_to’s code with the sections settings and data (no history, no package: the package a link ran is kept once, as the package’s previous version of §1.4, not once more in every link’s restore point). It is sealed how: broker (a key from secrets.key), so a restore point needs no passphrase and no backups.export_secrets, and never leaves the broker by itself; install_backup on the same broker takes one as any link backup. A rollback gives the stopped link its secrets and private data back (Control::link_restore_data): the data directory is built new beside the old one and swapped in with two renames. wyrm_admin::restore_point keeps the directory only (names, .meta, list, prune); it knows no archive format. The provisional sealed zip of the first build is gone. The order of §1.3 is kept (the copy is taken while the link runs), so the copy follows no symlink: each entry of the link’s data is opened once with O_NOFOLLOW, checked against the held parent directory and sealed from that handle; what is not a file or directory is skipped and counted; a restore creates every directory and file new. This walk is wyrm_admin::nofollow, and every copy of a link’s private data into a backup goes through it (a link backup, the links section of a broker backup, a restore point). Scratch (uploads/, tmp, *.tmp, agent.next) is left out; at most 50 000 files and 8 GiB (what the reader of a link backup takes). Replacing a link through install_backup takes the same kind of restore point first (§3.5), listed in restore_points and pruned with the others; it has no key list (a restore has no health check). Not copied to a warm standby.
  • After a rollback nothing is kept: previous is empty and the directory of the version that was rolled back is deleted. Installing the kept version again (same bytes) reuses its directory.
  • Store format. state ≥ 1; reads_state has 1 to 32 entries and must hold the package’s own state. The repository index may carry both (wyr repo add and the official index copy them from a manifest that names them), so changes_state is known before the fetch; the manifest in the zip decides. restore_point: false is refused when the format changes, and such a rollback is refused for a link that has no restore point.

2. Broker updates

  1. Install layout for self-updating brokers: <prefix>/versions/<v>/wyrmd, <prefix>/current → versions/<v>, <prefix>/bin/wyrmd-guard (a copy of the running binary, refreshed only after an update is confirmed). The systemd unit runs ExecStartPre=<prefix>/bin/wyrmd-guard update-guard and ExecStart=<prefix>/current/wyrmd. docs/operations.md gains the layout and the unit.
  2. Config: updates: {mode: "off" (default) | "external" | "self", channel: <URL of the releases index>, keys: [<Ed25519 public keys>], trial_s: 180, keep_days: 7}. The WYRM release key is built in; keys adds others (a company mirror). external (containers, distribution packages) refuses update with a message and shows how to update outside.
  3. Releases: a new release workflow publishes wyrmd-<version>-<target>.tar.gz, a signed release document with its SHA-256, and a signed releases.json (version, date, notes URL, targets, min from version, schemas it writes, replication protocol version). Until that workflow exists, update {file} takes an uploaded archive with its signature (parts, as ADR 0028).
  4. sys shows update_available, latest, update_state (none | staged | trial | confirmed | rolled_back) and update_last (map). Action sys/~act/update {version, confirm_site} (config, audited; confirm_site must equal the site name):
    1. download into versions/<v>.part, check signature and SHA-256;
    2. run versions/<v>/wyrmd check -c <config> (the new binary checks this configuration);
    3. pre-update backup of the control plane and keys (§3 sections control and keys, sealed with a key derived from secrets.key, so no passphrase is needed) into data_dir/backups/pre-update-<v>.wyrm-backup;
    4. write data_dir/update.json {from, to, state: "trial", attempts: 0, deadline, backup}, point current at versions/<v>, copy the running binary to bin/wyrmd-guard, and stop cleanly (exit 0; systemd Restart=always starts the new one).
  5. Trial: the new wyrmd increments attempts first thing. It is healthy when the router is up, the gateway listens, the admin answers and every link that was connected before the update says hello (process links get trial_s). Healthy → state: confirmed, audit update_confirmed, the guard binary is replaced by the new one. Not healthy by deadline, or attempts ≥ 3: it exits with code 76.
  6. update-guard (the previous binary) runs before every start: with state: trial and (attempts ≥ 3 or the deadline passed or a 76 recorded), it points current back at from, restores the control-plane files from the pre-update backup when the new version moved a SCHEMA, sets state: rolled_back and lets systemd start the old binary. Audit update_rollback is written by the old binary at start.
  7. sys/~act/rollback_update (config) after a confirmed update, until keep_days: same as §2.6, on purpose. Changes made after the update are lost (the pre-update backup is restored); the review says so.
  8. Standby pair (ADR 0036): update refuses on the active while the standby runs an older version and the release changes the replication protocol; Studio offers to update the standby first (through its own sys, reached via the peer link). The same action reaches a downstream broker through its upstream with allow_config (ADR 0018).

Rules fixed when §2 was built (2026-11-13; the guide is docs/operations.md §2 “A broker that updates itself”, the release side packaging/wyrmd/README.md). Code: wyrm_admin::release (format, unpack, layout, guard: files only), wyrm_admin::control::broker_update (what a running broker does), wyrmd::update (identity, check mode, the standby’s side, release tooling), tests crates/wyrmd/tests/update.rs.

  • Mode. updates.mode is off by default: nothing is fetched, update is refused. external needs updates.channel, reads the index and shows latest, update_available and, in update_hint, what to run outside the broker; update is refused with that text. self is refused with the reason (update_hint shows it too) when the running binary is not <prefix>/versions/<its version>/wyrmd with <prefix>/current a symbolic link to that version and a file <prefix>/bin/wyrmd-guard, and when the guard did not run before this start (it leaves data_dir/update.guard; without the guard a failed update could not be taken back). wyrmd install-layout <prefix> makes the layout from a binary. Unix only; other targets compile and refuse.
  • Signature and keys. A release is one JSON document: wyrmd_release: 1, version, date, notes, min_from, schemas (registry, audit, users, flows), replication, and per target (<arch>-<os>[-musl]) the archive’s file, size, sha256, url and bin_sha256 (the SHA-256 of the binary in the archive). Its signature is detached: Ed25519 over wyrmd-release-v1\n + the document’s bytes, hex, one a line (several lines: one good one is enough, for a key that is replaced). The index is {wyrmd_releases, sequence, created, releases} with entries {release, signature}: each a release document as text with its own signature; the index as a whole is signed over wyrmd-releases-v1\n + its bytes. The two domains keep an index signature from signing a release. updates.channel serves one file, {wyrmd_channel, index, signature}: the index text and its signature together, so a reader never has one without the other (review of PR 74, point 7; a read that fails is also tried again after 5 minutes and never replaces the index read before). A broker checks the index’s signature and then every entry’s own; one entry that does not verify refuses the whole index, and nothing of an entry is used that its signature does not cover (version, SCHEMA numbers, size and SHA-256 of each archive, SHA-256 of each binary). So an index that was signed without being checked cannot carry an unsigned entry (security review of the workflow, 2026-11-13). The keys are the ones built into the binary (release::RELEASE_KEYS, empty today: the project has no release key yet) and updates.keys; with no key pinned nothing is trusted. No key is ever read from a release file. The archive is .tar.gz (the workspace has flate2, no zstd).
  • Freshness of the index (review of PR 74, point 5). sequence goes up by one with every index published and is under the index’s signature. A broker keeps the highest sequence it has read in data_dir/update.seen and refuses a lower one: an old, validly signed index that is put back (to hide a release with a fix) is refused, and the index read before stays in use. The file is not in the registry (no SCHEMA change for it); a host whose data_dir is new starts at 0. Only a missing file is 0: a file that is there and cannot be read as one number (not readable, not a plain file, over 32 bytes, not a u64) refuses every index and is never written over, and the directory is synced after the file is renamed into place, so a power loss does not bring an older number back (issue 184; recovery in docs/operations.md §2). wyrmd release index --from <channel file> writes the next index (sequence + 1) only when the published one verifies and holds every version given with --have; the workflow passes every release tag that exists, so it does not sign on top of an index that was put back.
  • The signing job (review of PR 74, point 6). The workflow builds without a build cache. The key is in the environment of two steps of the job sign (environment wyrmd-release), which builds its tool from the tagged source itself and has contents: read; the job publish has contents: write and no key. release doc checks each archive against its description and the binary in it against the hash that is signed.
  • The channel holds no credential. updates.channel is https:// (plain http only to loopback), without userinfo, query string or fragment: refused when the configuration is read, with a message that does not repeat the URL. It is shown in sys and in the config copy of a backup (CONFIG_SHOWN; the mask’s second net strips userinfo and what follows ? or # all the same). A private channel that needs a credential would take it from the secret store; not built.
  • Before anything is unpacked or run: the signature of the document, its bounds, the rules below, then the size and SHA-256 of the archive against the signed document.
  • Version and SCHEMA rules (Release::compatible). A build for this host must exist. The version must be newer than the one that runs (dotted numbers as numbers, a release over its pre-release; a name that is not dotted numbers is never newer): an update never goes down, rollback_update is the only way back. min_from must not be newer than what runs. Every SCHEMA the release writes must be at least the one this broker writes, and none may be left out: a release never goes below what data_dir holds. A release (or a running version) that names a store other than registry, audit, users, flows is refused: the guard of this version could not put such a store back (review of PR 74, point 1); it is installed by hand. With state_anchor_dir set, a release that moves a SCHEMA is refused (a rollback would put back a WAL older than its anchor): update by hand.
  • Unpack. Into the new directory versions/.<v>.part, renamed to versions/<v> when all of it is on disk. Plain files only, by plain name (no directory, no .., no leading .), at most 9, the binary wyrmd among them and executable in the archive; symbolic and hard links, devices, pipes, directories and extension headers refuse the whole archive, and so do the names release.json and release.sig; each file is created new; the modes are the broker’s (0755 the binary, 0644 the rest), no owner or time is taken; the binary at most 1 GiB, another file 1 MiB, the archive 512 MiB; data after the end mark refuses it. The SHA-256 of the unpacked binary must be the bin_sha256 of the signed release. The release document and its signature are then written beside the binary (versions/<v>/release.json, release.sig).
  • The new binary proves itself before the switch, each time with an argument vector, an empty environment and 120 s: wyrmd release-info must say the version, schemas and replication of the signed release and this host’s target; wyrmd -c <config> check --state <copy> must take this broker’s configuration and open every control-plane store with its own state types. The copy is data_dir/update.check (0700): each WAL as of one sequence number (wyrm_state::replicate::copy_to) with its key file, removed after the check. The live stores are never opened by the new binary before the switch.
  • The pre-update backup is a job of sys/backups with kind: pre-update, pinned, of the section control alone, sealed for this broker (how: broker: its manifest carries a MAC under a key from secrets.key). Decided: no keys section (§2.4.3 said both). An update replaces a binary, never a key file, the guard restores WALs only, and keys without a passphrase is refused by §3.4. The guard checks the file’s SHA-256 against update.json, the manifest’s MAC with secrets.key, and every file it reads against the manifest. It is unpinned when the update is rolled back, when it is no longer kept (below), or when the next update is committed.
  • update answers at once ({success, message, version, restart}), like a package update: the admin serves one action at a time and the fetch, the check and the backup take minutes. Studio follows update_state (none, staged, trial, confirmed, rolled_back, failed) and update_last (from, to, result, at, by, reason, attempts, deadline, keep_until, restored, without_s, links, backup, schemas_moved; step while one is prepared: fetching, checking, staged, backup). An update that ends before the switch leaves update_state: none, update_last.result: failed with the reason, an audit record, and no version directory. update?check (ADR 0047) refuses what update refuses before it fetches the archive; it answers ok or a refusal, not a list.
  • Without a releases index (today): the archive is uploaded in parts with the upload of the backups (sys/backups/~act/restore_begin, restore_part, restore_abort; ADR 0028 bounds), then update {upload, release, signature, confirm_site} with the release document and its signature as text. check_updates reads the index now.
  • One job at a time. update and rollback_update are refused with busy while a backup is made or sent, a restore is staged, a package or a link is held by an operation (the claims of §1.9), another update is prepared or in its trial, and while the router is rebuilt; the check is made again after the pre-update backup, right before the switch. From its first step an update of the active holds the broker with the claim a restore with mode: replace takes (Control::replacing): no install, update, rollback or restore of a package or link starts until the update ended before the switch or the broker has restarted. (The refusal others then get is the one of a staged restore: its text names a restore.)
  • Commit order: the guard becomes the binary that runs (if it is not, and if the broker may write it: with the hardened unit a root step keeps it), update.json is written (trial, attempts: 0, trial_s, ran_s: 0, the backup’s id, file and SHA-256, both sets of schemas, the stores that exist, the links that are connected), current is switched by one rename of a new symbolic link, update_start is audited, the broker stops with code 0. A broker that stops between the file and the switch is found by the guard (current still names the old version): rolled_back, nothing restored.
  • Trial. It is counted in the time the new version ran, not in wall time (review of PR 74, point 2): the version adds to ran_s in update.json every 5 s and the trial ends when ran_s reaches trial_s. A host that is off for longer than the trial, a broker that is down, a clock that jumps: none of them ends a trial or fails it. deadline in update.json and update_last is an estimate for people (now + what is left), set at each start; nothing is decided by it. The guard counts the starts (not the new binary, §2.5: a binary that cannot start is counted too) and lets three go; a power cut during a trial is one of them. At the end of the trial the new version is healthy when its admin answers on sys through the router, the gateway accepts a connection (if it is configured) and every link of update.json that is still installed has its liveliness token; asked again for 10 s. Healthy: confirmed, update_confirmed, the guard becomes the new binary. Not healthy: the reason goes into update.json and the process ends with code 76 (Restart=always starts the guard). update_confirmed is never written before the version ran trial_s. A link stopped by hand during the trial counts as not back. A new version that hangs without ending is not seen by the guard (it acts at a start).
  • Guard (wyrmd update-guard, run as <prefix>/bin/wyrmd-guard). It takes the update back when the new version gave up (76 and its reason), when three starts did not end the trial, or when rollback_update asked. It never asks the clock. Where the update moved a SCHEMA (told by the two sets in update.json), it first puts those stores back from the pre-update backup (release::restore_control): a store that existed before the update (update.json stores) is replaced by the backup’s; one that did not (the gateway’s users on a broker that had no gateway) is moved into data_dir/update.aside and left out. Everything is read into data_dir/update.restore first, so an error up to there changes nothing; then the directories are swapped, and a swap that fails is undone. Then current goes back by one rename and the state is rolled_back.
  • The guard never leaves the broker without a version to start because a restore failed (review of PR 74, point 1; before, it ended with code 1 and neither version started). When the stores cannot be put back (the backup is gone, changed or not sealed for this broker; a file cannot be written), the old version is made current on the state as it is: state failed, the reason in update.json, update_last.reason and the audit (update_rollback, status internal_error). When the version a rollback made current does not come up in three starts (the old binary cannot read what the new one wrote), the guard makes the other version current, three starts each, until one comes up; a version that came up marks update.json settled and the guard leaves current alone from then on. When the old version’s directory is gone the new version stays (failed). Errors of writing update.json are said and passed over. The one case in which the guard ends with an error and nothing starts is a binary that is not verified (next rule).
  • Only a verified binary is started (review of PR 74, point 4a). With updates.mode: "self", the guard before it lets a version start, and the broker at its own start, check that the SHA-256 of versions/<v>/wyrmd (a plain file, no link) is the bin_sha256 that a release document kept beside it names for this host’s target, that a pinned key signed that document, and that the document is of version <v>; or that bin/trusted.json names <v> with that hash (a version put there by hand with wyrmd install-layout has no signed release). A binary that fails is never started: the guard makes the other version of the update current when that one verifies (state failed, with the reason), else it ends with code 1. A broker outside the layout is not checked (it cannot update itself either).
  • Threat model of the layout: a known limit (review of PR 74, point 4). A process link runs with the broker’s uid. If the broker’s user owns the whole layout, such a process can replace bin/wyrmd-guard, bin/trusted.json, a version’s binary, current, update.json or a backup, and gain code execution that survives restarts. Mitigation, in docs/operations.md §2: <prefix> owned by root with the sticky bit, bin/ and the configuration owned by root, versions/ and current by the broker; the guard is then refreshed by a root step of the unit (ExecStartPre=+… guard-refresh, which reads the current binary once, through no link, verifies it and writes what it hashed). With that, replacing a binary or pointing current at an unsigned one is stopped. Not stopped, also with it: current pointed at another release the key did sign and that is still in versions/ (the check proves a signed release, not which one; update.json is the broker’s to write); everything in data_dir (the site’s keys, the control plane, the backups: the seal of the pre-update backup is under secrets.key, which the same user reads, so it stops a file that was damaged or swapped by mistake, not that user); the configuration when the broker’s user may write it. A process link under the broker’s uid is inside the trust boundary until links get a uid of their own.
  • rollback_update {confirm_site} while the old version and the backup are kept: marks update.json, stops; the guard does the rest. Refused for a caller that comes through an upstream, as restore_apply replace is: it puts the control plane back.
  • How long a confirmed update can be rolled back (review of PR 74, point 2). keep_until is the confirmation + keep_days. One reading of the clock removes nothing (a host without a clock battery starts with a wrong time): the old version’s directory goes and the backup is unpinned only when the time was past keep_until at two starts of the broker, or for a full hour of one run (UpdateFile::expire); a clock that is before keep_until again forgets the starts counted. Never during a trial, and after a rollback only once the version it left current came up.
  • update through an upstream (allow_config) is allowed, as §2.8 says: what may run is decided by the keys this host pinned and by the version rules, not by the caller, and both hosts opted in (updates.mode: "self", allow_config).
  • Standby pair (§2.8), as built. The standby runs no router, so it has no sys: it cannot be reached “through its own sys”. Instead the active stages a release for it: update {target: "standby", upload, release, signature, confirm_site} checks the release and the archive’s SHA-256 and keeps both in data_dir/update.standby. With every fifth poll the standby tells the active its version and update state (sys/replication/update/<version>/<state>/<to>) and gets the order; it fetches the archive in parts of 1 MiB (update_part/<offset>/<len>), checks the signature under its own pinned keys, the rules, the SHA-256, unpacks, runs release-info and check --state on its followed stores, writes update.json with role: standby, switches and stops. It is proven when it has made one complete sync on the new version by the end of its trial; else it ends with 76 and its guard takes the version back (nothing is restored: a standby follows). update for the active is then allowed only when the standby is connected and reports that version, confirmed; without_standby: true allows it when the standby is not connected. A release whose replication protocol differs from the running one is refused for a pair (one host after the other cannot follow across it): both hosts are updated by hand. Before it stops, the active asks the standby to wait 120 s; if the new active is not back by then the standby, already on the new version, takes over. The active audits update_start and update_confirmed / update_rollback with the key standby and shows sys/standby_version and sys/standby_update. An order carries the release document and its own signature, from the upload or from the index entry. The guard is looked for before the start of the process (UpdateConfig::process_start), not of the daemon: a promoted standby opens its daemon hours after it started, and update was refused on it until a restart (review of PR 74, point 3). A standby in its trial counts run time as the active does. When its guard takes a version back it restores nothing: a standby follows, and what it holds are the active’s records as they were sent (the old version reads them). A standby that was promoted during its trial and wrote with the new version has no pre-update backup: if the old version then does not come up, the guard’s three-starts rule makes the new one current again.
  • Audit: update_start (at the commit, with the archive’s SHA-256, the backup, the SCHEMA moved; with status internal_error when an update ends before the switch), update_confirmed, update_rollback (at the call of rollback_update, and by the version that serves after a rollback, with the reason and whether the control plane was restored).
  • Looked at after the review (the places it did not read). fetch::get: TLS with the webpki roots and the default verifier, at most three redirects, each target parsed again (https, or http to loopback only: an https URL may be redirected to the broker’s own loopback, and what comes back is still checked against a signature or a signed hash), a size limit (the signed size for an archive) and one time limit for the whole exchange. backup_now: the job is pinned from the moment it is made, before a byte is written, and the SHA-256 in update.json is of the finished file. sys/replication/update and update_part: the queryable is the standby’s alone (ACL subject standby, a certificate standby:<site> of the site’s CA); version, state and offset are checked, a part is at most 1 MiB; a holder of that certificate could report a standby as updated, which lets the active update without one (as without_standby does). Exit code 76 under the documented unit: Restart=always starts the guard again; the guide says not to prevent it and not to set a start limit below 8.
  • Not built: a built-in release key and a published index (the workflow file is in packaging/wyrmd, not enabled); a list of checks as the answer of update?check; the link’s wyrm_link protocol check before an update; cross-version replication; a uid of their own for process links; a watchdog for a new version that hangs; Windows.

3. Backups

  1. Format: .wyrm-backup, a zip with manifest.json first: wyrm_backup: 1, site, broker (version), created, schemas (registry, users, flows, audit), sealed (how keys and secrets are sealed: passphrase with Argon2id parameters, or broker), and sections[], each with its files, sizes and SHA-256. A link backup is the same format with kind: "link", extension .wyrm-link. The format lives in wyrm_admin::backup (wyrmd reaches it too). Rules of the sealed field and of the reader (2026-11-13, after the security review of the first commit):
    • sealed: {how, kdf?, check, id, mac}. how is none, passphrase (Argon2id, parameters in kdf, bounded by the reader) or broker (a key derived from secrets.key). id is 16 random bytes per backup; it is part of every file key, so a sealed part of another backup under the same passphrase does not open. mac is HMAC-SHA-256 over the whole manifest (every path, size, SHA-256, sealed and exec flag, every info) under a key from the master key and id.
    • A manifest with how: passphrase | broker and no id, check or mac is refused. The master key is handed out only after the MAC matches (Manifest::key); a restore of a sealed backup always asks for the key, also for its plain sections.
    • The reader, not the file, decides what must be sealed: every file of keys; in links each link’s secrets, token and files/**; every file of a link backup’s data. A manifest that lists one of them with sealed: false is refused, and so is any such file in a backup with how: none. link.cbor holds no secret (no token hash; params are linted at install).
    • A sealed file is a stream of parts of 1 MiB, each ChaCha20-Poly1305 under a key of its own file and backup, bound to its index and to the end of the stream.
    • Bounds: at most 100 000 entries, a manifest of 16 MiB, a path of 512 bytes and 24 segments without ., .., \, :; each file at most 1 TiB; sizes are added with an overflow check; every zip entry must be listed with its size, and every file is hashed as it is read.
    • A backup with how: none has no secret in it and no MAC: its SHA-256 (shown in sys/backups/<id>) is what proves it unchanged.
  2. Sections: control (registry, users, flows store and audit: their WAL and snapshot as of one sequence number; always included, needed by the others), keys (CA, state.key, secrets.key, flows.key, gateway keys, secrets.bin, link tokens; sealed, never in clear), dataflows (the flow store; also inside control, listed for restore by itself), storage (the storage tree as wyrm_storage export plus its redb file), history (day files of a chosen range and index.redb), links (per chosen link: its LinkDef, the framework export when it has one, its private data dir sealed, its package archive), packages (all package archives), config (a copy of wyrmd.json5 for people to read, never restored; masked by default, see “Decided after the review of PR 72”, 13).
  3. Consistency while running: WAL stores are copied as of one sequence; redb files are copied from inside one read transaction each; history days are copied whole (closed days) or through Store::changes for today; the storage journal fixes the storage at one rev. These are the standby’s primitives (control/replication.rs), reused, not copied.
  4. API at sys/backups (config, audited; the arguments never carry the passphrase into the audit):
    • create {sections, links?, history_days?, passphrase?} → {id}; a job, one at a time; sys/backups/<id> shows status, progress, size, sha256, created, expires;
    • download_part {offset, len ≤ 16 MiB} (as ADR 0028), remove;
    • Secrets leave the broker only when the host allows it (security review, 2026-11-13). backups.export_secrets in wyrmd.json5, default false. While false: keys is refused, a passphrase is refused (the message names the option), link secrets and private data are sealed with how: broker and open only on a broker that holds this site’s keys; every other section works. While true: a passphrase of at least 12 characters (Argon2id, as keys export) seals them; backup_create is audited with keys: true|false and secrets: true|false and logged at warn. A caller whose token a limited key signed (an upstream with allow_config) is refused keys and a passphrase in both cases: a downstream site’s keys never travel up. sys/backups has the attribute export_secrets. The config section is the configuration as JSON, masked by default (decision 13 below).
    • send {link, connection, path?} on sys/backups/<id>: the broker writes the file through a file-store link (S3, WebDAV, Google Drive, localfs) with its own key. Decided 2026-11-13 (the admin has no signing key links trust, and a grant “to the admin” would need registry state): the host names the links in backups.send_links (wyrmd.json5, default empty = send refused). For those links only, the broker adds one limited key to the link’s trust (LinkConfig.limited_keys, as the flow key and requester keys reach it; embedded links at start, process links in hello): the backup sender key, at write, scoped to wy/<site>/downstream/<link>, bound to the subject broker:backup. The key is a secret the broker makes on first use (secret store entry broker:backup-sender, no link’s secret, so in no link backup); no registry state, no SCHEMA change. send uploads with the link’s own upload_begin / upload_part / upload_commit (ADR 0028) in parts of 1 MiB with the backup’s SHA-256, answers {to, upload, parts} once the link took the upload, and goes on in the background: sys/backups/<id> shows sent_to, send_status (sending, done, failed), send_progress, send_error; one send at a time. sys/backups has the attribute send_links.
    • send is no deputy of its caller (security review of send.rs, 2026-11-13). The broker writes with its own key for whoever has config on sys, whatever that caller may do on the link, so the host decides where a backup may land:
      1. An entry of backups.send_links is {link, folder}; a plain link id means the folder backups. One folder a link. folder is relative, of plain names (checked when the broker starts).
      2. The caller names connection (one name) and path: a file name, or sub-folders and a file name, of checked segments (not absolute, no .., no empty segment, no \ or :); default the backup’s own file name. It is always joined under <connection>/files/<folder>. A path that climbs out is refused by the broker before any call to the link.
      3. Every token of a send is good for …/<link>/<connection>/files/<folder>/** and for the four keys …/<link>/<connection>/~act/{upload_part, upload_commit, upload_status, upload_abort} only, at write. That is as narrow as the file-store key layout allows: those four are actions of the connection node, and they act only on uploads the same subject began, so only on ones begun in the folder. The limited key itself stays scoped to the link’s subtree (a scope is a prefix, and the connection is not known when the link starts).
      4. send never overwrites: overwrite: false always; the link refuses a name that exists (its tree, and If-None-Match: * at the store), so a send replaces no file.
      5. The admin’s audit record backup_send carries the caller as its subject and, in its detail, the link, the path, the size and the SHA-256 (the backup id is its key), at the start and at the end. The link’s own audit names claimed:broker:backup: the upload actions take no note or claimed subject, so the caller is not in the link’s records.
      6. A backup that holds keys is never sent. A send of any other backup is allowed to a caller from an upstream too: the host named the destination.
    • kept under data_dir/backups for backups.keep_days (7) within backups.max_mb (oldest removed first; pre-update backups of an unconfirmed update are never removed).
  5. Link backup: sys/links/<id>/~act/backup {sections: [settings, data, package, history], history_days?, passphrase?} → a job in sys/backups with kind: link. Restore: sys/links/~act/install_backup (Add a link ▸ From backup) with the file in parts, id (same or new), accept (its grants and net, as install_*), passphrase; replacing an existing link takes a restore point first. Rules of the restore (security review, 2026-11-13): a backup carries a package as its files only, never a registry record; the files are packed again and pass packages::unpack, the validator of install_zip (entry of Component::Normal parts and among the files, requester grants through check_grant and the whole-root rule, WASM world and capabilities, SHA-256 of the files), which builds the PackageDef. The LinkDef passes the checks of a new link before anything is written: validate_new_link_id for a new id, the driver, lint_params, the driver’s own validation, every grant through check_grant. accept covers the link’s grants and net and the requester grants and net of a package the install brings. Secrets a broker makes for a link’s identity (requester key, agent signing key) are filtered on export and on restore by one predicate; the token is in no link backup.
  6. Restore of a broker backup: restore_begin / restore_part / restore_check {passphrase} (returns the checks: site, keys, versions, what differs) / restore_apply {sections, mode}:
    • mode: add: live, no restart; only links, dataflows and storage nodes that do not exist yet;
    • mode: replace: a backup of what is replaced is made first, the chosen sections are staged into data_dir/restore.pending, the broker stops, and the next start applies them before opening any store (and removes the folder).
    • The keys section of another site is refused unless replace_keys: true (it changes the site’s identity: peers and process links must enrol again; the check says which). Decided 2026-11-13: “another site” means another CA under the same site name; a backup of another site name is always refused. The pre-restore backup holds the old keys only when keys are replaced, under the same passphrase.
    • Rules of the restore (automated security review of restore_broker.rs, 2026-11-13; each has a negative test):
      1. Every restore of keys passes the gates: backups.export_secrets: true, a caller of this site, the passphrase. The CA does not decide: a backup with this broker’s ca.pem and another state.key, secrets.key, gateway key, secrets.bin or link token takes the site over as well. replace_keys: true is needed unless every key file of the backup is byte for byte this broker’s; restore_check answers keys: none | same | differ | other and lists the files in keys_differ.
      2. A restore writes only files a section defines. Under keys/: exactly the key files of the bundle (key_files()), secrets.bin, and links/<valid link id>/token. control/<store>/<file> for the four WAL stores; dataflows/artifacts/**; storage/{tree.cbor, export.json}; history/index.redb, history/days/<day>.redb; links/<valid link id>/{link.cbor, secrets, files/**}; packages/<name>/files/**; config/wyrmd.json. Any other path refuses the whole backup, in restore_check and in both modes. Every destination is built from the checked parts (Place), never by joining a path of the archive.
      3. Broker-made link secrets. Without keys, replace puts a link’s secrets into this broker’s store and drops the ones a broker makes for a link’s identity, with the predicate of install_backup (broker_made_secret), at staging and again at the start that applies the plan. With keys, secrets.bin comes back whole, the broker-made secrets in it: they are the restored site’s own identity and came through the gates of rule 1; filtering them would leave a restored site whose links lost their requester keys for no gain.
      4. mode: replace is refused for a caller from an upstream (allow_config), before the file is read; mode: add stays, with its accept. In replace, packages pass packages::unpack and what they ask for (requester grants, network) needs accept, unless this broker has the same version with the same files. The detection of such a caller (Caller.signer.is_some()) is proved by e2e chain_of_three_brokers (central calls edge’s restore_apply), the local side by backup_restores_into_a_fresh_data_dir. add takes links and storage; flows need replace (a deploy carries proofs). control under other keys goes only with keys; with state_anchor_dir it is restored offline. The audit journal is replaced only with state.key. Audit: restore_apply at the call, restore_applied at the start that applied it.

4. Rights and audit

config on sys is not enough for the site’s secrets: see §3.4 (backups.export_secrets, never for an upstream caller). Every action here is config on sys (or on sys/links / sys/packages), only the admin role reaches it through the gateway (ADR 0009), and an upstream only with allow_config. Audit records: package_update, update_rollback, restore_point, update_start, update_confirmed, backup_create, backup_download, backup_send, restore_apply, link_backup, link_restore. A backup is as sensitive as data_dir: Studio says so where it is made and downloaded.

Consequences

  • Package updates stop being one-way; the kept previous version and the restore points cost disk (a few MiB per link) for keep_previous_days.
  • The package manifest gains state / reads_state (ADR 0011 format note); older packages read as state: 1.
  • wyrmd gains update-guard, a release workflow and a signed index; self-update is opt-in (updates.mode: "self") and needs the new install layout.
  • Backups no longer need the broker stopped; docs/operations.md §3 keeps the offline copy as the way for a dead broker.
  • New tests: e2e update of a package with a link that loses keys (rolls back), an update that changes state, a broker update whose trial fails (guard rolls back, SCHEMA restored; crates/wyrmd/tests/update.rs), backup while writing and restore into a fresh data_dir, a link backup restored on a second broker under a new id.

Decided during the build of §3 (2026-11-13)

Guide: docs/backups.md. Code: wyrm_admin::backup (format), wyrm_admin::control::{backups, restore}.

  1. Order. Link backup and install_backup (§3.5) and the job plumbing of sys/backups (create, download_part, remove) come first; the broker restore (§3.6) and send follow.
  2. control holds every WAL once. Registry, flow store, gateway users and audit are control/<store>/wal.…wyw, each copied as of one sequence number and checked against its HMAC chain (wyrm_state::replicate::copy_to, beside the standby’s records_after). The dataflows section adds only the flow artifacts and names control/flows as its store, so no WAL is in a file twice.
  3. Storage is a tree, not a redb file. storage/tree.cbor is the standby’s full page at one revision (Store::changes_since), with storage/export.json for people. The redb file is rebuilt from it on restore; a raw copy of an open redb file is never taken.
  4. History, today included, is copied inside one read transaction per file (Store::copy_day, then copy_index), not through Store::changes: the days first and the index last, so the index knows every series and journal number the days hold.
  5. Packages are files, not archives. The original zip is not kept after an install, so a package goes into a backup as its unpacked files (wyrm-link.json among them) with their execute bits, and nothing else. A restore packs them again (packages::repack, the same bytes for the same files) and runs the install validator; the SHA-256 in the registry is then of that zip. It installs the package only when the broker has no version of it; the same version must hold the same files; another version is refused (§1.8, one version per package).
  6. A link’s settings is its definition. The framework’s runtime edits are in data (framework.tree, sealed); the framework export JSON is not added, because the admin holds no key that may call a link’s export. link.cbor carries no token hash.
  7. Restored under another id, a framework tree is sealed again for the new id with the store key that came with it (wyrm_link_sdk::driver::persist::rebind): the tree is bound to its link’s id. Secrets a broker makes for a link’s identity (requester key, agent key) and its token are never carried over.
  8. An existing link is replaced in place (stop, restore point, params, data, start), never removed and installed again: the id of a removed remote link is retired (ADR 0006). It must run the same driver in the same mode and not come from wyrmd.json5.
  9. Without a passphrase secret-bearing parts are sealed for the site (how: broker); keys is refused. See §3.4.
  10. Uploads (restore_begin, restore_part, restore_abort) are sequential parts of at most 16 MiB, two open at once, removed after an hour without a part. install_backup also takes the file itself (file).
  11. Limits. backups.max_mb defaults to 2048; the newest backup and a pinned one are never pruned; a failed job is forgotten after a day; a job needs about twice its estimate free on the disk of data_dir.
  12. Audit. backup_create, link_backup (one record at the start, one more if it fails), backup_download (once per download, at offset 0), backup_remove, restore_point, link_restore. The admin writes its own journal (no hash of the arguments), so the passphrase is in no record.

Decided after the review of PR 72 (2026-11-13)

  1. A rollback applies the restore points its update took. The update stores (link, point id) of each point in the kept version’s record (PreviousDef.points), and reads the time of the update after the last point. A rollback applies exactly those points. A link without one gets none, never an older point. A record without names (made by the first build) keeps the old rule: the newest point at or before replaced.
  2. One operation on a package or a link at a time (§1.9). An update (to the end of its health check), a rollback, an install, a package removal and a restore of a link take the package from their first step (Control::claim_package); a restore of a link also takes the link (claim_link). The claim is given back when its holder ends, whatever way. While a claim is held, start, stop, remove, update and rollback of the link, a backup that copies its data, and a restore with mode: replace answer busy. While a backup copies a link’s data, or a replace is staged, no claim is given. Each side shows itself first and then looks, so one of the two always sees the other.
  3. A rollback is recorded before it changes anything. data_dir/restore/.rollback/<package>.cbor names the version, the kept record and each link’s point. A broker that ends in the middle finishes it at its next start, before any link runs (Control::complete_rollbacks); every step may run again.
  4. A link whose data did not come back is held. When the update changed the store format and a link’s restore point does not apply, the link is not started: data_dir/links/<id>/hold holds the reason, start answers it, last_update.reason and the audit name the link. A start of the broker skips a held link. A restore of the link’s data lifts the hold; start {force: true} lifts it by hand. Without a change of the store format the data stays and the link starts, as before.
  5. A restore of a link’s data is all or nothing (§3.5). The steps: data → data.replaced; data.restoring → data; the new secrets, with the old ones kept beside them in the same save of secrets.bin; data.replaced → data.done (the commit); the kept secrets and data.done go. Until the commit an error, or the next start of the broker (Control::recover_link_data), puts the old data and the old secrets back; after it the new ones stay. The link’s params are applied last. A framework tree is sealed for a new id in the new directory, before the swap.
  6. Key derivation of a backup is bounded for a small host (§3.1). The Argon2id parameters of a manifest run before its MAC can be checked. The reader takes at most 128 MiB, 4 passes and 4 lanes (a broker writes 19 MiB, 2 passes, 1 lane). A restore derives the key once and uses it for every link of the file.
  7. What a backup opens into is bounded before a byte is extracted (§3.1). The reader already stops each entry at its listed size and takes at most 64 GiB (8 GiB for a link backup). Added: a file may declare at most 200 times its own size plus 64 MiB; one package holds at most 256 MiB, one flow artifact 64 MiB, one link’s private data 8 GiB; and before a restore opens anything, what it will open (plus the largest sealed file once more, plus 64 MiB) must fit on the disk of data_dir.
  8. A staged restore is all or nothing and never stops the broker (§3.6). The staging parses all that the start will read (the storage is built from its tree, the history files and the secret store are opened, the plan is read back). The start writes what was there (before.json), sets aside what the plan replaces or removes (restore.pending/old/), and moves the new state in. It commits only after the stores have opened: the folder is renamed to restore.done, then removed. When a step fails, or a store does not open, everything set aside goes back; the folder becomes restore.failed with plan.json and error.txt only, and the broker runs on the state it had. The audit gets restore_failed once. Every step, the undo too, may run again after a start that stopped in it. The start fails only when the old state cannot be put back.
  9. The upstream rule holds for a download too (§3.4). download_part refuses a caller from an upstream when the backup holds keys or secrets sealed with a passphrase, whoever made it. A backup sealed for this broker, or without secrets, may be downloaded from above. send is unchanged: it gives no bytes to its caller, the host names the destination, and a backup with keys is never sent.
  10. No orphan of an install stays (§1). A start removes, under data_dir/packages, every .tmp-* and .git-* directory and every version directory that neither a package record nor its kept previous version names. An install or an update of a version removes such a directory first; only the kept previous version with other content is still refused.
  11. A rollback restores the links’ data only when it must, is suspect, or is asked (§1.6). rollback {restore_data?}. Default true when the update changed the store format (false is then refused), when the update did not end ok, or when it lost nodes (gone > 0); the rollback of the health check always restores. Default false for an update that ended well: the links keep the data they have, with all that was configured since. last_update.reason and the audit say which of the two was done.
  12. A restore point is a copy file by file (§1.3). Each file is whole: the portable store, framework.tree and the agent’s snapshot are written by rename, and a WAL with a torn tail is read up to it. The files of a link that runs are not of one moment. When the update changes the store format, the restore point is the only way back, so the links of the package stop for the copy (their key lists are read first) and start on the new version, or again on the old one when the update fails before the registry is written. For other updates the copy is taken while the links run, as §1.3 says.
  13. The config section is masked by default and shown by list (§3.2). A list of names to hide kept leaking (camel case, joined words, name = value inside a text), so the rule is the other way round. A text of wyrmd.json5 is in clear only when its key path is in CONFIG_SHOWN (wyrmd): fields known to hold no secret. Every other text is replaced by ***, whole: every text under links.*.params and uplink.upstreams, under an unknown section, free text. Nothing is parsed for name=value pieces. Numbers and flags are kept. Under the list there is a second net, never the only guard: a shown text, URL or Zenoh locator or other, loses everything after its first ? or # (a query, a locator’s config) and the userinfo before an @; a PEM private key is masked anywhere; a shown text or a number under a name that says secret is masked. A test reads the config structs from the sources and fails when a text field is on neither CONFIG_SHOWN nor CONFIG_MASKED. Declared secret params of drivers are not used: the configuration holds bootstrap params only, and under this rule every text of them is masked anyway.

Decided after the audit of PR 152 (2026-11-20)

  • What a version in its trial leaves on disk is what the version before it opens. A kill in a trial is followed by the previous version (§2.5), so a new on-disk form may not appear before update_confirmed. First case: the audit journal’s group commit announces a batch in the anchor (<lsn> <mac> +<n>, state_anchor_dir), which a version from before it refuses with more than one record after the head; the guard then failed three starts of the old version and made the failed new one current again. While update.json says trial (from the staging of an update to its confirmation, read at Control::open and at both changes: Control::audit_follows_update), the journal writes record by record with the plain anchor (Journal::one_by_one). The same from the moment a rollback of a confirmed update is asked (rollback_update writes who asked into update.json; second audit of PR 152): the predicate is “the previous version may be the next to open these files” (previous_version_may_start: trial, or confirmed with rollback set), every change of update.json by the running broker that moves it goes through Control::save_update, and switching it on returns only when a batch in flight is on disk and the anchor is the plain head, before the action answers. The order matters where the running version is the newer one (third audit of PR 152): rollback_update switches the journal first (Control::audit_one_by_one, an error goes to the caller) and writes update.json only after the writer answered, so a kill finds either no rollback asked or a journal the previous version opens; with the file first, a batch announced between the two was refused by the previous version. A change that lets batches come back (confirmed, rolled back) keeps the file first. Staging an update needs no order: the version that stages is the one the guard goes back to, and it opens its own batches; the new version switches at Control::open, before its first record. Other ways to an older binary were looked at: the guard’s way back after exit 76 or a kill is inside the trial; a standby updates as a broker of its own with its own update.json; restore_apply replace is applied by the same version at its next start; a downgrade by hand is a stop. The WAL itself has one form in all versions. A later change of a store’s files follows the same rule: the old form until the confirmation, or a SCHEMA move with the pre-update backup.

Not decided here

  • Scheduled backups (a scheduler target can call sys/backups/~act/create once this exists; ADR 0022).
  • Updates of many sites at once from a central broker (one action per site for now).
  • Delta backups of history.