Skip to content

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

refactor(agent): create approval subscription after context derivation

Steven Enamakelfa8aa5a6de9b
diff --git a/crates/openhuman-embed/src/agent/build.rs b/crates/openhuman-embed/src/agent/build.rs
index 29806548d9..af5bef46ac 100644
--- a/crates/openhuman-embed/src/agent/build.rs
+++ b/crates/openhuman-embed/src/agent/build.rs
@@ -300,14 +300,6 @@ pub(crate) fn instantiate(runtime: &Runtime, spec: AgentSpec) -> Result<AgentInn
for hook in parts.tool_hooks {
overrides.tool_hook(hook.name(), Some(hook.clone()));
}
- let approval_subscription = parts.approval_handler.map(|handler| {
- super::approval_handler::ApprovalSubscription::new(
- &id,
- handler,
- lifecycle.removed(),
- lifecycle.approval_state(),
- )
- });
let overlay = ContextOverlay {
host_overrides: Some(overrides.clone()),
config: context_config,
@@ -329,6 +321,15 @@ pub(crate) fn instantiate(runtime: &Runtime, spec: AgentSpec) -> Result<AgentInn
definitions,
};
let ctx = runtime.core_runtime().context().derive_with(overlay);
+ let approval_subscription = parts.approval_handler.map(|handler| {
+ super::approval_handler::ApprovalSubscription::new(
+ &id,
+ handler,
+ lifecycle.removed(),
+ lifecycle.approval_state(),
+ Some(std::sync::Arc::downgrade(&ctx)),
+ )
+ });
openhuman_core::core::runtime::AgentContextRegistry::register(&id, &ctx);
log::debug!(