Skip to content

Prune stale Quickshell instance logs on shell launch - #13651

Open
AnPod wants to merge 2 commits into
omacom:quattrofrom
AnPod:cursor/fix-quickshell-log-prune-e0d3
Open

AnPod wants to merge 2 commits into
omacom:quattrofrom
AnPod:cursor/fix-quickshell-log-prune-e0d3

Conversation

@AnPod

@AnPod AnPod commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #13287

Quickshell accumulated per-instance log dirs under /run/user/$UID until tmpfs filled, breaking app launches.

Change

  • Prune stale Quickshell instance logs when launching/restarting the shell

Test plan

  • Focused shell-log prune test on the branch
  • After many shell restarts, $XDG_RUNTIME_DIR should not fill with old quickshell log dirs

Co-authored-by: AnPod <AnPod@users.noreply.github.com>
@cursor
cursor Bot force-pushed the cursor/fix-quickshell-log-prune-e0d3 branch from 200ee06 to bf467d4 Compare September 29, 2026 21:14
@omarchybot omarchybot added the bug Something isn't working label Oct 1, 2026
The by-pid targets are compared after readlink -f, but the by-id paths were globbed from XDG_RUNTIME_DIR as given, so a trailing slash or a symlinked runtime dir made the live instance look unreferenced and deleted its lock and IPC socket. Resolve the runtime dir once so both sides compare in the same form.

The test now runs with a trailing slash, and checks the dead by-pid link with -L, since -e is already false for a link whose target was pruned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 3, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed and tested on a disposable Omarchy VM running a real Hyprland session, with the shell loaded from this branch.

Reproduction. On quattro, three omarchy-restart-shell runs left four directories under $XDG_RUNTIME_DIR/quickshell/by-id/ with only one instance alive. On this branch the count stayed at one across four restarts, and quickshell list, omarchy-shell shell ping and further restarts all still worked. With the omarchy-quickshell-prune-logs call removed from bin/omarchy-launch-shell, the dead directories built up again. quickshell-log-prune-test.sh, launch-shell-test.sh and restart-shell-test.sh pass. ./test/cli has one failure, vscode generated theme references current theme file, which fails the same way on quattro and has nothing to do with this change.

Pushed a fix (8e9d02d). The helper compared each live by-pid target after readlink -f against by-id paths globbed from XDG_RUNTIME_DIR as given. If that variable had a trailing slash or went through a symlink, the paths didn't match, so the helper deleted the live instance's directory, including its instance.lock and ipc.sock. That leaves the running shell undiscoverable, so quickshell kill, which is how omarchy-restart-shell stops it, can no longer reach it. The runtime dir is now resolved once with readlink -f. The test now runs with a trailing slash and failed before this change. It also checks the dead by-pid link with -L, because -e is already false for a link whose target was pruned.

Second opinion: Codex Medium reviewed this in two rounds. The first round found the path mismatch and the weak -e assertion that the commit above fixes. The second round, at 8e9d02d, found nothing open. It also pointed out that a different Quickshell config starting at the same moment as the prune could lose its directory. That can't happen on a stock install, where the shell is the only instance and the prune finishes before it starts, so I've left it as it is.

For the maintainer: this PR says it fixes #13287, so merging it will close that issue. It clears out the logs of dead instances, which is what the original report describes. A later comment on #13287 describes a single live instance's log.qslog reaching 1.5 GB in eight days, and that log is deliberately kept here. Whether #13287 should close with this PR, or stay open for capping the live log, is your call. The PR is waiting on that decision and on the ./test/cli failure it shares with quattro.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 3, 2026
@greptile-apps

greptile-apps Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 3/5

[Medium risk] Adds log cleanup to shell startup.

The PR is not ready to merge because automatic relaunches skip cleanup and a redirected by-id path can cause unintended recursive deletion.

Findings

  1. P1 Crash relaunches skip pruning ▶
  2. P1 Redirected directory risks data loss ▶
  3. P2 Reused PIDs retain old logs ▶
  4. P2 Failed tests leave sleep running ▶

Summary

The PR adds a helper to remove Quickshell instance directories without a live PID link, calls it when the shell launcher starts, and adds a focused shell test.

  • Automatic relaunches within the launcher do not run the cleanup.
  • A redirected by-id directory makes recursive deletion unsafe.
  • PID reuse can preserve stale logs, and failed tests can leave a background process running.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Start launcher] --> B[Prune instance directories]
  B --> C[Run Quickshell]
  C --> D{Exit status}
  D -->|Crash; session alive| E[Backoff]
  E --> C
  D -->|Clean exit or stop| F[Launcher exits]
Loading

Reviews (1) · Last reviewed commit: "Keep the live Quickshell instance when t..."

Comment thread bin/omarchy-launch-shell

# Drop dead Quickshell instance dirs before a new one starts writing. Stale
# by-id logs otherwise grow without bound on the user runtime tmpfs.
omarchy-quickshell-prune-logs >/dev/null 2>&1 || true

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 Crash relaunches skip pruning When Quickshell crashes and this launcher starts it again, execution returns to the loop below, not to this prune call. Each crashed instance can leave another log directory behind until a separate launcher process starts, so logs can keep accumulating during repeated relaunches.

Comment on lines +40 to +45
for dir in "$by_id"/*; do
[[ -d $dir ]] || continue
if [[ -n ${keep[$dir]+x} ]]; then
continue
fi
rm -rf -- "$dir"

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 Redirected directory risks data loss If by-id is a symlink to another directory, the earlier -d check accepts it and this glob visits the destination’s children. The prune can then recursively delete directories unrelated to Quickshell instead of only instance logs. Constrain by-id to the intended runtime directory before removing its children.

pid=${link##*/}
[[ $pid =~ ^[0-9]+$ ]] || continue

if ! kill -0 "$pid" 2>/dev/null; then

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.

P2 Reused PIDs retain old logs If an unrelated process takes over the PID of a dead Quickshell instance, kill -0 succeeds and the old directory enters the keep set. It will remain on subsequent prunes while that process lives, reducing the effectiveness of the log cleanup. Check that the PID still belongs to the instance, rather than checking only that it exists.

Comment on lines +21 to +22
sleep 120 &
live_pid=$!

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.

P2 Failed tests leave sleep running If the prune command or a later assertion fails, the test exits before its final kill. The EXIT trap removes only the temporary directory, leaving this sleep 120 process running for up to two minutes. Include the child process in exit cleanup.

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 shell (quickshell) accumulates per-instance log dirs in /run/user/1000 until tmpfs is full, breaking all app launches

3 participants