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: honor library host boundaries
Steven Enamakeld3cd4019435f
diff --git a/gitbooks/developing/architecture/agent-harness.md b/gitbooks/developing/architecture/agent-harness.mdindex 86842db435..e5ed412826 100644--- a/gitbooks/developing/architecture/agent-harness.md+++ b/gitbooks/developing/architecture/agent-harness.md@@ -7,6 +7,26 @@ icon: layer-group# Agent Harness+## Embedding OpenHuman as a library++`openhuman_core::Harness` builds one in-process core for a caller that supplies+its workspace, provider endpoint and credential, skills, MCP servers, and tool+policy. Such a harness identifies as `HostKind::Library`: inference does not+depend on OpenHuman app login, including inference-readiness checks for workflow+agent nodes. Backend features such as integrations and managed services still+need whatever identity their endpoint requires.++Build one harness and issue concurrent `run` or `turn(...).send()` calls on it;+do not build one core per agent. Each call owns a distinct session unless a+prior session id is supplied. The conversation store coordinates metadata per+workspace and message writes per thread, so independent agents do not serialize+on one process-wide store mutex.++`Workspace::Inherit` together with `Provider::inherit()` is deliberately not+library-routed inference. It borrows the installed OpenHuman configuration and+therefore keeps the installed application's session checks. Supply an explicit+provider when embedding without app login.+> **Status (issue #4249, tinyagents migration):** the agent turn no longer runs> on the in-tree `run_turn_engine` loop. **All three entry points (`Agent::turn`,> the channel/CLI bus path, and `run_subagent`) now drive every turn through thediff --git a/src/embed/harness/builder.rs b/src/embed/harness/builder.rsindex b6f50a2c41..d6dc7f4714 100644--- a/src/embed/harness/builder.rs+++ b/src/embed/harness/builder.rs@@ -239,6 +239,7 @@ impl HarnessBuilder {async fn build_inner(self) -> Result<Harness, HarnessError> {let inherit = self.workspace.is_operator_owned();+ let host_kind = effective_host_kind(self.host_kind, inherit, &self.provider);if self.skills_dir.is_some() && inherit {return Err(HarnessError::Invalid(@@ -342,11 +343,11 @@ impl HarnessBuilder {log::debug!("[embed][harness] building host_kind={:?} inherit_workspace={inherit} \routed_provider={} domains={domains:?} tool_groups={tool_groups:?}",- self.host_kind,+ host_kind,self.provider.is_routed(),);- let mut builder = CoreBuilder::new(self.host_kind)+ let mut builder = CoreBuilder::new(host_kind).domains(domains).tool_groups(tool_groups).services(services)@@ -374,6 +375,22 @@ impl HarnessBuilder {}}+/// Preserve the installed application's authentication policy when the+/// harness borrows both its workspace and provider. `Library` means the host+/// supplied inference; it must not become a blanket way to bypass the session+/// gate around an operator-installed provider.+fn effective_host_kind(+ requested: HostKind,+ inherit_workspace: bool,+ provider: &Provider,+) -> HostKind {+ if requested == HostKind::Library && inherit_workspace && !provider.is_routed() {+ HostKind::Cli+ } else {+ requested+ }+}+/// Apply a [`Provider`]'s model to the config.////// Only the model: the *route* is a per-turn parameter, never a config write,diff --git a/src/embed/harness/builder_tests.rs b/src/embed/harness/builder_tests.rsindex 39a6d33b19..e926972842 100644--- a/src/embed/harness/builder_tests.rs+++ b/src/embed/harness/builder_tests.rs@@ -25,6 +25,26 @@ fn a_harness_identifies_as_a_library_host_by_default() {assert_eq!(HarnessBuilder::new().host_kind, HostKind::Library);}+#[test]+fn inherited_workspace_and_provider_keep_installed_session_policy() {+ assert_eq!(+ effective_host_kind(HostKind::Library, true, &Provider::inherit()),+ HostKind::Cli+ );+ assert_eq!(+ effective_host_kind(+ HostKind::Library,+ true,+ &Provider::openai_compatible("https://api.example/v1", "sk")+ ),+ HostKind::Library+ );+ assert_eq!(+ effective_host_kind(HostKind::Library, false, &Provider::inherit()),+ HostKind::Library+ );+}+#[test]fn default_services_start_no_background_writers() {// cron, heartbeat and the memory queue each write to the workspace on theirdiff --git a/src/openhuman/flows/ops_part_03.rs b/src/openhuman/flows/ops_part_03.rsindex 4082408298..634a50acaa 100644--- a/src/openhuman/flows/ops_part_03.rs+++ b/src/openhuman/flows/ops_part_03.rs@@ -192,7 +192,9 @@ async fn evaluate_inference_readiness(// Layer 1: signed-out is the cheapest, most decisive check. Session-wide// — checked once for the whole graph, not per node/role.- if crate::openhuman::cron::scheduler_gate::is_signed_out() {+ if crate::openhuman::inference::provider::factory::current_host_requires_session()+ && crate::openhuman::cron::scheduler_gate::is_signed_out()+ {tracing::debug!(target: "flows",node = %first_node.id,diff --git a/src/openhuman/inference/provider/factory_part_03.rs b/src/openhuman/inference/provider/factory_part_03.rsindex 9df135e6e6..3f1cc786af 100644--- a/src/openhuman/inference/provider/factory_part_03.rs+++ b/src/openhuman/inference/provider/factory_part_03.rs@@ -525,9 +525,7 @@ pub(crate) fn verify_session_active(config: &Config) -> anyhow::Result<()> {// would mix desktop product policy into the library contract. The ambient// context is installed by the dispatch chokepoint; all other host kinds// retain the registration gate below.- if crate::core::runtime::context::CoreContext::current()- .is_some_and(|ctx| ctx.host_kind() == crate::core::types::HostKind::Library)- {+ if !current_host_requires_session() {return Ok(());}@@ -561,6 +559,19 @@ pub(crate) fn verify_session_active(config: &Config) -> anyhow::Result<()> {Ok(())}+/// Whether inference in the ambient host participates in OpenHuman app login.+/// Library hosts receive their provider configuration from the embedding+/// process; every other host retains the product session policy.+pub(crate) fn current_host_requires_session() -> bool {+ crate::core::runtime::context::CoreContext::current()+ .map(|ctx| host_requires_session(ctx.host_kind()))+ .unwrap_or(true)+}++fn host_requires_session(host_kind: crate::core::types::HostKind) -> bool {+ host_kind != crate::core::types::HostKind::Library+}+fn resolve_primary_cloud_provider_string(config: &Config) -> String {let primary = config.primary_clouddiff --git a/src/openhuman/inference/provider/factory_tests.rs b/src/openhuman/inference/provider/factory_tests.rsindex e4bd27891f..696f8cfe84 100644--- a/src/openhuman/inference/provider/factory_tests.rs+++ b/src/openhuman/inference/provider/factory_tests.rs@@ -171,6 +171,16 @@ fn routed_config(endpoint: &str, api_key: &str, model: &str) -> Config {config}+#[test]+fn only_library_hosts_are_exempt_from_app_login() {+ use crate::core::types::HostKind;++ assert!(!host_requires_session(HostKind::Library));+ for host in [HostKind::TauriShell, HostKind::Cli, HostKind::Docker] {+ assert!(host_requires_session(host));+ }+}+#[path = "factory_tests_part_01_tests.rs"]mod part_01_tests;#[path = "factory_tests_part_02_tests.rs"]diff --git a/src/openhuman/memory/conversations/store/store_locks.rs b/src/openhuman/memory/conversations/store/store_locks.rsindex 2401abb449..9222107d68 100644--- a/src/openhuman/memory/conversations/store/store_locks.rs+++ b/src/openhuman/memory/conversations/store/store_locks.rs@@ -38,11 +38,40 @@ static ROOTS: LazyLock<Mutex<HashMap<PathBuf, Weak<StoreLocks>>>> =LazyLock::new(|| Mutex::new(HashMap::new()));pub(super) fn for_root(root: &Path) -> Arc<StoreLocks> {+ let root = stable_root_key(root);let mut roots = ROOTS.lock();- if let Some(existing) = roots.get(root).and_then(Weak::upgrade) {+ if let Some(existing) = roots.get(&root).and_then(Weak::upgrade) {return existing;}let locks = Arc::new(StoreLocks::default());- roots.insert(root.to_path_buf(), Arc::downgrade(&locks));+ roots.insert(root, Arc::downgrade(&locks));locks}++/// Resolve aliases even before the conversation directory itself exists.+/// Canonicalizing the nearest existing ancestor handles symlinks and `..`;+/// the missing suffix is then appended without touching the filesystem.+fn stable_root_key(root: &Path) -> PathBuf {+ if let Ok(canonical) = root.canonicalize() {+ return canonical;+ }++ let mut suffix = Vec::new();+ let mut ancestor = root;+ loop {+ if let Ok(canonical) = ancestor.canonicalize() {+ return suffix+ .iter()+ .rev()+ .fold(canonical, |path, component| path.join(component));+ }+ let Some(name) = ancestor.file_name() else {+ return root.to_path_buf();+ };+ suffix.push(name.to_os_string());+ let Some(parent) = ancestor.parent() else {+ return root.to_path_buf();+ };+ ancestor = parent;+ }+}diff --git a/src/openhuman/memory/conversations/store/store_tests_late.rs b/src/openhuman/memory/conversations/store/store_tests_late.rsindex 6566d6e40c..a86f706f61 100644--- a/src/openhuman/memory/conversations/store/store_tests_late.rs+++ b/src/openhuman/memory/conversations/store/store_tests_late.rs@@ -192,6 +192,39 @@ fn one_hundred_agent_threads_use_independent_message_locks() {assert_eq!(message_locks.len(), 100);}+#[test]+fn equivalent_workspace_paths_share_the_same_lock_registry_entry() {+ let temp = TempDir::new().unwrap();+ let child = temp.path().join("child");+ std::fs::create_dir(&child).unwrap();++ let direct = ConversationStore::new(temp.path().to_path_buf());+ let dotted = ConversationStore::new(child.join(".."));++ assert_eq!(+ direct.lock_identity_for_test(),+ dotted.lock_identity_for_test()+ );+}++#[cfg(unix)]+#[test]+fn symlinked_workspace_paths_share_the_same_lock_registry_entry() {+ let temp = TempDir::new().unwrap();+ let workspace = temp.path().join("workspace");+ let alias = temp.path().join("alias");+ std::fs::create_dir(&workspace).unwrap();+ std::os::unix::fs::symlink(&workspace, &alias).unwrap();++ let direct = ConversationStore::new(workspace);+ let linked = ConversationStore::new(alias);++ assert_eq!(+ direct.lock_identity_for_test(),+ linked.lock_identity_for_test()+ );+}+// ── concurrency: search cold rebuild must not block concurrent append ────────/// Regression test for issue #2849.