Skip to content

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

feat(modules): add fallback resolution for bundled release directories

Steven Enamakel9cb296593c3d
diff --git a/crates/openhuman-core/src/modules/ops.rs b/crates/openhuman-core/src/modules/ops.rs
index 89bd7da343..4b41c61396 100644
--- a/crates/openhuman-core/src/modules/ops.rs
+++ b/crates/openhuman-core/src/modules/ops.rs
@@ -42,8 +42,16 @@ use tinybus::module::platform::host_candidates;
use tinybus::module::resolution::{self, Claim, Resolution, ResolutionState, Waited};
use tinybus::module::{load_first_admitted, prune_stale_versions, ReleaseAsset, ReleasePlan};
+/// Environment variable naming a directory of bundled release archives, for
+/// headless hosts (the Docker image, the CLI tarball, bench bundles).
+pub const BUNDLED_MODULES_ENV: &str = "OPENHUMAN_BUNDLED_MODULES";
+
+/// Directory name searched beside the executable when nothing else is set.
+const BUNDLED_MODULES_DIR: &str = "bundled-modules";
+
/// Installer-owned, read-only release cache. The desktop host sets this before
-/// starting the embedded core; other hosts continue using the user cache.
+/// starting the embedded core; headless hosts name it with
+/// [`BUNDLED_MODULES_ENV`] or ship it beside the binary.
static BUNDLED_RELEASES: OnceLock<PathBuf> = OnceLock::new();
/// Register the directory of release archives shipped with the desktop app.
@@ -52,6 +60,35 @@ pub fn set_bundled_releases_dir(path: PathBuf) -> Result<(), PathBuf> {
BUNDLED_RELEASES.set(path)
}
+/// The bundled release directory: the one the host registered, else
+/// [`BUNDLED_MODULES_ENV`], else `bundled-modules/` beside the executable.
+/// Only an existing directory counts; nothing here creates one.
+fn bundled_releases_dir() -> Option<PathBuf> {
+ let exe_dir = std::env::current_exe()
+ .ok()
+ .and_then(|exe| exe.parent().map(Path::to_path_buf));
+ resolve_bundled_dir(
+ BUNDLED_RELEASES.get().cloned(),
+ std::env::var_os(BUNDLED_MODULES_ENV).map(PathBuf::from),
+ exe_dir,
+ )
+}
+
+fn resolve_bundled_dir(
+ registered: Option<PathBuf>,
+ from_env: Option<PathBuf>,
+ exe_dir: Option<PathBuf>,
+) -> Option<PathBuf> {
+ let found = registered
+ .or(from_env)
+ .or_else(|| exe_dir.map(|dir| dir.join(BUNDLED_MODULES_DIR)))
+ .filter(|dir| dir.is_dir());
+ if let Some(dir) = &found {
+ log::debug!("[modules] bundled release directory: {}", dir.display());
+ }
+ found
+}
+
/// Why a bounded [`ensure_loaded_within`] did not end with the module serving.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum LoadError {
@@ -239,6 +276,7 @@ async fn resolve(config: &Config, record: &'static ModuleRecord) -> Result<(), S
let allow_download = config.modules.allow_download;
let module_config = module_config(config, record.id);
let cache_root = root.clone();
+ let bundled = bundled_releases_dir();
let outcome = blocking(move || {
load_cached(
runtime,
@@ -246,7 +284,7 @@ async fn resolve(config: &Config, record: &'static ModuleRecord) -> Result<(), S
&cache_root,
module_config,
allow_download,
- BUNDLED_RELEASES.get().map(PathBuf::as_path),
+ bundled.as_deref(),
)
})
.await;
diff --git a/crates/openhuman-core/src/modules/ops_tests.rs b/crates/openhuman-core/src/modules/ops_tests.rs
index e4965c9892..44bb7acc3b 100644
--- a/crates/openhuman-core/src/modules/ops_tests.rs
+++ b/crates/openhuman-core/src/modules/ops_tests.rs
@@ -345,3 +345,41 @@ fn load_errors_render_for_callers_that_cannot_wait_again() {
let message = ops::LoadError::StillLoading.into_message();
assert!(message.contains("still loading"), "{message}");
}
+
+#[test]
+fn bundled_dir_prefers_registered_then_env_then_exe_sibling() {
+ let root = tempfile::tempdir().unwrap();
+ let registered = root.path().join("registered");
+ let from_env = root.path().join("env");
+ let exe_dir = root.path().join("bin");
+ std::fs::create_dir_all(&registered).unwrap();
+ std::fs::create_dir_all(&from_env).unwrap();
+ std::fs::create_dir_all(exe_dir.join("bundled-modules")).unwrap();
+
+ assert_eq!(
+ resolve_bundled_dir(
+ Some(registered.clone()),
+ Some(from_env.clone()),
+ Some(exe_dir.clone())
+ ),
+ Some(registered)
+ );
+ assert_eq!(
+ resolve_bundled_dir(None, Some(from_env.clone()), Some(exe_dir.clone())),
+ Some(from_env)
+ );
+ assert_eq!(
+ resolve_bundled_dir(None, None, Some(exe_dir.clone())),
+ Some(exe_dir.join("bundled-modules"))
+ );
+}
+
+#[test]
+fn bundled_dir_ignores_paths_that_do_not_exist() {
+ let root = tempfile::tempdir().unwrap();
+ assert_eq!(
+ resolve_bundled_dir(None, Some(root.path().join("missing")), None),
+ None
+ );
+ assert_eq!(resolve_bundled_dir(None, None, Some(root.path().into())), None);
+}