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
fix(sandbox): load config before resolving docker backend status
Steven Enamakel1758ac9a2b88
diff --git a/crates/openhuman-core/src/sandbox/docker_exec_tests.rs b/crates/openhuman-core/src/sandbox/docker_exec_tests.rsindex 82c707d52d..8d6c471bb8 100644--- a/crates/openhuman-core/src/sandbox/docker_exec_tests.rs+++ b/crates/openhuman-core/src/sandbox/docker_exec_tests.rs@@ -1,6 +1,4 @@-//! Docker sandbox request mapping and Docker CLI health/cleanup probes.-//! Execution mapping is tested without a daemon; TinyBox owns command-line-//! construction, execution, and output limits.+//! Docker sandbox request mapping. TinyBox owns daemon status and cleanup.#![cfg(unix)]use super::*;@@ -8,60 +6,10 @@ use super::*;use crate::sandbox::types::DockerOverrides;#[cfg(feature = "modules")]use std::ffi::OsString;-use std::os::unix::fs::PermissionsExt;use std::path::{Path, PathBuf};#[cfg(feature = "modules")]use std::time::Duration;-/// Install a fake `docker` that records argv (NUL separated) to `argv.out` and-/// then runs `body`. Returns (bin dir, argv file).-fn fake_docker(dir: &Path, body: &str) -> (PathBuf, PathBuf) {- let bin = dir.join("bin");- std::fs::create_dir_all(&bin).unwrap();- let out = dir.join("argv.out");- let script = format!(- "#!/bin/sh\n: > '{out}'\nfor a in \"$@\"; do printf '%s\\0' \"$a\" >> '{out}'; done\n{body}\n",- out = out.display()- );- let path = bin.join("docker");- std::fs::write(&path, script).unwrap();- std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)).unwrap();- (bin, out)-}--fn recorded(out: &Path) -> Vec<String> {- let raw = std::fs::read(out).unwrap();- raw.split(|b| *b == 0)- .filter(|s| !s.is_empty())- .map(|s| String::from_utf8_lossy(s).into_owned())- .collect()-}--/// Run `f` with `bin` first on `PATH`, serialised against other env tests.-fn with_fake_path<T>(bin: &Path, f: impl FnOnce() -> T) -> T {- let _guard = crate::config::TEST_ENV_LOCK.blocking_lock();- let prev = std::env::var_os("PATH");- let mut paths = vec![bin.to_path_buf()];- if let Some(p) = &prev {- paths.extend(std::env::split_paths(p));- }- std::env::set_var("PATH", std::env::join_paths(paths).unwrap());- let result = f();- match prev {- Some(p) => std::env::set_var("PATH", p),- None => std::env::remove_var("PATH"),- }- result-}--fn block_on<T>(fut: impl std::future::Future<Output = T>) -> T {- tokio::runtime::Builder::new_current_thread()- .enable_all()- .build()- .unwrap()- .block_on(fut)-}-#[cfg(feature = "modules")]fn policy(workspace: &Path) -> SandboxPolicy {SandboxPolicy {@@ -86,10 +34,6 @@ fn request(command: &str, timeout: Duration) -> SandboxExecRequest {}}-fn s(v: &[&str]) -> Vec<String> {- v.iter().map(|x| (*x).to_string()).collect()-}-#[cfg(feature = "modules")]#[test]fn module_request_preserves_policy_and_only_forwards_allowed_environment() {@@ -184,29 +128,3 @@ fn module_request_rejects_non_utf8_host_paths_without_lossy_remapping() {.expect_err("the module contract cannot represent an arbitrary OS path");assert!(error.to_string().contains("workspace path is not UTF-8"));}--#[test]-fn availability_probe_argv_and_status() {- let tmp = tempfile::tempdir().unwrap();- let (bin, out) = fake_docker(tmp.path(), "exit 0");- assert!(with_fake_path(&bin, || block_on(is_docker_available())));- assert_eq!(- recorded(&out),- s(&["info", "--format", "{{.ServerVersion}}"])- );-- let tmp = tempfile::tempdir().unwrap();- let (bin, _) = fake_docker(tmp.path(), "exit 1");- assert!(!with_fake_path(&bin, || block_on(is_docker_available())));-}--#[test]-fn orphan_cleanup_lists_by_label_then_kills() {- let tmp = tempfile::tempdir().unwrap();- // `ps` prints two ids; `kill` is recorded last (argv.out is rewritten per call).- let body = "if [ \"$1\" = ps ]; then echo abc; echo def; fi";- let (bin, out) = fake_docker(tmp.path(), body);- let n = with_fake_path(&bin, || block_on(cleanup_orphaned_containers())).unwrap();- assert_eq!(n, 2);- assert_eq!(recorded(&out), s(&["kill", "abc", "def"]));-}diff --git a/crates/openhuman-core/src/sandbox/ops.rs b/crates/openhuman-core/src/sandbox/ops.rsindex 28e486924b..c559b236ba 100644--- a/crates/openhuman-core/src/sandbox/ops.rs+++ b/crates/openhuman-core/src/sandbox/ops.rs@@ -229,12 +229,29 @@ pub(crate) fn local_status_for_backend(backend_name: &str) -> SandboxStatus {}pub async fn create_sandbox_backend(policy: &SandboxPolicy) -> SandboxBackendHandle {+ let config = match crate::config::ops::load_config_with_timeout().await {+ Ok(config) => config,+ Err(_) if policy.backend == SandboxBackendKind::Docker => {+ return docker_error_handle();+ }+ Err(_) => crate::config::Config::default(),+ };+ create_sandbox_backend_with_config(policy, &config)+ .await+ .unwrap_or_else(|_| docker_error_handle())+}++/// Resolve backend status with the caller's loaded configuration.+pub async fn create_sandbox_backend_with_config(+ policy: &SandboxPolicy,+ config: &crate::config::Config,+) -> Result<SandboxBackendHandle, String> {match policy.backend {- SandboxBackendKind::None => SandboxBackendHandle {+ SandboxBackendKind::None => Ok(SandboxBackendHandle {kind: SandboxBackendKind::None,status: SandboxStatus::Ready,backend_id: None,- },+ }),SandboxBackendKind::Local => {let os_backend = cwd_jail::default_backend();let backend_name = os_backend.name();@@ -263,13 +280,21 @@ pub async fn create_sandbox_backend(policy: &SandboxPolicy) -> SandboxBackendHanthe handle reports inactive");}- SandboxBackendHandle {+ Ok(SandboxBackendHandle {kind: SandboxBackendKind::Local,status,backend_id: Some(backend_name.to_string()),- }+ })}- SandboxBackendKind::Docker => docker::docker_backend_handle().await,+ SandboxBackendKind::Docker => docker::docker_backend_handle(config).await,+ }+}++fn docker_error_handle() -> SandboxBackendHandle {+ SandboxBackendHandle {+ kind: SandboxBackendKind::Docker,+ status: SandboxStatus::Error,+ backend_id: None,}}diff --git a/crates/openhuman-core/src/sandbox/schemas.rs b/crates/openhuman-core/src/sandbox/schemas.rsindex 5776fade41..7569211fbd 100644--- a/crates/openhuman-core/src/sandbox/schemas.rs+++ b/crates/openhuman-core/src/sandbox/schemas.rs@@ -203,7 +203,7 @@ fn handle_status(params: Map<String, Value>) -> ControllerFuture {super::ops::apply_requested_backend(&mut policy, &config.sandbox, &config.runtime).map_err(|e| e.to_string())?;}- let handle = super::ops::create_sandbox_backend(&policy).await;+ let handle = super::ops::create_sandbox_backend_with_config(&policy, &config).await?;to_json(Outcome::new(handle, vec![]))})}@@ -262,7 +262,11 @@ fn handle_resolve_policy(params: Map<String, Value>) -> ControllerFuture {fn handle_cleanup_orphans(_params: Map<String, Value>) -> ControllerFuture {Box::pin(async {- match super::docker::cleanup_orphaned_containers().await {+ let config = match crate::config::ops::load_config_with_timeout().await {+ Ok(config) => config,+ Err(error) => return Err(error),+ };+ match super::docker::cleanup_orphaned_containers(&config).await {Ok(count) => to_json(Outcome::new(serde_json::json!({ "cleaned": count }),vec![],