Skip to content

Keep supervising unexpected clean shell exits - #10709

Closed
adi-IL wants to merge 5 commits into
omacom:quattrofrom
adi-IL:fix/issue-10703-launch-shell-clean-exit
Closed

adi-IL wants to merge 5 commits into
omacom:quattrofrom
adi-IL:fix/issue-10703-launch-shell-clean-exit

Conversation

@adi-IL

@adi-IL adi-IL commented Sep 7, 2026

Copy link
Copy Markdown

Summary

Fixes #10703.

omarchy-launch-shell treated every Quickshell exit 0 as a deliberate stop because omarchy-restart-shell starts a replacement. When that replacement fails (IPC race, plugin reload storm, "already running"), the old supervisor is already gone and the seat stays without a bar until someone restarts by hand.

Change

  • Keep supervising unexpected clean exits while Hyprland answers hyprctl -j monitors, unless the supervisor was signalled to stop.
  • Publish $XDG_RUNTIME_DIR/omarchy/launch-shell.pid so restart can stop the living supervisor before it relaunches the shell being replaced.
  • omarchy-restart-shell stops that supervisor first, then kills Quickshell, then launches a replacement. If ping still fails halfway through the wait, it kicks a second launcher and keeps polling.

Intentional stops still work: session teardown (compositor gone) and TERM/INT/HUP on the supervisor.

Test plan

  • Updated test/shell.d/launch-shell-test.sh for the new clean-exit policy
  • ./test/shell.d/launch-shell-test.sh on an Omarchy checkout
  • ./test/shell.d/restart-shell-test.sh still passes
  • Manual: omarchy restart shell recovers the bar; kill Quickshell with an IPC clean exit while Hyprland is up and confirm the supervisor brings it back

I could not run the shell harness on this machine (no Omarchy tree / compositor). Happy to adjust if CI disagrees.

@adi-IL
adi-IL force-pushed the fix/issue-10703-launch-shell-clean-exit branch from 4b1a245 to 39c872f Compare September 15, 2026 18:28
An IPC clean exit used to stop omarchy-launch-shell because restart-shell
starts a replacement. When that replacement fails, the seat stays without a
bar. Relaunch while Hyprland is alive unless the supervisor was signalled to
stop, and have restart-shell stop the old supervisor before replacing it.

Fixes omacom#10703
Clean exit while Hyprland lives is now relaunched. Keep proving a clean
exit into a dead compositor still stops, and that TERM still wins.
@omarchybot omarchybot added the bug Something isn't working label Sep 27, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed against quattro at bb279bd. The diff and the surrounding launcher and restart code were read; nothing was run on a worker, because another open pull request fixes the same bug more narrowly.

The bug in #10703 is real: Quickshell's -n path reports "An instance of this configuration is already running." with exit status 0, so when the replacement launch loses to the dying instance, the new omarchy-launch-shell stops as if asked to and the seat has no bar.

#11014 fixes the same symptom inside omarchy-restart-shell alone: it re-dispatches the launch every two seconds until the shell answers, within a 30-second deadline, and leaves the launcher's exit-0-means-stop rule intact. Comparing the two, it is the more proportionate fix, for three reasons found in this change:

  • A second launcher started while a healthy shell is running (the mid-wait re-launch at bin/omarchy-restart-shell:122 when startup takes more than two seconds, or anyone running the launcher by hand) now gets exit 0 from -n six times in a row, logs "Giving up", and on exit removes the pid file it overwrote at bin/omarchy-launch-shell:54. The real supervisor keeps running, but nothing records its pid any more, so the next restart cannot stop it.
  • stop_launch_supervisor (bin/omarchy-restart-shell:79-95) signals whatever process holds the recorded pid without checking it is a launcher. A pid file left behind by a supervisor that was SIGKILLed, which this function's own fallback does, can point at an unrelated process after pid reuse, and that process gets TERM and then KILL.
  • Every clean exit while Hyprland answers is now relaunched, not only the one restart causes, which widens the change beyond the bug.

Related: #7546 (draft) stops launchers before restarting, #8630 only waits longer, and #10634 coalesces concurrent restarts; the last two address different problems.

Second opinion: Codex Medium was asked to choose among these without being given this conclusion. It also picked #11014 and named the same two pid-file defects; since it can read this session, its agreement is not guaranteed to be independent. #11014 currently conflicts with quattro.

Which fix to take is the maintainer's call, so this waits on them.

@adi-IL

adi-IL commented Oct 3, 2026

Copy link
Copy Markdown
Author

I fixed the two pid-file issues from the review in cfd6911.

  • bin/omarchy-launch-shell: before writing its pid, the launcher checks whether the recorded pid is still a live omarchy-launch-shell. If it is, the launcher exits and leaves that record alone. A second launcher can no longer overwrite the pid file and then remove it.
  • bin/omarchy-restart-shell: a new is_launch_supervisor helper checks /proc/<pid>/cmdline before any signal, including the KILL fallback. A stale pid that now belongs to another process is never signalled.

I checked this with a local script. On the previous commit it removes the pid file and sends TERM to an unrelated process. With this commit both checks pass. shellcheck is clean on both scripts, and test/shell.d/launch-shell-test.sh and restart-shell-test.sh pass 9 of 9 each.

If you prefer #11014 as the narrower fix, that is fine with me.

@greptile-apps

greptile-apps Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 3/5

[Medium risk] Changes shell supervisor restart logic and process lifecycle.

The PR does not appear safe to merge until concurrent launcher ownership and the ineffective early retry are addressed.

Findings

  1. P1 Concurrent launches create duplicate supervisors ▶
  2. P1 Halfway retry can do nothing ▶

Summary

The PR keeps supervising clean Quickshell exits, adds a PID-file handoff for restarts, and retries launching during readiness polling. The handoff is not atomic, and the halfway retry can occur too early to recover from a supervisor that subsequently gives up.

Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Restart stops recorded supervisor] --> B[Dispatch first launcher]
  B --> C[First supervisor records PID and launches shell]
  C --> D{Ping ready?}
  D -- Yes --> E[Restart succeeds]
  D -- No, halfway --> F[Dispatch second launcher]
  F --> G{First supervisor still alive?}
  G -- Yes --> H[Second launcher exits at PID guard]
  G -- No --> I[Second launcher starts shell]
  H --> J[First supervisor may later exhaust retry budget]
Loading

Reviews (1) · Last reviewed commit: "Keep launch-shell pid file tied to a liv..."

Comment thread bin/omarchy-launch-shell
Comment on lines +57 to +62
recorded_pid=$(cat "$pid_file" 2>/dev/null)
if [[ $recorded_pid =~ ^[0-9]+$ ]] && (( recorded_pid != $$ )) &&
[[ $(tr '\0' ' ' 2>/dev/null <"/proc/$recorded_pid/cmdline") == *omarchy-launch-shell* ]]; then
exit 0
fi
printf '%s\n' "$$" >"$pid_file"

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 Concurrent launches create duplicate supervisors

If two restarts launch supervisors while the PID file is absent, both can pass this check before either writes its PID. Both then start Quickshell, but only the last supervisor’s PID is recorded. A later restart stops only that supervisor, leaving the other free to relaunch a duplicate shell.

Comment thread bin/omarchy-restart-shell
Comment on lines +130 to +131
if (( attempt == 19 )); then
launch_replacement

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 Halfway retry can do nothing

If the first replacement repeatedly exits immediately, its supervisor can still be alive at this retry. The second launcher then sees that supervisor’s PID and exits without starting a shell. Fast failed pings can finish before the first supervisor exhausts its relaunch budget; when it later gives up, no retry remains and the seat is left without a bar.

@omarchybot

Copy link
Copy Markdown
Collaborator

Re-reviewed at cfd6911 against quattro. The diff and the launcher and restart code around it were read, not run: another open pull request fixing the same bug has already been verified on a worker, so this one was not.

cfd6911 does fix the two pid-file problems from the last review. A second launcher now leaves a live supervisor's record alone, and restart signals the recorded pid only while its command line is still omarchy-launch-shell. Thanks for turning that round so quickly.

Since then, #13141 has been tested on a disposable Omarchy VM and is labelled ready. It goes after the cause in omarchy-restart-shell: it waits until quickshell list shows the old instance gone before it launches the replacement, force-stops one that outlasts a grace period, and refuses to launch a duplicate if it still won't go. Compared with that, this change still has three gaps:

  • bin/omarchy-launch-shell:95 no longer treats a clean exit as a stop, so any deliberate quickshell kill while Hyprland is up now gets relaunched unless the caller knows to stop the supervisor first. That is a wider behaviour change than the bug needs.
  • bin/omarchy-restart-shell:115 still launches straight after a kill that timed out with the old shell alive. The replacement is refused, and the readiness ping can be answered by the dying shell, so restart can report success just before the bar goes. The new supervisor's retries cover an exit up to about six seconds, not longer.
  • The guard at bin/omarchy-launch-shell:57-62 reads the pid file and writes it as two separate steps, so two launchers starting together can both pass it. The command-line check is a substring match, so any process whose arguments contain omarchy-launch-shell (an editor open on the file, say) counts as a live launcher.

#11014 retries the launch instead, but stops as soon as the dying shell answers the ping, and it conflicts with quattro.

Second opinion: Codex Medium compared #10709, #11014, #13141, #11015 and #7546 without being told my conclusion. It also picked #13141 and found the three points above, which I checked against the source. Codex can read this session, so its agreement is not guaranteed to be independent.

Choosing between competing fixes is up to the maintainer, so this is waiting on them.

@omarchybot

Copy link
Copy Markdown
Collaborator

Looked at again at cfd6911, because the rule for choosing between competing fixes has changed: the oldest fix now wins by default, and a newer one only wins when the older misses a case, breaks something, or does not fix the cause. This one predates #13141, so it was compared again on that basis. The code was read on both branches against quattro. Nothing was run, because the comparison turns on code paths rather than on a test result.

#13141 still wins, because of one case this change does not handle: an old shell that is slow to finish exiting.

  • Restart sends TERM to the supervisor, waits up to 5 s, and then KILLs the supervisor (bin/omarchy-restart-shell:94-101). The shell it was supervising is not killed and keeps exiting.
  • timeout 5 quickshell kill (:115) then gives up on that shell after another 5 s, and the replacement is launched while the old shell is still alive (:119).
  • The new supervisor gets "already running" with exit 0 each time, relaunches once a second, and gives up after its sixth try (bin/omarchy-launch-shell:105-111). So if the old shell takes more than about 16 s to go, nothing is left to start the bar. The mid-wait launch at bin/omarchy-restart-shell:131 is turned away by the pid-file guard while that supervisor is still retrying. If the dying shell answers the readiness ping, restart reports success anyway.

#13141 waits until quickshell list no longer shows the old instance, KILLs it after a 5 s grace period, and refuses to launch a duplicate if it still won't go. The 5–6 s exits reported in #14085 and #14013 fall inside this change's retry window, so this is about a shell that hangs on exit, not the timings reported so far. But it is a case this change misses and the newer one handles, which is the exception the rule allows.

Two smaller points remain from the last review. Both the guard and is_launch_supervisor match omarchy-launch-shell anywhere in a process's command line, so an editor open on that file can pass for a launcher if it reuses a stale pid. The guard also reads and then writes the pid file in two separate steps, so two launchers starting together can both pass it.

Second opinion: Codex Medium was given all four fixes and the rule, but not this conclusion. It chose #13141 for the same reason and worked out the same timeline, which matches the source. It also found the two pid-file points. Codex can read this session, so its agreement is not guaranteed to be independent. The draft #7546 is older than this change, but it launches nothing if the old shell outlasts 5 s. #11014 stops retrying once the dying shell answers the ping.

#13141 is already labelled ready, so which fix lands is up to the maintainer.

@adi-IL

adi-IL commented Oct 4, 2026

Copy link
Copy Markdown
Author

Closing as superseded by #11015, which waits for the old shell to fully exit before launching the replacement, so the race behind #10703 no longer occurs in practice. If it still happens on current quattro, a log of that would justify a small follow-up in restart-shell.

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-launch-shell treats IPC exit 0 as a stop; a failed replacement leaves no bar

2 participants