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
perf(core): avoid cloning embedder config on read paths
Steven Enamakeld5d77adffdb4
diff --git a/crates/openhuman-core/src/config/schema/load/dirs.rs b/crates/openhuman-core/src/config/schema/load/dirs.rsindex b0a8e57c33..4c6ff0cd3a 100644--- a/crates/openhuman-core/src/config/schema/load/dirs.rs+++ b/crates/openhuman-core/src/config/schema/load/dirs.rs@@ -332,9 +332,13 @@ pub async fn active_workspace_snapshot() -> Result<(PathBuf, u64)> {// mismatch there is not a wrong banner, it is *no* banner, permanently,// with only a `debug!` line to say so. See AGENTS.md, "CoreBuilder::config// alone configures boot and nothing else".- if let Some(config) = crate::core::runtime::context::CoreContext::current_embedder_config() {- let revision = super::active_workspace::publish_active_workspace(&config.workspace_dir);- return Ok((config.workspace_dir, revision));+ if let Some(workspace_dir) =+ crate::core::runtime::context::CoreContext::with_current_embedder_config(|config| {+ config.workspace_dir.clone()+ })+ {+ let revision = super::active_workspace::publish_active_workspace(&workspace_dir);+ return Ok((workspace_dir, revision));}let (default_openhuman_dir, default_workspace_dir) = default_config_and_workspace_dirs()?;let (_, workspace_dir, source) =diff --git a/crates/openhuman-core/src/core/runtime/context.rs b/crates/openhuman-core/src/core/runtime/context.rsindex 3759a48ed4..14e05bce74 100644--- a/crates/openhuman-core/src/core/runtime/context.rs+++ b/crates/openhuman-core/src/core/runtime/context.rs@@ -467,6 +467,15 @@ impl CoreContext {Self::current().and_then(|ctx| ctx.embedder_config.clone())}+ /// Read the embedder-supplied config for the current dispatch without+ /// cloning it. Prefer this over [`Self::current_embedder_config`] when only+ /// a field or a predicate is needed: a `Config` clone is a large copy.+ pub fn with_current_embedder_config<R>(+ f: impl FnOnce(&crate::config::Config) -> R,+ ) -> Option<R> {+ Self::current().and_then(|ctx| ctx.embedder_config.as_ref().map(f))+ }+/// Rebind the process default context to the current active user's/// workspace. Desktop login, logout, and pending-session revalidation can/// switch the active workspace after boot without rebuilding the core.diff --git a/crates/openhuman-core/src/security/credentials/ops/gated_services.rs b/crates/openhuman-core/src/security/credentials/ops/gated_services.rsindex 7411393ba7..6ed6fa0182 100644--- a/crates/openhuman-core/src/security/credentials/ops/gated_services.rs+++ b/crates/openhuman-core/src/security/credentials/ops/gated_services.rs@@ -12,7 +12,7 @@ use crate::config::Config;/// that config's path and never touch the operator's global/// `~/.openhuman/active_user.toml` / `users/` tree.pub(super) fn is_embedder_host() -> bool {- crate::core::runtime::context::CoreContext::current_embedder_config().is_some()+ crate::core::runtime::context::CoreContext::with_current_embedder_config(|_| ()).is_some()}/// Populate the process cache away from the next chat turn after startup or adiff --git a/crates/openhuman-core/src/security/credentials/session_support.rs b/crates/openhuman-core/src/security/credentials/session_support.rsindex 9f91c456ad..27d20d54e2 100644--- a/crates/openhuman-core/src/security/credentials/session_support.rs+++ b/crates/openhuman-core/src/security/credentials/session_support.rs@@ -546,8 +546,8 @@ pub fn session_token_from_profile(profile: Option<&AuthProfile>) -> Option<Strin/// when there is one; a host that discovers its config from disk has no API/// key by construction (it is only ever installed by a library runtime).pub fn ambient_config_has_api_key() -> bool {- crate::core::runtime::CoreContext::current_embedder_config()- .is_some_and(|config| super::api_key::has_api_key(&config))+ crate::core::runtime::CoreContext::with_current_embedder_config(super::api_key::has_api_key)+ .unwrap_or(false)}#[cfg(test)]