Skip to content

Keep hibernation resume offset in sync with the swapfile - #13768

Closed
rand0mdud3 wants to merge 2 commits into
omacom:quattrofrom
rand0mdud3:fix-hibernation-stale-resume-conf
Closed

rand0mdud3 wants to merge 2 commits into
omacom:quattrofrom
rand0mdud3:fix-hibernation-stale-resume-conf

Conversation

@rand0mdud3

Copy link
Copy Markdown

Fixes #13583.

Removing hibernation deleted the swapfile, fstab entry, and mkinitcpio hook but left /etc/limine-entry-tool.d/resume.conf behind — and setup kept any existing file ([[ ! -f ]] guard). A later setup then resumed from a stale offset and silently lost the session.

  • omarchy-hibernation-remove now deletes the resume kernel parameters with the rest of the teardown.
  • omarchy-hibernation-setup always recomputes device and offset from the current swapfile instead of keeping a leftover file.

Verified: new test/shell.d/hibernation-resume-conf-test.sh 4/4 (fails on base, passes with the fix), style suite green, ./test/cli and unowned-system-paths-test show only failures that reproduce identically on pristine base.

@sanjyay

sanjyay commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

This is an independent community review and unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Tested commit 6e3991d8ad632ba5ab06925ed56b8cd2358abdc2 in an isolated Omarchy test environment.

Verification Summary

  • Base Reproduction (origin/quattro): On the base branch, running omarchy-hibernation-remove removed the swapfile and mkinitcpio hook but left /etc/limine-entry-tool.d/resume.conf on disk. Because omarchy-hibernation-setup previously guarded offset calculation behind if [[ ! -f $RESUME_DROP_IN ]], re-enabling hibernation preserved the old swapfile's offset instead of recomputing it for the new swapfile extents, silently risking resume failure and session loss. Running the regression test on base reproduces the defect:
    not ok - remove deletes the resume kernel parameters
    
  • PR Branch Verification (pr-13768):
    • bin/omarchy-hibernation-remove now deletes /etc/limine-entry-tool.d/resume.conf during teardown before limine-mkinitcpio regenerates entries.
    • bin/omarchy-hibernation-setup unconditionally recomputes the resume device and btrfs swapfile offset from the newly active swapfile.
    • All 4 assertions in test/shell.d/hibernation-resume-conf-test.sh pass cleanly:
      • Teardown deletes kernel resume drop-in and hook config.
      • Clean teardown on unconfigured systems no-ops without error.
      • Re-running setup over a stale drop-in refreshes the offset.
      • Fresh setup correctly computes and writes the parameters.
    • omarchy commands --check passed across 467 commands, and git diff --check reported no formatting issues.
Verification output
$ ./test/shell.d/hibernation-resume-conf-test.sh
ok - remove deletes the resume kernel parameters
ok - remove without a setup touches nothing
ok - setup refreshes a stale resume offset
ok - fresh setup writes the resume parameters

$ omarchy commands --check
Command metadata check passed (467 commands)

The fix directly addresses #13583 with clean teardown, reliable offset recomputation, and thorough test coverage.

If you'd prefer not to receive these independent reviews on your PRs, reply to this comment and say so, and I won't review your future PRs.

@rand0mdud3

Copy link
Copy Markdown
Author

Thanks for the thorough independent verification — base reproduction, all four test assertions, plus the command-metadata and whitespace checks. Good to have the defect and the fix both confirmed outside my own environment. Nothing to change from my side; this one is awaiting maintainer review.

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 6e3991d and verified on an Omarchy worker VM (real btrfs root, Limine, hibernation already configured), against quattro at a85e29a.

Reproduction. On quattro, omarchy-hibernation-remove left /etc/limine-entry-tool.d/resume.conf in place, and with a leftover resume_offset=1111 a fresh omarchy-hibernation-setup --force kept 1111 while the new swapfile's real offset was 2893056. On this branch, remove deletes the drop-in and setup rewrites it to the swapfile's actual offset (4465920 in that run). The new test/shell.d/hibernation-resume-conf-test.sh fails on quattro, passes here, and fails again with either half of the fix reverted, so both the remove and the setup change are needed.

Suite. ./test/cli has one failure, vscode generated theme references current theme file, which fails the same way on quattro and is unrelated to this change. bin-style-test, command-operand-boundaries-test, unowned-system-paths-test and omarchy commands --check pass.

Review. Claude Opus 5.5 and Codex Medium, as a second opinion, both read the diff and its callers, including omarchy-system-factory-reset, which still deletes both drop-ins before it runs setup and is unaffected. Codex agreed the bug is real and the change proportionate (its independence from the first review is not guaranteed). Neither found a defect. One limit carries over from quattro unchanged: if btrfs inspect-internal map-swapfile returns nothing, setup warns and leaves any existing resume.conf as it was.

Related. It overlaps with #13908 (empty resume device), which rewrites the same block of omarchy-hibernation-setup. They fix different bugs, but whichever lands second will need a rebase.

Nothing is needed from the author. This waits on the maintainer, and on the unrelated test/cli failure being resolved on quattro.

@brightmeows

Copy link
Copy Markdown

Heads-up from #14379: I'm planning to pick up the complementary half — a boot-time consistency check that catches a swapfile whose live offset drifted from what resume.conf/cmdline carries (e.g. the swapfile was recreated or moved outside omarchy tooling after your setup/remove sync ran). Your PR keeps them in sync at setup/remove; the runtime check covers drift after the fact. I don't see overlap with this diff, but shout if you do — particularly around where the swapfile path is recorded, so both ends reference it the same way.

@rand0mdud3

Copy link
Copy Markdown
Author

No overlap from my side — welcome complement. This diff only touches the setup/remove sync path (resume.conf deleted on teardown, unconditionally recomputed on setup); a boot-time drift check lives entirely outside it.

On the path question: the swapfile path is not recorded anywhere. It's a hardcoded SWAP_FILE="/swap/swapfile" constant in omarchy-hibernation-setup, and resume.conf carries only resume=<device> resume_offset=<N>. Your #14379 snippet uses the same literal, so both ends already converge by convention — I'd keep it that way while the single-swapfile assumption holds rather than inventing a registry for it. The one thing I'd note: if someone ever relocates the swapfile, setup itself would need the new path too, so a drift check reading the literal fails in exactly the case setup would also mishandle. Consistent failure beats silent divergence.

Your real-world case (configured 1630758 vs actual 1894950 after a move outside the tooling) is precisely the hole this PR can't cover — glad it's being picked up.

Removing hibernation deleted the swapfile, fstab entry, and mkinitcpio hook but left /etc/limine-entry-tool.d/resume.conf behind, and setup kept any existing file. A later setup then resumed from a stale offset and silently lost the session.

Remove now deletes the resume kernel parameters with the rest of the teardown; setup always recomputes device and offset from the current swapfile.
@rand0mdud3

Copy link
Copy Markdown
Author

Rebased onto current quattro (ee8ad06) — the rebase was needed, not cosmetic: the PR had gone dirty (textual conflict) and lost its verified label, so it could no longer merge.

Conflict and resolution: upstream added resume_device() (names the resume device by filesystem UUID, or by its device-mapper name) plus the rename_resume_device / rebuild_renamed_resume_device repair path, which collided with this PR's inline findmnt -no SOURCE line. Resolved by keeping this PR's unconditional recompute and calling resume_device() instead of the inline expression, so the refreshed drop-in now inherits upstream's UUID naming rather than reintroducing a kernel device name.

Unchanged in intent: remove still deletes resume.conf; setup still always recomputes device+offset instead of keeping a leftover file.

Verification on the rebased head (9d5c0a6): test/shell.d/hibernation-resume-conf-test.sh 4/4, and upstream's hibernation-setup-test.sh 5/5 — so the UUID-naming, rename-once, interrupted-rebuild-retry and hand-edited-drop-in behaviours all still hold with the guard removed.

Scope note for #14360 and #11437: this covers the stale-offset-on-setup and remove paths only. The empty resume= and the rerun-on-an-already-configured-install case (the early exit before the recompute) remain with #12630 / #11437 and #11477.

@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with a non-blocking test isolation fix recommended.

Findings

  1. P2 Test reaches the host directory ▶

Summary

Removes leftover resume parameters during hibernation teardown and recomputes them during fresh setup.

  • Hibernation setup keeps boot resume settings matched to the swapfile.

Reviews (2) · Last reviewed commit: "Fold the regression cases into the hiber..." · Reviewed by Greptile

Greptile asked for both: the new file repeated the setup stubs in
hibernation-setup-test.sh, and AGENTS.md says to extend the area's existing
test rather than add another *-test.sh. The two setup cases become one (a fresh
setup was already covered), the stub for gum can now confirm removal, and the
build stub tolerates the drop-in remove has just deleted.

Each added case fails on the base branch for the reason the fix exists: the
leftover resume.conf keeps its stale offset, and remove leaves the kernel
parameters behind.
@rand0mdud3

Copy link
Copy Markdown
Author

Both Greptile findings addressed in 409200dc:

Test depended on host settings (P1). Correct: the separate file only stubbed the helpers it thought it needed, so on a host with sleep disabled, or an Apple Silicon Mac, the real omarchy-sleep-disabled / omarchy-hw-aarch64-apple would have made setup exit before replacing the stale drop-in. Moot now that the cases live in hibernation-setup-test.sh, which stubs both to exit 1 already; nothing in the file reads the host.

New test duplicated the existing setup (P2). Correct per AGENTS.md. test/shell.d/hibernation-resume-conf-test.sh is gone and its cases now sit in hibernation-setup-test.sh on that file's own harness (machine / setup, the sed-rewritten real script, its stubs). Net: 205 new lines replaced by 46 added lines.

What the merge changed, and why it is smaller than a straight move:

  • The "fresh setup writes the parameters" case was dropped: the existing first case already sets up a fresh machine and asserts the drop-in line, so it restated coverage.
  • Two setup cases became one: only "a setup with no resume hook recomputes a leftover resume.conf" is new behaviour, and it now asserts the 1111 → 4242 offset change rather than just a match.
  • gum in the shared stub loop now exits ${GUM_CONFIRM:-1}, so the setup cases keep refusing the prompt while the removal cases can confirm it.
  • The limine-mkinitcpio stub only cats $DROP_IN when it exists, since removal deletes it before rebuilding.
  • The btrfs stub fails subvolume, so removal does not try to delete one in the scratch tree.

Verification, each case failing on the base branch for the reason the fix exists:

Case base head
setup recomputes a leftover resume.conf not ok ok
remove deletes the resume kernel parameters not ok ok
remove without a setup leaves them alone ok ok

hibernation-setup-test.sh 8/8 on the head, ./test/cli passes (exit 0).

printf '#!/bin/bash\nexit 0\n' >"$rtmp/bin/swaplabel"
printf '#!/bin/bash\n[[ $1 == --show ]] && echo "$SWAP_FILE_PATH"\nexit 0\n' >"$rtmp/bin/swapon"
printf '#!/bin/bash\n[[ $1 == inspect-internal ]] && echo 4242\nexit 0\n' >"$rtmp/bin/btrfs"
printf '#!/bin/bash\n[[ $1 == subvolume ]] && exit 1\n[[ $1 == inspect-internal ]] && echo 4242\nexit 0\n' >"$rtmp/bin/btrfs"

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.

P2 Test reaches the host directory

The new btrfs stub makes fresh setup enter the subvolume-creation branch, which calls the real chattr +C /swap. The setup copy rewrites /swap/swapfile but leaves SWAP_SUBVOLUME="/swap" unchanged, and the fake sudo simply runs the command.

Ordinary runs hide the resulting permission error. If the test runs as root, it can change the real directory's flags. Rewrite "/swap" in the setup copy too, and stub chattr.

@omarchybot

Copy link
Copy Markdown
Collaborator

Re-reviewed at 409200d, against quattro at 7eedd17. The bug is still present on quattro, and this pull request fixes the case #13583 describes. Three open pull requests fix it, though, and #8199, opened on 25 August, is the one to carry.

Why #8199. By default the oldest fix wins. A newer one wins only when it is clearly better, and this one isn't. #8199 makes the same setup change: it always recomputes the device and offset with resume_device(). It also handles three cases this branch does not:

Nothing here needs to be folded into #8199. Its tests already cover the leftover-drop-in setup case, and its remove test checks that the drop-in is gone when the boot image is rebuilt.

Two problems in this branch's test, for the record:

  • The btrfs stub now fails every subvolume call. In the setup cases, btrfs subvolume show therefore fails and setup runs the real chattr +C /swap on the machine running the test: the setup copy rewrites /swap/swapfile but not SWAP_SUBVOLUME="/swap", and the stubbed sudo just runs the command. This is the finding Greptile raised on line 28.
  • In the remove cases, machine() creates $rtmp/swapfile, but the rewritten remove script looks for $rtmp/swap/swapfile, so deleting the swapfile is never exercised.

What was checked: the diff and both scripts at this head, read against quattro and compared with #8199 and #13584. Nothing was run this time: verifying a fix that won't be the one merged would spend a worker on nothing. The second opinion was Codex Medium. I asked it to choose among the three without giving it my answer. It picked #8199 for the same reasons, found nothing here worth folding in, and independently found the chattr path and the fixture mismatch. Its independence from my reasoning is not guaranteed.

The choice between the competing fixes belongs to the maintainer, so this waits on them. @rand0mdud3, thank you for the careful rebase onto resume_device() and the clear case table. Nothing is needed from you unless the maintainer prefers this branch.

@rand0mdud3

Copy link
Copy Markdown
Author

Checked #8199 against ours: the assessment is right, and I'd rather it be the one carried.

Verified in #8199's diff, the three cases this branch does not handle:

  • Its remove only exits early when neither the hook nor the drop-in is present, then deletes the drop-in unconditionally — so a machine an older remove already left with a stale resume.conf is repaired. Ours exits on the missing hook, and our new test asserts the drop-in stays, which encodes the wrong behaviour.
  • Its setup exits 1 when map-swapfile returns nothing, changing nothing. Ours warns and lets the stale offset through to the rebuild.
  • Its rm -f "$RESUME_DROP_IN" || exit 1 stops before rebuilding; ours ignores the result and then prints "Hibernation removed".
  • It also writes the drop-in before the hook, so a failed lookup cannot leave the machine reporting hibernation as set up with no parameters.

Both test findings are real, and both are mine — they came in with the fold-in at 409200d, not with the original change:

  • The btrfs stub I added to keep the remove cases off the host's subvolume makes btrfs subvolume show fail in the setup cases too, so setup takes the create path and runs the real chattr +C /swap on whatever machine runs the test. The setup copy rewrites /swap/swapfile but not SWAP_SUBVOLUME="/swap".
  • The remove cases' fixture is $rtmp/swapfile while the rewritten remove resolves $SWAP_SUBVOLUME/swapfile to $rtmp/swap/swapfile, so the swapfile-deletion path never runs.

That is enough to say this branch should not be merged as it stands: the test as written can touch the host, which is worse than the coverage it adds. Nothing here needs folding into #8199.

The choice stays with the maintainer. If #8199 is the one, I'll close this as superseded; if you'd rather keep this branch, I'll fix the two test defects and add the missing cases rather than leave it as is.

@rand0mdud3

Copy link
Copy Markdown
Author

Closing as superseded by #8199.

It covers the same fix for #13583 and the three cases this branch missed (stale drop-in left by an older remove, an empty offset lookup, a failed delete), and it has been open since 25 August. The test in this branch can touch the host through the btrfs stub, so it should not merge in this state.

Nothing to fold in; #8199's own tests cover the leftover-drop-in setup case. Reopen if the maintainer ever prefers this branch, and I'll fix the two test defects first.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

omarchy hibernation remove leaves resume.conf behind, so a later setup keeps a stale resume_offset

4 participants