Skip to content

feat(rollback): add features rollback that holds updates until a newer revision - #461

Merged
bketelsen merged 19 commits into
mainfrom
feat/feature-rollback
Oct 24, 2026
Merged

bketelsen merged 19 commits into
mainfrom
feat/feature-rollback

Conversation

@frostyard-machines

@frostyard-machines frostyard-machines commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Stacked on #460 (Phase 3), which is stacked on #458 (Phase 1). This branch contains their commits plus one commit, feat(rollback): …. Review only feat(rollback): … and the merge dbc4903, which brings in the #460 follow-up and adds 2 README sentences from review: the feature-wide hold, and a rollback across an image update. Merge #458 and then #460 first, then rebase this PR. It targets main, because the Tests workflow runs only for PRs into main. I stacked it because it extends #458's stage-then-link pipeline and vacuum protection, and #460's status output.

Phase 4 of plan 0001, which implements ADR-0016, "Rollback" (and the rejected-version item in "Retention").

updex features rollback <name> [--to VERSION] [--now] [--clear] [--dry-run], with Client.RollbackFeature(ctx, name, RollbackFeatureOptions):

  • Target.
    • By default, each transfer goes to its own newest staged version older than its link. With --to VERSION, every transfer goes to that version. It must be staged and older than the version the transfer rolls back from.
    • If any transfer cannot be rolled back, nothing changes, and one error lists every blocking transfer.
    • The links of the feature move all or none: a failure on the second transfer restores the first link, through the linkAllOrNone code shared with feat(update): keep linked and running images, link a feature's transfers together, add the operation lock #458. A failure also restores the previous record.
  • Record.
    • Path: <RollbackDir>/<feature> (default /var/lib/updex/rollback, the new RuntimePaths.RollbackDir field).
    • Format: JSON {"format":1,"feature":…,"created":…,"rejected":{"<component>":"<version>"}}, read with a 64 KiB cap and a format check.
    • It is written before the links move, with a temp file and rename after Lstat checks. A crash between the two steps leaves only a harmless hold.
    • A symlink or a traversal-shaped name is refused, and the name is checked with catalog.ValidateSysextName.
    • A second rollback keeps the higher rejected version.
  • Updates honour the record (installTransfers, so features update, the timer and enable --now):
    • If any transfer's newest available version is less than or equal to its rejected version (version.Compare), the whole feature is held: nothing is downloaded or linked, and the result is Held plus RejectedVersion. A hold is not an error, and the run exits 0. The "already staged, relink" branch cannot move the link back to the rejected image, because the hold check runs before the stage step.
    • When a newer revision is published, it is staged and linked as usual, then the vacuum runs, then the record is deleted.
    • An unreadable or malformed record fails closed for that feature only: nothing is linked, and it is reported as an error. The other features continue.
  • Retention. While the record exists, the vacuum keeps the rejected version (VacuumPaths.ProtectVersions).
  • --now refreshes, with the feat(status): report running and linked sysext versions and warn about pending activations #460 pending-activations warning. Without it, the change takes effect at the next boot. --clear deletes only the record. A missing record is reported, not an error.
  • Status. rollback_rejected appears on the per-transfer status and on CheckResult. UpdateAvailable is false while held. The text output shows held (rejected X) in check and a HELD BY ROLLBACK: footer in list.
  • sysext. New LinkVersionAt and StagedVersionsAt, and an optional VersionSysextRunner interface. A runner without it gets ErrLegacySysextRunner before any change.

Checks

  • make fmt
  • make ci: ==> CI gate passed locally. Coverage is 88.1%, and .coverage-baseline is bumped. /var/lib/updex was not created.
  • CLI/e2e green
  • Focused tests (updex/rollback_test.go, cmd/updex/features_rollback_test.go, sysext/link_test.go):
    • the default target, --to, the multi-transfer default and a second rollback;
    • six refusal cases that leave no link, no record and no directory;
    • a link failure on the second transfer, which restores the first link and leaves no record;
    • a timer run with the record: no download and no relink;
    • a newer revision is linked and the record is deleted;
    • the whole-feature hold;
    • the vacuum keeps the rejected version;
    • 9 kinds of unreadable record, each failing only its own feature;
    • --clear, --now, a refresh failure, a dry run that writes nothing, ErrBusy, a legacy runner;
    • record path safety: a symlink path, a symlinked directory, traversal-shaped names, file modes;
    • CLI text and JSON, with root required except for --dry-run.

Risk classification

  • Tier 4: Critical

Rationale:

  • This PR touches sysext/** and adds a new root-written state file under /var/lib/updex.
  • Trust boundary: root writes in /var/lib/updex/rollback and /var/lib/extensions.
  • Abuse cases:
    • The record path is checked with Lstat, written with a temp file and rename, and the name is validated.
    • A record that cannot be trusted never permits a link (fail closed).
  • Failure modes: a rollback that cannot complete changes nothing. A held feature exits 0, so the timer does not show a failure.
  • Rollback of this change: revert it. A leftover record is ignored by older updex releases, so the hold is lost and the next update links the newest version. Remove it with features rollback --clear before you downgrade.

Docs housekeeping

  • README.md, docs/design/overview.md, docs/specs/sdk-api.md, docs/specs/config-reference.md and AGENTS.md updated (the rollback record, and the rule that every link path must honour it)
  • Conformance aliases untouched

Verification

  • node scripts/check-docs.mjs green

Not verified on a real host. Plan 0001's "Done when" for this phase, rollback incus followed by a timer run, needs one.

Known limits:

  • A rollback does not refuse a target older than the running version.
  • disable --now and catalog remove do not delete a feature's record. rollback --clear works for a removed feature.

…sfers together, add the operation lock

Phase 1 of plan 0001 (ADR-0016).
…activations

Phase 3 of plan 0001 (ADR-0016).
…that updates honour

Phase 4 of plan 0001 (ADR-0016).
@github-actions github-actions Bot added documentation Improvements or additions to documentation go Pull requests that update go code labels Oct 23, 2026
@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.49618% with 95 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
updex/rollback.go 81.10% 40 Missing and 32 partials ⚠️
cmd/updex/features_run.go 79.24% 7 Missing and 4 partials ⚠️
sysext/manager.go 83.33% 2 Missing and 2 partials ⚠️
updex/install.go 95.40% 2 Missing and 2 partials ⚠️
updex/status.go 80.00% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@frostyard-machines frostyard-machines left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Murbella (snosi owner): host and image review of the last commit (feat(rollback): …), comment only. I do not approve.

Verdict: no blocking finding. It matches Brian's decision "rollback skips and resumes": the record rejects the version rolled back from, features update and the timer link neither it nor an older one, the next newer revision links and deletes the record, and --clear resumes at once. The rollback takes the lock, refuses a target that is not staged, links all-or-none, and puts the old record back when a link fails. A held feature downloads nothing (only manifests). The rejected version stays protected from the vacuum while the record exists. Without --now, it applies at the next boot.

Non-blocking:

  1. Rollback across a base change. The minimum-image check does not run on rollback (#462), on the reasoning that an older revision needs at most the same base. That holds for base shrinks. It does not hold when a later base dropped something that the older delta expects from the base; the newer delta then carries it, and the older one does not. This is rare and the command is run by a person, so a sentence in the README is enough: "a rollback across an image update can need the older image too".
  2. The hold is feature-wide. A feature with 2 transfers stays held until every transferred component has a version newer than its rejected one. That is the safe choice; say it in the docs, because a publisher that bumps only one component of a feature keeps the hold.
  3. --now refresh. It activates every other pending link too. The warning lists them (#460). Fine for a person at a shell.

Needs a real host (plan "Done when"): after rollback incus, a timer run keeps the old link, and the next published revision is linked automatically. That needs a publication, so I propose a local test catalog on a throwaway VM. Host test plan: see my comment on #462.

Review follow-up (Murbella): a sysext that is merged but not linked is
unmerged by the refresh; list it, and tell SDK callers to show the list.
…ature-wide hold and rollback across an image update
@bsherman

Copy link
Copy Markdown
Contributor

Blocking: another enabled feature sharing a transfer can bypass its rollback hold.

A transfer can legitimately belong to multiple features, for example Features=grp other. The rollback record is keyed by feature, and installTransfers reads only the record for the feature currently being processed. After rolling back grp, UpdateFeatures can therefore process the same transfer through other, see no record, and relink the rejected version.

I reproduced this against commit dbc49039bd14501da0c14626ff0eb5203fbc8734 using the existing rollback fixture: alpha has staged versions 1.0.0 and 2.0.0, with 2.0.0 linked; both grp and other are enabled and alpha.transfer declares Features=grp other. RollbackFeature(grp) correctly links 1.0.0 and records rejected 2.0.0. The next UpdateFeatures call succeeds but links alpha_2.0.0.raw again. A focused preservation test fails.

Please enforce all applicable rollback holds when updating a shared transfer, including enable --now, or refuse ambiguous rollbacks before making changes. Add regression coverage for a shared transfer across two enabled features. The rejected version must not become linked merely because another feature has no rollback record.

…re failures

Review follow-up (bsherman, blocking): a regular file at the link path
is hard-linked to a backup before any link moves and renamed back when a
later transfer fails; other non-symlink entries are refused up front;
restore failures are joined into the returned error.
Review follow-up (bsherman): with ClientConfig.Definitions set, the
refresh warning also reads the host's normal definitions.
… into feat/running-linked-status

# Conflicts:
#	.coverage-baseline
#	updex/features.go
linkAllOrNone now carries #458's regular-file backup and joined restore
errors, so rollback gets the same protection.
Review follow-up (bsherman, blocking): a transfer named by several
features is held by the rollback record of any of them; an unreadable
applicable record fails closed; a record is deleted only when every
rejected version is behind a link.
@frostyard-machines

Copy link
Copy Markdown
Contributor Author

Fixed in fc62e42 (Lucilla). #458's link-backup fix is merged in f919e10, so linkAllOrNone and rollback now use the same regular-file backup and joined restore errors.

  • collectRollbackHolds reads, once per call, the record of every feature that names a transfer (in Features= or RequisiteFeatures=), enabled or not, and keeps the highest rejected version per component. installTransfers uses it for the hold, the results and the vacuum protection, so it covers UpdateFeatures and enable --now. Features and CheckFeatures show the hold under every sharing feature.
  • An unreadable applicable record fails closed: nothing is linked, and the error names the feature whose record failed.
  • A record is deleted only when every rejected component is linked to a newer version. A component outside the feature's transfers is looked up in the loaded domain; if it is unknown or unreadable, the record stays.
  • Tests in updex/rollback_test.go: your reproduction (Features=grp other, after which UpdateFeatures keeps alpha at 1.0.0 and downloads nothing, also with grp disabled); enable --now other; a published 3.0.0 that links once and deletes grp's record; a malformed grp record (both sharing features fail closed, an unrelated feature updates); rollback_rejected shown under other; the vacuum keeps the rejected version.

@bsherman

Copy link
Copy Markdown
Contributor

Follow-up blocking concern on fc62e42: the original rejected-version bypass is fixed, but a sharing feature can still bypass the feature-wide hold and split the rolled-back feature.

Reproduction with the existing rollback fixture:

  1. grp contains alpha and beta; other shares only alpha.
  2. Both components have 1.0.0 and 2.0.0 staged, with 2.0.0 linked.
  3. Roll back grp: both links become 1.0.0, and its record rejects 2.0.0 for both components.
  4. Publish alpha 3.0.0, but leave beta newest at 2.0.0.
  5. Run UpdateFeatures.

The call succeeds. Its grp results say both components are held at 1.0.0, but processing other subsequently downloads and links alpha 3.0.0. The final links are alpha 3.0.0 and beta 1.0.0, despite the documented feature-wide hold. A focused regression test against fc62e42 fails on the alpha link preservation assertion.

collectRollbackHolds retains the applicable record, but holdByRollback checks only the transfers of the feature currently being processed. When processing other, it never checks the beta rejection in grp record. Keeping the record until all components advance does not prevent this partial advancement.

Please enforce the whole applicable rollback record before allowing a shared transfer to advance, or refuse this ambiguous sharing arrangement before rollback. Add coverage for a two-transfer rolled-back feature where another enabled feature shares only one transfer and only that transfer has a newer published revision. Cover enable --now through the sharing feature as well.

Review follow-up (bsherman): when the transfer whose link failed cannot
be restored, its result and the returned error carry the restore failure
and say that the link may point at the new version.
…ble record can

Review follow-up (bsherman, blocking): a feature that shares only some
transfers of a rolled-back feature is held while any component of that
record is still held, so it cannot split the rolled-back feature.
…ck branch

linkAllOrNone records a restore failure of the failing transfer itself.
@frostyard-machines

Copy link
Copy Markdown
Contributor Author

Fixed in 9c9c47e (Lucilla). #458's fix for a failed restore of the failing transfer itself is merged in 131f26c, through linkAllOrNone.

  • Rule. A shared transfer advances only when the whole applicable record can advance. For each record that applies to feature F, rollbackHoldReason checks every component the record names, also one outside F's transfers. Its transfer comes from the loaded domain, and its newest available version is read through the call's manifest cache.
  • When a record still holds. If any of its components has no version newer than its rejected version, the whole of F is held: nothing is downloaded or linked. The hold message names the component that holds, for example held by rollback of grp: beta has no version newer than 2.0.0.
  • Fail closed. A component with no transfer in the domain also holds. A version read error is an error for the feature.
  • Status. Features and CheckFeatures make the same decision. They report the new rollback_held_by field and keep update_available false while the record holds.
  • Tests:
    • your reproduction (grp has alpha and beta; other shares only alpha; alpha 3.0.0 is published): alpha and beta both stay at 1.0.0, nothing is downloaded, and other's result names beta;
    • the same through EnableFeature(other, Now);
    • beta 3.0.0 is published too: both components link 3.0.0 and grp's record is deleted;
    • a record component that is missing from the domain holds;
    • a version lookup failure is an error;
    • Features and CheckFeatures show the hold under other.

@bsherman

Copy link
Copy Markdown
Contributor

Follow-up blocking concern on 131f26c: checking publication of every record component still permits a shared transfer to split the rolled-back feature after a download failure.

The previous reproduction is fixed, and make verify plus the docs-integrity gate pass. However, I reproduced this additional failure path with the existing newSplitRollbackFixture:

  1. grp contains alpha and beta; other shares only alpha.
  2. grp is rolled back to 1.0.0, rejecting 2.0.0 for both components.
  3. Publish 3.0.0 for both components, so the whole-record availability check passes.
  4. Make beta image requests return 404 while keeping its manifest readable.
  5. Run UpdateFeatures.

Processing grp stages alpha 3.0.0, fails to download beta, and correctly links neither. But processing other then finds alpha already staged and relinks it to 3.0.0. Final links are alpha 3.0.0 and beta 1.0.0. grp alpha result says not linked while other alpha result reports it installed. The call returns the beta failure, but the rolled-back feature is nevertheless partially advanced. A focused regression test against 131f26c fails on alpha link preservation.

rollbackHoldReason establishes only that newer versions are published. It does not establish that all components of the applicable rollback group have successfully staged and can be linked together. Please prevent a sharing feature from advancing a transfer independently after another component of that group fails, or explicitly refuse ambiguous sharing before rollback. Add coverage for this download-failure case, and the analogous partial link failure, so the all-or-none guarantee survives processing another sharing feature.

…k record names

Review follow-up (bsherman, blocking): a sharing feature is held while
another feature's rollback record names one of its transfers, so a
download or link failure in the owner cannot be bypassed by relinking a
staged image through the sharing feature.
@frostyard-machines

Copy link
Copy Markdown
Contributor Author

Fixed in c4f019c (Lucilla).

New rule: only the owning feature advances a held group. While a rollback record of feature G exists, only G advances the transfers that the record names. G's transfers link all or none, and G deletes its record only after that link succeeds. Any other feature F that shares such a transfer is held as a whole: nothing is downloaded and no link moves. F reports held by rollback of grp: it advances only when grp updates (or run 'updex features rollback --clear grp').

  • So processing order, a download failure and a link failure in G can no longer let F relink an image that G staged.
  • Features and CheckFeatures report the same hold in rollback_held_by, with update_available=false.
  • G's own record keeps the earlier check: every component of the record must have a newer published version, then G stages and links all or none.
  • deleteFinishedRollbackRecords deletes only the processed feature's own record.

Documented limits:

  • A disabled or masked owner keeps the hold until someone runs --clear. updex never clears a record by itself.
  • Two sharing features that both have a record hold each other.

Tests:

  • your download-failure case (beta image 404; alpha and beta stay at 1.0.0, other is held, the run returns beta's error), with other processed before and after grp;
  • the partial link failure (beta's link fails), in both orders;
  • the happy path: grp links both at 3.0.0 and deletes its record, and on the next run other finds alpha current and downloads nothing;
  • mutual records;
  • enable --now other held;
  • status.

I updated the earlier shared-transfer tests to the owner message. make verify and make ci pass.

bsherman
bsherman previously approved these changes Oct 24, 2026

@bsherman bsherman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

…tatus

# Conflicts:
#	.coverage-baseline
#	docs/specs/sdk-api.md
#	sysext/manager_test.go
#	updex/features.go
# Conflicts:
#	cmd/updex/features_run.go
#	cmd/updex/features_status_test.go
#	docs/specs/sdk-api.md
#	updex/features.go
#	updex/results.go
#	updex/status.go
@bketelsen
bketelsen enabled auto-merge October 24, 2026 02:10
@bketelsen
bketelsen added this pull request to the merge queue Oct 24, 2026
Merged via the queue into main with commit ab4a382 Oct 24, 2026
19 checks passed
@bketelsen
bketelsen deleted the feat/feature-rollback branch October 24, 2026 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants