Upgrades & migrations
An upgrade moves an app instance to another bundle, usually another release of its package, and reshapes its state if the new code expects a different shape. Writing the migration itself is covered in Migrations; this page is about what the cluster does with it. How a release is parsed, verified and trusted when it is installed is in Packages & frontends.
Who may upgrade
Section titled “Who may upgrade”New code reads the app’s data, so an upgrade is one of the three decisions deployment governance assigns:
-
Owner side (default): each app’s package declares who, in its signed manifest (
upgrades, App upgrades):owner(the default): the app’s owner, or, for an organization’s app, whoever holdsMANAGE_APPLICATIONon its team or organization-wide;publisher: whoever holdsMANAGE_APPLICATIONin the organization the package’s signing key is bound to, for every instance; nobody until the key is bound.
Each upgrades with a passkey session and a step-up over the exact upgrade (
POST /apps/{app}/upgrade { version | bundle, migrate? }, then the412challenge). The assertion is recorded asconsenton the directory’sUpgradeAppcommand. A package may move frompublishertoownerin a later release, never back, and an app is never upgraded from anownerrelease to apublisherone. -
Operator: only the operator (
POST /ops/apps/{app}/upgrade), to a release it installed itself.
An owner-side upgrader may hand one app’s upgrades to CI with an upgrade key: made once with a passkey, it signs each upgrade of that app to a signed release of its package in place of the step-up, and the node refuses it everything else. Who may upgrade and the deadline below are judged for it exactly as for a passkey.
Past a release deadline its
approver has not met, an upgrade is refused 409 RELEASE_DEADLINE before the
migration runs.
A version alone means the app’s own package and service.
What the passkey signs. The challenge’s arguments are
{ bundle, migrate, manifest }: the target WASM’s hash and the target
release’s signed-manifest hash, so another manifest installed under the same
version (other outbound prefixes or frontend origins, the same WASM) is not
the upgrade that was approved. The node computes both; a target that changes
between the challenge and the assertion no longer matches it, and the upgrade
is refused. A raw development bundle has no manifest, and manifest is
null.
From the app itself. An app’s frontend cannot upgrade its instance (its
session is bound to its package). It asks the node for a consent request
({ kind: "upgrade", subject: { app, toVersion } }); the node’s own page shows
the capability sheet (outbound, frontend origins, interfaces, methods,
events, timers, migration, build) and takes the owner’s passkey there
(The consent page).
Planning the migration
Section titled “Planning the migration”Unless the request names a migration (migrate), the leader plans one from the
two bundles’ embedded ABIs (services::plan_upgrade):
| Current → target state version | Plan |
|---|---|
| Same version | Code-only: switch the bundle, run nothing |
| One version up | Run the target’s #[app::migrate] edge from the current version |
| Down | Refused: no silent downgrade |
| More than one up | Refused: upgrade one version at a time |
| One up, no edge from the current version | Refused |
| One side embeds an ABI and the other does not | Refused |
| Neither embeds an ABI | Code-only |
Running it
Section titled “Running it”The upgrade is an entry in the app’s own log, so it is ordered against the app’s calls: every call before it ran on the old code, every call after it runs on the new.
- The leader runs the migration export on the target bundle over the current
state (
Executor::migrate). The export returns the new root state (borsh). - If the target exports
__calimero_migration_check, it runs over the migrated state and an optional witness the migration returned (a value the new schema no longer keeps). It must returntrue; anything else, or a trap, refuses the upgrade. Whatever the check writes is dropped, and the witness is never stored. - A migration that addresses the host’s key space is refused.
- The host writes the returned state as the app’s root entry, stamped after
whatever the root entry held so it wins (
write_root_state), and the writes become the entry’s diff. - The leader appends
AppCmd::Upgrade { bundle, base_index, outcome }. Every replica applies the diff and, if the outcome succeeded, switches to the new bundle. As with every entry, followers do not run the migration. - Only then does the node record the new bundle in the system directory
(
UpgradeApp, which checks the upgrader’s authority again and noteslastUpgrade).
A migration runs once, on the leader, and its result is replicated like any other entry: no replica migrates on its own, so there is no window in which replicas hold different schemas.
Failure
Section titled “Failure”A refused plan, a failing migration or a failing check leaves the app on its
bundle with its state untouched. The node answers 422 UPGRADE_FAILED with the
reason and records it on the instance (UpgradeFailed sets the app’s lastUpgrade with
ok: false and the error), so a client can see why. The app’s members read the last upgrade, with the
release it went from and to and the kind of actor, in GET /orgs/{org}/apps
or GET /auth/apps; the operator reads it without the account or the error
in GET /ops/apps (Deployment governance).
Organization-wide upgrade runs
Section titled “Organization-wide upgrade runs”An upgrade run moves every app of an
organization that runs package — or only a team’s apps, and with cascade
the apps of the teams below it — to version.
- Start.
POST /orgs/{org}/upgrade { package, version, team?, cascade?, migrate? }by aMANAGE_APPLICATIONholder there, with one passkey step-up for the whole run;POST /orgs/{org}/packages/{package}/upgrade { version, migrate? }by a publisher’sMANAGE_APPLICATIONholder, over every instance of apublisherpackage, its customers’ included (the run is kept on the publisher); orPOST /ops/orgs/{org}/upgradewhere the operator holds app upgrades. An app the starter may not upgrade is recorded as failed without running anything. A release missing from the cluster is installed from the registry first (owner runs). - Record.
StartUpgradeRunstores anUpgradeRunon the organization (run id, package, version, team, cascade, who started it, its apps, which are done and which failed, and whether it finished); the organization keeps its newest 20 runs. - Progress. A background task on the node that started it upgrades the apps
one by one; each
UpgradeApporUpgradeFailednotes the app on the run and on the instance. An app already on the target bundle is recorded as done.FinishUpgradeRunmarks the end. - Follow and retry.
GET /orgs/{org}/upgrades/{run}shows the run;POST …/retrystarts a new run over the apps that failed.
The task lives in the memory of the node that started it: if that node stops mid-run, the run stays unfinished and the remaining apps are not upgraded until a retry or a new run.
Upgrading the cluster itself
Section titled “Upgrading the cluster itself”Moving nodes to a new mero-tee release is not an app upgrade: it is a new node
image. Nodes on the new release join the cluster, but receive an app’s data
only once that app’s approver has approved the release
(Release approvals). App frontends
follow the package: {label}.{apps-domain}/ serves the newest installed
release.