Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2ffd46b
Time alias dispatch against a full command-table load
dhh Oct 12, 2026
869b46e
Hold the shipped menu's guard batch and each guard to a time budget
dhh Oct 12, 2026
50f3d44
Hold a theme switch to a time budget with slow apps stubbed in
dhh Oct 12, 2026
cc91b13
Fail when an idle shell starts any process
dhh Oct 12, 2026
837fdd8
Document the performance guards and point the polling rule at them
dhh Oct 12, 2026
c56259c
Close the theme budget's PATH and follow forks and spawns in the exec…
dhh Oct 12, 2026
eb901d8
Allow the remote session and Wi-Fi strength fallback probes in the id…
dhh Oct 12, 2026
55577a5
Judge idle spawns on full ancestry, count fork-only children, and stu…
dhh Oct 12, 2026
6189c12
Hold each theme to the switch budget and keep the idle test shell awake
dhh Oct 12, 2026
1820237
Judge the idle window from one copy of the exec log
dhh Oct 12, 2026
19e484b
Log the exec list forms, vforks and pidfd spawns, and keep errno
dhh Oct 12, 2026
cb60643
Scale the timing budgets to the machine and check the theme waits dir…
dhh Oct 12, 2026
4a6ba5f
Tell session events from polls in the idle test and allow probes only…
dhh Oct 12, 2026
805806d
Describe the scaled budgets and the idle test's events in docs/testin…
dhh Oct 12, 2026
b7e611e
Recheck idle allowances at each window's ends, gate Hunk's nudge, and…
dhh Oct 12, 2026
364a504
Allow the keyboard widget's recovery probe and count screens afresh p…
dhh Oct 12, 2026
88a35f8
Let the gated Hunk nudge finish before the theme test removes its san…
dhh Oct 12, 2026
4883af9
Snapshot the idle window's log before the closing checks take time
dhh Oct 12, 2026
37c65ae
Judge the keyboard probe by the widget's own keyboard filter, read nm…
dhh Oct 12, 2026
0309758
Accept a missing pidfd slot in the exec logger's pidfd_spawn wrappers
dhh Oct 12, 2026
9062478
Merge remote-tracking branch 'origin/quattro' into perf-regression-gu…
dhh Oct 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ Exceptions are allowed for migration and package-helper scripts where the helper
# Background Work

- Long-running code (the shell, daemons, watchers) reacts to events instead of polling with a timer. Polling is the last resort, for state with no change signal; [`agents/skills/shell-dev.md`](agents/skills/shell-dev.md) lists the event sources and the push-refresh pattern.
- `test/shell.d/shell-idle-spawn-test.sh` fails when an idle shell starts any process, and other tests hold the router, menu guards and theme switch to budgets; see "Performance guards" in [`docs/testing.md`](docs/testing.md).

# Menu

Expand Down
12 changes: 12 additions & 0 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ Gate only what needs gating — put `require_compositor` in files whose runtime
half needs a live session, and keep static analysis of the same area in code
that runs unconditionally before or beside it.

## Performance guards

A handful of tests fail when a fast path gets slow again. Each prefers a count that is the same on every machine over a wall-clock time, and where it has to time something it takes the fastest of several runs against a budget several times today's cost, or compares two paths timed in the same run.

- `test/shell.d/shell-idle-spawn-test.sh` starts a second shell on the default config, waits for its startup work to go quiet, then fails if it starts any process over 30 idle seconds, naming each command line. A preloaded shim (`fixtures/idle-shell/exec-log.c`, built with `cc` at test time) logs every exec the shell and its descendants make, so a probe that lives for a millisecond is caught, and nothing outside the shell's process tree can be. A command that legitimately runs while idle goes in the file's `ALLOWED` list with the reason it is not polling. Compositor-gated, and skipped without a C compiler.
- `test/cli` times `omarchy screenshot` against help for it on a copy of the real command table, and fails unless the alias dispatch costs under a quarter of the full load (13ms against 190ms today).
- `test/shell.d/menu-guard-budget-test.sh` runs the shipped menu's guard batch on this machine's real hardware: the batch within 200ms (about 50ms today) and each guard alone within 100ms (the slowest is about 30ms), listing the slowest guards when either fails.
- `test/shell.d/theme-set-budget-test.sh` runs the whole `omarchy-theme-set` in a scratch home where every app is a stub given its real cost (a running Hunk, VS Code's Electron boot, three tmux sessions), and fails when the switch takes over 500ms (about 80ms today) or starts more than a handful of tmux clients.

Override a budget through the environment variable named at the top of each file when measuring something slower on purpose.

## Unit-testing shell JavaScript from bash

The Quickshell plugins keep their logic in plain `.js` modules
Expand Down Expand Up @@ -119,6 +130,7 @@ only a live session can prove.
executables (`sudo`, `tmux`, `gsettings`, helper commands) that log their
arguments to a file, prepend it to `PATH`, and then run the real script
under test. Assertions grep the call log and the files the script wrote.
- **Login shells drop the stubs.** A `bash -l` rereads `/etc/profile`, which resets `OMARCHY_PATH` from `/etc/omarchy.conf` and puts that checkout's `bin/` ahead of the stub directory, so a command run through one reaches the real commands again. Commands that start `bash -lc` (`omarchy-theme-set` runs its app retints that way) need a `bash` stub that drops the `-l`.
- **Fake `$HOME`, real `$OMARCHY_PATH`.** Anything touching user state runs
with `HOME` pointed at a `mktemp -d` directory (cleaned up via
`trap ... EXIT`) and `OMARCHY_PATH="$ROOT"`, so tests exercise the checkout
Expand Down
37 changes: 37 additions & 0 deletions test/cli
Original file line number Diff line number Diff line change
Expand Up @@ -837,3 +837,40 @@ if (( EUID != 0 )); then
rm -f "$TMPDIR/omarchy-zz-unreadable"
pass "an alias dispatch reads only the commands that can own its route"
fi

# The same guarantee against the real command table, timed: an alias dispatch
# that loads every header costs what help on it costs (about 190ms either way
# before the candidates-only path, against 13ms after). Timing both in the same
# run keeps the check independent of how fast the machine is.
make_tmpdir ROUTER_BIN
cp -a "$ROOT/bin/." "$ROUTER_BIN/"
# The real header, so the alias resolves as shipped, over a body that takes no
# screenshot.
{
awk 'NR == 1 || /^#/ || /^[[:space:]]*$/ { print; next } { exit }' "$ROOT/bin/omarchy-capture-screenshot"
printf 'echo screenshot-stub-ran\n'
} >"$ROUTER_BIN/omarchy-capture-screenshot"

fastest_ms() {
local best="" start end elapsed

for _ in 1 2 3 4 5; do
start=$EPOCHREALTIME
"$@" >/dev/null 2>&1
end=$EPOCHREALTIME
elapsed=$(( (${end/[.,]/} - ${start/[.,]/}) / 1000 ))
if [[ -z $best ]] || (( elapsed < best )); then
best=$elapsed
fi
done
echo "$best"
}

[[ $("$ROUTER_BIN/omarchy" screenshot) == "screenshot-stub-ran" ]] || fail "omarchy screenshot dispatches to the capture command"
alias_ms=$(fastest_ms "$ROUTER_BIN/omarchy" screenshot)
full_ms=$(fastest_ms "$ROUTER_BIN/omarchy" screenshot --help)
if (( alias_ms * 4 > full_ms )); then
printf 'omarchy screenshot took %dms; loading the whole table for its help took %dms.\n' "$alias_ms" "$full_ms" >&2
fail "an alias dispatch costs a fraction of loading the whole command table"
fi
pass "an alias dispatch costs a fraction of loading the whole command table (${alias_ms}ms vs ${full_ms}ms)"
137 changes: 137 additions & 0 deletions test/shell.d/fixtures/idle-shell/exec-log.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// Preloaded into the shell under test and inherited by everything it starts,
// so every program any descendant runs is logged, however briefly it lives.
// Sampling the process tree instead misses the short-lived probes polling
// spawns. One line per exec: the pid that runs the program and its parent's,
// then argv joined by spaces. A fork logs the same line without a command, so
// a reader can follow ancestry through a subshell that never execs.
//
// The exec family can run in a vfork child, which shares the parent's memory,
// so the logging path allocates nothing and takes no locks: raw syscalls from
// a stack buffer. The real functions are resolved once, at load.
#define _GNU_SOURCE
#include <dlfcn.h>
#include <fcntl.h>
#include <spawn.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

typedef int (*execve_fn)(const char *, char *const[], char *const[]);
typedef int (*execv_fn)(const char *, char *const[]);
typedef int (*fexecve_fn)(int, char *const[], char *const[]);
typedef pid_t (*fork_fn)(void);
typedef int (*spawn_fn)(pid_t *, const char *, const posix_spawn_file_actions_t *,
const posix_spawnattr_t *, char *const[], char *const[]);

static execve_fn real_execve;
static execv_fn real_execv;
static execv_fn real_execvp;
static execve_fn real_execvpe;
static fexecve_fn real_fexecve;
static spawn_fn real_posix_spawn;
static spawn_fn real_posix_spawnp;
static fork_fn real_fork;
static char log_path[4096];

__attribute__((constructor)) static void init(void) {
real_execve = (execve_fn)dlsym(RTLD_NEXT, "execve");
real_execv = (execv_fn)dlsym(RTLD_NEXT, "execv");
real_execvp = (execv_fn)dlsym(RTLD_NEXT, "execvp");
real_execvpe = (execve_fn)dlsym(RTLD_NEXT, "execvpe");
real_fexecve = (fexecve_fn)dlsym(RTLD_NEXT, "fexecve");
real_posix_spawn = (spawn_fn)dlsym(RTLD_NEXT, "posix_spawn");
real_posix_spawnp = (spawn_fn)dlsym(RTLD_NEXT, "posix_spawnp");
real_fork = (fork_fn)dlsym(RTLD_NEXT, "fork");

const char *path = getenv("OMARCHY_EXEC_LOG");
if (path && strlen(path) < sizeof(log_path)) strcpy(log_path, path);
}

static size_t put_number(char *buf, size_t at, size_t cap, long value) {
char digits[24];
int count = 0;

do {
digits[count++] = (char)('0' + value % 10);
value /= 10;
} while (value > 0 && count < (int)sizeof(digits));
while (count > 0 && at < cap) buf[at++] = digits[--count];
return at;
}

static void record_as(pid_t pid, pid_t parent, char *const argv[]) {
if (!log_path[0]) return;

char line[8192];
size_t cap = sizeof(line) - 1, at = 0;

at = put_number(line, at, cap, (long)pid);
if (at < cap) line[at++] = ' ';
at = put_number(line, at, cap, (long)parent);
for (int i = 0; argv && argv[i]; i++) {
if (at < cap) line[at++] = ' ';
for (const char *c = argv[i]; *c && at < cap; c++) line[at++] = *c == '\n' ? ' ' : *c;
}
line[at++] = '\n';

int fd = open(log_path, O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC, 0600);
if (fd < 0) return;
ssize_t written = write(fd, line, at);
(void)written;
close(fd);
}

static void record(char *const argv[]) {
record_as(getpid(), getppid(), argv);
}

int execve(const char *path, char *const argv[], char *const envp[]) {
record(argv);
return real_execve(path, argv, envp);
}

int execv(const char *path, char *const argv[]) {
record(argv);
return real_execv(path, argv);
}

int execvp(const char *file, char *const argv[]) {
record(argv);
return real_execvp(file, argv);
}

int execvpe(const char *file, char *const argv[], char *const envp[]) {
record(argv);
return real_execvpe(file, argv, envp);
}

int fexecve(int fd, char *const argv[], char *const envp[]) {
record(argv);
return real_fexecve(fd, argv, envp);
}

pid_t fork(void) {
pid_t pid = real_fork();
if (pid == 0) record(NULL);
return pid;
}

// The spawned child runs its program from inside libc, past these wrappers, so
// it is logged from the parent, under the child's pid, once it exists.
int posix_spawn(pid_t *pid, const char *path, const posix_spawn_file_actions_t *actions,
const posix_spawnattr_t *attr, char *const argv[], char *const envp[]) {
pid_t child = 0;
int status = real_posix_spawn(&child, path, actions, attr, argv, envp);
if (status == 0) record_as(child, getpid(), argv);
if (pid) *pid = child;
return status;
}

int posix_spawnp(pid_t *pid, const char *file, const posix_spawn_file_actions_t *actions,
const posix_spawnattr_t *attr, char *const argv[], char *const envp[]) {
pid_t child = 0;
int status = real_posix_spawnp(&child, file, actions, attr, argv, envp);
if (status == 0) record_as(child, getpid(), argv);
if (pid) *pid = child;
return status;
}
105 changes: 105 additions & 0 deletions test/shell.d/menu-guard-budget-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/bash

# The menu opens on its last guard answers, so however long the guard batch
# takes is how long a row can contradict the state it describes. This runs the
# batch for the shipped menu on this machine, against its real hardware and
# packages, and fails when it gets slow again: as a whole, or because one guard
# has turned expensive. A slow guard alone barely moves the batch, since the
# batch runs its guards side by side, but it holds up every menu evaluation.
#
# menu-guards-test.sh and menu-guards-parallel-test.sh pin down how the batch
# is built; this catches what they can't see, such as a guard calling a
# command that has become slow.

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

require_command node

# On a current laptop the batch takes about 50ms and its slowest guard, run
# alone, 30ms. Before the guards ran side by side and the hardware and network
# guards were made cheap, the batch took 380ms, and five guards alone took
# 130-150ms each. The budgets leave several times today's cost and still
# catch either.
BATCH_BUDGET_MS=${OMARCHY_MENU_GUARD_BUDGET_MS:-200}
GUARD_BUDGET_MS=${OMARCHY_MENU_SINGLE_GUARD_BUDGET_MS:-100}

# Prints the batch for the whole shipped menu, then one batch per guarded row,
# each as a NUL-terminated id and script.
guard_scripts() {
node -e '
const path = require("path")
const fs = require("fs")
const menu = require(path.join(process.env.ROOT, "shell/plugins/menu/MenuModel.js"))
const shipped = menu.parseMenuJsonc(fs.readFileSync(path.join(process.env.ROOT, "default/omarchy/omarchy-menu.jsonc"), "utf8"))
const all = {}
for (const item of shipped) all[item.id] = item
process.stdout.write(`menu\0${menu.guardScript(all)}\0`)
for (const item of shipped) {
const script = menu.guardScript({ [item.id]: item })
if (script) process.stdout.write(`${item.id}\0${script}\0`)
}
'
}

# The menu runs the batch from its own checkout, so the guards call this
# checkout's commands. Prints the fastest of three runs, in milliseconds. A run
# that never returns is cut off at 10s and counts as taking all of it, so a
# stuck guard is named among the slowest instead of hanging the test.
fastest_ms() {
local best="" start end elapsed status

for _ in 1 2 3; do
start=$EPOCHREALTIME
status=0
OMARCHY_PATH="$ROOT" PATH="$ROOT/bin:$PATH" timeout --kill-after=1s 10s bash -c "$1" >"$output" 2>/dev/null || status=$?
end=$EPOCHREALTIME
elapsed=$(( (${end/[.,]/} - ${start/[.,]/}) / 1000 ))
(( status != 124 && status != 137 )) || elapsed=10000
if [[ -z $best ]] || (( elapsed < best )); then
best=$elapsed
fi
done
echo "$best"
}

output=$(mktemp)
trap 'rm -f "$output"' EXIT

declare -A scripts=()
ids=()
while IFS= read -r -d '' id && IFS= read -r -d '' script; do
scripts[$id]=$script
[[ $id == "menu" ]] || ids+=("$id")
done < <(guard_scripts)

[[ -n ${scripts[menu]:-} ]] || fail "the shipped menu has guards to evaluate"
(( ${#ids[@]} > 0 )) || fail "the shipped menu has guarded rows"

batch_ms=$(fastest_ms "${scripts[menu]}")
(( $(wc -l <"$output") >= ${#ids[@]} )) || fail "the guard batch answers every guarded row" "$(cat "$output")"

timings=()
slowest=0
for id in "${ids[@]}"; do
elapsed=$(fastest_ms "${scripts[$id]}")
timings+=("$(printf '%6dms %s' "$elapsed" "$id")")
(( elapsed > slowest )) && slowest=$elapsed
done

slowest_guards() {
printf 'Slowest guards, each run alone (fastest of three runs):\n'
printf '%s\n' "${timings[@]}" | sort -rn | head -8
}

(( batch_ms <= BATCH_BUDGET_MS )) ||
fail "the shipped menu's guard batch runs within ${BATCH_BUDGET_MS}ms" "$(
printf 'Fastest of three batches took %dms.\n' "$batch_ms"
slowest_guards
)"
pass "the shipped menu's guard batch runs within ${BATCH_BUDGET_MS}ms (${batch_ms}ms)"

(( slowest <= GUARD_BUDGET_MS )) ||
fail "every shipped menu guard runs within ${GUARD_BUDGET_MS}ms alone" "$(slowest_guards)"
pass "every shipped menu guard runs within ${GUARD_BUDGET_MS}ms alone (slowest ${slowest}ms)"
Loading