From af0ec3e78ab3761c046419d4737ba05acef29c21 Mon Sep 17 00:00:00 2001 From: Mario Mohar Date: Thu, 10 Sep 2026 13:10:08 +0200 Subject: [PATCH] Give the plugin commands an IPC budget that fits a reload `omarchy-plugin-enable`, `-disable` and `-remove` each depend on a single IPC call, made in a command substitution under `set -e`. They are normally run right after something started a plugin reload: add and clone call them a step after their own rescan, and saving a file under ~/.config/omarchy/plugins/ starts the same reload through inotify. Rebuilding every plugin instance blocks the shell's IPC for seconds, which is longer than the 2s default budget. The call expires inside that window and the command reports a shell that is not responding, when the shell is merely busy with the very work the command is waiting on. For enable that is the difference between a plugin being activated and being left installed but disabled. Raise the default budget to 15s in these three commands. A shell that is genuinely not running still fails at once, because that is a connection error rather than a timeout, and an explicitly set OMARCHY_SHELL_IPC_TIMEOUT is left alone. --- bin/omarchy-plugin-disable | 10 +++ bin/omarchy-plugin-enable | 10 +++ bin/omarchy-plugin-remove | 10 +++ test/shell.d/plugin-ipc-budget-test.sh | 116 +++++++++++++++++++++++++ 4 files changed, 146 insertions(+) create mode 100755 test/shell.d/plugin-ipc-budget-test.sh diff --git a/bin/omarchy-plugin-disable b/bin/omarchy-plugin-disable index 5968fa8429d2..ac38bf95a91c 100755 --- a/bin/omarchy-plugin-disable +++ b/bin/omarchy-plugin-disable @@ -6,6 +6,16 @@ set -euo pipefail +# A rescan makes the shell rebuild every plugin instance, which blocks its IPC +# for seconds, and these commands normally run right inside that window: +# omarchy-plugin-add and omarchy-plugin-clone call them a step after their own +# rescan, and saving a file under ~/.config/omarchy/plugins/ starts the same +# reload through inotify. The 2s default expires there and reports a shell that +# is not responding, when the shell is merely busy with work this command is +# waiting on. A shell that is genuinely not running still fails at once, since +# that is a connection error rather than a timeout. +export OMARCHY_SHELL_IPC_TIMEOUT="${OMARCHY_SHELL_IPC_TIMEOUT:-15s}" + fail() { echo "omarchy-plugin-disable: $*" >&2 exit 1 diff --git a/bin/omarchy-plugin-enable b/bin/omarchy-plugin-enable index ece1283d82e5..a3f6ad23e931 100755 --- a/bin/omarchy-plugin-enable +++ b/bin/omarchy-plugin-enable @@ -7,6 +7,16 @@ set -euo pipefail +# A rescan makes the shell rebuild every plugin instance, which blocks its IPC +# for seconds, and these commands normally run right inside that window: +# omarchy-plugin-add and omarchy-plugin-clone call them a step after their own +# rescan, and saving a file under ~/.config/omarchy/plugins/ starts the same +# reload through inotify. The 2s default expires there and reports a shell that +# is not responding, when the shell is merely busy with work this command is +# waiting on. A shell that is genuinely not running still fails at once, since +# that is a connection error rather than a timeout. +export OMARCHY_SHELL_IPC_TIMEOUT="${OMARCHY_SHELL_IPC_TIMEOUT:-15s}" + fail() { echo "omarchy-plugin-enable: $*" >&2 exit 1 diff --git a/bin/omarchy-plugin-remove b/bin/omarchy-plugin-remove index 2e8591f74f6f..dd22dee85c23 100755 --- a/bin/omarchy-plugin-remove +++ b/bin/omarchy-plugin-remove @@ -7,6 +7,16 @@ set -euo pipefail +# A rescan makes the shell rebuild every plugin instance, which blocks its IPC +# for seconds, and these commands normally run right inside that window: +# omarchy-plugin-add and omarchy-plugin-clone call them a step after their own +# rescan, and saving a file under ~/.config/omarchy/plugins/ starts the same +# reload through inotify. The 2s default expires there and reports a shell that +# is not responding, when the shell is merely busy with work this command is +# waiting on. A shell that is genuinely not running still fails at once, since +# that is a connection error rather than a timeout. +export OMARCHY_SHELL_IPC_TIMEOUT="${OMARCHY_SHELL_IPC_TIMEOUT:-15s}" + PLUGINS_DIR="$HOME/.config/omarchy/plugins" ASSUME_YES=0 diff --git a/test/shell.d/plugin-ipc-budget-test.sh b/test/shell.d/plugin-ipc-budget-test.sh new file mode 100755 index 000000000000..3dcd8ef67068 --- /dev/null +++ b/test/shell.d/plugin-ipc-budget-test.sh @@ -0,0 +1,116 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +require_command jq + +TMPDIR=$(mktemp -d) +trap 'rm -rf "$TMPDIR"' EXIT + +# How long the stub shell takes to answer. Longer than the 2s default these +# commands used to run with, shorter than the budget they ask for now, so the +# same call fails or succeeds purely on the budget. +BUSY_SECONDS=3 + +stub_dir="$TMPDIR/stubs" +mkdir -p "$stub_dir" + +# A stand-in for omarchy-shell that keeps the part under test: the caller's +# budget wraps the call, and expiry becomes "is not responding" on exit 1. +cat >"$stub_dir/omarchy-shell" <<'STUB' +#!/bin/bash + +[[ ${1:-} == "-q" ]] && shift + +printf '%s\n' "${OMARCHY_SHELL_IPC_TIMEOUT:-unset}" >>"$BUDGET_LOG" + +answer=$(timeout "${OMARCHY_SHELL_IPC_TIMEOUT:-2s}" \ + bash -c 'sleep "$1"; printf ok' _ "${SHELL_BUSY_SECONDS:-0}") +status=$? + +if (( status == 124 || status == 137 )); then + echo "omarchy-shell is not responding" >&2 + exit 1 +fi + +if [[ ${2:-} == "listPlugins" ]]; then + printf '%s\n' "${STUB_PLUGINS:-[]}" +else + printf '%s\n' "$answer" +fi +exit 0 +STUB +chmod +x "$stub_dir/omarchy-shell" + +export BUDGET_LOG="$TMPDIR/budgets" + +run_plugin_cmd() { + local home="$1" + shift + + HOME="$home" OMARCHY_PATH="$ROOT" PATH="$stub_dir:$ROOT/bin:$PATH" "$@" +} + +home="$TMPDIR/home" +mkdir -p "$home/.config/omarchy/plugins" + +# --- enable and disable ride out a busy shell ------------------------------ +# +# omarchy-plugin-add and omarchy-plugin-clone call these one step after their +# own rescan, and an editor saving into ~/.config/omarchy/plugins/ starts the +# same reload through inotify. Reporting an unreachable shell there turns work +# in progress into a failure (#9304). + +: >"$BUDGET_LOG" +output=$(SHELL_BUSY_SECONDS="$BUSY_SECONDS" run_plugin_cmd "$home" \ + omarchy-plugin-disable acme.busy 2>&1) || + fail "plugin disable waits out a shell that is rebuilding plugins" "$output" +grep -qF "Disabled acme.busy" <<<"$output" || + fail "plugin disable reports the change it made" "$output" +pass "plugin disable waits for a shell busy with a plugin reload" + +: >"$BUDGET_LOG" +output=$(SHELL_BUSY_SECONDS="$BUSY_SECONDS" run_plugin_cmd "$home" \ + omarchy-plugin-enable acme.busy 2>&1) || + fail "plugin enable waits out a shell that is rebuilding plugins" "$output" +grep -qF "Enabled acme.busy" <<<"$output" || + fail "plugin enable reports the change it made" "$output" +pass "plugin enable waits for a shell busy with a plugin reload" + +# --- remove asks for the same budget --------------------------------------- +# +# Its setPluginEnabled call sits between the confirmation and the deletion, so +# an expiry there aborts a removal that was already agreed to. + +write_plugin() { + mkdir -p "$1" + jq -n --arg id "$2" '{ + schemaVersion: 1, id: $id, name: "Busy", version: "1.0.0", + kinds: ["bar-widget"], entryPoints: {barWidget: "Widget.qml"}, + barWidget: {displayName: "Busy", category: "Test", allowMultiple: false} + }' >"$1/manifest.json" + printf 'import QtQuick\nItem {}\n' >"$1/Widget.qml" +} + +write_plugin "$home/.config/omarchy/plugins/acme.removable" "acme.removable" +: >"$BUDGET_LOG" +output=$(STUB_PLUGINS='[{"id":"acme.removable","enabled":true}]' \ + run_plugin_cmd "$home" omarchy-plugin-remove acme.removable --yes 2>&1) || + fail "plugin remove runs against the stub shell" "$output" +grep -qFx '15s' "$BUDGET_LOG" || + fail "plugin remove asks for the raised budget" "$(cat "$BUDGET_LOG")" +pass "plugin remove asks the shell for a budget that fits a reload" + +# --- an explicit budget still wins ----------------------------------------- +# +# The commands raise the default; they do not override someone who set one. + +: >"$BUDGET_LOG" +output=$(OMARCHY_SHELL_IPC_TIMEOUT=1s SHELL_BUSY_SECONDS="$BUSY_SECONDS" \ + run_plugin_cmd "$home" omarchy-plugin-disable acme.busy 2>&1) && + fail "an explicit 1s budget still expires against a busy shell" "$output" +grep -qFx '1s' "$BUDGET_LOG" || + fail "plugin disable keeps the caller's budget" "$(cat "$BUDGET_LOG")" +pass "an explicit OMARCHY_SHELL_IPC_TIMEOUT is left alone"