Skip to content

feat: add shell -r/--restart for race-free shell restarts - #146

Open
dadams-AU wants to merge 1 commit into
caelestia-dots:mainfrom
dadams-AU:feat/shell-restart
Open

feat: add shell -r/--restart for race-free shell restarts#146
dadams-AU wants to merge 1 commit into
caelestia-dots:mainfrom
dadams-AU:feat/shell-restart

Conversation

@dadams-AU

Copy link
Copy Markdown

Implements option 2 from #139, as discussed there.

What it does

caelestia shell -r (composes with -d and --log-rules):

  1. If an instance is running, asks it to quit (qs -c caelestia kill).
  2. Polls qs -c caelestia list -j until the instance actually disappears — teardown is not instant, and is slowest while a session lock is up, which is exactly when a reliable restart matters most.
  3. If the instance is still there after 5s (hung shell), escalates to SIGKILL on the recorded PIDs (with a warning), waits again briefly, then proceeds.
  4. Starts the shell as usual.

With no instance running it behaves like a plain start, so it's safe as the default "get me a shell" keybind.

Why not just propagate the exit status (option 1)

While implementing this I found that qs -n itself exits 0 on the duplicate no-op:

$ qs -c caelestia -n -d; echo $?
An instance of this configuration is already running.
0

so propagating subprocess.run's return code from shell -d wouldn't have helped — polling qs list is the only reliable way to detect the case. That makes --restart the fix rather than a convenience.

Testing

On a live session (Hyprland, quickshell-git):

  • shell -r -d with a running instance: old instance killed and fully gone, new instance up and IPC-responsive, exactly one instance in qs list afterwards.
  • The race from the issue: qs -c caelestia kill; sleep .1; caelestia shell -r -d (restart requested mid-teardown) — waits out the dying instance and launches cleanly, where shell -d previously no-op'd and left zero shells.
  • Regression: plain shell -d with a running instance is unchanged (message + exit 0, no second instance).

Also adds the flag to the fish completions.

🤖 Generated with Claude Code

Kills any running instance, waits for it to actually disappear from
`qs list`, then starts the shell. Escalates to SIGKILL if the instance
does not exit gracefully within 5s.

Closes caelestia-dots#139

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@dark3txr

Copy link
Copy Markdown
Contributor

read contributing, NO AI CODE

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants