Skip to content

Run migrations again when a snapshot restore rolled them back - #21021

Open
photuris wants to merge 2 commits into
omacom:quattrofrom
photuris:feat/migrate-rollback-reconcile
Open

photuris wants to merge 2 commits into
omacom:quattrofrom
photuris:feat/migrate-rollback-reconcile

Conversation

@photuris

@photuris photuris commented Dec 1, 2026

Copy link
Copy Markdown

What changes

Fixes #9828. omarchy-migrate decides a migration is done by one test: its marker exists under ~/.local/state/omarchy/migrations/. That directory is on @home, and much of what migrations change is on @. A Snapper restore of / puts @ back and leaves the markers, so the next omarchy update runs no migrations and says nothing. On 4.6.0-rc1 a tester restored the pre-update snapshot, updated again, and 131 migrations were skipped (comment in #9828).

The runner now keeps two more empty files for each migration it completes:

  • a root record, /var/lib/omarchy/migration-records/<uid>/<migration>, on the root filesystem, so a restore takes it back;
  • a receipt, ~/.local/state/omarchy/migrations-receipts/<machine-id>/<migration>, which says a root record was written on this machine.

A migration whose receipt is there while its root record is gone was rolled back by a restore. It is pending again: omarchy-migrate --pending lists it, and omarchy update, the login notifier and a manual omarchy-migrate pick it up with no new command. The rerun is announced as "Running migration again after a snapshot restore (…)".

Only those migrations run again. #9828 found that replaying every migration is unsafe, so a marker without a receipt is trusted exactly as today. That covers every marker written before this change, the markers from /etc/skel, and a home directory carried to another machine or a reinstall (the receipt is keyed by /etc/machine-id). Nothing that is complete today becomes pending.

Privilege: the records directory belongs to the user but sits under root-owned directories, so creating it takes root once. The runner creates it only in a process that inherited the update lock, with sudo -n, so it never asks for a password; inside omarchy update the authorization is already there. Any other run writes records when the directory exists and otherwise completes without them. Records and receipts are best effort and never fail a migration. A user can only misreport their own migrations, which is equally true of their markers.

The manual paragraph that #15159 added as a warning now describes this, and keeps the warning for the cases below.

Limits:

  • A migration is covered only once it has a receipt. Migrations run before this change, or run by hand before the first update with it, are still not noticed after a restore.
  • A rerun applies the migration's home-side part again. An edit made between the first run and the rerun to a file that migration overwrites is lost.
  • A rerun that fails stops the queue, like any failed migration. Removing its receipt accepts it as done (agents/skills/migrations.md).
  • Detection relies on /var/lib/omarchy being on the snapshotted root subvolume, as it is on the default layout.

Overlap: #16100 (multi-user) contains a wheel-writable /var/lib/omarchy/admin-migrations record that also reruns an administrator's migration after a rollback. This PR is the small standalone fix for #9828 and will conflict with it in bin/omarchy-migrate. It also conflicts textually, not in behaviour, with #14827, #17237, #18210 and #12906; it does not read or write marker content.

Verification

  • bash test/shell.d/migrate-scope-test.sh: 13 pass (8 before). The five new cases: exactly the rolled-back migration reruns; markers without a receipt are trusted; another machine's receipts are ignored; sudo is called only when the update lock is held, as sudo -n install -d -m 755 -o <uid> <dir>; the run falls back to plain markers when no record can be written. Each new case fails when the line it covers is changed (12 mutations, run by an independent reviewer).
  • bash test/shell.d/i18n-test.sh and bash test/shell.d/migrate-notify-test.sh pass.
  • In an Omarchy VM (Limine, btrfs, Snapper), with a temporary home and two synthetic migrations: holding the update lock, the runner created /var/lib/omarchy/migration-records/1000 (owner 1000, mode 755, parent owned by root) and recorded the first migration. I took a Snapper snapshot of /, ran the second migration, and checked that the snapshot holds the first record and not the second. Given the snapshot's records, omarchy-migrate --pending printed only the second migration and the runner ran only it, with the new heading.
  • ./test/all: test/cli passes. test/shell reports two failures in files this PR does not touch: agent-account-test.sh ("a failed save while promoting keeps the next primary's login") fails the same way on quattro at 0d649d8, and default-agent-test.sh failed once in the full run and passes alone on this branch.
  • Not checked: a real limine-snapper-restore followed by a reboot and omarchy update. The VM check uses the content of a real snapshot instead. The systemd-boot restore path (omarchy-boot-sync restore-stage) was not exercised; it also replaces / from a snapshot.

Screenshots

No visible change: a terminal heading in omarchy-migrate after a restore; no shell, menu or config change.

Written by Claude (Fable 5.2) with an implementer (Gemini 4 Neon) and an independent reviewer and verifier (GPT 6.1 Sol), directed by @photuris.

@greptile-apps

greptile-apps Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Adds root-side migration records and machine-specific receipts so migrations can run again after a snapshot restore.

  • Migrations rerun when a snapshot restore removes their root records.

photuris explicitly acknowledges that older migrations and failed record writes lack restore detection, reruns can overwrite later home edits, failed reruns stop the queue, and detection requires records on the snapshotted root. These intentional limits are not findings.

Review was based on source inspection; no tests were executed.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Check migration] --> B{Home marker exists?}
  B -->|No| E[Run migration]
  B -->|Yes| C{Receipt exists for this machine?}
  C -->|No| D[Skip migration]
  C -->|Yes| F{Root record exists?}
  F -->|Yes| D
  F -->|No| E
  E --> G{Succeeded?}
  G -->|No| H[Leave pending and stop queue]
  G -->|Yes| I[Try to write root record and receipt]
  I --> J[Write home marker]
Loading

Reviews (1) · Last reviewed commit: "Document migration records and the rerun..." · Reviewed by Greptile

@chessing234

Copy link
Copy Markdown
Contributor

@dhh @omarchybot rerunning migrations whose records a snapshot restore rolled back, and the note on those records, is in #21027. The migration runner cases in migrate-scope-test.sh passed here. The last case in that file dies on this Mac because BSD find has no -printf.

Please consider closing this as superseded only after #21027 is accepted. Leaving the close to you.

@omarchybot

Copy link
Copy Markdown
Collaborator

GPT-6.2 Sol High in Codex read the migration runner diff and #9828 and classified this as a bug fix because a root snapshot restore can undo a migration while its completion marker survives in the home directory. DeepSeek V4.1 Flash in Pi, using the default reasoning setting, classified it as an enhancement, so worker verification is paused until the classification is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Snapper rollbacks silently un-apply Omarchy migrations (surfaced as: LUKS prompt still QWERTY after e891e5c)

3 participants