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
fix(hooks): scope hook matching to the active agent
Steven Enamakel68dbed2d1373
diff --git a/crates/openhuman-core/src/agent/hooks.rs b/crates/openhuman-core/src/agent/hooks.rsindex 9f3c015bd2..31c21abd8b 100644--- a/crates/openhuman-core/src/agent/hooks.rs+++ b/crates/openhuman-core/src/agent/hooks.rs@@ -38,11 +38,14 @@ pub fn replace_embedder_post_turn_hook(name: &str, hook: Option<Arc<dyn PostTurn}}-/// Snapshot hooks supplied by the embedding host, for the calling task's-/// ambient context. Library callers outside a turn use this; the core passes-/// its own context to [`embedder_post_turn_hooks_in`].+/// Snapshot of the process-wide hooks the embedding host registered, without+/// any agent-local ones. The host's install/restore bookkeeping reads this; a+/// turn passes its own context to [`embedder_post_turn_hooks_in`].pub fn embedder_post_turn_hooks() -> Vec<Arc<dyn PostTurnHook>> {- embedder_post_turn_hooks_in(&crate::core::runtime::DispatchCtx::ambient())+ EMBEDDER_POST_TURN_HOOKS+ .lock()+ .expect("embedder post-turn hooks poisoned")+ .clone()}/// Snapshot hooks supplied by the embedding host, plus the agent-local ones of@@ -50,10 +53,7 @@ pub fn embedder_post_turn_hooks() -> Vec<Arc<dyn PostTurnHook>> {pub fn embedder_post_turn_hooks_in(ctx: &crate::core::runtime::DispatchCtx,) -> Vec<Arc<dyn PostTurnHook>> {- let mut hooks = EMBEDDER_POST_TURN_HOOKS- .lock()- .expect("embedder post-turn hooks poisoned")- .clone();+ let mut hooks = embedder_post_turn_hooks();if let Some(local) = ctx.host_overrides() {hooks.extend(local.post_turn_hooks());}@@ -285,19 +285,19 @@ pub fn replace_embedder_tool_hook(name: &str, hook: Option<Arc<dyn ToolHook>>) {}}-/// Snapshot tool hooks supplied by the embedding host, for the calling task's-/// ambient context. See [`embedder_post_turn_hooks`].+/// Snapshot of the process-wide tool hooks the embedding host registered,+/// without any agent-local ones. See [`embedder_post_turn_hooks`].pub fn embedder_tool_hooks() -> Vec<Arc<dyn ToolHook>> {- embedder_tool_hooks_in(&crate::core::runtime::DispatchCtx::ambient())+ EMBEDDER_TOOL_HOOKS+ .lock()+ .expect("embedder tool hooks poisoned")+ .clone()}/// Snapshot tool hooks supplied by the embedding host, plus the agent-local/// ones of the agent `ctx` runs for.pub fn embedder_tool_hooks_in(ctx: &crate::core::runtime::DispatchCtx) -> Vec<Arc<dyn ToolHook>> {- let mut hooks = EMBEDDER_TOOL_HOOKS- .lock()- .expect("embedder tool hooks poisoned")- .clone();+ let mut hooks = embedder_tool_hooks();if let Some(local) = ctx.host_overrides() {hooks.extend(local.tool_hooks());}diff --git a/crates/openhuman-embed/tests/scoped_hooks.rs b/crates/openhuman-embed/tests/scoped_hooks.rsindex 1d0455f42b..88b1c28d43 100644--- a/crates/openhuman-embed/tests/scoped_hooks.rs+++ b/crates/openhuman-embed/tests/scoped_hooks.rs@@ -161,12 +161,18 @@ async fn scenario() {scheduled.scope(async {assert_eq!(- openhuman_core::agent::hooks::embedder_tool_hooks().len(),+ openhuman_core::agent::hooks::embedder_tool_hooks_in(+ &openhuman_core::core::runtime::DispatchCtx::ambient()+ )+ .len(),2,"scheduled turns lost the agent's tool hooks");assert_eq!(- openhuman_core::agent::hooks::embedder_post_turn_hooks().len(),+ openhuman_core::agent::hooks::embedder_post_turn_hooks_in(+ &openhuman_core::core::runtime::DispatchCtx::ambient()+ )+ .len(),2,"scheduled turns lost the agent's post-turn hooks");