Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(linux): stage native runtime dependencies for loaded modules

Steven Enamakel125df757b6ed
diff --git a/crates/openhuman-app/tauri.conf.json b/crates/openhuman-app/tauri.conf.json
index 8c739278bb..d96e51d04d 100644
--- a/crates/openhuman-app/tauri.conf.json
+++ b/crates/openhuman-app/tauri.conf.json
@@ -58,6 +58,7 @@
"linux": {
"deb": {
"depends": [
+ "libasound2t64 | libasound2",
"libatk-bridge2.0-0",
"libgbm1",
"libgdk-pixbuf-2.0-0",
diff --git a/scripts/__tests__/tauri-deb-depends.test.mjs b/scripts/__tests__/tauri-deb-depends.test.mjs
index 8e2d75d92f..4f6924f007 100644
--- a/scripts/__tests__/tauri-deb-depends.test.mjs
+++ b/scripts/__tests__/tauri-deb-depends.test.mjs
@@ -1,6 +1,6 @@
// Guards the Linux .deb runtime dependency list in tauri.conf.json (moved from
// the former tests/linux_cef_deb_runtime_e2e.rs). libxdo3 in particular keeps
-// the binary from segfaulting on launch when the legacy soname is missing.
+// loaded Computer module usable even though the host no longer links it.
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { dirname, resolve } from "node:path";
@@ -28,3 +28,12 @@ test("tauri.conf.json linux deb depends lists the required runtime libraries onc
}
assert.equal(deps.filter((d) => d === "libxdo3").length, 1, "libxdo3 should be listed exactly once");
});
+
+// Loaded audio modules need ALSA even after host-side audio dependencies go away.
+test("Linux deb declares the ALSA runtime for both supported Ubuntu package names", () => {
+ const config = JSON.parse(
+ readFileSync(resolve(root, "crates/openhuman-app/tauri.conf.json"), "utf8"),
+ );
+ const deps = config.bundle.linux.deb.depends;
+ assert.equal(deps.filter((dep) => dep === "libasound2t64 | libasound2").length, 1);
+});
diff --git a/scripts/release/strip-appimage-graphics-libs.sh b/scripts/release/strip-appimage-graphics-libs.sh
index 5fc967b79e..aab68283ef 100755
--- a/scripts/release/strip-appimage-graphics-libs.sh
+++ b/scripts/release/strip-appimage-graphics-libs.sh
@@ -631,55 +631,80 @@ sanitize_elf_rpaths() {
return $rewrote
}
-# validate_appimage_required_libs — fail the build loudly if the sharun preload
-# library or a runtime library the app hard-links (NEEDED) is absent from the
-# bundle.
-#
-# Problem (issues #3224 and #4020): the app links libxdo.so.3 via enigo
-# (`#[link(name = "xdo")]`, used by crates/openhuman-core/src/tools/impl/computer for Linux
-# mouse/keyboard control). lib4bin's ldd-walk normally bundles it into
-# shared/lib, but if a future runner image drops libxdo-dev or bumps its soname,
-# the lib silently vanishes from the AppImage and the binary segfaults on launch
-# on any host lacking the legacy soname (e.g. Arch, which ships libxdo.so.4). The
-# .deb path already guards this via its `depends` (libxdo3) +
-# scripts/__tests__/tauri-deb-depends.test.mjs; the AppImage path had no equivalent. This turns a
-# silent runtime segfault into a loud build failure. CEF is staged separately
-# from the ldd walk, so verify its runtime library survived bundling as well.
-# anylinux.so establishes sharun's portable runtime before either dependency
-# can load, so it is part of the same release contract.
-validate_appimage_required_libs() {
- local appdir="$1"
- if ! uses_sharun_launcher "$appdir"; then
- return 0
- fi
+# These system libraries belong to the loaded Computer/Voice artifacts, so
+# walking the host's NEEDED entries no longer reliably stages them.
+MODULE_RUNTIME_LIBRARIES=(libxdo.so.3 libasound.so.2)
- local root pattern found
- # libcef.so* was here until #5606. CEF was removed in #5456 and there is no
- # cef package in either Cargo.lock, so no build can satisfy it - it would fail
- # every sharun bundle this function is still able to see.
- for pattern in 'anylinux.so' 'libxdo.so*'; do
- found=0
- for root in "$appdir/shared/lib" "$appdir/usr/lib" "$appdir/lib"; do
- [ -d "$root" ] || continue
- if [ -n "$(find "$root" -name "$pattern" -print -quit 2>/dev/null)" ]; then
- found=1
- break
- fi
- done
- [ "$found" -eq 1 ] && continue
+appimage_has_runtime_library() {
+ local appdir="$1" name="$2" root found
+ for root in "$appdir/shared/lib" "$appdir/usr/lib" "$appdir/lib"; do
+ [ -d "$root" ] || continue
+ while IFS= read -r -d '' found; do
+ [ -f "$found" ] && return 0
+ done < <(find "$root" -name "$name" -print0)
+ done
+ return 1
+}
- case "$pattern" in
- anylinux.so)
- echo "[strip-libs] ERROR: AppImage is missing anylinux.so — the sharun preload library was not copied into the final bundle. The AppImage launcher cannot establish its portable runtime without it." >&2
- ;;
- libxdo.so\*)
- echo "[strip-libs] ERROR: AppImage is missing libxdo.so.* — the enigo NEEDED dependency was not bundled (issue #3224). The app would segfault on launch on hosts without the legacy libxdo soname (e.g. Arch). Ensure libxdo-dev is installed on the build runner so lib4bin's ldd-walk bundles it." >&2
- ;;
- esac
- return 1
+system_module_runtime_library() {
+ local name="$1"
+ # CI builds on the target architecture and installs libxdo-dev/libasound2-dev.
+ # Use the loader cache rather than a runner-specific multiarch directory.
+ /sbin/ldconfig -p | awk -v name="$name" '$1 == name && !found++ { print $NF }'
+}
+
+# Copy only missing module dependencies; bundled libraries stay authoritative.
+# Sanitization and final-artifact validation run after this staging step.
+stage_module_runtime_libraries() {
+ local appdir="$1" name source destination main_binary
+ MODULE_RUNTIME_LIBRARIES_ADDED=0
+ if uses_sharun_launcher "$appdir"; then
+ destination="$appdir/shared/lib"
+ main_binary="$appdir/shared/bin/OpenHuman"
+ else
+ destination="$appdir/usr/lib"
+ main_binary="$appdir/usr/bin/OpenHuman"
+ fi
+ local machine
+ machine="$(LC_ALL=C readelf -h "$main_binary" | awk '/Class:|Machine:/ { print }')" || return 1
+ [ -n "$machine" ] || return 1
+ for name in "${MODULE_RUNTIME_LIBRARIES[@]}"; do
+ appimage_has_runtime_library "$appdir" "$name" && continue
+ source="$(system_module_runtime_library "$name")" || return 1
+ if [ ! -f "$source" ] || [ "$machine" != "$(LC_ALL=C readelf -h "$source" 2>/dev/null | awk '/Class:|Machine:/ { print }')" ]; then
+ echo "[strip-libs] ERROR: missing compatible module runtime library '$name' on the build runner" >&2
+ return 1
+ fi
+ mkdir -p "$destination"
+ # Remove a dangling destination symlink instead of writing through it.
+ rm -f "$destination/$name"
+ cp -L "$source" "$destination/$name" || return 1
+ MODULE_RUNTIME_LIBRARIES_ADDED=$((MODULE_RUNTIME_LIBRARIES_ADDED + 1))
+ echo "[strip-libs] staged module runtime library $name"
+ done
+}
+
+validate_module_runtime_libraries() {
+ local appdir="$1" name
+ for name in "${MODULE_RUNTIME_LIBRARIES[@]}"; do
+ if ! appimage_has_runtime_library "$appdir" "$name"; then
+ echo "[strip-libs] ERROR: AppImage is missing $name — required by a loaded module" >&2
+ return 1
+ fi
done
}
+# The sharun preload is specific to that launcher; module dependencies apply
+# to both supported AppImage layouts and need no host implementation linkage.
+validate_appimage_required_libs() {
+ local appdir="$1"
+ if uses_sharun_launcher "$appdir" && ! appimage_has_runtime_library "$appdir" anylinux.so; then
+ echo "[strip-libs] ERROR: AppImage is missing anylinux.so — required by the sharun launcher" >&2
+ return 1
+ fi
+ validate_module_runtime_libraries "$appdir" || return 1
+}
+
# patch_apprun_sharun_cwd — retain historical shell-AppRun CWD hardening.
#
# Canonical `+` entries in shared/lib/lib.path are the primary fix for released
@@ -778,6 +803,11 @@ strip_one_appimage() {
local rewrote_libpath=0
local patched_apprun=0
local rewrote_rpaths=0
+ if ! stage_module_runtime_libraries "$appdir"; then
+ rm -rf "$workdir"
+ return 1
+ fi
+ local added_module_libraries="$MODULE_RUNTIME_LIBRARIES_ADDED"
local lib_roots=()
for candidate in \
"$appdir/usr/lib" \
@@ -827,7 +857,7 @@ strip_one_appimage() {
return 1
fi
- if [ "$removed" -eq 0 ] && [ "$added_loader" -eq 0 ] && [ "$rewrote_libpath" -eq 0 ] && [ "$patched_apprun" -eq 0 ] && [ "$rewrote_rpaths" -eq 0 ]; then
+ if [ "$removed" -eq 0 ] && [ "$added_loader" -eq 0 ] && [ "$rewrote_libpath" -eq 0 ] && [ "$patched_apprun" -eq 0 ] && [ "$rewrote_rpaths" -eq 0 ] && [ "$added_module_libraries" -eq 0 ]; then
echo "[strip-libs] No graphics libs, missing sharun interpreter, or build-machine RPATHs found in $original; leaving unchanged."
if ! validate_rebuilt_appimage "$original"; then
rm -rf "$workdir"
@@ -836,7 +866,7 @@ strip_one_appimage() {
rm -rf "$workdir"
return
fi
- echo "[strip-libs] Removed $removed file(s), added $added_loader loader file(s), patched AppRun=$patched_apprun, rewrote RPATHs=$rewrote_rpaths; repacking AppImage."
+ echo "[strip-libs] Removed $removed file(s), added $added_loader loader file(s), patched AppRun=$patched_apprun, rewrote RPATHs=$rewrote_rpaths, staged module libraries=$added_module_libraries; repacking AppImage."
local rebuilt="$workdir/$name"
local appimage_arch
diff --git a/scripts/release/test-strip-appimage-rpaths.sh b/scripts/release/test-strip-appimage-rpaths.sh
index 8f152d7b44..a2a643b19f 100644
--- a/scripts/release/test-strip-appimage-rpaths.sh
+++ b/scripts/release/test-strip-appimage-rpaths.sh
@@ -289,6 +289,7 @@ make_runtime_appdir() {
cp "$HOST_ELF" "$appdir/shared/lib/anylinux.so"
cp "$HOST_ELF" "$appdir/shared/lib/libxdo.so.3"
+ cp "$HOST_ELF" "$appdir/shared/lib/libasound.so.2"
# Since #5606 libcef.so is no longer a REQUIRED library (CEF was removed in
# #5456). It stays in the fixture purely as a sample bundled ELF for the
# RPATH-injection cases below.
@@ -351,6 +352,57 @@ inject_actions_rpath() {
"$1/shared/lib/libcef.so"
}
+# The host no longer links libxdo; it must remain available to loaded modules.
+case " $APPIMAGE_PRODUCTION_NEEDED " in
+ *" libxdo.so.3 "*) fail "module libxdo still requires a host NEEDED entry" ;;
+esac
+
+MODULE_RUNTIME="$WORK/module-runtime"
+make_runtime_appdir "$MODULE_RUNTIME"
+rm "$MODULE_RUNTIME/shared/lib/libxdo.so.3" "$MODULE_RUNTIME/shared/lib/libasound.so.2"
+MODULE_SOURCES="$WORK/module-sources"
+mkdir -p "$MODULE_SOURCES"
+cp "$HOST_ELF" "$MODULE_SOURCES/libxdo.so.3"
+cp "$HOST_ELF" "$MODULE_SOURCES/libasound.so.2"
+SAVED_SYSTEM_LOOKUP="$(declare -f system_module_runtime_library || true)"
+system_module_runtime_library() { printf '%s/%s\n' "$MODULE_SOURCES" "$1"; }
+stage_module_runtime_libraries "$MODULE_RUNTIME" \
+ || fail "module runtime dependencies were not staged"
+[ "$MODULE_RUNTIME_LIBRARIES_ADDED" -eq 2 ] \
+ || fail "module runtime staging did not count both dependencies"
+cmp "$MODULE_SOURCES/libxdo.so.3" "$MODULE_RUNTIME/shared/lib/libxdo.so.3" \
+ || fail "staged libxdo differs from the runner library"
+stage_module_runtime_libraries "$MODULE_RUNTIME" \
+ || fail "module runtime staging is not repeatable"
+[ "$MODULE_RUNTIME_LIBRARIES_ADDED" -eq 0 ] \
+ || fail "existing module runtime libraries were replaced"
+rm "$MODULE_RUNTIME/shared/lib/libasound.so.2" "$MODULE_SOURCES/libasound.so.2"
+if stage_module_runtime_libraries "$MODULE_RUNTIME" >"$WORK/missing-module-source.log" 2>&1; then
+ fail "missing runner module library was accepted"
+fi
+[ ! -e "$MODULE_RUNTIME/shared/lib/libasound.so.2" ] \
+ || fail "missing source produced a destination library"
+printf 'not a shared library' >"$MODULE_SOURCES/libasound.so.2"
+if stage_module_runtime_libraries "$MODULE_RUNTIME" >"$WORK/invalid-module-source.log" 2>&1; then
+ fail "non-ELF module runtime library was accepted"
+fi
+
+MODULE_LINUXDEPLOY="$WORK/module-linuxdeploy"
+mkdir -p "$MODULE_LINUXDEPLOY/usr/bin"
+cp "$HOST_ELF" "$MODULE_LINUXDEPLOY/usr/bin/OpenHuman"
+cp "$HOST_ELF" "$MODULE_SOURCES/libasound.so.2"
+stage_module_runtime_libraries "$MODULE_LINUXDEPLOY" \
+ || fail "linuxdeploy module runtime dependencies were not staged"
+validate_module_runtime_libraries "$MODULE_LINUXDEPLOY" \
+ || fail "linuxdeploy module runtime dependencies were rejected"
+rm "$MODULE_LINUXDEPLOY/usr/lib/libasound.so.2"
+if validate_module_runtime_libraries "$MODULE_LINUXDEPLOY" >/dev/null 2>&1; then
+ fail "linuxdeploy accepted missing module ALSA runtime"
+fi
+[ -z "$SAVED_SYSTEM_LOOKUP" ] || eval "$SAVED_SYSTEM_LOOKUP"
+
+echo "[test-rpaths] ok: module libraries are staged without host implementation linkage"
+
RUNTIME_COMPLETE="$WORK/runtime-complete"
make_runtime_appdir "$RUNTIME_COMPLETE"
APPIMAGE_EXPECTED_NEEDED="" validate_extracted_appdir "$RUNTIME_COMPLETE" \
@@ -381,7 +433,7 @@ if APPIMAGE_EXPECTED_NEEDED="" \
>"$WORK/direct-validator.log" 2>&1; then
fail "direct validator allowed a fixture override to disable production NEEDED checks"
fi
-grep -F "missing NEEDED entry 'libxdo.so.3'" \
+grep -F "missing NEEDED entry 'libwebkit2gtk-4.1.so.0'" \
"$WORK/direct-validator.log" >/dev/null \
|| fail "direct validator did not enforce the production NEEDED contract"
@@ -563,7 +615,7 @@ fi
assert_runtime_layout_rejected missing-anylinux \
"missing anylinux.so" remove_anylinux
assert_runtime_layout_rejected missing-libxdo \
- "missing libxdo.so.*" remove_libxdo
+ "missing libxdo.so.3" remove_libxdo
assert_runtime_layout_rejected missing-real-app \
"shared/bin/OpenHuman is not an executable ELF" remove_real_app
assert_runtime_layout_rejected text-real-app \
@@ -648,6 +700,7 @@ CLEANUP_WORKDIR="$CLEANUP_WORKDIR" \
command mktemp "$@"
fi
}
+ stage_module_runtime_libraries() { MODULE_RUNTIME_LIBRARIES_ADDED=0; }
ensure_sharun_interpreter() { return 1; }
rewrite_sharun_lib_path() { return 1; }
patch_apprun_sharun_cwd() { return 1; }
@@ -673,7 +726,10 @@ NOOP_IMAGE="$WORK/noop-final.AppImage"
printf '%s\n' \
'#!/usr/bin/env bash' \
'[ "$1" = "--appimage-extract" ] || exit 9' \
- 'mkdir -p squashfs-root' \
+ 'mkdir -p squashfs-root/usr/bin squashfs-root/usr/lib' \
+ 'cp "$NOOP_HOST_ELF" squashfs-root/usr/bin/OpenHuman' \
+ 'cp "$NOOP_HOST_ELF" squashfs-root/usr/lib/libxdo.so.3' \
+ 'cp "$NOOP_HOST_ELF" squashfs-root/usr/lib/libasound.so.2' \
>"$NOOP_IMAGE"
chmod +x "$NOOP_IMAGE"
NOOP_IMAGE_BEFORE="$(sha256sum "$NOOP_IMAGE" | awk '{print $1}')"
@@ -684,6 +740,7 @@ noop_runtime_validator_stub() {
printf '%s\n' "$1" >>"$NOOP_VALIDATOR_RECORD"
}
MODIFIED_PATHS=()
+export NOOP_HOST_ELF="$HOST_ELF"
APPIMAGE_RUNTIME_VALIDATOR=noop_runtime_validator_stub \
strip_one_appimage "$NOOP_IMAGE" \
|| fail "strip_one_appimage rejected a valid no-change final artifact"
@@ -799,6 +856,7 @@ fi
echo "[test-rpaths] ok: guard fails when anylinux.so is absent"
: > "$GUARD_DIR/shared/lib/anylinux.so"
+: > "$GUARD_DIR/shared/lib/libasound.so.2"
# 2b — libxdo absent → must exit non-zero.
if ( validate_appimage_required_libs "$GUARD_DIR" ) 2>/dev/null; then
diff --git a/scripts/release/validate-appimage-runtime.sh b/scripts/release/validate-appimage-runtime.sh
index 524ec7c738..562243b23d 100755
--- a/scripts/release/validate-appimage-runtime.sh
+++ b/scripts/release/validate-appimage-runtime.sh
@@ -26,9 +26,9 @@ source "$RUNTIME_VALIDATOR_SCRIPT_DIR/strip-appimage-graphics-libs.sh"
# — the previous code duplicated the list, and the stale copy (libcef.so)
# outlived CEF by two weeks.
#
-# Verified against a real linuxdeploy bundle on both Linux arches: usr/bin/OpenHuman
-# declares and bundles libxdo.so.3 and libwebkit2gtk-4.1.so.0.
-APPIMAGE_PRODUCTION_NEEDED="libxdo.so.3 libwebkit2gtk-4.1.so.0"
+# Wry remains linked in the host. libxdo is now owned by the loaded Computer
+# module and is checked independently of the host ELF.
+APPIMAGE_PRODUCTION_NEEDED="libwebkit2gtk-4.1.so.0"
runtime_validation_error() {
echo "[appimage-runtime] ERROR: $*" >&2
@@ -268,19 +268,11 @@ validate_extracted_appdir() {
fi
done
- # Tripwire for libraries that have historically vanished from the bundle
- # silently. libxdo is linked directly by enigo via #[link(name = "xdo")] - not
- # through any crate, so it does not appear in Cargo.lock - and its absence
- # segfaulted the app on launch (#4020). libcef.so used to be on this list; CEF
- # was removed in #5456 and no build can produce it any more.
- #
- # Both halves are fatal, and they catch different regressions. A NEEDED entry
- # that is not bundled is #4020 itself: the loader fails at startup. An entry
- # that is no longer declared at all means the dependency was dropped upstream
- # — no segfault, but a silent capability loss, which is precisely the class of
- # regression this tripwire exists to surface. Warning instead would put it in a
- # 90-minute release log where nobody reads it. If a drop is intentional, remove
- # the name from APPIMAGE_PRODUCTION_NEEDED in the same commit.
+ # Loaded modules need their native runtime libraries in either layout, even
+ # when the host ELF has no corresponding NEEDED entry.
+ validate_module_runtime_libraries "$appdir" || return 1
+
+ # Host-linked dependencies still require both a NEEDED entry and a bundle.
local expected_needed="${APPIMAGE_EXPECTED_NEEDED-$APPIMAGE_PRODUCTION_NEEDED}"
local needed_name found
for needed_name in $expected_needed; do