Skip to content

Fail tests when the shell polls while idle or the fast paths get slow again - #15196

Merged
dhh merged 21 commits into
quattrofrom
perf-regression-guards
Oct 13, 2026
Merged

dhh merged 21 commits into
quattrofrom
perf-regression-guards

Conversation

@dhh

@dhh dhh commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

The recent performance PRs (#15026–#15049) only had a sentence in AGENTS.md keeping them from regressing. This adds tests that fail when they do. Where possible a test counts something that comes out the same on every machine (processes, tmux clients). Where it has to time something, it takes the fastest of several runs against a budget several times today's cost, or times two paths in the same run and compares them.

The guards

Idle shell spawns nothing (test/shell.d/shell-idle-spawn-test.sh). Starts a second shell on the default config with its own OMARCHY_PATH copy, so it gets its own IPC socket and leaves the live one alone. Waits until IPC answers and the startup cover has finished, then waits for 4s with no spawns, then watches for 30s. It fails naming every command line the shell started in that window. Spawns are recorded from inside the shell's own process tree: a small LD_PRELOAD shim (fixtures/idle-shell/exec-log.c, built with cc at test time) logs every exec, fork and posix_spawn the shell and its descendants make. So a probe that lives a millisecond is caught, and nothing outside the tree (the sampler included) can be mistaken for it. It skips without a compositor, like the other runtime tests, and also skips without a C compiler. Cleanup kills everything the test shell started, including children Quickshell leaves behind on exit (see below).

The test shell is kept from acting on the session: it gets stubs for pkill/killall, omarchy-powerprofiles-set/powerprofilesctl, and a bash that drops -l (a login shell would reset PATH and OMARCHY_PATH from /etc/omarchy.conf). Stay-awake is seeded so a long window cannot reach the screensaver or lock. Cleanup stops everything with a bounded TERM-then-KILL.

During each window the test records Hyprland socket2, upower --monitor and nmcli monitor events. If spawns coincide with an event, it watches a second window and prints the events with any failure, so a reaction to a config reload, a charger or a screencast is told apart from a poll.

Allowances are each enabled only while their condition holds (checked when the window opens and again when it closes), and capped at the rate their reason implies:

  • the clipboard capture.sh and whatever it runs: once per clipboard change, an event; unbounded.
  • hyprctl -j devices from the keyboard layout widget, only while the seat has more than one keyboard or none it can read, at most one per screen per 10s. Read the keyboard seat again when /dev/input changes instead of every 10 seconds #15203 replaces the multi-keyboard part with a /dev/input and udev watch.
  • the remote-session probe.sh, only while gliff-server runs, at most one per 2s.
  • nmcli ... device wifi list, only while Wi-Fi is connected, at most one per screen per 5s.

Router alias dispatch (test/cli). Copies the real bin/ with a stub screenshot body and times omarchy screenshot against omarchy screenshot --help (the full table load). It fails unless the dispatch costs under a quarter of the load. This adds to the existing unreadable-header check, and this one runs against the real command table.

Menu guards (test/shell.d/menu-guard-budget-test.sh). Builds the guard batch for the shipped menu with MenuModel.guardScript and runs it on this machine's real hardware. Budgets: the batch within 200ms, each guard alone within 100ms, both scaled to the machine (below). On failure it lists the slowest guards. Skipped without XDG_RUNTIME_DIR, which holds the package snapshot every real menu has.

Theme switch (test/shell.d/theme-set-budget-test.sh). Runs the whole omarchy-theme-set (not headless) in a scratch home, under env -i, with a closed PATH: stubs, $ROOT/bin, and a symlink dir of plain tools. Optional host apps (asusctl, VSCodium, browsers) are therefore absent rather than retinted. The stubs get the costs the real apps have: a running Hunk, VS Code whose --list-extensions takes an Electron boot, a Framework 16 keyboard, and three tmux sessions. Checks: each theme's switch within 500ms scaled to the machine (Tokyo Night and Catppuccin take different paths through the VS Code hook); at most 8 tmux clients; VS Code is never started to list extensions; and the switch returns before Hunk's settle nudge, which waits on a gate rather than the clock. The last three are structural, so a slow machine's larger budget cannot hide them.

Scaling. process_speed_percent in base-test.sh times 100 fork/execs of true, which take 25ms on the reference laptop, and the menu and theme budgets are multiplied by the ratio. A Raspberry Pi or ARM VM gets the room it needs. A machine more than 8x slower skips the timing (require_comparable_speed). The router check compares two paths in the same run, and the structural counts are unscaled.

Docs: a "Performance guards" section in docs/testing.md, a pointer from the Background Work rule in AGENTS.md, and a note that bash -l drops PATH stubs (more below).

Measurements (this laptop; "old" is defbf90, just before #15039)

Guard Now Old Budget
omarchy screenshot vs full load 13ms vs 187ms 187ms vs 187ms dispatch × 4 ≤ load
Menu guard batch 52ms 379–385ms 200ms
Slowest single menu guard 30ms 149ms 100ms
omarchy-theme-set, stubbed apps 75–80ms 1066ms 500ms
tmux clients per switch 6 592 (with #15040 reverted) 8
Idle shell spawns in 30s 0 outside the allowlist — 0

Mutation checks

  • Idle: a Timer { interval: 5000 } starting a Process added to Indicators.qml fails with 6 /usr/bin/sudo -n true named.
  • Router: load_route_candidates forced to return 1 (the old full-load path) fails the existing header test. With that test neutralised, the new timing check fails on its own: 181ms vs 181ms.
  • Menu: MenuModel.js, the hw guards and the menu restored to defbf90 fails at 379ms. Not caught: reverting only Run the menu's guard readers and guards side by side #15049 (serial groups: 115ms) or only Make the menu's slowest hardware and network guards cheap #15039's hardware guards (96ms batch, 73ms slowest guard). Those still pass the wall-clock budgets, which can't sit closer to today's 52ms without flaking on slower machines. The structural tests those PRs added (menu-guards-parallel-test.sh, hw-hybrid-gpu-test.sh, network-wifi-connected-test.sh) remain what catches them.
  • Theme: restoring omarchy-theme-set-hunk (1054ms) or omarchy-theme-set-vscode (1064ms) from defbf90 fails the time budget. Restoring omarchy-theme-set-tmux fails the client count (592), and the time too (537ms).

Testing

  • ./test/cli passes.
  • The three new shell tests pass, the idle one in several runs against the live desktop (under the desktop lock).
  • ./test/all: the baseline failures, plus default-agent, toggle-input-device, runtime-smoke (bar put), screenshot-sanity and hyprland-startup-cursor-cold. These fail only in the run against the live desktop while other sessions were busy on it; the first two pass when rerun. This PR changes no code outside test/, docs/ and AGENTS.md.
  • Codex review: first pass found three issues, fixed in "Close the theme budget's PATH..." (closed PATH for the theme test, fork and posix_spawn ancestry in the exec log). Later passes asked for the two conditional fallback probes to be allowlisted, for each theme to be held to the budget on its own, and for the idle test shell to be kept awake so a long window can't reach the screensaver or lock. All three are done, and Codex is clean on the head commit.
  • Claude review (P2/P3), all addressed: session events and the retry; conditional, rate-capped allowances; speed-scaled budgets plus the XDG_RUNTIME_DIR gate; shim coverage (execl*, vfork as a logged fork, pidfd_spawn*, errno preserved; system()/popen() documented as a gap); the bash -l stub; bounded cleanup. The runtime-smoke cleanup is Stop the runtime smoke test's leftover shell children with a bounded wait #15202, and the keyboard poll is now event-driven in Read the keyboard seat again when /dev/input changes instead of every 10 seconds #15203.
  • Greptile: fixed the clipboard pkill reaching the live shell's watchers (the test shell now gets pkill/killall stubs), ancestry order, fork-only children, a timeout for stuck menu guards, and one log snapshot for both passes.

Found along the way

  • A test shell started from a copied OMARCHY_PATH (as runtime-smoke-test.sh does) leaves its plugin-directory inotifywait running after Quickshell is killed. Under flock that orphan kept the desktop lock open indefinitely. The new test cleans up what its shell started. runtime-smoke-test.sh still leaks it.
  • A login shell (bash -lc, which omarchy-theme-set uses for its app retints) rereads /etc/omarchy.conf and puts that checkout's bin/ back ahead of any stub directory. Any test that stubs commands under omarchy-theme-set needs a bash stub, now documented in docs/testing.md.

For a human to check

  • Whether the 200ms/100ms menu and 500ms theme budgets hold on your slowest machine. Each can be overridden by the env var named at the top of its file.
  • Whether the keyboard-layout hyprctl -j devices poll should become event-driven, which would remove that allowlist entry.

🤖 Generated with Claude Code

dhh and others added 6 commits October 12, 2026 16:28
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… log

Addresses Codex review: the theme hooks reached optional host apps such as
asusctl and VSCodium, a subshell under an allowed command lost its
allowance, and posix_spawn logged the parent instead of the child.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium impact] Adds performance regression tests for shell and menu.

Record input-device events before merging so keyboard reconnects do not fail a healthy idle shell.

Findings

  1. P1 Keyboard reconnects falsely fail tests ▶

Summary

Adds performance tests for idle shell process starts, router dispatch, menu guards and theme switching.

  • The idle-shell test catches processes started after startup settles.
  • CLI tests keep screenshot aliases faster than a full table load.
  • Menu tests cap guard-run time for the shipped menu.
  • Theme-switch tests cap switch time and check extra app work.

Reviews (12) · Last reviewed commit: "Merge remote-tracking branch 'origin/qua..." · Reviewed by Greptile

Comment thread test/shell.d/shell-idle-spawn-test.sh Resolved
Comment thread test/shell.d/shell-idle-spawn-test.sh Resolved
Comment thread test/shell.d/shell-idle-spawn-test.sh Resolved
Comment thread test/shell.d/menu-guard-budget-test.sh Resolved
dhh and others added 2 commits October 12, 2026 18:04
…le test

Addresses Codex review: both poll only for state with no change signal,
and only while a session is active or the strength is missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…b pkill

Addresses Greptile review: the test shell's clipboard startup pkill reached
the session shell's watchers, a posix_spawn child could be logged after its
own children, a subshell running only built-ins went uncounted, and a stuck
menu guard could hang its budget test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread test/shell.d/shell-idle-spawn-test.sh Resolved
dhh and others added 6 commits October 12, 2026 18:43
Addresses Codex review: a fast theme could cover for a slow one, and a long
idle window reached the screensaver and lock, which run on the desktop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Addresses Greptile review: the shell kept appending between the two passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Addresses Claude review: execl and friends, vfork and pidfd_spawn went
unlogged. vfork becomes a fork, since a wrapper cannot return into a vfork
child. system() and popen() remain a documented gap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ectly

Addresses Claude review: Raspberry Pis and ARM VMs start processes several
times slower. The menu budget now needs XDG_RUNTIME_DIR, and the theme test
checks the VS Code and Hunk waits structurally, which a scaled budget could
hide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… while their reason holds

Addresses Claude review: a spawn that coincides with a Hyprland, UPower or
NetworkManager event gets a second window, and the events are printed. Each
allowance is enabled by its condition and capped at its rate. The test shell
gets power profile and login shell stubs, and cleanup no longer waits
unbounded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…g.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread test/shell.d/shell-idle-spawn-test.sh Resolved
Comment thread test/shell.d/theme-set-budget-test.sh Resolved
Comment thread test/shell.d/shell-idle-spawn-test.sh Resolved
… stop monitors on exit

Addresses Codex review: a session starting mid-window kept its probes
disallowed on the retry, a long switch on a slow machine could let Hunk's
timed nudge land before return, and an interrupted run left its event
monitor pipelines running.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread test/shell.d/shell-idle-spawn-test.sh Resolved
Comment thread test/shell.d/theme-set-budget-test.sh Resolved
dhh and others added 6 commits October 12, 2026 19:57
…er window

Addresses Codex review: a seat with no readable keyboard is probed by design,
and a monitor plugged in mid-run adds a widget.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dbox

Addresses Codex review: the waiting sleep stub outlived the test by up to
ten seconds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Addresses Greptile review: the closing allowance checks ran inside the
window, against limits sized for its nominal length.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cli unlocalized, and reject failing guard batches

Addresses Codex review: a power button counted as a second keyboard, a
German session never matched wifi:connected, and a guard batch that failed
fast was timed as a fast success though the menu throws its answers away.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Addresses Codex review: glibc allows pidfd_spawn(NULL, ...), which the
wrappers dereferenced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dhh
dhh merged commit f5006bd into quattro Oct 13, 2026
1 check passed
Comment on lines +303 to +306
start_event_monitors() {
local events="$1" socket="${XDG_RUNTIME_DIR:-/run/user/$UID}/hypr/${HYPRLAND_INSTANCE_SIGNATURE:-}/.socket2.sock"

MONITOR_PIDS=()

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 Keyboard reconnects falsely fail tests

start_event_monitors misses input-device events. InputDevices watches /dev/input and udev, then asks each keyboard widget to run hyprctl -j devices when a device changes. Those normal reads can fail this test without triggering its second window.

For example, unplugging and reconnecting the only keyboard leaves one readable keyboard at both allowance checks, so no keyboard allowance applies. Record input-device events too, and let them trigger the retry.

@emirb emirb added this to the 4.5 milestone Oct 17, 2026
aledbf added a commit to Construct-Linux/os that referenced this pull request Oct 18, 2026
Omarchy found its shell polling on timers all over (omacom/omarchy#15196 and the series it
closed); ours is GNOME, but nothing measured what the desktop does when nobody uses it. The
report now leaves the session alone for 30 s after its checks and records every process's CPU
share and scheduler runs - each timer an extension keeps is a wakeup - in idle.txt, with the
shell's line in the report and, when something else is busiest, that process named with its
threads, kernel stacks and open files.

The shell at rest is under 1% of a core and 3 to 8 wakeups a second, three of them Vitals'.
What the measurement found instead was gnome-software at a quarter of a core and over a
thousand runs a second minutes after the first login, its files open in the Flatpak repos:
Flathub's first catalogue refresh, which a fresh machine does once. Not a gate.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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