Skip to content

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

refactor(config): capture runtime bindings in dedicated struct

Steven Enamakel808bae234f9c
diff --git a/crates/openhuman-core/src/config/schema/load/context_overlay.rs b/crates/openhuman-core/src/config/schema/load/context_overlay.rs
index df9260e2c9..11804edc4a 100644
--- a/crates/openhuman-core/src/config/schema/load/context_overlay.rs
+++ b/crates/openhuman-core/src/config/schema/load/context_overlay.rs
@@ -1,14 +1,41 @@
//! Per-context config overrides reapplied after a fresh persisted reload.
+use crate::config::schema::{
+ AppliedInferenceOverride, ComposioHostCredential, EphemeralRoute, ResolvedEndpoints,
+ SearchHostCredential,
+};
use crate::config::Config;
+use crate::profiles::provider_settings::ProfileProviderSettings;
use serde_json::Value;
+use std::collections::{BTreeMap, BTreeSet};
+use std::path::PathBuf;
use std::sync::Arc;
#[derive(Clone)]
pub(crate) struct ConfigContextOverlay {
base: Value,
changes: Vec<Change>,
- runtime: Box<Config>,
+ runtime: RuntimeBindings,
+}
+
+#[derive(Clone)]
+struct RuntimeBindings {
+ profile_providers: Option<Arc<ProfileProviderSettings>>,
+ workspace_dir: PathBuf,
+ action_dir: PathBuf,
+ config_path: PathBuf,
+ cli_inference_snapshot: Option<AppliedInferenceOverride>,
+ recovered_from_corruption: bool,
+ ephemeral_route: Option<EphemeralRoute>,
+ resolved_endpoints: ResolvedEndpoints,
+ legacy_memory_sources: Vec<Value>,
+ memory_legacy_backend: Option<crate::config::schema::memory::LegacyBackend>,
+ composio_host_credential: Option<ComposioHostCredential>,
+ search_engine: Option<String>,
+ search_enabled_providers: Option<BTreeSet<String>>,
+ search_parallel_route: Option<String>,
+ search_gemini_route: Option<String>,
+ search_host_credentials: BTreeMap<String, SearchHostCredential>,
}
#[derive(Clone)]
@@ -42,13 +69,11 @@ impl ConfigContextOverlay {
let target = serde_json::to_value(child)?;
diff_values(&parent_value, &target, &mut Vec::new(), &mut changes);
- let mut runtime = child.clone();
- runtime.context_overlay = std::sync::Mutex::new(None);
- runtime.context_snapshot = None;
+ let runtime = RuntimeBindings::capture(child);
Ok(Arc::new(Self {
base,
changes,
- runtime: Box::new(runtime),
+ runtime,
}))
}
@@ -60,7 +85,7 @@ impl ConfigContextOverlay {
}
let mut result: Config = serde_json::from_value(value)?;
copy_runtime_bindings(fresh, &mut result);
- copy_runtime_bindings(&self.runtime, &mut result);
+ self.runtime.apply(&mut result);
result.document_snapshot =
std::sync::Mutex::new(fresh.document_snapshot.lock().unwrap().clone());
result.context_snapshot = fresh.context_snapshot.clone();
@@ -73,6 +98,48 @@ impl ConfigContextOverlay {
}
}
+impl RuntimeBindings {
+ fn capture(source: &Config) -> Self {
+ Self {
+ profile_providers: source.profile_providers.clone(),
+ workspace_dir: source.workspace_dir.clone(),
+ action_dir: source.action_dir.clone(),
+ config_path: source.config_path.clone(),
+ cli_inference_snapshot: source.cli_inference_snapshot.clone(),
+ recovered_from_corruption: source.recovered_from_corruption,
+ ephemeral_route: source.ephemeral_route.clone(),
+ resolved_endpoints: source.resolved_endpoints.clone(),
+ legacy_memory_sources: source.legacy_memory_sources.clone(),
+ memory_legacy_backend: source.memory.legacy_backend.clone(),
+ composio_host_credential: source.composio.host_credential.clone(),
+ search_engine: source.search.engine.clone(),
+ search_enabled_providers: source.search.enabled_providers.clone(),
+ search_parallel_route: source.search.parallel_route.clone(),
+ search_gemini_route: source.search.gemini_route.clone(),
+ search_host_credentials: source.search.host_credentials.clone(),
+ }
+ }
+
+ fn apply(&self, target: &mut Config) {
+ target.profile_providers = self.profile_providers.clone();
+ target.workspace_dir = self.workspace_dir.clone();
+ target.action_dir = self.action_dir.clone();
+ target.config_path = self.config_path.clone();
+ target.cli_inference_snapshot = self.cli_inference_snapshot.clone();
+ target.recovered_from_corruption = self.recovered_from_corruption;
+ target.ephemeral_route = self.ephemeral_route.clone();
+ target.resolved_endpoints = self.resolved_endpoints.clone();
+ target.legacy_memory_sources = self.legacy_memory_sources.clone();
+ target.memory.legacy_backend = self.memory_legacy_backend.clone();
+ target.composio.host_credential = self.composio_host_credential.clone();
+ target.search.engine = self.search_engine.clone();
+ target.search.enabled_providers = self.search_enabled_providers.clone();
+ target.search.parallel_route = self.search_parallel_route.clone();
+ target.search.gemini_route = self.search_gemini_route.clone();
+ target.search.host_credentials = self.search_host_credentials.clone();
+ }
+}
+
fn diff_values(base: &Value, target: &Value, path: &mut Vec<String>, changes: &mut Vec<Change>) {
match (base, target) {
(Value::Object(base), Value::Object(target)) => {
@@ -136,20 +203,5 @@ fn apply_change(current: &mut Value, path: &[String], value: Option<Value>) {
}
pub(crate) fn copy_runtime_bindings(source: &Config, target: &mut Config) {
- target.profile_providers = source.profile_providers.clone();
- target.workspace_dir = source.workspace_dir.clone();
- target.action_dir = source.action_dir.clone();
- target.config_path = source.config_path.clone();
- target.cli_inference_snapshot = source.cli_inference_snapshot.clone();
- target.recovered_from_corruption = source.recovered_from_corruption;
- target.ephemeral_route = source.ephemeral_route.clone();
- target.resolved_endpoints = source.resolved_endpoints.clone();
- target.legacy_memory_sources = source.legacy_memory_sources.clone();
- target.memory.legacy_backend = source.memory.legacy_backend.clone();
- target.composio.host_credential = source.composio.host_credential.clone();
- target.search.engine = source.search.engine.clone();
- target.search.enabled_providers = source.search.enabled_providers.clone();
- target.search.parallel_route = source.search.parallel_route.clone();
- target.search.gemini_route = source.search.gemini_route.clone();
- target.search.host_credentials = source.search.host_credentials.clone();
+ RuntimeBindings::capture(source).apply(target);
}
diff --git a/crates/openhuman-core/src/config/schema/mod.rs b/crates/openhuman-core/src/config/schema/mod.rs
index 38e728022e..17a76ecea4 100644
--- a/crates/openhuman-core/src/config/schema/mod.rs
+++ b/crates/openhuman-core/src/config/schema/mod.rs
@@ -3,9 +3,9 @@
//! Split into submodules; this module re-exports the main `Config` and all public types.
pub mod cloud_providers;
-pub use cloud_providers::{AuthStyle, CloudProviderCreds, generate_provider_id, is_slug_reserved};
+pub use cloud_providers::{generate_provider_id, is_slug_reserved, AuthStyle, CloudProviderCreds};
pub mod ephemeral_route;
-pub use ephemeral_route::{EPHEMERAL_ROUTE_SLUG, EphemeralRoute};
+pub use ephemeral_route::{EphemeralRoute, EPHEMERAL_ROUTE_SLUG};
pub mod resolved_endpoints;
pub use resolved_endpoints::ResolvedEndpoints;
mod agent;
@@ -33,17 +33,17 @@ pub use hosting::HostingConfig;
pub mod storage;
pub use storage::StorageConfig;
pub mod profile_layout;
-pub use profile_layout::{ProfileLayout, users_dir};
+pub use profile_layout::{users_dir, ProfileLayout};
mod identity_cost;
pub(crate) mod load;
pub(crate) use load::config_from_toml_str;
pub(crate) use load::source::storage_schema::storage_schema as config_storage_schema;
pub use load::{
- PRE_LOGIN_USER_ID, action_dir_env_override, active_user_marker_path, active_workspace_dir,
+ action_dir_env_override, active_user_marker_path, active_workspace_dir,
active_workspace_dir_cached, active_workspace_snapshot, clear_active_user, default_action_dir,
default_files_dir, default_projects_dir, default_root_openhuman_dir, pre_login_user_dir,
read_active_user_id, resolve_action_dir, resolve_files_dir, user_openhuman_dir,
- write_active_user_id,
+ write_active_user_id, PRE_LOGIN_USER_ID,
};
// Crate-internal: the invalidation half of the cached active workspace. The
// marker writers in `load_user_state` call it from outside `load`; the
@@ -62,7 +62,7 @@ pub mod claude_agent_sdk;
pub use claude_agent_sdk::ClaudeAgentSdkConfig;
mod local_ai;
mod memes;
-mod memory;
+pub(crate) mod memory;
mod modules;
mod observability;
mod privacy;
@@ -100,18 +100,19 @@ pub use identity_cost::{
pub use local_ai::{LocalAiConfig, LocalAiUsage};
pub use memes::MemesConfig;
pub use memory::{
- MEMORY_CORTEXDB_KEY_NAME, MemoryAgentConfig, MemoryConfig, MemoryConversationsConfig,
+ migrate_legacy_source, MemoryAgentConfig, MemoryConfig, MemoryConversationsConfig,
MemoryEngineSettings, MemoryLayoutMode, MemoryRecallConfig, MemorySourceConfig,
- MemorySourceKind, migrate_legacy_source,
+ MemorySourceKind, MEMORY_CORTEXDB_KEY_NAME,
};
pub use modules::{
- MODULE_SOURCE_ENV, ModuleOverride, ModuleSourceMode, ModulesConfig, module_source_env_for,
+ module_source_env_for, ModuleOverride, ModuleSourceMode, ModulesConfig, MODULE_SOURCE_ENV,
};
pub use observability::{AgentTracingBackend, AgentTracingConfig, ObservabilityConfig};
pub use privacy::{PrivacyConfig, PrivacyMode};
pub use proxy::{
- ProxyConfig, ProxyScope, apply_runtime_proxy_to_builder, build_runtime_proxy_client,
+ apply_runtime_proxy_to_builder, build_runtime_proxy_client,
build_runtime_proxy_client_with_timeouts, runtime_proxy_config, set_runtime_proxy_config,
+ ProxyConfig, ProxyScope,
};
pub use routes::{EmbeddingRouteConfig, ModelRouteConfig};
pub use runtime::{
@@ -122,17 +123,17 @@ pub use scheduler_gate::{PauseReason, Policy, SchedulerGateConfig, SchedulerGate
pub use task_sources::TaskSourcesConfig;
pub use tokenjuice::TokenjuiceConfig;
pub use tools::{
- BrowserComputerUseConfig, BrowserConfig, COMPOSIO_MODE_BACKEND, COMPOSIO_MODE_DIRECT,
- COMPOSIO_MODE_DISABLED, ComposioConfig, ComposioDirectBaseUrls, ComposioHostCredential,
- CurlConfig, GitbooksConfig, HttpHeader, HttpRequestConfig, IntegrationToggle,
- IntegrationsConfig, LegacySearchInputs, MANAGED_SEARCH_PROVIDERS, McpAuthConfig,
- McpClientConfig, McpClientIdentityConfig, McpServerConfig, McpToolExposure, MultimodalConfig,
- MultimodalFileConfig, PresentationMode, ProviderRoute, SEARCH_ENGINE_BRAVE,
- SEARCH_ENGINE_DISABLED, SEARCH_ENGINE_EXA, SEARCH_ENGINE_MANAGED, SEARCH_ENGINE_PARALLEL,
- SEARCH_ENGINE_QUERIT, SEARCH_ENGINE_TAVILY, SEARCH_PROVIDERS, SEARCH_ROLE_ANSWER,
- SEARCH_ROLE_CONTENTS, SEARCH_ROLE_SEARCH, SEARCH_ROLES, SearchConfig, SearchEngineCredentials,
+ BrowserComputerUseConfig, BrowserConfig, ComposioConfig, ComposioDirectBaseUrls,
+ ComposioHostCredential, CurlConfig, GitbooksConfig, HttpHeader, HttpRequestConfig,
+ IntegrationToggle, IntegrationsConfig, LegacySearchInputs, McpAuthConfig, McpClientConfig,
+ McpClientIdentityConfig, McpServerConfig, McpToolExposure, MultimodalConfig,
+ MultimodalFileConfig, PresentationMode, ProviderRoute, SearchConfig, SearchEngineCredentials,
SearchHostCredential, SearchProviderSettings, SearxngConfig, SecretsConfig, SeltzConfig,
- UnknownKeyedSearchProvider, WebSearchConfig,
+ UnknownKeyedSearchProvider, WebSearchConfig, COMPOSIO_MODE_BACKEND, COMPOSIO_MODE_DIRECT,
+ COMPOSIO_MODE_DISABLED, MANAGED_SEARCH_PROVIDERS, SEARCH_ENGINE_BRAVE, SEARCH_ENGINE_DISABLED,
+ SEARCH_ENGINE_EXA, SEARCH_ENGINE_MANAGED, SEARCH_ENGINE_PARALLEL, SEARCH_ENGINE_QUERIT,
+ SEARCH_ENGINE_TAVILY, SEARCH_PROVIDERS, SEARCH_ROLES, SEARCH_ROLE_ANSWER, SEARCH_ROLE_CONTENTS,
+ SEARCH_ROLE_SEARCH,
};
pub use update::{UpdateConfig, UpdateRestartStrategy};
pub use web_chat_config::WebChatConfig;
@@ -142,8 +143,8 @@ pub mod voice_live;
pub mod voice_providers;
pub use voice_live::LiveVoiceConfig;
pub use voice_providers::{
- BUILTIN_VOICE_PROVIDERS, BuiltinVoiceProvider, VoiceCapability, VoiceProviderCreds,
- generate_voice_provider_id, is_voice_slug_reserved,
+ generate_voice_provider_id, is_voice_slug_reserved, BuiltinVoiceProvider, VoiceCapability,
+ VoiceProviderCreds, BUILTIN_VOICE_PROVIDERS,
};
mod types;
pub(crate) use types::ConfigDocumentSnapshot;