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_packageunpacks 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.
wyrmdis 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_dirwith the broker stopped (docs/operations.md§3), pluswyrmd keys exportfor 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
sys/packages/<name>showsversion,latest(from the repository index; empty for custom packages),update_available(bool),previous(the version kept for a rollback, withkeep_until) andlast_update(a map:from,to,at,result=ok | rolled_back | failed,kept,new,gonecounts and up to 200 keys ofnewandgone).sys/linksgainsupdates_available(count) so Studio can badge it.- Action
sys/packages/<name>/~act/update {version?, accept, restore_point = true, auto_rollback_s = 120}(config, audited): installsversion(defaultlatest) from the repository with its SHA-256, the same flow asinstall_repo. A custom package is updated by the existinginstall_zip/install_url/install_gitwith the same package name; they take the same three new arguments. - 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=keysof its root). Restore points are listed atsys/links/<id>/restore_points(at,version,size) and pruned afterpackages.keep_previous_days(default 7). - The previous version’s directory is kept (no
remove_dir_all) untilkeep_until; the registry’sPackageDefkeepsprevious. - Health after the restart: every link of the package must say
helloand declare at least every key it had, withinauto_rollback_s. Keys that do not come back aregone; new ones arenew. Withauto_rollback_s > 0and anythinggone(or a link that never says hello), the broker rolls back by itself (§1.6) and auditsupdate_rollbackwith the reason. With0, it keeps the new version and reports. sys/packages/<name>/~act/rollback {to?}(config): reinstallspreviousfrom 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 inlast_update.- Store format: the package manifest gains
state(integer, default 1) andreads_state(list, default[state]). An update whosereads_statedoes not contain the installedstateis 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. - 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_updateare value nodes ofsys/packages/<name>(they move while an update runs), besidestateandchanges_state(the update tolatestchanges the store format).previousis{version, keep_until, changes_state}; times are unix seconds.last_updatecarries the countskept,new,gone, the listsnew_keysandgone_keys(<link>/<path>, ≤ 200 each),reason,links,changes_state,restore_point. Itsresulthas a fourth, passing value:checking, while the health check runs.updates_availableis an attribute ofsys/links, besidecatalog(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_availablecompares 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
hellois one of its actions, so the health check runs after the action answered ({success, message}, like an install); Studio followslast_update. Until it ends, installs of the package, its Remove and its links’ Start/Stop/Remove answerbusy;rollbackstops it and rolls back. - Health. A link is back when it answers
~meta?view=keysof 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_sis 0 to 600. With0the report is made when every link answers and its keys are stable for 3 s (ok, withgoneand a reason), orfailedafter 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 leavesfailedat the next start; the new version stays. - Rights.
acceptcovers grants andnetentries 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-linkand<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 byControl::link_backup_to’s code with the sectionssettingsanddata(no history, no package: the package a link ran is kept once, as the package’spreviousversion of §1.4, not once more in every link’s restore point). It is sealedhow: broker(a key fromsecrets.key), so a restore point needs no passphrase and nobackups.export_secrets, and never leaves the broker by itself;install_backupon 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_pointkeeps 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 withO_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 iswyrm_admin::nofollow, and every copy of a link’s private data into a backup goes through it (a link backup, thelinkssection 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 throughinstall_backuptakes the same kind of restore point first (§3.5), listed inrestore_pointsand 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:
previousis 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_statehas 1 to 32 entries and must hold the package’s ownstate. The repository index may carry both (wyr repo addand the official index copy them from a manifest that names them), sochanges_stateis known before the fetch; the manifest in the zip decides.restore_point: falseis refused when the format changes, and such a rollback is refused for a link that has no restore point.
2. Broker updates
- 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 runsExecStartPre=<prefix>/bin/wyrmd-guard update-guardandExecStart=<prefix>/current/wyrmd.docs/operations.mdgains the layout and the unit. - 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;keysadds others (a company mirror).external(containers, distribution packages) refusesupdatewith a message and shows how to update outside. - Releases: a new release workflow publishes
wyrmd-<version>-<target>.tar.gz, a signed release document with its SHA-256, and a signedreleases.json(version, date, notes URL, targets, minfromversion,schemasit writes, replication protocol version). Until that workflow exists,update {file}takes an uploaded archive with its signature (parts, as ADR 0028). sysshowsupdate_available,latest,update_state(none | staged | trial | confirmed | rolled_back) andupdate_last(map). Actionsys/~act/update {version, confirm_site}(config, audited;confirm_sitemust equal the site name):- download into
versions/<v>.part, check signature and SHA-256; - run
versions/<v>/wyrmd check -c <config>(the new binary checks this configuration); - pre-update backup of the control plane and keys (§3 sections
controlandkeys, sealed with a key derived fromsecrets.key, so no passphrase is needed) intodata_dir/backups/pre-update-<v>.wyrm-backup; - write
data_dir/update.json{from, to, state: "trial", attempts: 0, deadline, backup}, pointcurrentatversions/<v>, copy the running binary tobin/wyrmd-guard, and stop cleanly (exit 0; systemdRestart=alwaysstarts the new one).
- download into
- Trial: the new
wyrmdincrementsattemptsfirst thing. It is healthy when the router is up, the gateway listens, the admin answers and every link that was connected before the update sayshello(process links gettrial_s). Healthy →state: confirmed, auditupdate_confirmed, the guard binary is replaced by the new one. Not healthy bydeadline, orattempts ≥ 3: it exits with code 76. update-guard(the previous binary) runs before every start: withstate: trialand (attempts ≥ 3or the deadline passed or a 76 recorded), it pointscurrentback atfrom, restores the control-plane files from the pre-update backup when the new version moved a SCHEMA, setsstate: rolled_backand lets systemd start the old binary. Auditupdate_rollbackis written by the old binary at start.sys/~act/rollback_update(config) after a confirmed update, untilkeep_days: same as §2.6, on purpose. Changes made after the update are lost (the pre-update backup is restored); the review says so.- Standby pair (ADR 0036):
updaterefuses 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 ownsys, reached via the peer link). The same action reaches a downstream broker through its upstream withallow_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.modeisoffby default: nothing is fetched,updateis refused.externalneedsupdates.channel, reads the index and showslatest,update_availableand, inupdate_hint, what to run outside the broker;updateis refused with that text.selfis refused with the reason (update_hintshows it too) when the running binary is not<prefix>/versions/<its version>/wyrmdwith<prefix>/currenta symbolic link to that version and a file<prefix>/bin/wyrmd-guard, and when the guard did not run before this start (it leavesdata_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’sfile,size,sha256,urlandbin_sha256(the SHA-256 of the binary in the archive). Its signature is detached: Ed25519 overwyrmd-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 overwyrmd-releases-v1\n+ its bytes. The two domains keep an index signature from signing a release.updates.channelserves 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) andupdates.keys; with no key pinned nothing is trusted. No key is ever read from a release file. The archive is.tar.gz(the workspace hasflate2, no zstd). - Freshness of the index (review of PR 74, point 5).
sequencegoes up by one with every index published and is under the index’s signature. A broker keeps the highest sequence it has read indata_dir/update.seenand 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 whosedata_diris 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 au64) 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 indocs/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(environmentwyrmd-release), which builds its tool from the tagged source itself and hascontents: read; the jobpublishhascontents: writeand no key.release docchecks each archive against its description and the binary in it against the hash that is signed. - The channel holds no credential.
updates.channelishttps://(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 insysand 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_updateis the only way back.min_frommust 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 whatdata_dirholds. A release (or a running version) that names a store other thanregistry,audit,users,flowsis refused: the guard of this version could not put such a store back (review of PR 74, point 1); it is installed by hand. Withstate_anchor_dirset, 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 toversions/<v>when all of it is on disk. Plain files only, by plain name (no directory, no.., no leading.), at most 9, the binarywyrmdamong them and executable in the archive; symbolic and hard links, devices, pipes, directories and extension headers refuse the whole archive, and so do the namesrelease.jsonandrelease.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 thebin_sha256of 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-infomust 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 isdata_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/backupswithkind: pre-update, pinned, of the sectioncontrolalone, sealed for this broker (how: broker: its manifest carries a MAC under a key fromsecrets.key). Decided: nokeyssection (§2.4.3 said both). An update replaces a binary, never a key file, the guard restores WALs only, andkeyswithout a passphrase is refused by §3.4. The guard checks the file’s SHA-256 againstupdate.json, the manifest’s MAC withsecrets.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. updateanswers 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 followsupdate_state(none,staged,trial,confirmed,rolled_back,failed) andupdate_last(from,to,result,at,by,reason,attempts,deadline,keep_until,restored,without_s,links,backup,schemas_moved;stepwhile one is prepared:fetching,checking,staged,backup). An update that ends before the switch leavesupdate_state: none,update_last.result: failedwith the reason, an audit record, and no version directory.update?check(ADR 0047) refuses whatupdaterefuses before it fetches the archive; it answersokor 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), thenupdate {upload, release, signature, confirm_site}with the release document and its signature as text.check_updatesreads the index now. - One job at a time.
updateandrollback_updateare refused withbusywhile 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 withmode: replacetakes (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.jsonis 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),currentis switched by one rename of a new symbolic link,update_startis audited, the broker stops with code 0. A broker that stops between the file and the switch is found by the guard (currentstill 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_sinupdate.jsonevery 5 s and the trial ends whenran_sreachestrial_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.deadlineinupdate.jsonandupdate_lastis 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 onsysthrough the router, the gateway accepts a connection (if it is configured) and every link ofupdate.jsonthat 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 intoupdate.jsonand the process ends with code 76 (Restart=alwaysstarts the guard).update_confirmedis never written before the version rantrial_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 whenrollback_updateasked. It never asks the clock. Where the update moved a SCHEMA (told by the two sets inupdate.json), it first puts those stores back from the pre-update backup (release::restore_control): a store that existed before the update (update.jsonstores) is replaced by the backup’s; one that did not (the gateway’s users on a broker that had no gateway) is moved intodata_dir/update.asideand left out. Everything is read intodata_dir/update.restorefirst, so an error up to there changes nothing; then the directories are swapped, and a swap that fails is undone. Thencurrentgoes back by one rename and the state isrolled_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 inupdate.json,update_last.reasonand the audit (update_rollback, statusinternal_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 marksupdate.jsonsettledand the guard leavescurrentalone from then on. When the old version’s directory is gone the new version stays (failed). Errors of writingupdate.jsonare 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 ofversions/<v>/wyrmd(a plain file, no link) is thebin_sha256that 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 thatbin/trusted.jsonnames<v>with that hash (a version put there by hand withwyrmd install-layouthas no signed release). A binary that fails is never started: the guard makes the other version of the update current when that one verifies (statefailed, 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.jsonor a backup, and gain code execution that survives restarts. Mitigation, indocs/operations.md§2:<prefix>owned by root with the sticky bit,bin/and the configuration owned by root,versions/andcurrentby 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 pointingcurrentat an unsigned one is stopped. Not stopped, also with it:currentpointed at another release the key did sign and that is still inversions/(the check proves a signed release, not which one;update.jsonis the broker’s to write); everything indata_dir(the site’s keys, the control plane, the backups: the seal of the pre-update backup is undersecrets.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: marksupdate.json, stops; the guard does the rest. Refused for a caller that comes through an upstream, asrestore_apply replaceis: it puts the control plane back.- How long a confirmed update can be rolled back (review of PR 74, point 2).
keep_untilis 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 pastkeep_untilat two starts of the broker, or for a full hour of one run (UpdateFile::expire); a clock that is beforekeep_untilagain forgets the starts counted. Never during a trial, and after a rollback only once the version it left current came up. updatethrough 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 ownsys”. 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 indata_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, runsrelease-infoandcheck --stateon its followed stores, writesupdate.jsonwithrole: 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).updatefor the active is then allowed only when the standby is connected and reports that version, confirmed;without_standby: trueallows 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 auditsupdate_startandupdate_confirmed/update_rollbackwith the keystandbyand showssys/standby_versionandsys/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, andupdatewas 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 statusinternal_errorwhen an update ends before the switch),update_confirmed,update_rollback(at the call ofrollback_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 inupdate.jsonis of the finished file.sys/replication/updateandupdate_part: the queryable is the standby’s alone (ACL subjectstandby, a certificatestandby:<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 (aswithout_standbydoes). Exit code 76 under the documented unit:Restart=alwaysstarts 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 ofupdate?check; the link’swyrm_linkprotocol 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
- Format:
.wyrm-backup, a zip withmanifest.jsonfirst:wyrm_backup: 1,site,broker(version),created,schemas(registry, users, flows, audit),sealed(how keys and secrets are sealed:passphrasewith Argon2id parameters, orbroker), andsections[], each with its files, sizes and SHA-256. A link backup is the same format withkind: "link", extension.wyrm-link. The format lives inwyrm_admin::backup(wyrmdreaches it too). Rules of thesealedfield and of the reader (2026-11-13, after the security review of the first commit):sealed: {how, kdf?, check, id, mac}.howisnone,passphrase(Argon2id, parameters inkdf, bounded by the reader) orbroker(a key derived fromsecrets.key).idis 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.macis HMAC-SHA-256 over the whole manifest (every path, size, SHA-256,sealedandexecflag, everyinfo) under a key from the master key andid.- A manifest with
how: passphrase | brokerand noid,checkormacis 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; inlinkseach link’ssecrets,tokenandfiles/**; every file of a link backup’sdata. A manifest that lists one of them withsealed: falseis refused, and so is any such file in a backup withhow: none.link.cborholds 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: nonehas no secret in it and no MAC: its SHA-256 (shown insys/backups/<id>) is what proves it unchanged.
- 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 insidecontrol, listed for restore by itself),storage(the storage tree aswyrm_storageexport plus its redb file),history(day files of a chosen range andindex.redb),links(per chosen link: itsLinkDef, the frameworkexportwhen it has one, its private data dir sealed, its package archive),packages(all package archives),config(a copy ofwyrmd.json5for people to read, never restored; masked by default, see “Decided after the review of PR 72”, 13). - 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::changesfor today; the storage journal fixes the storage at onerev. These are the standby’s primitives (control/replication.rs), reused, not copied. - 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>showsstatus,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_secretsinwyrmd.json5, defaultfalse. Whilefalse:keysis refused, apassphraseis refused (the message names the option), link secrets and private data are sealed withhow: brokerand open only on a broker that holds this site’s keys; every other section works. Whiletrue: a passphrase of at least 12 characters (Argon2id, askeys export) seals them;backup_createis audited withkeys: true|falseandsecrets: true|falseand logged atwarn. A caller whose token a limited key signed (an upstream withallow_config) is refusedkeysand a passphrase in both cases: a downstream site’s keys never travel up.sys/backupshas the attributeexport_secrets. Theconfigsection is the configuration as JSON, masked by default (decision 13 below). send {link, connection, path?}onsys/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 inbackups.send_links(wyrmd.json5, default empty =sendrefused). 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 inhello): the backup sender key, atwrite, scoped towy/<site>/downstream/<link>, bound to the subjectbroker:backup. The key is a secret the broker makes on first use (secret store entrybroker:backup-sender, no link’s secret, so in no link backup); no registry state, no SCHEMA change.senduploads with the link’s ownupload_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>showssent_to,send_status(sending,done,failed),send_progress,send_error; one send at a time.sys/backupshas the attributesend_links.sendis no deputy of its caller (security review ofsend.rs, 2026-11-13). The broker writes with its own key for whoever hasconfigonsys, whatever that caller may do on the link, so the host decides where a backup may land:- An entry of
backups.send_linksis{link, folder}; a plain link id means the folderbackups. One folder a link.folderis relative, of plain names (checked when the broker starts). - The caller names
connection(one name) andpath: 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. - 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, atwrite. 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). sendnever overwrites:overwrite: falsealways; the link refuses a name that exists (its tree, andIf-None-Match: *at the store), so a send replaces no file.- The admin’s audit record
backup_sendcarries 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 namesclaimed:broker:backup: the upload actions take no note or claimed subject, so the caller is not in the link’s records. - A backup that holds
keysis never sent. A send of any other backup is allowed to a caller from an upstream too: the host named the destination.
- An entry of
- kept under
data_dir/backupsforbackups.keep_days(7) withinbackups.max_mb(oldest removed first; pre-update backups of an unconfirmed update are never removed).
- Link backup:
sys/links/<id>/~act/backup {sections: [settings, data, package, history], history_days?, passphrase?}→ a job insys/backupswithkind: 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, asinstall_*),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 passpackages::unpack, the validator ofinstall_zip(entry ofComponent::Normalparts and among the files, requester grants throughcheck_grantand the whole-root rule, WASM world and capabilities, SHA-256 of the files), which builds thePackageDef. TheLinkDefpasses the checks of a new link before anything is written:validate_new_link_idfor a new id, the driver,lint_params, the driver’s own validation, every grant throughcheck_grant.acceptcovers 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. - 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 intodata_dir/restore.pending, the broker stops, and the next start applies them before opening any store (and removes the folder).- The
keyssection of another site is refused unlessreplace_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. Thepre-restorebackup 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):- Every restore of
keyspasses the gates:backups.export_secrets: true, a caller of this site, the passphrase. The CA does not decide: a backup with this broker’sca.pemand anotherstate.key,secrets.key, gateway key,secrets.binor link token takes the site over as well.replace_keys: trueis needed unless every key file of the backup is byte for byte this broker’s;restore_checkanswerskeys: none | same | differ | otherand lists the files inkeys_differ. - A restore writes only files a section defines. Under
keys/: exactly the key files of the bundle (key_files()),secrets.bin, andlinks/<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, inrestore_checkand in both modes. Every destination is built from the checked parts (Place), never by joining a path of the archive. - Broker-made link secrets. Without
keys,replaceputs a link’s secrets into this broker’s store and drops the ones a broker makes for a link’s identity, with the predicate ofinstall_backup(broker_made_secret), at staging and again at the start that applies the plan. Withkeys,secrets.bincomes 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. mode: replaceis refused for a caller from an upstream (allow_config), before the file is read;mode: addstays, with itsaccept. Inreplace, packages passpackages::unpackand what they ask for (requester grants, network) needsaccept, unless this broker has the same version with the same files. The detection of such a caller (Caller.signer.is_some()) is proved by e2echain_of_three_brokers(central calls edge’srestore_apply), the local side bybackup_restores_into_a_fresh_data_dir.addtakeslinksandstorage; flows needreplace(a deploy carries proofs).controlunder other keys goes only withkeys; withstate_anchor_dirit is restored offline. The audit journal is replaced only withstate.key. Audit:restore_applyat the call,restore_appliedat the start that applied it.
- Every restore of
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 asstate: 1. wyrmdgainsupdate-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 freshdata_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}.
- Order. Link backup and
install_backup(§3.5) and the job plumbing ofsys/backups(create,download_part,remove) come first; the broker restore (§3.6) andsendfollow. controlholds every WAL once. Registry, flow store, gateway users and audit arecontrol/<store>/wal.…wyw, each copied as of one sequence number and checked against its HMAC chain (wyrm_state::replicate::copy_to, beside the standby’srecords_after). Thedataflowssection adds only the flow artifacts and namescontrol/flowsas its store, so no WAL is in a file twice.- Storage is a tree, not a redb file.
storage/tree.cboris the standby’s full page at one revision (Store::changes_since), withstorage/export.jsonfor people. The redb file is rebuilt from it on restore; a raw copy of an open redb file is never taken. - History, today included, is copied inside one read transaction per file (
Store::copy_day, thencopy_index), not throughStore::changes: the days first and the index last, so the index knows every series and journal number the days hold. - 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.jsonamong 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). - A link’s
settingsis its definition. The framework’s runtime edits are indata(framework.tree, sealed); the frameworkexportJSON is not added, because the admin holds no key that may call a link’sexport.link.cborcarries no token hash. - 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. - 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. - Without a passphrase secret-bearing parts are sealed for the site (
how: broker);keysis refused. See §3.4. - 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_backupalso takes the file itself (file). - Limits.
backups.max_mbdefaults 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 ofdata_dir. - 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)
- 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 beforereplaced. - 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,updateandrollbackof the link, a backup that copies its data, and a restore withmode: replaceanswerbusy. While a backup copies a link’s data, or areplaceis staged, no claim is given. Each side shows itself first and then looks, so one of the two always sees the other. - A rollback is recorded before it changes anything.
data_dir/restore/.rollback/<package>.cbornames 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. - 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>/holdholds the reason,startanswers it,last_update.reasonand 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. - 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 ofsecrets.bin;data.replaced→data.done(the commit); the kept secrets anddata.donego. 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. - 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.
- 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. - 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 torestore.done, then removed. When a step fails, or a store does not open, everything set aside goes back; the folder becomesrestore.failedwithplan.jsonanderror.txtonly, and the broker runs on the state it had. The audit getsrestore_failedonce. 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. - The upstream rule holds for a download too (§3.4).
download_partrefuses a caller from an upstream when the backup holdskeysor secrets sealed with a passphrase, whoever made it. A backup sealed for this broker, or without secrets, may be downloaded from above.sendis unchanged: it gives no bytes to its caller, the host names the destination, and a backup withkeysis never sent. - 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. - A rollback restores the links’ data only when it must, is suspect, or is asked (§1.6).
rollback {restore_data?}. Defaulttruewhen the update changed the store format (falseis then refused), when the update did not endok, or when it lost nodes (gone> 0); the rollback of the health check always restores. Defaultfalsefor an update that ended well: the links keep the data they have, with all that was configured since.last_update.reasonand the audit say which of the two was done. - A restore point is a copy file by file (§1.3). Each file is whole: the portable store,
framework.treeand 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. - The
configsection is masked by default and shown by list (§3.2). A list of names to hide kept leaking (camel case, joined words,name = valueinside a text), so the rule is the other way round. A text ofwyrmd.json5is in clear only when its key path is inCONFIG_SHOWN(wyrmd): fields known to hold no secret. Every other text is replaced by***, whole: every text underlinks.*.paramsanduplink.upstreams, under an unknown section, free text. Nothing is parsed forname=valuepieces. 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 neitherCONFIG_SHOWNnorCONFIG_MASKED. Declaredsecretparams 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. Whileupdate.jsonsaystrial(from the staging of an update to its confirmation, read atControl::openand 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_updatewrites who asked intoupdate.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, orconfirmedwithrollbackset), every change ofupdate.jsonby the running broker that moves it goes throughControl::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_updateswitches the journal first (Control::audit_one_by_one, an error goes to the caller) and writesupdate.jsononly 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 atControl::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 ownupdate.json;restore_applyreplaceis 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/createonce this exists; ADR 0022). - Updates of many sites at once from a central broker (one action per site for now).
- Delta backups of history.