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
refactor(config): group config runtime bookkeeping into ConfigRuntimeState
Steven Enamakelda54d6a9dab9
diff --git a/crates/openhuman-core/src/config/schema/load/context_overlay.rs b/crates/openhuman-core/src/config/schema/load/context_overlay.rsindex a38fd806d4..3f7f7e0db3 100644--- a/crates/openhuman-core/src/config/schema/load/context_overlay.rs+++ b/crates/openhuman-core/src/config/schema/load/context_overlay.rs@@ -58,7 +58,7 @@ impl ConfigContextOverlay {same_source,"cannot derive config overrides from different persistence sources");- let inherited = parent.context_overlay.lock().unwrap().clone();+ let inherited = parent.runtime_state.context_overlay.lock().unwrap().clone();let mut changes = inherited.as_ref().map(|overlay| overlay.changes.clone())@@ -81,7 +81,7 @@ impl ConfigContextOverlay {) -> anyhow::Result<Arc<Self>> {let mut changes = Vec::new();if let Some(parent) = parent.filter(|parent| same_source(parent, child)) {- if let Some(inherited) = parent.context_overlay.lock().unwrap().clone() {+ if let Some(inherited) = parent.runtime_state.context_overlay.lock().unwrap().clone() {changes.extend(inherited.changes.clone());}let parent_value = serde_json::to_value(parent)?;@@ -112,10 +112,10 @@ impl ConfigContextOverlay {let mut result: Config = serde_json::from_value(value)?;copy_runtime_bindings(fresh, &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();- result.context_overlay = std::sync::Mutex::new(Some(Arc::new(Self {+ result.runtime_state.document_snapshot =+ std::sync::Mutex::new(fresh.runtime_state.document_snapshot.lock().unwrap().clone());+ result.runtime_state.context_snapshot = fresh.runtime_state.context_snapshot.clone();+ result.runtime_state.context_overlay = std::sync::Mutex::new(Some(Arc::new(Self {changes: self.changes.clone(),runtime: self.runtime.clone(),})));@@ -137,8 +137,8 @@ const PROFILE_OWNED_PATHS: &[&[&str]] = &[];fn same_source(parent: &Config, child: &Config) -> bool {- let parent_anchor = parent.document_snapshot.lock().unwrap().anchor.clone();- let child_anchor = child.document_snapshot.lock().unwrap().anchor.clone();+ let parent_anchor = parent.runtime_state.document_snapshot.lock().unwrap().anchor.clone();+ let child_anchor = child.runtime_state.document_snapshot.lock().unwrap().anchor.clone();match (&parent_anchor, &child_anchor) {(Some(parent), Some(child)) => parent == child,(None, None) => {diff --git a/crates/openhuman-core/src/config/schema/load/context_refresh.rs b/crates/openhuman-core/src/config/schema/load/context_refresh.rsindex b0faefc187..76be3a2a56 100644--- a/crates/openhuman-core/src/config/schema/load/context_refresh.rs+++ b/crates/openhuman-core/src/config/schema/load/context_refresh.rs@@ -12,7 +12,7 @@ pub(super) fn is_document_conflict(error: &anyhow::Error) -> bool {impl Config {pub(crate) fn bind_context_snapshot(snapshot: &std::sync::Arc<std::sync::Mutex<Config>>) {- snapshot.lock().unwrap().context_snapshot = Some(std::sync::Arc::downgrade(snapshot));+ snapshot.lock().unwrap().runtime_state.context_snapshot = Some(std::sync::Arc::downgrade(snapshot));}pub(super) fn refresh_context_after_conflict<'a>(@@ -21,7 +21,7 @@ impl Config {) -> std::pin::Pin<Box<dyn std::future::Future<Output = ()> + Send + 'a>> {Box::pin(async move {let Some(snapshot) = self- .context_snapshot+ .runtime_state.context_snapshot.as_ref().and_then(std::sync::Weak::upgrade)else {@@ -29,7 +29,7 @@ impl Config {};let (config_path, workspace_dir, runtime) = {let current = snapshot.lock().unwrap();- if *current.document_snapshot.lock().unwrap() != *expected {+ if *current.runtime_state.document_snapshot.lock().unwrap() != *expected {return;}(@@ -42,10 +42,10 @@ impl Config {else {return;};- if refreshed.document_snapshot.lock().unwrap().anchor != expected.anchor {+ if refreshed.runtime_state.document_snapshot.lock().unwrap().anchor != expected.anchor {return;}- let overlay = runtime.context_overlay.lock().unwrap().clone();+ let overlay = runtime.runtime_state.context_overlay.lock().unwrap().clone();if let Some(overlay) = overlay {let Ok(merged) = overlay.reapply(&refreshed) else {return;@@ -54,10 +54,10 @@ impl Config {} else {super::context_overlay::copy_runtime_bindings(&runtime, &mut refreshed);}- refreshed.context_snapshot = Some(std::sync::Arc::downgrade(&snapshot));+ refreshed.runtime_state.context_snapshot = Some(std::sync::Arc::downgrade(&snapshot));let mut current = snapshot.lock().unwrap();- if *current.document_snapshot.lock().unwrap() == *expected {+ if *current.runtime_state.document_snapshot.lock().unwrap() == *expected {*current = refreshed;}})diff --git a/crates/openhuman-core/src/config/schema/load/impl_load.rs b/crates/openhuman-core/src/config/schema/load/impl_load.rsindex 17ebce7f89..d10a45c813 100644--- a/crates/openhuman-core/src/config/schema/load/impl_load.rs+++ b/crates/openhuman-core/src/config/schema/load/impl_load.rs@@ -410,7 +410,7 @@ impl Config {update_snapshot: bool,) -> Result<()> {let source_anchor = source.anchor();- let expected_snapshot = self.document_snapshot.lock().unwrap().clone();+ let expected_snapshot = self.runtime_state.document_snapshot.lock().unwrap().clone();let initial_file_import = matches!((&expected_snapshot.anchor, &source_anchor),(@@ -471,21 +471,21 @@ impl Config {if !update_snapshot {return Ok(());}- *self.document_snapshot.lock().unwrap() = super::super::ConfigDocumentSnapshot {+ *self.runtime_state.document_snapshot.lock().unwrap() = super::super::ConfigDocumentSnapshot {version,anchor: Some(source_anchor.clone()),};if let Some(snapshot) = self- .context_snapshot+ .runtime_state.context_snapshot.as_ref().and_then(std::sync::Weak::upgrade){let mut current = snapshot.lock().unwrap();- let current_state = current.document_snapshot.lock().unwrap().clone();+ let current_state = current.runtime_state.document_snapshot.lock().unwrap().clone();if current_state == expected_snapshot {let published = self.clone();- *published.document_snapshot.lock().unwrap() =+ *published.runtime_state.document_snapshot.lock().unwrap() =super::super::ConfigDocumentSnapshot {version,anchor: Some(source_anchor),diff --git a/crates/openhuman-core/src/config/schema/load/parse_source.rs b/crates/openhuman-core/src/config/schema/load/parse_source.rsindex 61ec181d7a..148594c443 100644--- a/crates/openhuman-core/src/config/schema/load/parse_source.rs+++ b/crates/openhuman-core/src/config/schema/load/parse_source.rs@@ -26,7 +26,7 @@ pub(super) async fn parse_source_contents(.map_err(|error| {anyhow::anyhow!("the config document for this scope could not be parsed: {error}")})?;- *config.document_snapshot.lock().unwrap() = super::super::ConfigDocumentSnapshot {+ *config.runtime_state.document_snapshot.lock().unwrap() = super::super::ConfigDocumentSnapshot {version: read.document_version,anchor: Some(read.source_anchor.clone()),};@@ -34,14 +34,14 @@ pub(super) async fn parse_source_contents(}if read_was_recovered && contents.is_empty() {let config = super::branches::default_config_boxed();- *config.document_snapshot.lock().unwrap() = super::super::ConfigDocumentSnapshot {+ *config.runtime_state.document_snapshot.lock().unwrap() = super::super::ConfigDocumentSnapshot {version: read.document_version,anchor: Some(read.source_anchor.clone()),};return Ok((config, true));}let (config, recovered) = Box::pin(parse_config_boxed(config_path, contents)).await;- *config.document_snapshot.lock().unwrap() = super::super::ConfigDocumentSnapshot {+ *config.runtime_state.document_snapshot.lock().unwrap() = super::super::ConfigDocumentSnapshot {version: read.document_version,anchor: Some(read.source_anchor.clone()),};diff --git a/crates/openhuman-core/src/config/schema/load/source/concurrency_tests.rs b/crates/openhuman-core/src/config/schema/load/source/concurrency_tests.rsindex 02582efd6b..007c5d6eec 100644--- a/crates/openhuman-core/src/config/schema/load/source/concurrency_tests.rs+++ b/crates/openhuman-core/src/config/schema/load/source/concurrency_tests.rs@@ -428,7 +428,7 @@ async fn config_snapshot_cannot_be_saved_into_a_different_tenant_scope() {let config = Config::load_from_config_path(&path, &workspace).await.unwrap();- let version = config.document_snapshot.lock().unwrap().version;+ let version = config.runtime_state.document_snapshot.lock().unwrap().version;(config, version)};@@ -442,7 +442,7 @@ async fn config_snapshot_cannot_be_saved_into_a_different_tenant_scope() {let config = Config::load_from_config_path(&path, &workspace).await.unwrap();- let version = config.document_snapshot.lock().unwrap().version;+ let version = config.runtime_state.document_snapshot.lock().unwrap().version;let docs = Arc::clone(scoped(&storage, "tenant-source-b").documents());let stored = docs.get(@@ -521,16 +521,16 @@ async fn config_snapshot_is_bound_to_its_backend_instance() {let config = Config::load_from_config_path(&path, &workspace).await.unwrap();- let version = config.document_snapshot.lock().unwrap().version;+ let version = config.runtime_state.document_snapshot.lock().unwrap().version;(config, version)};- let version_a = config_a.document_snapshot.lock().unwrap().version;+ let version_a = config_a.runtime_state.document_snapshot.lock().unwrap().version;assert_eq!(version_a, version_b,"fixture uses colliding document versions");- let anchor_a = config_a.document_snapshot.lock().unwrap().anchor.clone();- let anchor_b = config_b.document_snapshot.lock().unwrap().anchor.clone();+ let anchor_a = config_a.runtime_state.document_snapshot.lock().unwrap().anchor.clone();+ let anchor_b = config_b.runtime_state.document_snapshot.lock().unwrap().anchor.clone();assert_ne!(anchor_a, anchor_b, "source anchors retain backend identity");let error = {@@ -557,7 +557,7 @@ async fn a_file_snapshot_can_seed_an_absent_document_after_storage_bootstrap() {.await.unwrap();assert!(matches!(- snapshot.document_snapshot.lock().unwrap().anchor.clone(),+ snapshot.runtime_state.document_snapshot.lock().unwrap().anchor.clone(),Some(ConfigSourceAnchor::File(_))));diff --git a/crates/openhuman-core/src/config/schema/types.rs b/crates/openhuman-core/src/config/schema/types.rsindex cd4e4da6d2..63825e06b0 100644--- a/crates/openhuman-core/src/config/schema/types.rs+++ b/crates/openhuman-core/src/config/schema/types.rs@@ -12,7 +12,7 @@ mod resolvers;mod time_zone;pub(crate) use config::ConfigDocumentSnapshot;-pub use config::{Config, CustomEmbeddingsConfig, ModelRegistryEntry};+pub use config::{Config, ConfigRuntimeState, CustomEmbeddingsConfig, ModelRegistryEntry};pub use model_ids::{is_legacy_tier_model, legacy_tier_role, DEFAULT_MODEL, LEGACY_TIER_MODELS,MANAGED_MULTIMODAL_MODELS, MODEL_IMAGE_GENERATION_AGENT, MODEL_MANAGED_DEFAULT,diff --git a/crates/openhuman-core/src/config/schema/types/config.rs b/crates/openhuman-core/src/config/schema/types/config.rsindex 5f296bd8e5..3a8dde19c5 100644--- a/crates/openhuman-core/src/config/schema/types/config.rs+++ b/crates/openhuman-core/src/config/schema/types/config.rs@@ -14,6 +14,30 @@ pub(crate) struct ConfigDocumentSnapshot {pub anchor: Option<super::super::load::source::ConfigSourceAnchor>,}+/// Opaque runtime bookkeeping that accompanies a [`Config`] snapshot.+///+/// Public only to preserve `Config { ..Default::default() }` construction in+/// downstream crates; its fields remain private to this crate.+#[doc(hidden)]+#[derive(Debug, Default)]+pub struct ConfigRuntimeState {+ pub(crate) document_snapshot: std::sync::Mutex<ConfigDocumentSnapshot>,+ pub(crate) context_snapshot: Option<std::sync::Weak<std::sync::Mutex<Config>>>,+ pub(crate) context_overlay: std::sync::Mutex<+ Option<std::sync::Arc<super::super::load::context_overlay::ConfigContextOverlay>>,+ >,+}++impl Clone for ConfigRuntimeState {+ fn clone(&self) -> Self {+ Self {+ document_snapshot: std::sync::Mutex::new(self.runtime_state.document_snapshot.lock().unwrap().clone()),+ context_snapshot: self.runtime_state.context_snapshot.clone(),+ context_overlay: std::sync::Mutex::new(self.runtime_state.context_overlay.lock().unwrap().clone()),+ }+ }+}+#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]pub struct ModelRegistryEntry {pub id: String,@@ -60,18 +84,11 @@ pub struct CustomEmbeddingsConfig {/// `Clone` is implemented by hand in `config_clone.rs` so it is emitted once.#[derive(Debug, Serialize, Deserialize, JsonSchema)]pub struct Config {- /// Revision of the shared config document this snapshot was loaded from.+ /// Non-serialized persistence and context bookkeeping.#[serde(skip)]#[schemars(skip)]- pub(crate) document_snapshot: std::sync::Mutex<ConfigDocumentSnapshot>,- #[serde(skip)]- #[schemars(skip)]- pub(crate) context_snapshot: Option<std::sync::Weak<std::sync::Mutex<Config>>>,- #[serde(skip)]- #[schemars(skip)]- pub(crate) context_overlay: std::sync::Mutex<- Option<std::sync::Arc<super::super::load::context_overlay::ConfigContextOverlay>>,- >,+ #[doc(hidden)]+ pub runtime_state: ConfigRuntimeState,/// Immutable operator provider binding, absent from the user wire format.#[serde(skip)]#[schemars(skip)]diff --git a/crates/openhuman-core/src/config/schema/types/config_clone.rs b/crates/openhuman-core/src/config/schema/types/config_clone.rsindex 8eab48f5eb..635d583f45 100644--- a/crates/openhuman-core/src/config/schema/types/config_clone.rs+++ b/crates/openhuman-core/src/config/schema/types/config_clone.rs@@ -12,11 +12,7 @@ impl Clone for Config {#[inline(never)]fn clone(&self) -> Self {Self {- document_snapshot: std::sync::Mutex::new(- self.document_snapshot.lock().unwrap().clone(),- ),- context_snapshot: self.context_snapshot.clone(),- context_overlay: std::sync::Mutex::new(self.context_overlay.lock().unwrap().clone()),+ runtime_state: self.runtime_state.clone(),profile_providers: self.profile_providers.clone(),workspace_dir: self.workspace_dir.clone(),action_dir: self.action_dir.clone(),diff --git a/crates/openhuman-core/src/config/schema/types/defaults.rs b/crates/openhuman-core/src/config/schema/types/defaults.rsindex 4a345ec0bb..ec74add56c 100644--- a/crates/openhuman-core/src/config/schema/types/defaults.rs+++ b/crates/openhuman-core/src/config/schema/types/defaults.rs@@ -25,9 +25,7 @@ impl Default for Config {});Self {- document_snapshot: std::sync::Mutex::new(Default::default()),- context_snapshot: None,- context_overlay: std::sync::Mutex::new(None),+ runtime_state: super::config::ConfigRuntimeState::default(),profile_providers: None,workspace_dir: openhuman_dir.join("workspace"),action_dir: crate::config::default_action_dir(),diff --git a/crates/openhuman-core/src/core/runtime/context.rs b/crates/openhuman-core/src/core/runtime/context.rsindex 2a4e6518e0..79016c98fb 100644--- a/crates/openhuman-core/src/core/runtime/context.rs+++ b/crates/openhuman-core/src/core/runtime/context.rs@@ -425,7 +425,7 @@ impl CoreContext {};let agent = self.agent.derive(&mut overlay);config_access::record_context_config_overlay(self.profile(), parent_config, &mut overlay);- overlay.config.context_snapshot = None;+ overlay.config.runtime_state.context_snapshot = None;let latest_embedder_config = Some(Arc::new(std::sync::Mutex::new(overlay.config.clone())));if let Some(snapshot) = &latest_embedder_config {crate::config::Config::bind_context_snapshot(snapshot);diff --git a/crates/openhuman-core/src/core/runtime/context_config.rs b/crates/openhuman-core/src/core/runtime/context_config.rsindex 15adeee26d..416a0e1d8e 100644--- a/crates/openhuman-core/src/core/runtime/context_config.rs+++ b/crates/openhuman-core/src/core/runtime/context_config.rs@@ -28,7 +28,7 @@ pub(super) fn record_context_config_overlay(if let Some(config_overlay) = config_overlay {match config_overlay {Ok(config_overlay) => {- overlay.config.context_overlay = std::sync::Mutex::new(Some(config_overlay));+ overlay.config.runtime_state.context_overlay = std::sync::Mutex::new(Some(config_overlay));}Err(error) => {log::warn!("[core-context] unable to record derived config overrides: {error}")@@ -48,7 +48,7 @@ impl CoreContext {pub(crate) fn latest_embedder_config(&self) -> Option<crate::config::Config> {let snapshot = self.latest_embedder_config.as_ref()?;let mut config = snapshot.lock().ok()?.clone();- config.context_snapshot = Some(Arc::downgrade(snapshot));+ config.runtime_state.context_snapshot = Some(Arc::downgrade(snapshot));Some(config)}