The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(modules): move platform candidate logic into tinybus
Steven Enamakel420b8f56d746
diff --git a/crates/openhuman-core/src/modules/README.md b/crates/openhuman-core/src/modules/README.mdindex 2c40e9ffe6..9de21d4c08 100644--- a/crates/openhuman-core/src/modules/README.md+++ b/crates/openhuman-core/src/modules/README.md@@ -63,8 +63,8 @@ layer.a developer's `modules.overrides` (or a `*_TEST_MODULE` env var), themodule search path (`OPENHUMAN_MODULE_PATH`, then platform data dirs), thenthe release cache.-4. `platform::host_candidates()` picks the ordered list of artifact keys this- host can run; `ops::load_cached` tries each until one is admitted.+4. `tinybus::module::platform::host_candidates()` picks the ordered list of artifact keys this+ host can run; `ops::load_cached` hands them to `tinybus::module::load_first_admitted`, which tries each until one is admitted.5. The release cache (`tinybus::module::CachedRelease`) downloads if`modules.allow_download`, fetches the release's own `checksum.toml`, checksit against the digest pinned in `registry.rs`, hashes the archive, extracts,diff --git a/crates/openhuman-core/src/modules/mod.rs b/crates/openhuman-core/src/modules/mod.rsindex 3e1699c02f..feb58001e4 100644--- a/crates/openhuman-core/src/modules/mod.rs+++ b/crates/openhuman-core/src/modules/mod.rs@@ -32,7 +32,6 @@//! without linking the browser engine into the core.//! - [`wallet`] — the host half of the `tinywallet` module, which builds and//! assembles transactions while the signing key stays in this process.-//! - [`platform`] — which published artifact belongs to this host.//! - [`host`] — the module broker, connection and loader.//! - [`ops`] — resolving, loading, and reporting status.//! - [`runtime`] — calling `tinyruntime`: resolving a language runtime and@@ -53,7 +52,6 @@ pub mod host;pub mod memory;mod memory_host;pub mod ops;-pub mod platform;pub mod registry;pub mod runtime;pub mod schemas;diff --git a/crates/openhuman-core/src/modules/ops.rs b/crates/openhuman-core/src/modules/ops.rsindex 50ddc0233c..2f69a9406d 100644--- a/crates/openhuman-core/src/modules/ops.rs+++ b/crates/openhuman-core/src/modules/ops.rs@@ -36,12 +36,15 @@ use std::sync::OnceLock;use std::time::Duration;use super::types::{ModuleRecord, ModuleState, ModuleStatus};-use super::{host, platform, registry};+use super::{host, registry};use crate::config::Config;use tinybus::module::resolution::{self, Claim, Resolution, ResolutionState, ResolutionTable, Waited,};-use tinybus::module::{artifact_dir, prune_stale_versions};+use tinybus::module::platform::host_candidates;+use tinybus::module::{+ load_first_admitted, prune_stale_versions, ReleaseAsset, ReleasePlan,+};/// Installer-owned, read-only release cache. The desktop host sets this before/// starting the embedded core; other hosts continue using the user cache.@@ -295,120 +298,25 @@ fn load_cached(allow_download: bool,bundled_root: Option<&Path>,) -> Result<(), String> {- let candidates = platform::host_candidates();- let assets: Vec<_> = candidates+ let assets: Vec<ReleaseAsset<'static>> = host_candidates().iter().filter_map(|key| record.asset_for(key))+ .map(|asset| ReleaseAsset {+ host_key: asset.host_key,+ archive: asset.archive,+ sha256: asset.sha256,+ }).collect();- if assets.is_empty() {- return Err(format!(- "module '{}' is not available for this platform, so the feature it provides is \- unavailable in this build",- record.id- ));- }-- let mut last_error = String::new();- let mut found_bundled = false;- if let Some(bundled_root) = bundled_root {- for asset in &assets {- let Some(cache_dir) =- artifact_dir(bundled_root, record.id, record.version, asset.host_key)- else {- continue;- };- if !cache_dir.join(asset.archive).is_file() {- continue;- }- found_bundled = true;- let release = tinybus::module::CachedRelease {- release_url: record.release_url,- asset_name: asset.archive,- expected_sha256: Some(asset.sha256),- cache_dir: &cache_dir,- allow_download: false,- };- match runtime- .host()- .load_github_release_cached(&release, module_config.clone())- {- Ok(_) => {- log::info!("[modules] loaded '{}' from the installer bundle", record.id);- return Ok(());- }- Err(err) => {- last_error = err.to_string();- log::warn!(- "[modules] bundled '{}' artifact for {} was not admitted: {last_error}",- record.id,- asset.host_key- );- }- }- }- }- if found_bundled {- return Err(format!(- "module '{}' could not be loaded from the installer bundle: {last_error}. \- Restart the app after repairing the installation",- record.id- ));- }- for asset in assets {- let Some(cache_dir) = artifact_dir(install_root, record.id, record.version, asset.host_key)- else {- last_error =- "the module's cache path could not be built from its registry entry".to_string();- continue;- };- let release = tinybus::module::CachedRelease {- release_url: record.release_url,- asset_name: asset.archive,- expected_sha256: Some(asset.sha256),- cache_dir: &cache_dir,- allow_download,- };- match runtime- .host()- .load_github_release_cached(&release, module_config.clone())- {- Ok(_) => {- log::info!(- "[modules] loaded '{}' {} ({}) through the release cache",- record.id,- record.version,- asset.host_key- );- return Ok(());- }- Err(err) => {- // Sanitised: tinybus's own errors carry only a basename and a- // fixed reason, and nothing here adds a path or a URL.- last_error = err.to_string();- log::warn!(- "[modules] '{}' artifact for {} was not admitted: {last_error}",- record.id,- asset.host_key- );- }- }- }- if !allow_download {- log::debug!(- "[modules] '{}' release cache miss with downloads disabled: {last_error}",- record.id- );- return Err(format!(- "module '{}' is unavailable: no local artifact is installed and downloads are \- disabled in configuration",- record.id- ));- }- Err(format!(- "module '{}' could not be loaded: {last_error}. This is terminal for the running \- process; restart the app to try again",- record.id- ))+ let plan = ReleasePlan {+ id: record.id,+ version: record.version,+ release_url: record.release_url,+ assets: &assets,+ install_root,+ bundled_root,+ allow_download,+ };+ load_first_admitted(runtime.host(), &plan, &module_config).map(|_| ())}/// Load a platform library from `path`.diff --git a/crates/openhuman-core/src/modules/platform.rs b/crates/openhuman-core/src/modules/platform.rsdeleted file mode 100644index 02dca210b3..0000000000--- a/crates/openhuman-core/src/modules/platform.rs+++ /dev/null@@ -1,146 +0,0 @@-//! Choosing which published artifact belongs to this host.-//!-//! A target triple is not enough. tinybus admits a module only if its target,-//! pointer width, endianness and toolchain all match, and a `.so` built against-//! glibc 2.39 does not load on a host with glibc 2.35 — the failure is a-//! `dlopen` error about a missing symbol version, not something the ABI gate can-//! phrase helpfully. Releases therefore publish per-distro artifacts-//! (`ubuntu-22.04-x86_64` beside `ubuntu-24.04-x86_64`), and this module decides-//! which one to reach for.-//!-//! It returns an ordered list rather than a single answer. The newest build that-//! could work is tried first, and an admission failure falls through to the next-//! candidate: a host newer than every published artifact runs the newest one,-//! which is the case that works, while a host older than all of them gets the-//! oldest, which is the case most likely to.-//!-//! Every path here is pure — `std::env::consts` and, on Linux, the glibc version-//! string. That is what makes the whole table unit-testable on one machine.--/// Ordered artifact keys for this host, newest first.-///-/// Empty when no published artifact can run here, which is the honest answer for-/// a musl or BSD host: the alternative is downloading something that cannot-/// possibly `dlopen`.-#[must_use]-pub fn host_candidates() -> Vec<String> {- candidates_for(- std::env::consts::OS,- std::env::consts::ARCH,- glibc_version(),- )-}--/// The pure half of [`host_candidates`], with the host facts injected.-///-/// `glibc` is `None` off Linux, and `None` on a Linux host whose libc is not-/// glibc — which is the distinction that decides whether any Linux artifact is-/// usable at all.-#[must_use]-pub fn candidates_for(os: &str, arch: &str, glibc: Option<(u32, u32)>) -> Vec<String> {- let arch_key = match arch {- "x86_64" => "x86_64",- "aarch64" => "arm64",- _ => return Vec::new(),- };-- match os {- // Releases are cut on the two maintained LTS images. A host at or above- // the newer one takes the newer build; anything older takes the older- // build, which is the one whose glibc floor it can satisfy.- "linux" => {- let Some((major, minor)) = glibc else {- // musl, or a libc we could not identify. No published artifact- // targets it, and guessing produces a dlopen failure at first- // use rather than a clear answer now.- return Vec::new();- };- if (major, minor) >= (2, 39) {- vec![- format!("ubuntu-24.04-{arch_key}"),- format!("ubuntu-22.04-{arch_key}"),- ]- } else if (major, minor) >= (2, 35) {- vec![format!("ubuntu-22.04-{arch_key}")]- } else {- // Older than every published floor. Offering the oldest build- // anyway would fail at dlopen with a symbol-version error.- Vec::new()- }- }- // macOS artifacts are forward-compatible, so the ordering is newest- // first and an older host falls through to the older build.- "macos" => vec![- format!("macos-26-{arch_key}"),- format!("macos-15-{arch_key}"),- ],- "windows" => match arch_key {- // The arm64 build is published only against Windows 11.- "arm64" => vec!["windows-11-arm64".to_string()],- _ => vec![- "windows-2025-x86_64".to_string(),- "windows-2022-x86_64".to_string(),- ],- },- _ => Vec::new(),- }-}--/// The host's glibc version, or `None` if it is not glibc.-///-/// Gated on `target_env = "gnu"`, not merely on Linux: musl does not provide-/// this symbol, so a musl build would fail to *link* rather than fall through to-/// the `None` below. That fallback is what makes a musl host report "no-/// artifact for this platform" instead of downloading one it cannot load.-#[cfg(all(target_os = "linux", target_env = "gnu"))]-fn glibc_version() -> Option<(u32, u32)> {- // `gnu_get_libc_version` is the only reliable answer — parsing `ldd- // --version` means spawning a process and reading localised output, and- // reading a symlink target guesses. On musl the symbol is absent, which is- // exactly the distinction that matters.- unsafe extern "C" {- fn gnu_get_libc_version() -> *const std::os::raw::c_char;- }-- // SAFETY: `gnu_get_libc_version` takes no arguments and returns a pointer to- // a static NUL-terminated string owned by libc, valid for the process- // lifetime. On a non-glibc libc the symbol does not resolve and this code is- // not reached, because the binary would fail to link against it — which is- // why the musl case is handled by the returned `None` below rather than here.- let raw = unsafe { gnu_get_libc_version() };- if raw.is_null() {- return None;- }- // SAFETY: non-null, NUL-terminated, static for the process lifetime.- let version = unsafe { std::ffi::CStr::from_ptr(raw) }.to_str().ok()?;- parse_glibc_version(version)-}--/// Every other target: not glibc, so there is no version to report.-///-/// Covers musl and every non-Linux host. Both want the same answer — `None`,-/// which `candidates_for` turns into an empty candidate list.-#[cfg(not(all(target_os = "linux", target_env = "gnu")))]-fn glibc_version() -> Option<(u32, u32)> {- None-}--/// Parse a `major.minor` glibc version string, ignoring any suffix.-fn parse_glibc_version(raw: &str) -> Option<(u32, u32)> {- let mut parts = raw.trim().split('.');- let major = parts.next()?.parse().ok()?;- // A version like "2.39" has no third component; one like "2.39.1" does, and- // the patch level never affects which artifact is usable.- let minor_raw = parts.next()?;- let minor = minor_raw- .chars()- .take_while(char::is_ascii_digit)- .collect::<String>()- .parse()- .ok()?;- Some((major, minor))-}--#[cfg(test)]-#[path = "platform_tests.rs"]-mod tests;diff --git a/crates/openhuman-core/src/modules/platform_tests.rs b/crates/openhuman-core/src/modules/platform_tests.rsdeleted file mode 100644index 60bc3c2f9c..0000000000--- a/crates/openhuman-core/src/modules/platform_tests.rs+++ /dev/null@@ -1,90 +0,0 @@-use super::{candidates_for, host_candidates, parse_glibc_version};--#[test]-fn a_modern_linux_host_prefers_the_newer_build_but_can_fall_back() {- assert_eq!(- candidates_for("linux", "x86_64", Some((2, 39))),- vec!["ubuntu-24.04-x86_64", "ubuntu-22.04-x86_64"]- );- assert_eq!(- candidates_for("linux", "aarch64", Some((2, 41))),- vec!["ubuntu-24.04-arm64", "ubuntu-22.04-arm64"]- );-}--#[test]-fn an_older_linux_host_is_offered_only_what_its_glibc_can_load() {- // Offering the 24.04 build here would fail at dlopen with a symbol- // version error, which is a worse outcome than not offering it.- assert_eq!(- candidates_for("linux", "x86_64", Some((2, 35))),- vec!["ubuntu-22.04-x86_64"]- );-}--#[test]-fn a_linux_host_below_every_published_floor_gets_nothing() {- assert!(candidates_for("linux", "x86_64", Some((2, 31))).is_empty());-}--#[test]-fn a_non_glibc_linux_host_gets_nothing() {- // musl. No published artifact targets it; guessing produces a dlopen- // failure at first use rather than a clear answer now.- assert!(candidates_for("linux", "x86_64", None).is_empty());-}--#[test]-fn macos_prefers_the_newer_build_and_falls_back() {- assert_eq!(- candidates_for("macos", "aarch64", None),- vec!["macos-26-arm64", "macos-15-arm64"]- );- assert_eq!(- candidates_for("macos", "x86_64", None),- vec!["macos-26-x86_64", "macos-15-x86_64"]- );-}--#[test]-fn windows_arm64_has_only_the_windows_11_build() {- assert_eq!(- candidates_for("windows", "aarch64", None),- vec!["windows-11-arm64"]- );- assert_eq!(- candidates_for("windows", "x86_64", None),- vec!["windows-2025-x86_64", "windows-2022-x86_64"]- );-}--#[test]-fn an_unsupported_os_or_architecture_gets_nothing() {- assert!(candidates_for("freebsd", "x86_64", Some((2, 39))).is_empty());- assert!(candidates_for("linux", "riscv64", Some((2, 39))).is_empty());- assert!(candidates_for("macos", "powerpc", None).is_empty());-}--#[test]-fn glibc_versions_parse_with_and_without_a_patch_level() {- assert_eq!(parse_glibc_version("2.39"), Some((2, 39)));- assert_eq!(parse_glibc_version("2.39.1"), Some((2, 39)));- assert_eq!(parse_glibc_version(" 2.35 "), Some((2, 35)));- // Ubuntu ships versions like "2.39-0ubuntu8.3".- assert_eq!(parse_glibc_version("2.39-0ubuntu8.3"), Some((2, 39)));- assert_eq!(parse_glibc_version("garbage"), None);- assert_eq!(parse_glibc_version("2"), None);-}--#[test]-fn the_running_host_resolves_without_panicking() {- // Whatever this machine is, asking must be safe and must agree with the- // pure table for its own os/arch.- let live = host_candidates();- let expected = candidates_for(- std::env::consts::OS,- std::env::consts::ARCH,- super::glibc_version(),- );- assert_eq!(live, expected);-}