Skip to content

Skip lid suspend for working agents and on demand - #11525

Open
colorfulfool wants to merge 1 commit into
omacom:quattrofrom
colorfulfool:lid-suspend-guard
Open

colorfulfool wants to merge 1 commit into
omacom:quattrofrom
colorfulfool:lid-suspend-guard

Conversation

@colorfulfool

@colorfulfool colorfulfool commented Sep 12, 2026 •

Copy link
Copy Markdown

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:

  1. Skip once, anywhere. 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.
  2. Automatic lid guard, AC only. While herdr reports a working agent and the machine is on AC power, lid close never suspends. On battery the guard stays out of the way — a working agent must never silently drain a battery in a bag. The guard holds one live handle-lid-switch inhibitor 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 with omarchy-system-lid-close. No herdr installed, no guard — the lid behaves exactly as before.
  3. Stay awake while agents work. The stay-awake toggle (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 status shows whether a skip is armed and whether the guard currently holds the lid. omarchy toggle idle status reports the idle mode as JSON.

Rabbit holes (out of scope)

  • General activity detection (CPU, per-app heuristics) — herdr's working state is the only signal.
  • Battery-level-aware guarding (e.g. "guard below 80%") — the rule is binary: AC guards, battery doesn't.
  • A persistent "never suspend on lid close" mode — the manual side is one-shot by design; the permanent toggles (suspend-off) already exist for that.

No-gos

  • No new hard dependencies — herdr is optional, absence means fail-open everywhere.
  • Never suspend a docked closed lid — clamshell stays awake.
  • No double locking — the guard never locks; the lid-close binding owns that path.

Packaging note: default/systemd/user/omarchy-lid-guard.service is new, so omarchy-settings needs the matching install line (test/shell.d/config-test.sh already expects it).

@omarchybot omarchybot added the enhancement New feature or request label Sep 27, 2026
@llstrk

llstrk commented Oct 1, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their 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 inhibitor

The --why text names the working agents, and a changed reason runs stop_inhibitor before start_inhibitor (also when a skip expires while an agent works). Impact: logind rechecks a closed lid on every event (systemd source, not run), so an undocked lid on AC can suspend in the gap.

Suggested change: Keep a live inhibitor while any reason applies; use a fixed --why.

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 one

Reviewed head: 20a9407 (also fails identically with the PR merged into quattro 8b4eae6).

reconcile puts the working agents' names in the inhibitor's reason (agents working on AC: $names). When the reason text changes while an inhibitor is alive, it runs stop_inhibitor and then start_inhibitor. So the lid is briefly not inhibited. That happens when one of several agents finishes or a second agent starts, and also when an armed skip expires while an agent works.

Save as test/shell.d/lid-guard-reason-change-test.sh in a checkout of the PR head and run bash test/shell.d/lid-guard-reason-change-test.sh.

#!/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):

inhibitor 235 was killed and replaced by 277; between the two the lid was not inhibited
not ok - the held inhibitor survives a change in which agents are working

With the replacement removed (a live inhibitor is kept while any reason applies), the same test passes:

ok - the held inhibitor survives a change in which agents are working

Ordering detail from a separate run, with a stub systemd-inhibit that logs when it starts and when it is signalled (lid closed, AC):

## Scenario 1: lid closed, AC, agents 'claude codex' working -> only 'claude' working
   +0.000ms held=1  acquire pid=2523 why=agents working on AC: claude codex
  +20.259ms held=0  release pid=2523 signal=TERM
  +22.319ms held=1  acquire pid=2564 why=agents working on AC: claude
scenario1-gap: zero-held after release at 1790826594.794080
## Scenario 2: lid closed, AC, skip armed + agent working -> skip expires
   +0.000ms held=1  acquire pid=2613 why=manual skip of next lid suspend
  +20.645ms held=0  release pid=2613 signal=TERM
  +22.735ms held=1  acquire pid=2658 why=agents working on AC: claude
scenario2-gap: zero-held after release at 1790826595.448210

(The roughly 2 ms gap here is a bash stub's fork and exec. A real systemd-inhibit holds nothing until its D-Bus Inhibit call has passed polkit and been answered.)

Why the gap suspends: this part comes from reading systemd v262, not from running logind. In logind-button.c, a lid close installs a post event source (button_install_check_event_source) that re-runs the lid action on every event-loop iteration while the lid is closed. manager_handle_action in logind-action.c only declines while a handle-lid-switch inhibitor exists. The old inhibitor goes away when its fifo hangs up (inhibitor_dispatch_fifo). The replacement systemd-inhibit is only forked after the kill, and it still has to connect to the bus and pass polkit. So with the lid closed, undocked and HandleLidSwitch=suspend (Omarchy does not override it), logind can act on the gap.

The daemon ignores SIGTERM

trap stop_inhibitor TERM INT EXIT releases the inhibitor, then the loop retakes it. Impact: stopping the unit, including at logout, waits for SIGKILL after the 90 s user-unit stop timeout (source, not run).

Suggested change: trap 'exit 0' TERM INT and keep stop_inhibitor on EXIT.

Reproducer (fails at 20a9407; PIDs are from an isolated sandbox PID namespace)

Reproducer: the guard daemon keeps running after SIGTERM

Reviewed head: 20a9407 (also fails identically with the PR merged into quattro 8b4eae6).

cmd_daemon installs trap stop_inhibitor TERM INT EXIT. The TERM/INT handler releases the inhibitor but does not exit, so the while true loop carries on, calls reconcile again and takes a new inhibitor. systemd only escalates to SIGKILL after the stop timeout.

Save as test/shell.d/lid-guard-stop-test.sh in a checkout of the PR head and run bash test/shell.d/lid-guard-stop-test.sh.

#!/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):

Terminated                 sleep "$INTERVAL"
daemon 301 still running 3s after SIGTERM; pidfile now names 352 23900288
not ok - the guard exits on SIGTERM

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 (trap stop_inhibitor EXIT plus trap 'exit 0' TERM INT), the same test passes:

ok - the guard exits on SIGTERM
More findings

The guard locks a docked (clamshell) lid close

reconcile calls omarchy-system-lock on every guarded open-to-closed transition. omarchy-system-lid-close deliberately skips that when an external monitor is connected, and lid-close-test.sh asserts it. Impact: with an agent working on AC or a skip armed, closing the lid to work on an external display locks the session within one poll (5 s). In the undocked case the guard's lock only duplicates the Hyprland lid bind's lock.

Suggested change: Drop the guard's lock, or gate it on ! omarchy-hw-external-monitors like omarchy-system-lid-close.

The new unit is not in the package recipe

The omarchy-settings PKGBUILD in omacom/omarchy-pkgs installs each user unit explicitly and has no omarchy-lid-guard.service, and test/shell.d/config-test.sh package_defaults does not list it either. Impact (source reading, not run): enable-user-units.sh enables its user units in one systemctl --user enable --now, and systemd rejects the whole list when one unit is missing, so a new install would get none of them. The migration prints an error and is still marked done.

Suggested change: Add the unit to package_defaults together with a matching omarchy-pkgs change, and consider enabling the guard in its own command.

Reproducer for the docked lock (fails at 20a9407)

Reproducer: the guard locks a docked (clamshell) lid close

Reviewed head: 20a9407 (also fails identically with the PR merged into quattro 8b4eae6).

omarchy-system-lid-close locks only when the lid is closed and no external monitor is connected. A docked close is clamshell mode, and test/shell.d/lid-close-test.sh asserts that it does not lock. The guard's reconcile calls omarchy-system-lock whenever a reason applies (agent working on AC, or skip armed) and it saw the lid go from open to closed. It never checks for an external monitor.

Save as test/shell.d/lid-guard-docked-test.sh in a checkout of the PR head and run bash test/shell.d/lid-guard-docked-test.sh.

#!/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):

ok - docked lid close does not lock
calls: omarchy-system-lock 
not ok - guarded docked lid close does not lock

With the guard's lock gated on ! omarchy-hw-external-monitors, the same test passes:

ok - docked lid close does not lock
ok - guarded docked lid close does not lock

Matrix from a separate run (lock calls made by the guard vs by omarchy-system-lid-close for the same close):

docked, agent working on AC        docked=1 herdr=working-one skip=0  guard_lock_calls=1  lid_close_lock_calls=0
docked, manual skip armed          docked=1 herdr=idle        skip=1  guard_lock_calls=1  lid_close_lock_calls=0
undocked, agent working on AC      docked=0 herdr=working-one skip=0  guard_lock_calls=1  lid_close_lock_calls=1
docked, no reason (control)        docked=1 herdr=idle        skip=0  guard_lock_calls=0  lid_close_lock_calls=0

In the undocked case the guard's lock duplicates the one omarchy-system-lid-close already made through the Hyprland lid bind, which the inhibitor does not affect.

Packaging check (static, at 20a9407)

Check: the new user unit is not installed by the omarchy-settings package

Reviewed head: 20a9407. This is a static check, not a run. Unit files under default/systemd/user/ are installed one by one by the omarchy-settings PKGBUILD in omacom/omarchy-pkgs. There is no glob. test/shell.d/config-test.sh keeps a package_defaults list that fails when a listed unit is missing from that PKGBUILD, and plans/backup.md describes adding a unit the same way. The PR adds default/systemd/user/omarchy-lid-guard.service but touches neither.

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' PKGBUILD

Actual output:

0
210:  install -Dm644 default/systemd/user/bt-agent.service "$pkgdir/usr/lib/systemd/user/bt-agent.service"
211:  install -Dm644 default/systemd/user/omarchy-sleep-lock.service "$pkgdir/usr/lib/systemd/user/omarchy-sleep-lock.service"
212:  install -Dm644 default/systemd/user/omarchy-recover-internal-monitor.service "$pkgdir/usr/lib/systemd/user/omarchy-recover-internal-monitor.service"
213:  install -Dm644 default/systemd/user/omarchy-migrate-notify.service "$pkgdir/usr/lib/systemd/user/omarchy-migrate-notify.service"
221:  install -Dm644 default/systemd/user/omarchy-tailscale-receive.service "$pkgdir/usr/lib/systemd/user/omarchy-tailscale-receive.service"
222:  install -Dm644 default/systemd/user/omarchy-fcitx5.service "$pkgdir/usr/lib/systemd/user/omarchy-fcitx5.service"
223:  install -Dm644 default/systemd/user/omarchy-crash-watch.service "$pkgdir/usr/lib/systemd/user/omarchy-crash-watch.service"
225:  if [[ -f default/systemd/user/omarchy-brightness-keyboard-auto.service ]]; then
226:    install -Dm644 default/systemd/user/omarchy-brightness-keyboard-auto.service "$pkgdir/usr/lib/systemd/user/omarchy-brightness-keyboard-auto.service"

The omarchy-settings-dev PKGBUILD at the same commit has the same explicit list (lines 205 to 221), also without the lid guard.

Consequences, from source reading only (not executed against systemd):

  • install/user/first-run/enable-user-units.sh enables every unit in one systemctl --user enable --now ... under set -euo pipefail. systemd v262 do_unit_file_enable (src/shared/install.c) validates every name before applying any change and returns on the first missing unit. So none of the listed units (bt-agent, sleep-lock, migrate-notify, fcitx5, crash-watch, and owed on quattro) would be enabled, and --now would not start them. omarchy-provision-first-run records the step as failed and retries it at every login. Fix ARM Snapper dependency and first-run keyboard service packaging omarchy-pkgs#341 describes the same failure mode for a first-run unit missing from packaging.
  • migrations/1789231389.sh would print Could not enable omarchy-lid-guard.service: ... and still be marked done, so it never runs again once the unit ships.
  • omarchy-toggle-lid-suspend would arm the flag and show "Next lid close locks without suspending" with nothing enforcing it.
Details

Verified:

  • handle-lid-switch block inhibitors are honoured by logind 262 regardless of LidSwitchIgnoreInhibited, and polkit allows them from a user service through the graphical session (source).
  • The PR test passes at the head (15 of 15) and with the PR merged into current quattro; existing lid, toggle, binding-conflict and menu tests still pass.
  • Fail-open when herdr (the PR's agent-status source) is missing or broken, the PID start-time check, AC gating, the 30-minute expiry and consumption on reopen behave as described.

Optional notes:

  • Poke signals every process. systemctl --user kill -s USR1 defaults to --kill-whom=all, so every skip, allow or toggle also kills the held inhibitor (reproduced in a sandbox, retaken about 15 ms later). --kill-whom=main avoids it; sleep "$INTERVAL" & wait $! || true (the trapped signal makes wait fail under set -e) keeps the wake-up immediate.
  • Overlapping PRs. Debounce lid-close suspend so a quick reopen does not sleep in the dark #12210 sets HandleLidSwitch=ignore and suspends via systemctl suspend, which this inhibitor cannot block, and adds a different test/shell.d/lid-suspend-test.sh. Keep a closed lid awake from the power panel #12882 adds a competing lid Stay Awake mode. enable-user-units.sh also conflicts with current quattro (8b4eae6), which appended an omarchy-hook-install line after the unit list.
  • Migration fallback. The newer migrations that enable session units (crash-watch, fcitx5, migrate-notify, and owed on quattro) fall back to the graphical-session.target.wants symlink when systemctl --user enable fails (TTY or SSH updates); this one follows the older print-only tailscale-receive migration.

Review information

Test scope: Source and sandbox tests with stubbed herdr agent list and systemd at 20a9407; no real logind or lid.

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.

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Adds lid-suspend guard and three-mode idle toggle.

The PR appears safe to merge based on the reviewed changes.

Summary

The PR adds a one-shot lid-suspend skip, an AC-only lid guard for working agents, and an agent-conditional stay-awake mode. The latest change removes a mode-change re-read intended to avoid undoing an idle selection.

  • Adds lid-guard service setup, a shortcut, status commands, documentation, and tests.
  • Extends the idle service and bar indicator to show and cycle through three modes.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Manual skip] --> G[Lid guard]
  B[Working agent] --> C{AC power?}
  C -- Yes --> G
  G --> I[Lid-switch inhibitor]
  B --> D[Agents idle mode]
  D --> E[Hold off idle lock while working]
Loading

Reviews (3) · Last reviewed commit: "Drop mode-change re-read that could undo..."

Comment thread bin/omarchy-toggle-lid-suspend Resolved
Comment thread bin/omarchy-system-lid-guard Resolved
Comment thread bin/omarchy-system-lid-guard Resolved
@colorfulfool

Copy link
Copy Markdown
Author

Thanks to both reviewers — all findings below are addressed in the latest commits (rebased onto current quattro, lid-suspend-test.sh covers each fix).

llstrk review

Reason change drops the inhibitor — fixed. The guard no longer puts agent names in --why. It holds one live inhibitor with a fixed reason (lid suspend guard (manual skip or working agents on AC)) and never restarts it while any reason applies, so a change in which agents are working (or a skip expiring under a working agent) can't open a suspend gap. Covered by the held inhibitor survives a change in which agents are working.

Daemon ignores SIGTERM — fixed. The daemon now traps exit 0 on TERM/INT and keeps stop_inhibitor on EXIT, and the poll loop is sleep … & wait so signals (including the USR1 poke) act immediately.

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 omarchy-system-lid-close locks every close exactly once. This also resolves the double-lock below. Covered by guard leaves locking to the lid-close binding.

Unit missing from the package recipe — half here, half in omarchy-pkgs. The unit is now in test/shell.d/config-test.sh package_defaults (so CI fails until packaging catches up), enable-user-units.sh enables it in its own guarded command so one missing unit can't take down the whole list, and the migration follows the crash-watch TTY fallback (symlink into graphical-session.target.wants when no live user manager). The omarchy-settings PKGBUILD still needs the matching install line.

Also applied: poke uses --kill-whom=main so it can't hit the held inhibitor.

Greptile review

Skip confirmed without protection (P1) — fixed. poke_guard now reports failure and skip-once notifies Lid guard unavailable / Skip recorded but nothing is watching it in that case; the Lid suspend skipped confirmation only fires when the guard is watching. Covered by skip-once reports a missing guard.

Brief close leaves skip armed (P1) — fixed. omarchy-system-lid-close (which the Hyprland bind runs synchronously on every close) now records the close into the guard's prev-lid, so a close that reopens between two 5s polls still consumes the one-shot on the next reconcile. Covered by a close between polls consumes the skip.

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 push

The stay-awake toggle (Super + Ctrl + I, coffee-cup indicator) cycles allow → awake → agents, where idle holds off only while herdr reports a working agent (new omarchy-agents-working helper, fail-open). The bar shows the cup with a monochrome spinner badge knocked out of its corner, lit like the on state and spinning while holding. Legacy state files (empty, awake, update owner stamps) all still read as stay-awake.

Comment thread shell/plugins/services/idle/Service.qml Resolved
@colorfulfool

Copy link
Copy Markdown
Author

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.

@jandrusk

Copy link
Copy Markdown

Thanks for the thorough follow-ups. This now conflicts with quattro, and a couple of things landed nearby that are worth reconciling while you rebase:

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lid close suspends mid-task: skip suspend for working agents and on demand

4 participants