Skip to content

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

fix(test): share run context across before and after tool hooks

Steven Enamakelb831d9c531f8
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_memory_and_hooks_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_memory_and_hooks_tests.rs
index 9695ae602f..81fe7c9a9d 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware_memory_and_hooks_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_memory_and_hooks_tests.rs
@@ -109,10 +109,13 @@ async fn openhuman_spec_drives_the_upstream_memory_protocol() {
arguments: json!({}),
invalid: None,
};
- mw.before_tool(&mut ctx(), &(), &mut call).await.unwrap();
+ // One run context for both hooks: the middleware keys its protocol state
+ // by run instance, so `before_tool` and `after_tool` must see the same run.
+ let mut run_ctx = ctx();
+ mw.before_tool(&mut run_ctx, &(), &mut call).await.unwrap();
let mut result = TaToolResult::success("stored");
mw.after_tool(
- &mut ctx(),
+ &mut run_ctx,
&(),
&ToolInvocationIdentity::new("c1", "memory_store"),
&mut result,