Repository navigation
Skip lid suspend for working agents and on demand - #11525
colorfulfool wants to merge 1 commit into
Conversation
Automated AI review
Outcome: When the working agents change, the guard kills its inhibitor before starting a new one, so an undocked closed lid can suspend. Reason change drops the inhibitorThe Suggested change: Keep a live inhibitor while any reason applies; use a fixed Reproducer (fails at 20a9407; PIDs are from an isolated sandbox PID namespace)Reproducer: a change in which agents are working kills the held inhibitor before starting the next oneReviewed head: 20a9407 (also fails identically with the PR merged into quattro 8b4eae6).
Save as #!/bin/bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
guard="$ROOT/bin/omarchy-system-lid-guard"
tmpdir=$(mktemp -d)
pidfile=""
cleanup() {
[[ -n $pidfile && -f $pidfile ]] && kill "$(cut -d' ' -f1 "$pidfile")" 2>/dev/null || true
[[ -n ${first_pid:-} ]] && kill "$first_pid" 2>/dev/null || true
rm -rf "$tmpdir"
}
trap cleanup EXIT
export HOME="$tmpdir/home" XDG_RUNTIME_DIR="$tmpdir/runtime" AGENTS="$tmpdir/agents"
export OMARCHY_LID_STATE_GLOB="$tmpdir/lid/state"
pidfile="$XDG_RUNTIME_DIR/omarchy-lid-guard/inhibit.pid"
mkdir -p "$HOME" "$XDG_RUNTIME_DIR" "$tmpdir/bin" "$tmpdir/lid"
# Lid closed, undocked, on AC. While the lid stays closed logind re-checks it
# on every event, so any moment without a handle-lid-switch inhibitor suspends.
echo "state: closed" >"$tmpdir/lid/state"
cat >"$tmpdir/bin/herdr" <<'SH'
#!/bin/bash
cat "$AGENTS"
SH
cat >"$tmpdir/bin/systemd-inhibit" <<'SH'
#!/bin/bash
exec sleep 300
SH
cat >"$tmpdir/bin/omarchy-cmd-missing" <<'SH'
#!/bin/bash
exit 1
SH
for command in omarchy-power-present omarchy-system-lock; do
printf '#!/bin/bash\nexit 0\n' >"$tmpdir/bin/$command"
done
chmod +x "$tmpdir/bin"/*
export PATH="$tmpdir/bin:$PATH"
inhibitor_pid() {
head -n 1 "$pidfile" | cut -d' ' -f1
}
# Two agents are working, then one of them finishes while the other keeps
# working: the lid must stay inhibited throughout.
echo '{"result":{"agents":[{"agent":"claude","agent_status":"working"},{"agent":"codex","agent_status":"working"}]}}' >"$AGENTS"
"$guard" reconcile
first_pid=$(inhibitor_pid)
kill -0 "$first_pid" 2>/dev/null || fail "two working agents hold the lid" "pid $first_pid"
echo '{"result":{"agents":[{"agent":"claude","agent_status":"working"},{"agent":"codex","agent_status":"done"}]}}' >"$AGENTS"
"$guard" reconcile
sleep 0.2
kill -0 "$first_pid" 2>/dev/null ||
fail "the held inhibitor survives a change in which agents are working" \
"inhibitor $first_pid was killed and replaced by $(inhibitor_pid); between the two the lid was not inhibited"
pass "the held inhibitor survives a change in which agents are working"Actual output at the PR head (exit 1): With the replacement removed (a live inhibitor is kept while any reason applies), the same test passes: Ordering detail from a separate run, with a stub (The roughly 2 ms gap here is a bash stub's fork and exec. A real Why the gap suspends: this part comes from reading systemd v262, not from running logind. In The daemon ignores SIGTERM
Suggested change: Reproducer (fails at 20a9407; PIDs are from an isolated sandbox PID namespace)Reproducer: the guard daemon keeps running after SIGTERMReviewed head: 20a9407 (also fails identically with the PR merged into quattro 8b4eae6).
Save as #!/bin/bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
guard="$ROOT/bin/omarchy-system-lid-guard"
tmpdir=$(mktemp -d)
daemon_pid=""
cleanup() {
[[ -n $daemon_pid ]] && kill -KILL -- "-$daemon_pid" 2>/dev/null || true
rm -rf "$tmpdir"
}
trap cleanup EXIT
export HOME="$tmpdir/home" XDG_RUNTIME_DIR="$tmpdir/runtime"
export OMARCHY_LID_STATE_GLOB="$tmpdir/lid/state"
mkdir -p "$HOME" "$XDG_RUNTIME_DIR" "$tmpdir/bin" "$tmpdir/lid"
echo "state: open" >"$tmpdir/lid/state"
cat >"$tmpdir/bin/herdr" <<'SH'
#!/bin/bash
echo '{"result":{"agents":[{"agent":"claude","agent_status":"working"}]}}'
SH
cat >"$tmpdir/bin/systemd-inhibit" <<'SH'
#!/bin/bash
exec sleep 300
SH
cat >"$tmpdir/bin/omarchy-cmd-missing" <<'SH'
#!/bin/bash
exit 1
SH
for command in omarchy-power-present omarchy-system-lock; do
printf '#!/bin/bash\nexit 0\n' >"$tmpdir/bin/$command"
done
chmod +x "$tmpdir/bin"/*
export PATH="$tmpdir/bin:$PATH"
# Run the daemon in its own process group, the way systemd runs it in its own
# cgroup, and wait until it holds the inhibitor.
setsid "$guard" daemon &
daemon_pid=$!
for _ in {1..50}; do
[[ -s $XDG_RUNTIME_DIR/omarchy-lid-guard/inhibit.pid ]] && break
sleep 0.1
done
[[ -s $XDG_RUNTIME_DIR/omarchy-lid-guard/inhibit.pid ]] || fail "daemon takes the inhibitor"
# systemctl stop sends SIGTERM to every process in the unit (KillMode=control-group).
kill -TERM -- "-$daemon_pid"
for _ in {1..30}; do
kill -0 "$daemon_pid" 2>/dev/null || break
sleep 0.1
done
if kill -0 "$daemon_pid" 2>/dev/null; then
fail "the guard exits on SIGTERM" \
"daemon $daemon_pid still running 3s after SIGTERM; pidfile now names $(head -n 1 "$XDG_RUNTIME_DIR/omarchy-lid-guard/inhibit.pid" 2>/dev/null || echo nothing)"
fi
pass "the guard exits on SIGTERM"Actual output at the PR head (exit 1): The pidfile names a new inhibitor (352) started after the SIGTERM. A separate run that waited 7 seconds found the daemon still running and one inhibitor acquired 16 ms after the SIGTERM. With the TERM/INT trap changed to exit ( More findingsThe guard locks a docked (clamshell) lid close
Suggested change: Drop the guard's lock, or gate it on The new unit is not in the package recipeThe Suggested change: Add the unit to Reproducer for the docked lock (fails at 20a9407)Reproducer: the guard locks a docked (clamshell) lid closeReviewed head: 20a9407 (also fails identically with the PR merged into quattro 8b4eae6).
Save as #!/bin/bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
guard="$ROOT/bin/omarchy-system-lid-guard"
tmpdir=$(mktemp -d)
cleanup() {
local pidfile="$XDG_RUNTIME_DIR/omarchy-lid-guard/inhibit.pid"
[[ -f $pidfile ]] && kill "$(cut -d' ' -f1 "$pidfile")" 2>/dev/null || true
rm -rf "$tmpdir"
}
trap cleanup EXIT
export HOME="$tmpdir/home" XDG_RUNTIME_DIR="$tmpdir/runtime" CALL_LOG="$tmpdir/calls"
export OMARCHY_LID_STATE_GLOB="$tmpdir/lid/state"
mkdir -p "$HOME" "$XDG_RUNTIME_DIR" "$tmpdir/bin" "$tmpdir/lid"
: >"$CALL_LOG"
# Docked: lid closed with an external monitor connected, on AC, while herdr
# reports a working agent.
cat >"$tmpdir/bin/herdr" <<'SH'
#!/bin/bash
echo '{"result":{"agents":[{"agent":"claude","agent_status":"working"}]}}'
SH
cat >"$tmpdir/bin/systemd-inhibit" <<'SH'
#!/bin/bash
exec sleep 300
SH
cat >"$tmpdir/bin/omarchy-cmd-missing" <<'SH'
#!/bin/bash
exit 1
SH
for command in omarchy-power-present omarchy-hw-external-monitors omarchy-hw-laptop-closed omarchy-hyprland-monitor-clamshell; do
printf '#!/bin/bash\nexit 0\n' >"$tmpdir/bin/$command"
done
cat >"$tmpdir/bin/omarchy-system-lock" <<'SH'
#!/bin/bash
echo omarchy-system-lock >>"$CALL_LOG"
SH
chmod +x "$tmpdir/bin"/*
export PATH="$tmpdir/bin:$PATH"
# The existing lid handler leaves a docked close unlocked: that is clamshell
# mode, still in use on the external display.
"$ROOT/bin/omarchy-system-lid-close"
[[ ! -s $CALL_LOG ]] || fail "docked lid close does not lock" "$(cat "$CALL_LOG")"
pass "docked lid close does not lock"
# The guard sees the same close on its next poll.
echo "state: open" >"$tmpdir/lid/state"
"$guard" reconcile
echo "state: closed" >"$tmpdir/lid/state"
"$guard" reconcile
[[ ! -s $CALL_LOG ]] || fail "guarded docked lid close does not lock" "calls: $(tr '\n' ' ' <"$CALL_LOG")"
pass "guarded docked lid close does not lock"Actual output at the PR head (exit 1): With the guard's lock gated on Matrix from a separate run (lock calls made by the guard vs by In the undocked case the guard's lock duplicates the one Packaging check (static, at 20a9407)Check: the new user unit is not installed by the omarchy-settings packageReviewed head: 20a9407. This is a static check, not a run. Unit files under Commands (omarchy-pkgs master at 5a49a3fab56c2dea5190c8a1cfe42a38555bec48): curl -fsSL https://raw.githubusercontent.com/omacom/omarchy-pkgs/5a49a3fab56c2dea5190c8a1cfe42a38555bec48/pkgbuilds/omarchy-settings/PKGBUILD -o PKGBUILD
grep -c 'omarchy-lid-guard' PKGBUILD
grep -n 'default/systemd/user/.*\.service' PKGBUILDActual output: The Consequences, from source reading only (not executed against systemd):
DetailsVerified:
Optional notes:
Review informationTest scope: Source and sandbox tests with stubbed AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check. Opt out: To stop receiving these reviews, reply to this comment saying so. |
20a9407 to
503def2
Compare
|
|
Thanks to both reviewers — all findings below are addressed in the latest commits (rebased onto current llstrk reviewReason change drops the inhibitor — fixed. The guard no longer puts agent names in Daemon ignores SIGTERM — fixed. The daemon now traps Guard locks a docked close — fixed by removal. The guard no longer locks at all: the Hyprland lid-switch binding still fires while the inhibitor holds, so Unit missing from the package recipe — half here, half in omarchy-pkgs. The unit is now in Also applied: Greptile reviewSkip confirmed without protection (P1) — fixed. Brief close leaves skip armed (P1) — fixed. Guarded close locks twice (P2) — fixed by removal, same as above: the guard holds the inhibitor and does nothing else on a close. Guard failure interrupts first-run (P2) — fixed. The separate enable is now warn-and-continue, so first-run always reaches the theme-set hook. New in this pushThe stay-awake toggle ( |
|
Companion packaging PR: omacom/omarchy-pkgs#760 installs the new unit in both settings variants. It is blocked on this PR merging and the pinned source commit advancing past it. |
|
Thanks for the thorough follow-ups. This now conflicts with
It's also a large surface (new user unit, menu entry, bar indicator, idle service changes), so whether lid-skip should exist as a toggle is probably a product call for the maintainer before you put more time in. |
Rebased onto upstream quattro tip (84cfb93). Closes omacom#11524. Problem: closing the lid suspends immediately, whatever is running. The stay-awake feature is a single binary switch with no middle mode for staying awake while there is work to do. Solution (all fail-open): - Skip once, anywhere: omarchy toggle lid-suspend skip-once (Super + Shift + L) skips suspend for the next lid close only. - Automatic lid guard, AC only: while herdr reports a working agent and the machine is on AC power, lid close never suspends. - Stay awake while agents work: the stay-awake toggle cycles allow idle, stay awake, and agents modes. Note: skip-once uses Super + Shift + L because upstream claimed Super + Alt + L for cycling layouts in reverse.
c77275f to
4a7ac00
Compare
Closes #11524.
Problem
Closing the lid suspends the machine immediately, whatever is running. That regularly lands mid-task: #10203 tracks an update killed by a lid close, and the same fate hits coding agent runs — close the lid on the way to a meeting and hours of agent work stall on suspend.
The stay-awake feature answers this with a single binary switch: either the machine idles normally or it never locks at all. There is no middle mode for "stay awake while there is work to do" — flipping stay-awake on before a long agent run means remembering to flip it back off, and forgetting leaves the machine unlocked when you walk away. This adds that missing mode to the existing stay-awake UI: the top-bar coffee cup cycles allow idle, stay awake, and stay awake while agents work, with a spinner badge marking the new mode.
Solution
Lid safeguards plus a third stay-awake mode, all fail-open:
omarchy toggle lid-suspend skip-once(Super + Shift + L) skips suspend for the next lid close only, on AC or battery — the user explicitly asked for it, so we assume they know what they're doing. The lid still locks (via the unchanged Hyprland lid binding), it just does not suspend. Consumed on reopen — recorded synchronously by the close handler, so a close that reopens between two guard polls still consumes it — and disarms after 30 minutes. The confirmation is only sent when the guard is actually watching; otherwise it says the guard is unavailable.handle-lid-switchinhibitor with a fixed reason and never restarts it, so a change in which agents are working can't open a suspend gap. Locking stays entirely withomarchy-system-lid-close. No herdr installed, no guard — the lid behaves exactly as before.Super + Ctrl + I, top-bar coffee cup) now cycles three modes: allow idle, stay awake, and agents. In agents mode the idle lock/screensaver hold off only while herdr reports a working agent; otherwise the machine locks normally. The bar shows the coffee cup with a monochrome spinner badge knocked out of its corner, lit up like the on state, spinning while it holds.omarchy toggle lid-suspend statusshows whether a skip is armed and whether the guard currently holds the lid.omarchy toggle idle statusreports the idle mode as JSON.Rabbit holes (out of scope)
suspend-off) already exist for that.No-gos
Packaging note:
default/systemd/user/omarchy-lid-guard.serviceis new, soomarchy-settingsneeds the matching install line (test/shell.d/config-test.shalready expects it).