Skip to content

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

chore: files changed crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.

Steven Enamakel80da42f439a8
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rs
index 56b6a8e88a..ce3bdbc646 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rs
@@ -22,6 +22,7 @@ async fn varied_queries_against_one_forbidden_endpoint_stop_on_first_failure() {
let handle = SteeringHandle::allow_all();
let slot = std::sync::Arc::new(std::sync::Mutex::new(None));
let mw = RepeatedToolFailureMiddleware::new(handle.clone(), 3, slot.clone());
+ let mut context = ctx();
let mut call = TaToolCall::new(
"forbidden-1",
"web_fetch",
@@ -29,10 +30,10 @@ async fn varied_queries_against_one_forbidden_endpoint_stop_on_first_failure() {
"url": "https://example.test/restricted?query=first"
}),
);
- mw.before_tool(&mut ctx(), &(), &mut call).await.unwrap();
+ mw.before_tool(&mut context, &(), &mut call).await.unwrap();
let mut result = failing_result("web_fetch", "403 Forbidden");
mw.after_tool(
- &mut ctx(),
+ &mut context,
&(),
&invocation("forbidden-1", "web_fetch"),
&mut result,
@@ -56,16 +57,17 @@ async fn schema_repair_gets_three_attempts_before_stopping() {
let handle = SteeringHandle::allow_all();
let slot = std::sync::Arc::new(std::sync::Mutex::new(None));
let mw = RepeatedToolFailureMiddleware::new(handle.clone(), 8, slot.clone());
+ let mut context = ctx();
for (id, value) in [("schema-1", 1), ("schema-2", 2), ("schema-3", 3)] {
let mut call = TaToolCall::new(
id,
"search",
serde_json::json!({"query": value, "endpoint": "catalog"}),
);
- mw.before_tool(&mut ctx(), &(), &mut call).await.unwrap();
+ mw.before_tool(&mut context, &(), &mut call).await.unwrap();
let mut result =
failing_result("search", "schema validation failed: query must be a string");
- mw.after_tool(&mut ctx(), &(), &invocation(id, "search"), &mut result)
+ mw.after_tool(&mut context, &(), &invocation(id, "search"), &mut result)
.await
.unwrap();
}
@@ -81,10 +83,10 @@ async fn schema_repair_gets_three_attempts_before_stopping() {
"search",
serde_json::json!({"query": 4, "endpoint": "catalog"}),
);
- mw.before_tool(&mut ctx(), &(), &mut call).await.unwrap();
+ mw.before_tool(&mut context, &(), &mut call).await.unwrap();
let mut result = failing_result("search", "schema validation failed: query must be a string");
mw.after_tool(
- &mut ctx(),
+ &mut context,
&(),
&invocation("schema-4", "search"),
&mut result,
@@ -143,19 +145,20 @@ async fn missing_desktop_window_allows_one_rediscovery_then_stops() {
let handle = SteeringHandle::allow_all();
let slot = std::sync::Arc::new(std::sync::Mutex::new(None));
let mw = RepeatedToolFailureMiddleware::new(handle.clone(), 3, slot.clone());
+ let mut context = ctx();
for id in ["window-1", "window-2"] {
let mut call = TaToolCall::new(
id,
"tinydesktop_click",
serde_json::json!({"window_id": 17, "element": id}),
);
- mw.before_tool(&mut ctx(), &(), &mut call).await.unwrap();
+ mw.before_tool(&mut context, &(), &mut call).await.unwrap();
let mut result = failing_result(
"tinydesktop_click",
r#"{"error":{"code":"WINDOW_NOT_FOUND"}}"#,
);
mw.after_tool(
- &mut ctx(),
+ &mut context,
&(),
&invocation(id, "tinydesktop_click"),
&mut result,
@@ -174,15 +177,16 @@ async fn transient_failures_have_two_retries_and_success_clears_only_that_scope(
let handle = SteeringHandle::allow_all();
let slot = std::sync::Arc::new(std::sync::Mutex::new(None));
let mw = RepeatedToolFailureMiddleware::new(handle.clone(), 3, slot.clone());
+ let mut context = ctx();
for (id, endpoint) in [("a1", "alpha"), ("b1", "beta"), ("a2", "alpha")] {
let mut call = TaToolCall::new(
id,
"web_fetch",
serde_json::json!({"endpoint": endpoint, "query": id}),
);
- mw.before_tool(&mut ctx(), &(), &mut call).await.unwrap();
+ mw.before_tool(&mut context, &(), &mut call).await.unwrap();
let mut result = failing_result("web_fetch", "503 Service Unavailable");
- mw.after_tool(&mut ctx(), &(), &invocation(id, "web_fetch"), &mut result)
+ mw.after_tool(&mut context, &(), &invocation(id, "web_fetch"), &mut result)
.await
.unwrap();
}
@@ -192,11 +196,11 @@ async fn transient_failures_have_two_retries_and_success_clears_only_that_scope(
"web_fetch",
serde_json::json!({"endpoint": "alpha"}),
);
- mw.before_tool(&mut ctx(), &(), &mut recovered)
+ mw.before_tool(&mut context, &(), &mut recovered)
.await
.unwrap();
let mut ok = tool_result("web_fetch", "ready");
- mw.after_tool(&mut ctx(), &(), &invocation("a-ok", "web_fetch"), &mut ok)
+ mw.after_tool(&mut context, &(), &invocation("a-ok", "web_fetch"), &mut ok)
.await
.unwrap();
for id in ["b2", "b3"] {
@@ -205,9 +209,9 @@ async fn transient_failures_have_two_retries_and_success_clears_only_that_scope(
"web_fetch",
serde_json::json!({"endpoint": "beta", "query": id}),
);
- mw.before_tool(&mut ctx(), &(), &mut call).await.unwrap();
+ mw.before_tool(&mut context, &(), &mut call).await.unwrap();
let mut result = failing_result("web_fetch", "503 Service Unavailable");
- mw.after_tool(&mut ctx(), &(), &invocation(id, "web_fetch"), &mut result)
+ mw.after_tool(&mut context, &(), &invocation(id, "web_fetch"), &mut result)
.await
.unwrap();
}
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.rs
index e8a94a9021..1a40711389 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
@@ -118,12 +118,13 @@ async fn ordinary_web_fetch_status_ignores_timeout_words_in_body_excerpt() {
let handle = SteeringHandle::allow_all();
let slot = std::sync::Arc::new(std::sync::Mutex::new(None));
let mw = RepeatedToolFailureMiddleware::new(handle.clone(), 3, slot.clone());
+ let mut context = ctx();
let error = "HTTP 404 Not Found from example.com; the page could not be fetched.\nResponse excerpt: request timed out while rendering";
for index in 0..2 {
let mut result = failing_result("web_fetch", error);
mw.after_tool(
- &mut ctx(),
+ &mut context,
&(),
&invocation(format!("fetch-{index}"), "web_fetch"),
&mut result,
@@ -139,7 +140,7 @@ async fn ordinary_web_fetch_status_ignores_timeout_words_in_body_excerpt() {
let mut result = failing_result("web_fetch", error);
mw.after_tool(
- &mut ctx(),
+ &mut context,
&(),
&invocation("fetch-2", "web_fetch"),
&mut result,
@@ -261,15 +262,21 @@ async fn halt_on_missing_connection_asks_the_user_instead_of_reporting_back() {
let handle = SteeringHandle::allow_all();
let slot = std::sync::Arc::new(std::sync::Mutex::new(None));
let mw = RepeatedToolFailureMiddleware::new(handle.clone(), 3, slot.clone());
+ let mut context = ctx();
// Three identical not-connected failures → halt.
for _ in 0..3 {
let mut r = failing_result(
"slack_post",
"Slack is not connected — connect it in Connections.",
);
- mw.after_tool(&mut ctx(), &(), &invocation("slack", "slack_post"), &mut r)
- .await
- .unwrap();
+ mw.after_tool(
+ &mut context,
+ &(),
+ &invocation("slack", "slack_post"),
+ &mut r,
+ )
+ .await
+ .unwrap();
}
let summary = slot
.lock()
@@ -392,6 +399,7 @@ async fn repeated_validate_workflow_ok_false_trips_the_breaker() {
3,
std::sync::Arc::new(std::sync::Mutex::new(None)),
);
+ let mut context = ctx();
let mut halted = false;
// Same invalid graph re-validated repeatedly (same content each time, no
// `error` field): well within the varied-failure any-failure backstop
@@ -403,7 +411,7 @@ async fn repeated_validate_workflow_ok_false_trips_the_breaker() {
);
assert!(!r.is_error, "the tool call itself did not error");
mw.after_tool(
- &mut ctx(),
+ &mut context,
&(),
&invocation("validate", "validate_workflow"),
&mut r,
@@ -480,9 +488,10 @@ async fn existing_error_is_some_behavior_is_unchanged_by_body_level_check() {
3,
std::sync::Arc::new(std::sync::Mutex::new(None)),
);
+ let mut context = ctx();
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();
}
@@ -492,7 +501,7 @@ async fn existing_error_is_some_behavior_is_unchanged_by_body_level_check() {
"no halt before the threshold"
);
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!(
@@ -509,11 +518,12 @@ async fn existing_error_is_some_behavior_is_unchanged_by_body_level_check() {
3,
std::sync::Arc::new(std::sync::Mutex::new(None)),
);
+ let mut context2 = ctx();
for _ in 0..2 {
let mut r = body_failure_result("validate_workflow", json!({}));
r = TaToolResult::error(result_text(&r));
mw2.after_tool(
- &mut ctx(),
+ &mut context2,
&(),
&invocation("validate", "validate_workflow"),
&mut r,
@@ -529,7 +539,7 @@ async fn existing_error_is_some_behavior_is_unchanged_by_body_level_check() {
let mut r = body_failure_result("validate_workflow", json!({}));
r = TaToolResult::error(result_text(&r));
mw2.after_tool(
- &mut ctx(),
+ &mut context2,
&(),
&invocation("validate", "validate_workflow"),
&mut r,