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
test(middleware): drain nudges through the request-scoped injector
Steven Enamakel6995ab6a1351
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rsindex 8f9051d27b..0d6b00c769 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs@@ -101,11 +101,6 @@ impl RepeatedToolFailureMiddleware {self.owner.nudge_injector()}- /// Inspect pending product corrections in tests.- #[cfg(test)]- pub(crate) fn take_pending_nudges(&self) -> Vec<String> {- self.owner.drain_pending_nudges()- }}struct HostFailurePolicy {diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_loop_guard_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_loop_guard_tests.rsindex 8ce19dd563..2c0726d5ca 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware_loop_guard_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_loop_guard_tests.rs@@ -87,11 +87,12 @@ async fn repeated_tool_failure_pauses_only_after_the_threshold() {3,std::sync::Arc::new(std::sync::Mutex::new(None)),);+ let mut context = ctx();// Two identical failures: below the halt threshold. The crate ladder// nudges (Redirect) on the second, but must NOT pause (halt) yet.for _ in 0..2 {let mut r = failing_result("flaky", "boom");- mw.after_tool(&mut ctx(), &(), &invocation("flaky", "flaky"), &mut r)+ mw.after_tool(&mut context, &(), &invocation("flaky", "flaky"), &mut r).await.unwrap();}@@ -102,7 +103,7 @@ async fn repeated_tool_failure_pauses_only_after_the_threshold() {);// Third identical failure exhausts the same-strategy retries → halt.let mut r = failing_result("flaky", "boom");- mw.after_tool(&mut ctx(), &(), &invocation("flaky", "flaky"), &mut r)+ mw.after_tool(&mut context, &(), &invocation("flaky", "flaky"), &mut r).await.unwrap();assert_eq!(@@ -302,9 +303,10 @@ async fn repeated_tool_failure_nudges_change_of_strategy_before_the_halt() {3,std::sync::Arc::new(std::sync::Mutex::new(None)),);+ let mut context = ctx();// First identical failure: not a loop yet — no steering.let mut r = failing_result("read_file", "file not found");- mw.after_tool(&mut ctx(), &(), &invocation("read-1", "read_file"), &mut r)+ mw.after_tool(&mut context, &(), &invocation("read-1", "read_file"), &mut r).await.unwrap();assert!(@@ -313,10 +315,10 @@ async fn repeated_tool_failure_nudges_change_of_strategy_before_the_halt() {);// Second identical failure: the nudge fires, still no halt.let mut r = failing_result("read_file", "file not found");- mw.after_tool(&mut ctx(), &(), &invocation("read-2", "read_file"), &mut r)+ mw.after_tool(&mut context, &(), &invocation("read-2", "read_file"), &mut r).await.unwrap();- let nudges = drain_nudge_messages(&mw);+ let nudges = drain_nudge_messages(&mw, &mut context).await;assert_eq!(nudges.len(),1,diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rsindex 63a4491921..178c50eeb5 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs@@ -319,8 +319,30 @@ fn drain_pause_count(handle: &SteeringHandle) -> usize {/// Collect the nudge texts queued for the next model request. Nudges are/// request-scoped (#6725): they never ride a steering command.-fn drain_nudge_messages(mw: &RepeatedToolFailureMiddleware) -> Vec<String> {- mw.take_pending_nudges()+async fn drain_nudge_messages(+ mw: &RepeatedToolFailureMiddleware,+ context: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,+) -> Vec<String> {+ let injector = mw.nudge_injector();+ let mut request = ModelRequest {+ messages: vec![TaMessage::user("request")],+ ..Default::default()+ };+ injector+ .before_model_dispatch(context, &(), &mut request)+ .await+ .expect("queued correction is injected into the model request");+ let messages = request+ .messages+ .iter()+ .skip(1)+ .map(|message| message.text().to_owned())+ .collect();+ injector+ .after_model_dispatch(context, &(), true)+ .await+ .expect("request delivery consumes the staged correction");+ messages}// ── RepeatedToolFailureMiddleware body-level ok:false (flows breaker) ────