Skip to content

Stop AUR daemons from keeping the omarchy-update lock - #8081

Open
kdriedger wants to merge 9 commits into
omacom:quattrofrom
kdriedger:fix/update-lock-fd-leak
Open

kdriedger wants to merge 9 commits into
omacom:quattrofrom
kdriedger:fix/update-lock-fd-leak

Conversation

@kdriedger

Copy link
Copy Markdown

Fixes #8077

omarchy-update-lock used to exec the update, so every child inherited the flock. Flutter's adb daemonizes onto user systemd during AUR updates and kept that descriptor after the update exited. The next omarchy update then died immediately with An Omarchy update is already running.

The wrapper now holds the flock itself and runs the update with the descriptor closed — the same thing omarchy-update-stay-awake already does for the sleep inhibitor.

Proof

Before this change, a daemonized child of omarchy-update-lock run kept fd 10 on $XDG_RUNTIME_DIR/omarchy-update.lock and flock -n failed after the helper exited.

After:

test/shell.d/update-lock-test.sh
ok - omarchy-update-lock does not leak its flock to daemonized children
ok - omarchy-update does not leak its lock through AUR daemons
ok - omarchy-update-lock held is only true for the locked child

Overlapping-update exclusion, the sleep-inhibitor close, update sequence, and migrate-notify lock tests still pass. ./test/cli is green. Four shell files fail on this machine for reasons outside this change (no omarchy-pkgs checkout; one compositor animation check).

omarchy-update-lock used to exec the update, so every child inherited
the flock. Flutter's adb daemonizes onto user systemd and kept that
descriptor after the update exited, and the next omarchy update then
reported that one was already running.

Hold the flock in the wrapper and run the update with the descriptor
closed, the same trick stay-awake already uses for the sleep inhibitor.

Fixes omacom#8077
Copilot AI balanced review requested due to automatic review settings August 24, 2026 17:21

Copilot AI 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.

Pull request overview

Prevents daemonized AUR children from retaining the update lock.

Changes:

  • Keeps the flock in the wrapper and closes its descriptor for the update child.
  • Adds daemon lock-leak regression coverage.
  • Updates lock lifecycle documentation.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
bin/omarchy-update-lock Changes lock ownership and child execution.
test/shell.d/update-lock-test.sh Tests daemonized-child lock behavior.
docs/update-process.md Documents descriptor handling.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/update-process.md Outdated
Comment on lines +189 to +198
`omarchy-update-lock run` keeps the flock in the wrapper process and runs the
update with that descriptor closed. AUR children that daemonize (Flutter's `adb`
is the one that showed up in the wild) would otherwise inherit the flock, survive
the update, and make every later `omarchy update` report that one is already
running. `omarchy-update-stay-awake` still starts its sleep inhibitor with the
lock descriptor closed when it has one, for the same reason: that inhibitor
outlives the step that starts it, so an update killed before cleanup would
otherwise leave it holding the flock indefinitely — blocking later updates and,
now that the notifier reads the same lock, silencing migration notifications at
every login.
omarchybot and others added 4 commits September 28, 2026 18:48
quattro rebuilt update-lock-test.sh on the sudo-boundary fixture, which runs copies of the update commands against a per-run lock name. The daemon-leak tests now run those copies and look for $update_lock_name, and sit before the standalone-boundary section because it leaves SUDO_TEST_REVOKE_FAIL exported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AGENTS.md asks for full lines in docs/, with breaks only at structural boundaries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The stub standing in for the pre-upgrade stay-awake helper closed OMARCHY_UPDATE_LOCK_FD unconditionally. The update no longer receives that descriptor, so the close became an ambiguous redirect and the stub never started its inhibitor. Every shipped helper guards the close; the stub now does too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Now that the wrapper waits on the update instead of exec'ing it, the wrapper is what holds the flock. A closing terminal sends SIGHUP to the whole group, and bash's default is to die at once, so the lock was freed while omarchy-update was still running its HUP trap (stay-awake stop, sudo revocation). Before, the update held the lock itself until that cleanup finished.

A no-op trap keeps the wrapper alive until the update exits. Caught handlers reset on exec, so the update still sees HUP and TERM with its own traps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Sep 28, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks for the careful report and fix, @kdriedger. The leak is real on quattro: bin/omarchy-update-lock there still execs the update with the flock descriptor inherited by every child.

What was checked, on a disposable Omarchy worker VM:

  • test/shell.d/update-lock-test.sh passes 16/16 at the new head. With only bin/omarchy-update-lock put back to quattro's version, the check "daemonized child does not inherit the update lock descriptor" fails, so the new tests catch the bug and this change fixes it.
  • The full ./test/shell run and ./test/cli have the same failures as plain quattro (six shell tests in branding, kernel migrations, browser launch, captive portal and passwordless grant, plus one vscode theme check in test/cli). None of them touch the update lock.

Pushed to your branch (69a777d):

  • A merge of quattro. The branch conflicted. quattro rebuilt update-lock-test.sh on the sudo-boundary fixture, which runs copies of the update commands against a per-run lock name. Your tests now run on that fixture.
  • One upgrade stub guarded. A quattro test stub closed OMARCHY_UPDATE_LOCK_FD unconditionally. The update no longer receives that descriptor, so the stub failed with an ambiguous redirect. It now closes the descriptor only when it has one, as every shipped omarchy-update-stay-awake does.
  • The lock now survives a closing terminal. Because the wrapper now waits on the update instead of exec'ing it, the wrapper holds the flock. Closing the terminal sends SIGHUP to both, and the wrapper died at once, freeing the lock while omarchy-update was still running its hangup cleanup (stopping stay-awake, revoking sudo). A no-op trap : HUP TERM keeps the wrapper alive until the update exits. Handlers reset on exec, so the update still gets those signals and runs its own traps. There's a new test for it, which fails without the trap.
  • The docs/update-process.md paragraph is on one line. Copilot's review comment was right: the repository's AGENTS.md asks for unwrapped Markdown in docs/.

Second opinion: none. The configured reviewer (Codex Medium) answered a ping but had used up its daily review budget, so only Claude Opus 5.5 reviewed this change.

Next: this waits on that second review before it can be marked ready for the maintainer.

omarchybot and others added 2 commits October 31, 2026 21:40
quattro dropped the standalone sudo-boundary checks at the end of update-lock-test.sh; the lock tests from this branch stay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A process the update starts keeps OMARCHY_UPDATE_LOCKED=1 after the update has finished and the lock is free, so an omarchy update started from it would skip the lock and could run beside another. held() now checks that the wrapper named in the environment is still alive with the lock file open.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 31, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

@kdriedger, the leak is still there on quattro (e4fffc6). bin/omarchy-update-lock still execs the update, and every child inherits the flock. Your change fixes the cause. One part of the new wrapper needs another look before this can go to the maintainer: the lock can be released before the update's cleanup finishes when the terminal closes. Details are below.

What was checked, on a disposable Omarchy worker VM, at 93ea5dd:

  • A direct reproduction: with quattro's omarchy-update-lock, a setsid -f child of run keeps the lock after the wrapper exits, and the next run prints An Omarchy update is already running. At this head the lock is free and the next run goes through.
  • test/shell.d/update-lock-test.sh passes 14/14. With only bin/omarchy-update-lock put back to quattro's version, it fails on "daemonized child does not inherit the update lock descriptor".
  • ./test/cli passes. ./test/shell has five failing files (agent-account-exec, ascii, branding-about-animation, first-run and runtime-smoke). Each of the five fails the same way on plain quattro, and none of them touches the update lock.

Pushed to your branch:

  • A merge of quattro (facf2e8). The branch conflicted again. quattro dropped the standalone sudo-boundary checks at the end of update-lock-test.sh, so they are gone and your tests stay.
  • held now checks that the lock is still held (93ea5dd). OMARCHY_UPDATE_LOCKED=1 was inherited by everything the update started, so a process left behind by a finished update got true from omarchy-update-lock held while the lock was free. An omarchy update started from such a process would skip the lock and could run beside another update. The wrapper now exports OMARCHY_UPDATE_LOCK_HOLDER=<its pid>:<its fd>, and held is true only while that process still has the lock file open on that descriptor. A new check in the held block fails against the previous version and passes now.

Still open: the lock is released before the update's hangup cleanup when it runs under script(1). bin/omarchy-update-lock:43 ignores HUP and TERM so that the wrapper outlives the update's own cleanup. In a real update, though, the wrapper is script's direct child. When the terminal closes, script sends TERM to the wrapper only, and it kills the wrapper about two seconds later. The update gets no signal until then. On the worker, script -qefc 'omarchy-update-lock run <child that cleans up for 4s on HUP or TERM>' was sent HUP, and separately TERM:

  • On quattro, the child got TERM at once and the lock stayed held until the child was gone.
  • At this head, the child got nothing for two seconds. Then script killed the wrapper, which freed the lock, and only after that did the child get HUP. It ran its whole cleanup with the lock free.

In omarchy-update, that cleanup is the sudo keepalive shutdown and omarchy-update-stay-awake stop, so a second update can start while the first one is still cleaning up. The new HUP test sends the signal to the whole process group, so it doesn't cover this path, and it passes on quattro as well. Forwarding HUP and TERM from the wrapper to the update, then waiting for it, would close the window. Running the update as a background job loses Ctrl-C, though: bash makes background jobs ignore SIGINT, and the update could no longer trap it. So this needs a careful approach, and I have left it to you rather than pushing one.

Two smaller points from the review, for whoever picks this up:

Second opinion: Codex Medium and muse-wonder (via pi, thinking high) reviewed the pushed head. Both agreed the leak is real and that this change fixes its cause. Their independence from my reading is not guaranteed. Codex found the script(1) window above, and I reproduced it on the worker as described. muse-wonder pointed out that the HUP test passes on quattro and raised the upgrade point above.

Next: this waits on you for the signal handling. verified stands for the leak fix at this head, but this is not ready for the maintainer until the lock survives the update's cleanup under script.

@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change affects per-user update locking and workflows that check the same lock.

Cancellation through the original update PID still needs fixing before merge.

Findings

  1. P1 Update ignores cancellation ▶

Summary

The wrapper now keeps the update lock and closes its descriptor before starting the update.

  • Detached AUR processes no longer keep the update lock.

Reviews (2) · Last reviewed commit: "Record the update's PID in the lock file..." · Reviewed by Greptile

Comment thread bin/omarchy-update-lock
exec "$@"
export OMARCHY_UPDATE_LOCK_HOLDER="$$:$OMARCHY_UPDATE_LOCK_FD"
# A closing terminal signals the whole group; hold the lock until the update's own cleanup finishes.
trap : HUP TERM

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.

P1 Update ignores cancellation

Sending kill -TERM to the PID of OMARCHY_UPDATE_LOGGED=1 omarchy-update -y no longer stops the update. That process becomes the lock wrapper, whose new no-op trap discards the signal instead of forwarding it to the update child. The child can keep installing packages after the user requests cancellation.

Forward cancellation to the child while keeping the lock until its cleanup finishes.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Nov 15, 2026
omarchybot and others added 2 commits November 16, 2026 19:32
quattro's omacom#16045 records the acquiring PID in the lock file. Under this branch the wrapper is what holds the flock, so it writes its own PID there, and the stale-PID test compares against the locked command's parent rather than the command itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A contender reports "Update lock acquired by PID N", and N was the wrapper, which ignores TERM: kill N did nothing, and kill -9 N freed the lock while the update kept running. Writing the PID from a foreground subshell that then execs the command makes N the update itself, as it was before the wrapper, so TERM reaches its own traps and the lock is released only after its cleanup. Nothing is backgrounded, so Ctrl-C and stdin are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Nov 16, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

@kdriedger, quattro moved and this conflicted again, this time with #16045, which changed how omarchy update runs under script and started writing the lock holder's PID into the lock file. I merged it and pushed one fix on top. The signal-handling problem from my last comment no longer applies, so nothing here waits on you now.

Pushed to your branch:

  • A merge of quattro (62f504d). The conflict was in bin/omarchy-update-lock: your wrapper stays, and End omarchy update when its terminal closes at a prompt #16045's diagnostic PID is written once the lock is taken.
  • The lock file names the update, not the wrapper (1f3f0ca). Since End omarchy update when its terminal closes at a prompt #16045, a second omarchy update prints Update lock acquired by PID N. With the wrapper's PID there, kill N did nothing, because the wrapper ignores TERM, and kill -9 N freed the lock while the update kept running. The PID is now written from a foreground subshell that then execs the update, so N is the update itself, as on quattro: TERM reaches its own traps and the lock is released after its cleanup. Nothing is backgrounded, so Ctrl-C and reading from the terminal behave as before.

The script(1) window is closed by #16045. script's direct child is now an untrapped bash rather than your wrapper, so script's TERM, and its kill two seconds later, land on that shell. The wrapper only sees the terminal's hangup, which it outlives. On the worker, with a stand-in update that spends 3s cleaning up, closing the terminal, TERM to script and HUP to script all kept the lock held until the cleanup finished, at this head as on quattro.

What was checked, on a disposable Omarchy worker VM, at 1f3f0ca:

  • The leak: with quattro's omarchy-update-lock, a setsid -f child keeps the lock and the next run prints An Omarchy update is already running. At this head the next run goes through. With only bin/omarchy-update-lock put back to quattro's version, update-lock-test.sh fails on "daemonized child does not inherit the update lock descriptor".
  • test/shell.d/update-lock-test.sh passes 15/15, and End omarchy update when its terminal closes at a prompt #16045's test/shell.d/update-hangup-test.sh passes 4/4, repeated eight more times without a failure. ./test/cli passes.
  • ./test/shell has six failing files (ascii, branding-about-animation, first-run, provision-owner-keyboard, remote-session-service and runtime-smoke). All six fail the same way on plain quattro, and none of them touches the update lock.
  • The other readers of OMARCHY_UPDATE_LOCK_FD, in bin/omarchy-update and bin/omarchy-update-stay-awake, treat it as optional, so no longer exporting it changes nothing for them.

Second opinion: Codex Medium and muse-wonder (via pi, thinking high) reviewed the merge, then the pushed head. On the merge, both found the PID problem above, and both concluded that the script(1) window can no longer be reached on a real update, which matches what the worker showed. Their independence from my reading is not guaranteed. On 1f3f0ca, both found nothing left.

Related: #12094 and #13936 still change bin/omarchy-update-lock for other bugs, and #17020 changes the launcher in bin/omarchy-update. None of them competes with this one.

Next: this is verified at 1f3f0ca and waits on the maintainer. The full shell suite is red on quattro itself, and the new lock behaviour is theirs to accept: the wrapper holds the flock and outlives a hangup, and held trusts the wrapper's open descriptor.

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

Labels

bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

omarchy update lock leaks through AUR daemons (adb), so later updates report one is already running

3 participants