Repository navigation
Keep the shell supervisor attached after a locked Hyprland restart - #13490
MilesRomney wants to merge 2 commits into
Conversation
start-hyprland relaunches a crashed compositor as --safe-mode --locked. The supervisor still held the dead instance signature, so hyprctl monitors failed and it exited without relaunching Quickshell. Safe mode also skips allow_session_lock_restore, and requesting that stranded lock is fatal to Quickshell. Follow hyprctl instances onto the live compositor, and enable lock restore before starting the shell when a lock is already held.
Automated AI review
Outcome: The shell can start on another session's compositor. Shell can attach to another session's compositorAt every launch, login included, Suggested change: Keep the inherited signature while it answers, else try instances newest first. Reproducer (fails at b589086)Reproducer: a live compositor's shell is moved to another compositorSave as The supervisor is started by a compositor that is alive and answering ( #!/bin/bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
test_tmp=$(mktemp -d)
trap 'rm -rf "$test_tmp"' EXIT
fake_bin="$test_tmp/bin"
shell_root="$test_tmp/root"
qs_log="$test_tmp/quickshell.log"
mkdir -p "$fake_bin" "$shell_root/shell"
: >"$qs_log"
# Two compositors of this user share $XDG_RUNTIME_DIR/hypr and both answer: an
# older one, and the one that started this supervisor (a nested Hyprland, or a
# second login). hyprctl lists instances oldest first.
cat >"$fake_bin/hyprctl" <<'SH'
#!/bin/bash
case "$*" in
"instances -j")
printf '[\n{\n "instance": "older_1000_1",\n "time": 1000,\n "pid": 1000,\n "wl_socket": "wayland-1"\n},\n{\n "instance": "mine_1100_2",\n "time": 1100,\n "pid": 1100,\n "wl_socket": "wayland-2"\n}\n]\n'
;;
"-j monitors")
[[ $HYPRLAND_INSTANCE_SIGNATURE == "older_1000_1" || $HYPRLAND_INSTANCE_SIGNATURE == "mine_1100_2" ]] || exit 4
printf '[{"name":"eDP-1","solitaryBlockedBy":["WINDOWED","CANDIDATE"]}]\n'
;;
*)
exit 1
;;
esac
SH
cat >"$fake_bin/quickshell" <<'SH'
#!/bin/bash
printf '%s %s\n' "$HYPRLAND_INSTANCE_SIGNATURE" "$WAYLAND_DISPLAY" >>"$OMARCHY_TEST_QS_LOG"
SH
cat >"$fake_bin/systemd-cat" <<'SH'
#!/bin/bash
while (( $# > 0 )); do
[[ $1 == "--" ]] && { shift; break; }
shift
done
exec "$@"
SH
cat >"$fake_bin/logger" <<'SH'
#!/bin/bash
SH
chmod +x "$fake_bin/hyprctl" "$fake_bin/quickshell" "$fake_bin/systemd-cat" "$fake_bin/logger"
ln -s "$ROOT/bin/omarchy-hyprland-session-locked" "$fake_bin/omarchy-hyprland-session-locked"
PATH="$fake_bin:$PATH" \
OMARCHY_PATH="$shell_root" \
OMARCHY_TEST_QS_LOG="$qs_log" \
HYPRLAND_INSTANCE_SIGNATURE=mine_1100_2 \
WAYLAND_DISPLAY=wayland-2 \
timeout 30 "$ROOT/bin/omarchy-launch-shell" || fail "a clean launch succeeds"
[[ $(<"$qs_log") == "mine_1100_2 wayland-2" ]] ||
fail "a shell started by a live compositor stays on that compositor" "quickshell started against: $(<"$qs_log")"
pass "a shell started by a live compositor stays on that compositor"Actual output at the PR head (b589086): Actual output at the merge base (3faafba): What happens: Not reproduced here, from Quickshell v0.3.1 source ( With the supervisor keeping its inherited signature while Details: suggested launcher changeChecked in the sandbox: with this change and the stub updates below, --- a/bin/omarchy-launch-shell
+++ b/bin/omarchy-launch-shell
@@ -45,6 +45,12 @@
adopt_live_instance() {
local sig socket
+ # Stay with the compositor that started this supervisor while it answers.
+ if [[ -n ${HYPRLAND_INSTANCE_SIGNATURE:-} ]] && hyprctl -j monitors >/dev/null 2>&1; then
+ return 0
+ fi
+
+ # Otherwise follow the watchdog's replacement: the newest instance first.
while IFS=$'\t' read -r sig socket; do
[[ -n $sig ]] || continue
if HYPRLAND_INSTANCE_SIGNATURE=$sig hyprctl -j monitors >/dev/null 2>&1; then
@@ -54,7 +60,7 @@
fi
return 0
fi
- done < <(hyprctl instances -j 2>/dev/null | jq -r '.[] | "\(.instance)\t\(.wl_socket // "")"')
+ done < <(hyprctl instances -j 2>/dev/null | jq -r 'reverse | .[] | "\(.instance)\t\(.wl_socket // "")"' 2>/dev/null)
return 1
}
@@ -78,6 +84,7 @@
local attempt
for (( attempt = 1; attempt <= 10; attempt++ )); do
+ (( terminating )) && return 1
if adopt_live_instance; then
return 0
fiExisting launcher tests failThe Suggested change: Have both stubs list an instance, start "compositor gone" after the first shell, and add a watchdog test (below). Reproducer (fails at b589086)Reproducer: the existing launcher tests fail at the PR headRun from the repository root at the PR head (b589086), with no changes: Actual output at b589086: Actual output at the merge base (3faafba), same commands: Why: both tests stub Letting both stubs answer --- a/test/shell.d/launch-shell-test.sh
+++ b/test/shell.d/launch-shell-test.sh
@@ -55,7 +55,10 @@
cat >"$fake_bin/hyprctl" <<'SH'
#!/bin/bash
-[[ ${OMARCHY_TEST_COMPOSITOR_GONE:-0} == 1 ]] && exit 4
+# The compositor goes away with the first shell, not before it.
+if [[ ${OMARCHY_TEST_COMPOSITOR_GONE:-0} == 1 && -s $OMARCHY_TEST_QS_LOG ]]; then
+ exit 4
+fi
# Refuse the first OMARCHY_TEST_HYPRCTL_MISSES queries, then answer.
if (( ${OMARCHY_TEST_HYPRCTL_MISSES:-0} > 0 )); then
@@ -66,7 +69,11 @@
fi
fi
-printf '[]\n'
+if [[ $* == "instances -j" ]]; then
+ printf '[\n{\n "instance": "test_1000_1",\n "time": 1000,\n "pid": 1000,\n "wl_socket": "wayland-1"\n}\n]\n'
+else
+ printf '[]\n'
+fi
SH
cat >"$fake_bin/logger" <<'SH'
--- a/test/shell.d/restart-shell-test.sh
+++ b/test/shell.d/restart-shell-test.sh
@@ -131,7 +131,9 @@
cat >"$restart_bin/hyprctl" <<'SH'
#!/bin/bash
-if [[ ${1:-} == "-j" && ${2:-} == "monitors" ]]; then
+if [[ ${1:-} == "instances" && ${2:-} == "-j" ]]; then
+ printf '[\n{\n "instance": "test_1000_1",\n "time": 1000,\n "pid": 1000,\n "wl_socket": "wayland-1"\n}\n]\n'
+elif [[ ${1:-} == "-j" && ${2:-} == "monitors" ]]; then
# Hyprland reports an active session lock as a reason the monitor cannot hand
# a client the whole screen, not as a workspace.
if [[ ${OMARCHY_TEST_SESSION_LOCKED:-0} == 1 ]]; thenSuggested test: watchdog restart (fails at the merge base, passes at b589086)Suggested test: the supervisor follows a watchdog restart (passes at the head, fails at the merge base)This covers the behaviour the PR adds and would catch a regression of it. Save as #!/bin/bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
test_tmp=$(mktemp -d)
trap 'rm -rf "$test_tmp"' EXIT
fake_bin="$test_tmp/bin"
shell_root="$test_tmp/root"
qs_log="$test_tmp/quickshell.log"
hyprctl_log="$test_tmp/hyprctl.log"
state="$test_tmp/compositor"
mkdir -p "$fake_bin" "$shell_root/shell"
# $state names the compositor that is up: "crashed" before the first shell
# dies, "replacement" or "replacement-locked" after start-hyprland restarts it.
cat >"$fake_bin/hyprctl" <<'SH'
#!/bin/bash
printf '%s %s\n' "$HYPRLAND_INSTANCE_SIGNATURE" "$*" >>"$OMARCHY_TEST_HYPRCTL_LOG"
state=$(<"$OMARCHY_TEST_STATE")
if [[ $state == "crashed" ]]; then
live=crashed_1000_1 socket=wayland-1
else
live=replacement_2000_3 socket=wayland-3
fi
case "$*" in
"instances -j")
printf '[\n{\n "instance": "%s",\n "time": 1000,\n "pid": 1000,\n "wl_socket": "%s"\n}\n]\n' "$live" "$socket"
;;
"-j monitors")
[[ $HYPRLAND_INSTANCE_SIGNATURE == "$live" ]] || exit 4
if [[ $state == "replacement-locked" ]]; then
printf '[{"name":"eDP-1","solitaryBlockedBy":["WINDOWED","LOCK","CANDIDATE"]}]\n'
else
printf '[{"name":"eDP-1","solitaryBlockedBy":["WINDOWED","CANDIDATE"]}]\n'
fi
;;
"eval "*)
[[ $HYPRLAND_INSTANCE_SIGNATURE == "$live" ]] || exit 4
printf 'ok\n'
;;
*)
exit 1
;;
esac
SH
# The first shell dies with the compositor, and the watchdog's replacement is
# up by the time the supervisor looks again.
cat >"$fake_bin/quickshell" <<'SH'
#!/bin/bash
printf '%s %s\n' "$HYPRLAND_INSTANCE_SIGNATURE" "$WAYLAND_DISPLAY" >>"$OMARCHY_TEST_QS_LOG"
if [[ $(wc -l <"$OMARCHY_TEST_QS_LOG") == 1 ]]; then
printf '%s\n' "$OMARCHY_TEST_REPLACEMENT" >"$OMARCHY_TEST_STATE"
exit 255
fi
SH
cat >"$fake_bin/systemd-cat" <<'SH'
#!/bin/bash
while (( $# > 0 )); do
[[ $1 == "--" ]] && { shift; break; }
shift
done
exec "$@"
SH
cat >"$fake_bin/logger" <<'SH'
#!/bin/bash
SH
chmod +x "$fake_bin/hyprctl" "$fake_bin/quickshell" "$fake_bin/systemd-cat" "$fake_bin/logger"
ln -s "$ROOT/bin/omarchy-hyprland-session-locked" "$fake_bin/omarchy-hyprland-session-locked"
launch_shell() {
: >"$qs_log"
: >"$hyprctl_log"
printf 'crashed\n' >"$state"
PATH="$fake_bin:$PATH" \
OMARCHY_PATH="$shell_root" \
OMARCHY_TEST_QS_LOG="$qs_log" \
OMARCHY_TEST_HYPRCTL_LOG="$hyprctl_log" \
OMARCHY_TEST_STATE="$state" \
OMARCHY_TEST_REPLACEMENT="$1" \
HYPRLAND_INSTANCE_SIGNATURE=crashed_1000_1 \
WAYLAND_DISPLAY=wayland-1 \
timeout 30 "$ROOT/bin/omarchy-launch-shell"
}
launch_shell replacement || fail "the supervisor exits cleanly"
[[ $(wc -l <"$qs_log") == 2 ]] || fail "the shell is relaunched after a watchdog restart" "$(<"$qs_log")"
[[ $(sed -n 2p "$qs_log") == "replacement_2000_3 wayland-3" ]] ||
fail "the relaunched shell connects to the replacement compositor" "$(<"$qs_log")"
pass "the shell follows a watchdog restart to the replacement compositor"
launch_shell replacement-locked || fail "the supervisor exits cleanly"
[[ $(wc -l <"$qs_log") == 2 ]] || fail "the shell is relaunched after a locked watchdog restart" "$(<"$qs_log")"
grep -Fx 'replacement_2000_3 eval hl.config({ misc = { allow_session_lock_restore = true }})' "$hyprctl_log" >/dev/null ||
fail "lock restore is enabled on the locked replacement" "$(<"$hyprctl_log")"
pass "lock restore is enabled on a replacement that came back locked"Actual output at the PR head (b589086): Actual output at the merge base (3faafba): It also passes with the suggested launcher change (keep the inherited signature while it answers, newest instance first otherwise, check More findingsStop request ignored during the widened check. Reproducer: a stop request during the widened compositor check is ignored for about 4 secondsSave as The compositor goes away together with the shell and nothing replaces it (the session is ending). While the supervisor is checking whether a compositor is still there, it receives SIGTERM, as it does when the session unit is stopped. #!/bin/bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
test_tmp=$(mktemp -d)
launch_pid=""
cleanup() {
if [[ -n $launch_pid ]]; then
kill -KILL "$launch_pid" 2>/dev/null || true
wait "$launch_pid" 2>/dev/null || true
fi
rm -rf "$test_tmp"
}
trap cleanup EXIT
fake_bin="$test_tmp/bin"
shell_root="$test_tmp/root"
qs_log="$test_tmp/quickshell.log"
gone="$test_tmp/compositor-gone"
mkdir -p "$fake_bin" "$shell_root/shell"
: >"$qs_log"
# The session ends: the compositor goes with the shell and nothing replaces it.
# hyprctl then lists no instances, which it prints as a bare "]".
cat >"$fake_bin/hyprctl" <<'SH'
#!/bin/bash
if [[ -f $OMARCHY_TEST_GONE ]]; then
if [[ $* == "instances -j" ]]; then
printf '\n]\n'
exit 0
fi
exit 4
fi
case "$*" in
"instances -j")
printf '[\n{\n "instance": "session_1000_1",\n "time": 1000,\n "pid": 1000,\n "wl_socket": "wayland-1"\n}\n]\n'
;;
"-j monitors")
printf '[{"name":"eDP-1","solitaryBlockedBy":["WINDOWED","CANDIDATE"]}]\n'
;;
*)
exit 1
;;
esac
SH
cat >"$fake_bin/quickshell" <<'SH'
#!/bin/bash
printf 'launched\n' >>"$OMARCHY_TEST_QS_LOG"
touch "$OMARCHY_TEST_GONE"
exit 255
SH
cat >"$fake_bin/systemd-cat" <<'SH'
#!/bin/bash
while (( $# > 0 )); do
[[ $1 == "--" ]] && { shift; break; }
shift
done
exec "$@"
SH
cat >"$fake_bin/logger" <<'SH'
#!/bin/bash
SH
chmod +x "$fake_bin/hyprctl" "$fake_bin/quickshell" "$fake_bin/systemd-cat" "$fake_bin/logger"
ln -s "$ROOT/bin/omarchy-hyprland-session-locked" "$fake_bin/omarchy-hyprland-session-locked"
PATH="$fake_bin:$PATH" \
OMARCHY_PATH="$shell_root" \
OMARCHY_TEST_QS_LOG="$qs_log" \
OMARCHY_TEST_GONE="$gone" \
HYPRLAND_INSTANCE_SIGNATURE=session_1000_1 \
WAYLAND_DISPLAY=wayland-1 \
"$ROOT/bin/omarchy-launch-shell" 2>/dev/null &
launch_pid=$!
for (( waited = 0; waited < 100; waited++ )); do
[[ -f $gone ]] && break
sleep 0.05
done
[[ -f $gone ]] || fail "the supervised shell ran and exited"
sleep 0.3
kill -TERM "$launch_pid"
signalled_at=$EPOCHREALTIME
wait "$launch_pid" || fail "a signalled supervisor exits cleanly"
launch_pid=""
stopped_after=$(awk -v a="$signalled_at" -v b="$EPOCHREALTIME" 'BEGIN { printf "%.2f", b - a }')
awk -v s="$stopped_after" 'BEGIN { exit !(s < 1.5) }' ||
fail "a supervisor asked to stop while checking the compositor stops promptly" "exited ${stopped_after}s after SIGTERM"
pass "a supervisor asked to stop while checking the compositor stops promptly (${stopped_after}s)"Actual output at the PR head (b589086): Actual output at the merge base (3faafba): Related measurement from an equivalent setup without a signal: after the shell died and no compositor came back, the supervisor stood down after 4.54 s at the head and 1.01 s at the merge base. What happens: the Silent stand-down remains (from code reading, not reproduced). When adoption fails before a launch, Details: verified, optional note and related workVerified (Hyprland v0.56.2 source, and a stubbed watchdog restart):
Optional note (hypothesis, not reproduced): Related: #12612 describes this crash-while-locked scenario. #11827 conflicts in Review informationTest scope: Source and stubbed sandbox tests at 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. |
Adopting an instance before every launch moved a shell started by a live compositor onto whichever answering instance hyprctl listed first, and after a crash, before start-hyprland's replacement was up, onto another Hyprland of the same user: a nested one, or a second login. It also left the launcher tests with no shell at all, since their stubs list no instances. The main loop already adopts in compositor_alive before every relaunch, so the first launch keeps what the compositor handed it, a relaunch keeps it while it answers, and a dead one is replaced only by an instance whose parent is the start-hyprland that ran it. That is the supervisor's grandparent, read at startup because the compositor execs it before hyprctl lists the instance, and checked by name so a compositor started without the watchdog stands down as before. A stop request is honoured in the widened check and before launching, instead of waiting out ten attempts or starting a shell into a session that is ending. The launcher test now runs with a signature as a real session does, misses only monitor queries made after the shell dies so the pre-launch lock check doesn't use them up, and covers a relaunch beside another session and a locked watchdog restart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Codex Medium <noreply@openai.com>
|
Reviewed and tested on an Omarchy VM (Hyprland 0.56.2), and I pushed one commit on top, 08b00cc, which fixes what the review below found. The bug is real and this fixes it. On the VM I locked the session and killed Hyprland with SIGABRT. What 08b00cc changes, and why:
Tests on the VM: Second opinion: Codex at medium effort reviewed this over three rounds. It contributed the other-session adoption case, the stop arriving during the pre-launch lock check, and the unverified grandparent, all fixed above. Its last round on 08b00cc found nothing. The earlier community review's findings (broken tests, oldest-first adoption, the stop delay) hold and are covered by the same commit. This links #12612. It overlaps #11827 in |
|
| # normally set. A lock request against a stranded session is then a fatal | ||
| # Wayland error and Quickshell exits instead of drawing the unlock screen. | ||
| allow_lock_restore() { | ||
| if omarchy-hyprland-session-locked; then |
There was a problem hiding this comment.
Lock restoration can be skipped If the replacement compositor answers while its outputs still have no workspace,
omarchy-hyprland-session-locked returns “undetermined.” This check then skips enabling lock restoration. Quickshell retries its stranded-lock check later, but its attempt to reacquire the lock can fail fatally, leaving no unlock screen. Retry the lock-state check before launching Quickshell, or enable restoration for the safe-mode replacement without treating “undetermined” as unlocked.
| fi | ||
| [[ -n $watchdog_pid ]] || return 1 | ||
|
|
||
| while IFS=$'\t' read -r sig socket pid; do |
There was a problem hiding this comment.
Empty socket shifts instance fields If an instance has a missing or empty
wl_socket, the jq output contains two adjacent tabs. Bash read collapses them, putting the PID in socket and leaving pid empty. The parent-PID check then skips that instance before checking whether it responds, so the supervisor cannot adopt a live replacement in this case. Parse the fields without losing empty columns.
| eval*) | ||
| printf '%s\n' "$HYPRLAND_INSTANCE_SIGNATURE" >>"$OMARCHY_TEST_EVAL_LOG" | ||
| printf 'ok\n' | ||
| exit 0 |
There was a problem hiding this comment.
Test accepts any eval command The fake returns success for every
eval invocation, while the crash test checks only which instance received it. The test would still pass with a wrong setting name or expression, missing a failure that prevents the unlock screen from returning. Check the command argument and cover a failed response.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
Another real-world case of the problem this PR fixes, on an unlocked session. It also shows a knock-on effect: System: Omarchy 4.0.4-1, Hyprland 0.56.2-2, linux-omarchy 7.2.5-3, RX 6600 (Navi 23). An amdgpu page fault from What happened on 2026-10-14: The shell, including notifications and the polkit agent, was gone for about 11 minutes and through both crashes. Knock-on effect: Once this PR restores the shell after the watchdog restart, crash-watch should work again as long as Quickshell claims Filed by Claude Opus 5.5 via Claude Code. |
Problem
A Hyprland crash while the screen is locked comes back from
start-hyprlandas--safe-mode --locked. Two things then leave the seat stranded:omarchy-launch-shellkeeps the crashed process'sHYPRLAND_INSTANCE_SIGNATURE.hyprctl monitorsfollows that dead socket and fails, socompositor_aliveexits the supervisor with no log and Quickshell is never started again. Safe mode does not runhyprland.start, so nothing else starts it.misc:allow_session_lock_restorelives inlooknfeel.lua, which safe mode does not load. A later lock request against the stranded session is a fatal Wayland error (invalid object) and Quickshell dies instead of drawing the unlock screen.Change
omarchy-launch-shellnow adopts whichever instancehyprctl instancescan still talk to, including that instance's Wayland socket, before each Quickshell launch and before deciding the compositor is gone. The watchdog restart gets a few seconds to answer.When that instance is already locked, the supervisor enables
allow_session_lock_restorebefore Quickshell connects. The lock plugin's existing stranded-lock recovery can then put the password screen back. The desktop stays covered.Verification
On a running 0.56.2 / Omarchy 4.0.4 session:
hyprctl monitorswith a deadHYPRLAND_INSTANCE_SIGNATUREexits 4.hyprctl instancesstill lists the live compositor.hyprctl eval 'hl.config({ misc = { allow_session_lock_restore = true }})'returns ok.I have not run
./test/all.Fixes #12612