Skip to content

Stop screensavers through their supervisors - #6813

Open
grantwiley wants to merge 1 commit into
omacom:quattrofrom
grantwiley:fix/screensaver-supervisor-shutdown
Open

grantwiley wants to merge 1 commit into
omacom:quattrofrom
grantwiley:fix/screensaver-supervisor-shutdown

Conversation

@grantwiley

@grantwiley grantwiley commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Follow-up to #6764 and #6773.

Waiting for ttfx after pkill still leaves a race because omarchy-screensaver is a supervisor loop. A live supervisor can start another renderer after the global kill but before the terminal closes. pidwait only waits for processes that already exist, so the replacement can still lose its PTY and abort with the same EIO panic.

The dismissal path has the same underlying problem: every monitor's supervisor globally kills every ttfx and every screensaver terminal. This can race across monitors and also affects unrelated ttfx processes.

Solution

Make each screensaver supervisor own its renderer lifecycle:

  • coordinate multi-monitor dismissal by signalling supervisors rather than renderers or terminals
  • track the exact ttfx child and prevent respawning once shutdown starts
  • terminate and reap that child before allowing the terminal to close
  • force-stop a renderer if it does not exit within the grace period
  • prevent a renderer from starting during a concurrent lock
  • explicitly disable Ghostty's hold-after-command behavior

omarchy-system-lock now signals and briefly waits for the supervisors. It no longer kills ttfx or closes its PTY directly.

Tests

  • bash test/shell.d/screensaver-test.sh
  • bash test/shell.d/system-lock-test.sh
  • bash test/shell.d/bin-style-test.sh
  • bash -n bin/omarchy-screensaver bin/omarchy-system-lock test/shell.d/screensaver-test.sh test/shell.d/system-lock-test.sh

The lifecycle test covers two monitors, delayed renderer shutdown, respawn prevention, unrelated ttfx processes, forced termination, and a concurrent lock. It also passed ten consecutive runs.

Copilot AI balanced review requested due to automatic review settings August 13, 2026 16:08

Copilot AI left a comment

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.

Pull request overview

Moves screensaver shutdown responsibility into per-monitor supervisors to avoid renderer/PTY races.

Changes:

  • Coordinates shutdown through named supervisors.
  • Tracks, terminates, and reaps each renderer.
  • Adds lifecycle tests and disables Ghostty command holding.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
bin/omarchy-screensaver Implements supervised renderer lifecycle.
bin/omarchy-system-lock Signals and waits for supervisors.
default/ghostty/screensaver Disables hold-after-command behavior.
test/shell.d/screensaver-test.sh Adds lifecycle regression coverage.
test/shell.d/system-lock-test.sh Updates lock shutdown expectations.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copy link
Copy Markdown
Contributor Author

The newer reports on #6762 line up with the races this PR is intended to close.

This report shows that the bounded wait from #6773 wasn't sufficient on its own: ttfx could still crash even with pidwait in the lock script.

The follow-up found the two remaining races. In 10 of the 11 cores inspected, ttfx received SIGTERM but lost its PTY before it finished shutting down. In the other case, the screensaver loop spawned another ttfx before the terminal closed.

Those are the two cases I tried to address here. The supervisor marks itself as shutting down before stopping its renderer, so it can't spawn a replacement. It then terminates and reaps its own renderer before the terminal exits and the PTY disappears. Locking and normal dismissal both go through that same shutdown path.

The reports are from rc3 with #6773, so they don't directly verify this branch. But they do independently confirm both failure modes behind this change: the common shutdown race and the less frequent respawn race. The lifecycle test covers both, along with multiple monitors, delayed shutdown, forced termination, and unrelated ttfx processes.

@CodexOmega

Copy link
Copy Markdown

Live reproduction of the race this PR targets, on current code.

omarchy 4.0.0-1, ttfx 0.3.1-1, foot 1.27.0-2. Two ttfx SIGABRT core dumps
today, 2026-08-14 19:43:42 and 20:56:12 CDT, both on lock transitions within
~0.5s of the screensaver launching:

thread 'main' panicked at library/std/src/io/stdio.rs:1166:9:
failed printing to stdout: Input/output error (os error 5)

(Panic text recovered from the core via strings; ttfx is stripped and not
on debuginfod.) Both instances land on lock-system: lock-timeout /
lock secure=true while the renderer is mid-write — the supervisor-respawn /
concurrent-lock case described here. Confirms #6764/#6773 didn't close the
window the supervisor loop reopens. Happy to attach full coredumpctl info if
useful.

— big-pickle via opencode

@garymeyerca

Copy link
Copy Markdown

Tested commit d1b691a06 on omarchy-dev 4.0.0.r1744.gf002044-1, ttfx 0.3.1-1, using Foot. The focused tests and full ./test/all suite passed. I also ran one live screensaver → lock → unlock cycle and 20 live input-dismissal cycles using the PR scripts directly. No new ttfx core dumps occurred, and no renderer processes or screensaver windows remained afterward.

Tested by OpenAI Codex via Codex.

@jacobkjones

Copy link
Copy Markdown

Live dismissal-path abort on current 4.0.0-1, not a lock transition.

#6762 said the dismissal path was clean (exit_screensaver kills ttfx before the terminal). This dump is the opposite: two ttfx processes aborted at the same second the idle service logged screensaver-dismissed and ran omarchy-system-wake. No lock ran.

22:45:07.390  idle → omarchy-launch-screensaver
22:45:07.541  idle-monitor: active (cycle remained armed)
22:45:07.768  launcher exited 0 (foot windows already mapped)
22:45:09.858  idle-cycle-cancel: screensaver-dismissed
22:45:09.858  process-start: wake omarchy-system-wake
22:45:09      ttfx 3280492 and 3280489 SIGABRT

Same panic recovered from both cores (binary is stripped, not on debuginfod; offsets match the rest of the thread: +0xcc30a, +0xa48a9, +0xccd09, …):

thread 'main' (3280492) panicked at library/std/src/io/stdio.rs:1166:9:
failed printing to stderr: Input/output error (os error 5)

Adjacent on the heap: io error: Input/output error (os error 5). Built with panic_abort; si_code is SI_TKILL.

Four monitors, default terminal foot. Only two of the four renderers dumped core, which fits the race this PR describes: each supervisor's pkill -x ttfx / pkill -f '[o]rg.omarchy.screensaver' is global, so a pty can vanish under a renderer that is still writing at 120 fps.

omarchy-system-wake only restores brightness; it does not kill processes. The windows went away through the screensaver's own exit path.

Omarchy 4.0.0-1, ttfx 0.3.1-1, foot 1.27.0-2, Hyprland 0.56.2-1, Linux 7.1.8-arch1-3, x86_64. Happy to attach coredumpctl info if useful.

Filed by Grok 4.6 via Grok Build.

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at d1b691a0, merged onto current quattro, on a disposable Omarchy VM running foot on one monitor, with bash 5.3.15. None of the five files have changed on quattro since this branch was cut. Nothing was pushed to the branch.

The crash this fixes no longer happens on current Omarchy. ttfx 0.3.2 (omacom-io/ttfx@9edd376, "End the run when the terminal goes away") makes the renderer end its run when its terminal disappears, where it used to panic, and the repository now ships 0.4.0. All the crash reports in this thread are on 0.3.1. I measured it both ways by launching foot running each tree's bin/omarchy-screensaver:

  • With ttfx 0.3.1, killing the screensaver terminal outright aborted ttfx 12 times in 15 on quattro and 13 in 15 with this PR, so the probe can see the EIO abort.
  • With ttfx 0.3.2, the same terminal kill (8 cycles), the lock teardown from omarchy-system-lock (15 cycles) and a two-window dismissal (15 cycles) produced no ttfx cores, on quattro or with this PR.

So I could not find a failure on quattro that this branch fixes, and without one it cannot be marked verified.

It does not close the bash crash in #8386 and #8985 either. A tight, unbroken kill -HUP loop against the supervisor segfaulted bash 3 times in 3 on quattro and 3 in 5 with this PR, both in nested run_pending_traps. The pending trap re-enters while bash is still parsing the handler, before request_shutdown reaches its guard or trap ''. The same loop with a 10 ms pause crashed neither. #9042 is the smaller change aimed at that crash.

What the branch still changes today: dismissing or locking no longer kills unrelated ttfx processes, a supervisor that starts after a lock does not start a renderer, and each supervisor reaps its own renderer. One trade-off comes with it. omarchy-system-lock no longer closes the screensaver terminal itself (bin/omarchy-system-lock:23-25), so a supervisor that is stopped or stuck in a foreground command leaves its window behind the lock after pidwait gives up at 2s. #7193 also rewrites those lines of omarchy-system-lock.

Tests: test/shell.d/screensaver-test.sh, system-lock-test.sh and bin-style-test.sh pass on the VM. ./test/cli has one failure (vscode generated theme references current theme file), and quattro fails it the same way. Some of the new test cases pass without exercising what they name: the jq mock always succeeds, so focus loss is never tested; the stubborn renderer never writes an exit line, so the missing renderer-stubborn-exit line doesn't show that SIGKILL was sent; and the lock case starts already locked instead of locking mid-run.

Second opinion: Codex Medium reviewed the diff and the VM results. It agreed that the ttfx abort was fixed upstream and that the remaining change is out of proportion to the bash crash. It is the source of the stuck-terminal point and of the note on the test mocks, both of which I checked against the source. It could read this review's working notes, so its agreement is not guaranteed to be independent.

This now waits on the maintainer: keep the lifecycle rework on its own merits, or close it now that ttfx handles a lost terminal itself.

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.

6 participants