Skip to content

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

feat(config): allow deriving child contexts from an explicit parent config

Steven Enamakel594fcca3584e
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 d105d03230..6774bfb31c 100644
--- a/crates/openhuman-core/src/config/schema/load/context_overlay.rs
+++ b/crates/openhuman-core/src/config/schema/load/context_overlay.rs
@@ -53,6 +53,12 @@ impl std::fmt::Debug for ConfigContextOverlay {
impl ConfigContextOverlay {
pub(crate) fn derive(parent: &Config, child: &Config) -> anyhow::Result<Arc<Self>> {
+ let parent_anchor = parent.document_snapshot.lock().unwrap().anchor.clone();
+ let child_anchor = child.document_snapshot.lock().unwrap().anchor.clone();
+ anyhow::ensure!(
+ parent_anchor == child_anchor,
+ "cannot derive config overrides from different persistence sources"
+ );
let inherited = parent.context_overlay.lock().unwrap().clone();
let mut changes = inherited
.as_ref()
diff --git a/crates/openhuman-core/src/config/schema/load/source/revision_loader_tests.rs b/crates/openhuman-core/src/config/schema/load/source/revision_loader_tests.rs
index fd48ce63d4..9afbbfcc90 100644
--- a/crates/openhuman-core/src/config/schema/load/source/revision_loader_tests.rs
+++ b/crates/openhuman-core/src/config/schema/load/source/revision_loader_tests.rs
@@ -30,11 +30,14 @@ async fn discovered_parent_config_is_used_to_record_agent_overrides() {
agent_config.autonomy.enabled = true;
agent_config.mcp_client.enabled = false;
agent_config.memory.agent_id = Some("runtime-agent-memory".into());
- let child = parent.derive_with(ContextOverlay::new(
- agent_config,
- DomainSet::full(),
- crate::tools::toolpacks::ToolGroups::none(),
- ));
+ let child = parent.derive_with_parent_config(
+ &base,
+ ContextOverlay::new(
+ agent_config,
+ DomainSet::full(),
+ crate::tools::toolpacks::ToolGroups::none(),
+ ),
+ );
let mut external = Config::load_from_config_path(&seed.config_path, &seed.workspace_dir)
.await
diff --git a/crates/openhuman-core/src/core/runtime/context.rs b/crates/openhuman-core/src/core/runtime/context.rs
index 793540a129..6c19453e10 100644
--- a/crates/openhuman-core/src/core/runtime/context.rs
+++ b/crates/openhuman-core/src/core/runtime/context.rs
@@ -364,7 +364,30 @@ impl CoreContext {
/// The workspace binding is anchored to `overlay.config.workspace_dir`, so
/// an agent with its own workspace subdirectory resolves its own memory
/// binding lazily, exactly as an embedder-supplied config does at boot.
- pub fn derive_with(&self, mut overlay: ContextOverlay) -> Arc<CoreContext> {
+ pub fn derive_with(&self, overlay: ContextOverlay) -> Arc<CoreContext> {
+ let parent_config = self.latest_embedder_config();
+ self.derive_with_parent_config_inner(parent_config.as_ref(), overlay)
+ }
+
+ /// Derive a child using the exact parent configuration it was built from.
+ ///
+ /// This is used by embedders that load their config after core boot: the
+ /// context may intentionally have no published embedder snapshot, while
+ /// the child still needs the correct baseline for conflict-refresh
+ /// overrides.
+ pub fn derive_with_parent_config(
+ &self,
+ parent_config: &crate::config::Config,
+ overlay: ContextOverlay,
+ ) -> Arc<CoreContext> {
+ self.derive_with_parent_config_inner(Some(parent_config), overlay)
+ }
+
+ fn derive_with_parent_config_inner(
+ &self,
+ parent_config: Option<&crate::config::Config>,
+ mut overlay: ContextOverlay,
+ ) -> Arc<CoreContext> {
// Clamped to what this context can already dispatch. A derived
// overlay may only narrow: callers outside this crate (embed's
// `Runtime::agent`, for one) already refuse a spec that names a
@@ -412,9 +435,9 @@ impl CoreContext {
}
};
let agent = self.agent.derive(&mut overlay);
- if let Some(parent_config) = self.latest_embedder_config() {
+ if let Some(parent_config) = parent_config {
match crate::config::schema::load::context_overlay::ConfigContextOverlay::derive(
- &parent_config,
+ parent_config,
&overlay.config,
) {
Ok(config_overlay) => {
diff --git a/crates/openhuman-embed/src/agent/build.rs b/crates/openhuman-embed/src/agent/build.rs
index 79461259af..8313bab1d9 100644
--- a/crates/openhuman-embed/src/agent/build.rs
+++ b/crates/openhuman-embed/src/agent/build.rs
@@ -320,7 +320,10 @@ pub(crate) fn instantiate(runtime: &Runtime, spec: AgentSpec) -> Result<AgentInn
approvals_disabled: !access.approval_gate_enabled(),
definitions,
};
- let ctx = runtime.core_runtime().context().derive_with(overlay);
+ let ctx = runtime
+ .core_runtime()
+ .context()
+ .derive_with_parent_config(base, overlay);
let approval_subscription = parts.approval_handler.map(|handler| {
super::approval_handler::ApprovalSubscription::new(
&id,