Skip to content

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

fix(config): refresh nested context overlays from latest external state

Steven Enamakelc448f2902f93
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 c1606c9c98..a69e257dc0 100644
--- a/crates/openhuman-core/src/config/schema/load/context_overlay.rs
+++ b/crates/openhuman-core/src/config/schema/load/context_overlay.rs
@@ -54,9 +54,8 @@ impl ConfigContextOverlay {
let mut result: Config = serde_json::from_value(value)?;
copy_runtime_bindings(fresh, &mut result);
copy_runtime_bindings(&self.runtime, &mut result);
- result.document_snapshot = std::sync::Mutex::new(
- fresh.document_snapshot.lock().unwrap().clone(),
- );
+ 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.clone())));
Ok(result)
@@ -137,4 +136,3 @@ pub(crate) fn copy_runtime_bindings(source: &Config, target: &mut Config) {
target.search.gemini_route = source.search.gemini_route.clone();
target.search.host_credentials = source.search.host_credentials.clone();
}
-
diff --git a/crates/openhuman-core/src/config/schema/load/impl_load.rs b/crates/openhuman-core/src/config/schema/load/impl_load.rs
index 999cceab1a..2a2e7aa390 100644
--- a/crates/openhuman-core/src/config/schema/load/impl_load.rs
+++ b/crates/openhuman-core/src/config/schema/load/impl_load.rs
@@ -1,8 +1,8 @@
use super::super::Config;
use super::branches::pre_login_config_boxed;
use super::dirs::{
- ConfigResolutionSource, default_action_dir, default_config_and_workspace_dirs,
- resolve_action_dir, resolve_config_dirs_ignoring_env, resolve_runtime_config_dirs_with,
+ default_action_dir, default_config_and_workspace_dirs, resolve_action_dir,
+ resolve_config_dirs_ignoring_env, resolve_runtime_config_dirs_with, ConfigResolutionSource,
};
use super::env::{EnvLookup, ProcessEnv, ProcessEnvWithoutWorkspace};
use super::migrate::{
@@ -17,8 +17,8 @@ use std::path::Path;
use std::sync::{Mutex, OnceLock};
use tokio::fs;
-pub(crate) use super::config_file_read::CONFIG_OWNER_MISMATCH_MARKER;
pub(crate) use super::config_file_read::parse_config_with_recovery;
+pub(crate) use super::config_file_read::CONFIG_OWNER_MISMATCH_MARKER;
pub(super) use super::config_file_read::{
describe_config_ownership, migration_source, parse_config_boxed, parse_toml_off_worker,
};
@@ -403,9 +403,10 @@ impl Config {
&& expected_snapshot.version.is_none()
);
if update_snapshot
- && expected_snapshot.anchor.as_ref().is_some_and(|anchor| {
- anchor != &source_anchor && !initial_file_import
- })
+ && expected_snapshot
+ .anchor
+ .as_ref()
+ .is_some_and(|anchor| anchor != &source_anchor && !initial_file_import)
{
return Err(tinystoragedrivers::StorageError::conflict(
"config snapshot belongs to a different persistence source",
@@ -444,7 +445,8 @@ impl Config {
Ok(version) => version,
Err(error) => {
if is_document_conflict(&error) {
- self.refresh_context_after_conflict(&expected_snapshot).await;
+ self.refresh_context_after_conflict(&expected_snapshot)
+ .await;
}
return Err(error);
}
@@ -494,7 +496,11 @@ impl Config {
if *current.document_snapshot.lock().unwrap() != *expected {
return;
}
- (current.config_path.clone(), current.workspace_dir.clone(), current.clone())
+ (
+ current.config_path.clone(),
+ current.workspace_dir.clone(),
+ current.clone(),
+ )
};
let Ok(mut refreshed) = Self::load_from_config_path(&config_path, &workspace_dir).await
else {
diff --git a/crates/openhuman-core/src/config/schema/load/mod.rs b/crates/openhuman-core/src/config/schema/load/mod.rs
index 8e85aedc9f..43ac15684c 100644
--- a/crates/openhuman-core/src/config/schema/load/mod.rs
+++ b/crates/openhuman-core/src/config/schema/load/mod.rs
@@ -18,10 +18,11 @@ pub(crate) mod source;
pub use active_workspace::active_workspace_dir_cached;
pub(crate) use active_workspace::invalidate_active_workspace;
pub use dirs::{
- 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_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,
+ PRE_LOGIN_USER_ID,
};
// redact_url_for_log is pub(super) for the schema module; tests inside load
@@ -50,7 +51,7 @@ pub(crate) use dirs::read_active_user_id_checked;
pub(crate) use dirs::resolve_config_dir_for_workspace;
#[cfg(test)]
pub(crate) use dirs::{
- ConfigResolutionSource, resolve_runtime_config_dirs, resolve_runtime_config_dirs_with,
+ resolve_runtime_config_dirs, resolve_runtime_config_dirs_with, ConfigResolutionSource,
};
// PathBuf and Config were in scope via `use super::*` in the original load.rs.
#[cfg(test)]
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.rs
index f8c6f6f710..70acc92d02 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
@@ -245,6 +245,95 @@ async fn external_config_conflict_refresh_keeps_derived_runtime_overrides() {
assert!(refreshed.composio.host_credential.is_some());
}
+#[tokio::test]
+async fn nested_context_refresh_does_not_pin_a_previous_external_value() {
+ let tmp = tempfile::tempdir().unwrap();
+ let storage = MemoryStorage::new();
+ let _forced = ForcedDocumentSource::new(
+ scoped(&storage, "tenant-refresh-nested-overlay"),
+ Scope::new("tenant-refresh-nested-overlay").unwrap(),
+ keys(15),
+ );
+ let seed = config_at(tmp.path(), "initial");
+ seed.save().await.unwrap();
+ let base = Config::load_from_config_path(&seed.config_path, &seed.workspace_dir)
+ .await
+ .unwrap();
+ let parent = CoreContext::for_test_with_config(DomainSet::full(), base.clone());
+ let mut first_config = base;
+ first_config.memory.root = Some("team:runtime".into());
+ let first_context = parent.derive_with(ContextOverlay::new(
+ first_config,
+ DomainSet::full(),
+ crate::tools::toolpacks::ToolGroups::none(),
+ ));
+
+ let controller = crate::core::all::all_registered_controllers()
+ .into_iter()
+ .find(|controller| controller.rpc_method_name() == "openhuman.config_update_model_settings")
+ .expect("config model settings RPC is registered");
+ let mut external = Config::load_from_config_path(&seed.config_path, &seed.workspace_dir)
+ .await
+ .unwrap();
+ external.default_model = Some("external-first".into());
+ external.save().await.unwrap();
+ let first_conflict = CoreContext::scope(first_context.clone(), async {
+ (controller.handler)(
+ DispatchCtx::new(first_context.clone()),
+ json!({"default_temperature": 0.8})
+ .as_object()
+ .unwrap()
+ .clone(),
+ )
+ .await
+ .unwrap_err()
+ })
+ .await;
+ assert!(crate::core::StructuredRpcError::decode(&first_conflict).is_some());
+
+ let after_first_refresh = CoreContext::scope(first_context.clone(), async {
+ DispatchCtx::new(first_context.clone())
+ .load_config()
+ .await
+ .unwrap()
+ })
+ .await;
+ let nested = first_context.derive_with(ContextOverlay::new(
+ after_first_refresh,
+ DomainSet::full(),
+ crate::tools::toolpacks::ToolGroups::none(),
+ ));
+
+ external = Config::load_from_config_path(&seed.config_path, &seed.workspace_dir)
+ .await
+ .unwrap();
+ external.default_model = Some("external-second".into());
+ external.save().await.unwrap();
+ let second_conflict = CoreContext::scope(nested.clone(), async {
+ (controller.handler)(
+ DispatchCtx::new(nested.clone()),
+ json!({"default_temperature": 0.7})
+ .as_object()
+ .unwrap()
+ .clone(),
+ )
+ .await
+ .unwrap_err()
+ })
+ .await;
+ assert!(crate::core::StructuredRpcError::decode(&second_conflict).is_some());
+
+ let refreshed = CoreContext::scope(nested.clone(), async {
+ DispatchCtx::new(nested.clone())
+ .load_config()
+ .await
+ .unwrap()
+ })
+ .await;
+ assert_eq!(refreshed.default_model.as_deref(), Some("external-second"));
+ assert_eq!(refreshed.memory.root.as_deref(), Some("team:runtime"));
+}
+
#[tokio::test]
async fn config_snapshot_cannot_be_saved_into_a_different_tenant_scope() {
let tmp = tempfile::tempdir().unwrap();
diff --git a/crates/openhuman-core/src/config/schema/types/config.rs b/crates/openhuman-core/src/config/schema/types/config.rs
index c368aba9c8..5f296bd8e5 100644
--- a/crates/openhuman-core/src/config/schema/types/config.rs
+++ b/crates/openhuman-core/src/config/schema/types/config.rs
@@ -69,8 +69,9 @@ pub struct Config {
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>>>,
+ pub(crate) context_overlay: std::sync::Mutex<
+ Option<std::sync::Arc<super::super::load::context_overlay::ConfigContextOverlay>>,
+ >,
/// 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.rs
index 6fc07f76cd..8eab48f5eb 100644
--- a/crates/openhuman-core/src/config/schema/types/config_clone.rs
+++ b/crates/openhuman-core/src/config/schema/types/config_clone.rs
@@ -16,9 +16,7 @@ impl Clone for Config {
self.document_snapshot.lock().unwrap().clone(),
),
context_snapshot: self.context_snapshot.clone(),
- context_overlay: std::sync::Mutex::new(
- self.context_overlay.lock().unwrap().clone(),
- ),
+ context_overlay: std::sync::Mutex::new(self.context_overlay.lock().unwrap().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.rs
index 11dae6f6bd..4a345ec0bb 100644
--- a/crates/openhuman-core/src/config/schema/types/defaults.rs
+++ b/crates/openhuman-core/src/config/schema/types/defaults.rs
@@ -4,8 +4,8 @@ use directories::UserDirs;
use std::collections::HashMap;
use std::path::PathBuf;
-use super::config::DEFAULT_TEMPERATURE;
use super::config::default_temperature_unsupported_models;
+use super::config::DEFAULT_TEMPERATURE;
use super::model_ids::DEFAULT_MODEL;
use crate::config::schema::*;
diff --git a/crates/openhuman-core/src/core/runtime/context.rs b/crates/openhuman-core/src/core/runtime/context.rs
index ae036472d0..fff565f516 100644
--- a/crates/openhuman-core/src/core/runtime/context.rs
+++ b/crates/openhuman-core/src/core/runtime/context.rs
@@ -418,12 +418,11 @@ impl CoreContext {
&overlay.config,
) {
Ok(config_overlay) => {
- overlay.config.context_overlay =
- std::sync::Mutex::new(Some(config_overlay));
+ overlay.config.context_overlay = std::sync::Mutex::new(Some(config_overlay));
+ }
+ Err(error) => {
+ log::warn!("[core-context] unable to record derived config overrides: {error}")
}
- Err(error) => log::warn!(
- "[core-context] unable to record derived config overrides: {error}"
- ),
}
}
overlay.config.context_snapshot = None;