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
Split classified failure tests for Rust layout gate
Steven Enamakeld30e0088c27b
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.rsnew file mode 100644index 0000000000..d9b26582d0--- /dev/null+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rs@@ -0,0 +1,224 @@+use super::*;++#[tokio::test]+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 call = TaToolCall::new(+ "forbidden-1",+ "web_fetch",+ serde_json::json!({+ "url": "https://example.test/restricted?query=first"+ }),+ );+ mw.before_tool(&mut ctx(), &(), &mut call).await.unwrap();+ let mut result = failing_result("web_fetch", "403 Forbidden");+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("forbidden-1", "web_fetch"),+ &mut result,+ )+ .await+ .unwrap();+ assert_eq!(drain_pause_count(&handle), 1);+ let summary = slot.lock().unwrap().clone().unwrap();+ assert!(summary.contains("authentication"), "{summary}");+ assert!(summary.contains("example.test/restricted"), "{summary}");+ assert!(!summary.contains("query=first"), "{summary}");+}++#[tokio::test]+async fn schema_repair_gets_one_attempt_even_when_arguments_change() {+ 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());+ for (id, value) in [("schema-1", 1), ("schema-2", 2)] {+ let mut call = TaToolCall::new(+ id,+ "search",+ serde_json::json!({"query": value, "endpoint": "catalog"}),+ );+ mw.before_tool(&mut ctx(), &(), &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)+ .await+ .unwrap();+ }+ assert_eq!(drain_pause_count(&handle), 1);+ let summary = slot.lock().unwrap().clone().unwrap();+ assert!(summary.contains("validation"), "{summary}");+ assert!(summary.contains("2 attempt(s)"), "{summary}");+}++#[tokio::test]+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());+ 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();+ let mut result = failing_result(+ "tinydesktop_click",+ r#"{"error":{"code":"WINDOW_NOT_FOUND"}}"#,+ );+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation(id, "tinydesktop_click"),+ &mut result,+ )+ .await+ .unwrap();+ }+ assert_eq!(drain_pause_count(&handle), 1);+ let summary = slot.lock().unwrap().clone().unwrap();+ assert!(summary.contains("missing_window"), "{summary}");+ assert!(summary.contains("17"), "{summary}");+}++#[tokio::test]+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());+ 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();+ let mut result = failing_result("web_fetch", "503 Service Unavailable");+ mw.after_tool(&mut ctx(), &(), &invocation(id, "web_fetch"), &mut result)+ .await+ .unwrap();+ }+ assert_eq!(drain_pause_count(&handle), 0);+ let mut recovered = TaToolCall::new(+ "a-ok",+ "web_fetch",+ serde_json::json!({"endpoint": "alpha"}),+ );+ mw.before_tool(&mut ctx(), &(), &mut recovered)+ .await+ .unwrap();+ let mut ok = tool_result("web_fetch", "ready");+ mw.after_tool(&mut ctx(), &(), &invocation("a-ok", "web_fetch"), &mut ok)+ .await+ .unwrap();+ for id in ["b2", "b3"] {+ let mut call = TaToolCall::new(+ id,+ "web_fetch",+ serde_json::json!({"endpoint": "beta", "query": id}),+ );+ mw.before_tool(&mut ctx(), &(), &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)+ .await+ .unwrap();+ }+ assert_eq!(drain_pause_count(&handle), 1);+ let summary = slot.lock().unwrap().clone().unwrap();+ assert!(summary.contains("3 attempt(s)"), "{summary}");+ assert!(summary.contains("beta"), "{summary}");+}++#[test]+fn uncertain_timeout_requires_reconciliation() {+ assert_eq!(+ super::super::repeated_failure::recovery_policy("gmail_send", "timed out", false),+ Some(("uncertain_side_effect", 0))+ );+ assert_eq!(+ super::super::repeated_failure::recovery_policy("web_fetch", "timed out", false),+ Some(("transient", 2))+ );+}++#[test]+fn structured_status_precedes_ambiguous_error_prose() {+ assert_eq!(+ super::super::repeated_failure::recovery_policy(+ "search",+ r#"{"status_code":403,"message":"try again later"}"#,+ false+ ),+ Some(("permission", 0))+ );+ assert_eq!(+ super::super::repeated_failure::recovery_policy(+ "search",+ r#"{"error":{"code":"INVALID_ARGUMENT"}}"#,+ false+ ),+ Some(("validation", 1))+ );+ assert_eq!(+ super::super::repeated_failure::recovery_policy(+ "tinydesktop_click",+ r#"{"error":{"code":"WINDOW_NOT_FOUND"}}"#,+ false+ ),+ Some(("missing_window", 1))+ );+}++#[test]+fn failure_scope_keeps_resource_and_permission_context_but_ignores_query() {+ let first = super::super::repeated_failure::failure_scope(+ "web_fetch",+ &serde_json::json!({"account_id": "team-a", "url": "https://example.test/restricted?q=one"}),+ );+ let second = super::super::repeated_failure::failure_scope(+ "web_fetch",+ &serde_json::json!({"account_id": "team-a", "url": "https://example.test/restricted?q=two"}),+ );+ let other = super::super::repeated_failure::failure_scope(+ "web_fetch",+ &serde_json::json!({"account_id": "team-b", "url": "https://example.test/restricted?q=two"}),+ );+ assert_eq!(first, second);+ assert_ne!(first, other);+ assert!(!first.contains("q="));+ assert_ne!(+ super::super::repeated_failure::failure_scope(+ "desktop_click",+ &serde_json::json!({"app":"Browser", "window_id": 1})+ ),+ super::super::repeated_failure::failure_scope(+ "desktop_click",+ &serde_json::json!({"app":"Browser", "window_id": 2})+ ),+ );+}++#[tokio::test]+async fn legitimate_wait_polling_does_not_consume_transient_budget() {+ let handle = SteeringHandle::allow_all();+ let mw = RepeatedToolFailureMiddleware::new(+ handle.clone(),+ 3,+ std::sync::Arc::new(std::sync::Mutex::new(None)),+ );+ for id in 0..5 {+ let mut result = failing_result("wait_subagent", "timed out waiting for child");+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation(format!("wait-{id}"), "wait_subagent"),+ &mut result,+ )+ .await+ .unwrap();+ }+ assert_eq!(drain_pause_count(&handle), 0);+}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 36bd673a3e..685b8249f5 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@@ -1,228 +1,5 @@use super::*;-#[tokio::test]-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 call = TaToolCall::new(- "forbidden-1",- "web_fetch",- serde_json::json!({- "url": "https://example.test/restricted?query=first"- }),- );- mw.before_tool(&mut ctx(), &(), &mut call).await.unwrap();- let mut result = failing_result("web_fetch", "403 Forbidden");- mw.after_tool(- &mut ctx(),- &(),- &invocation("forbidden-1", "web_fetch"),- &mut result,- )- .await- .unwrap();- assert_eq!(drain_pause_count(&handle), 1);- let summary = slot.lock().unwrap().clone().unwrap();- assert!(summary.contains("authentication"), "{summary}");- assert!(summary.contains("example.test/restricted"), "{summary}");- assert!(!summary.contains("query=first"), "{summary}");-}--#[tokio::test]-async fn schema_repair_gets_one_attempt_even_when_arguments_change() {- 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());- for (id, value) in [("schema-1", 1), ("schema-2", 2)] {- let mut call = TaToolCall::new(- id,- "search",- serde_json::json!({"query": value, "endpoint": "catalog"}),- );- mw.before_tool(&mut ctx(), &(), &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)- .await- .unwrap();- }- assert_eq!(drain_pause_count(&handle), 1);- let summary = slot.lock().unwrap().clone().unwrap();- assert!(summary.contains("validation"), "{summary}");- assert!(summary.contains("2 attempt(s)"), "{summary}");-}--#[tokio::test]-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());- 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();- let mut result = failing_result(- "tinydesktop_click",- r#"{"error":{"code":"WINDOW_NOT_FOUND"}}"#,- );- mw.after_tool(- &mut ctx(),- &(),- &invocation(id, "tinydesktop_click"),- &mut result,- )- .await- .unwrap();- }- assert_eq!(drain_pause_count(&handle), 1);- let summary = slot.lock().unwrap().clone().unwrap();- assert!(summary.contains("missing_window"), "{summary}");- assert!(summary.contains("17"), "{summary}");-}--#[tokio::test]-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());- 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();- let mut result = failing_result("web_fetch", "503 Service Unavailable");- mw.after_tool(&mut ctx(), &(), &invocation(id, "web_fetch"), &mut result)- .await- .unwrap();- }- assert_eq!(drain_pause_count(&handle), 0);- let mut recovered = TaToolCall::new(- "a-ok",- "web_fetch",- serde_json::json!({"endpoint": "alpha"}),- );- mw.before_tool(&mut ctx(), &(), &mut recovered)- .await- .unwrap();- let mut ok = tool_result("web_fetch", "ready");- mw.after_tool(&mut ctx(), &(), &invocation("a-ok", "web_fetch"), &mut ok)- .await- .unwrap();- for id in ["b2", "b3"] {- let mut call = TaToolCall::new(- id,- "web_fetch",- serde_json::json!({"endpoint": "beta", "query": id}),- );- mw.before_tool(&mut ctx(), &(), &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)- .await- .unwrap();- }- assert_eq!(drain_pause_count(&handle), 1);- let summary = slot.lock().unwrap().clone().unwrap();- assert!(summary.contains("3 attempt(s)"), "{summary}");- assert!(summary.contains("beta"), "{summary}");-}--#[test]-fn uncertain_timeout_requires_reconciliation() {- assert_eq!(- super::super::repeated_failure::recovery_policy("gmail_send", "timed out", false),- Some(("uncertain_side_effect", 0))- );- assert_eq!(- super::super::repeated_failure::recovery_policy("web_fetch", "timed out", false),- Some(("transient", 2))- );-}--#[test]-fn structured_status_precedes_ambiguous_error_prose() {- assert_eq!(- super::super::repeated_failure::recovery_policy(- "search",- r#"{"status_code":403,"message":"try again later"}"#,- false- ),- Some(("permission", 0))- );- assert_eq!(- super::super::repeated_failure::recovery_policy(- "search",- r#"{"error":{"code":"INVALID_ARGUMENT"}}"#,- false- ),- Some(("validation", 1))- );- assert_eq!(- super::super::repeated_failure::recovery_policy(- "tinydesktop_click",- r#"{"error":{"code":"WINDOW_NOT_FOUND"}}"#,- false- ),- Some(("missing_window", 1))- );-}--#[test]-fn failure_scope_keeps_resource_and_permission_context_but_ignores_query() {- let first = super::super::repeated_failure::failure_scope(- "web_fetch",- &serde_json::json!({"account_id": "team-a", "url": "https://example.test/restricted?q=one"}),- );- let second = super::super::repeated_failure::failure_scope(- "web_fetch",- &serde_json::json!({"account_id": "team-a", "url": "https://example.test/restricted?q=two"}),- );- let other = super::super::repeated_failure::failure_scope(- "web_fetch",- &serde_json::json!({"account_id": "team-b", "url": "https://example.test/restricted?q=two"}),- );- assert_eq!(first, second);- assert_ne!(first, other);- assert!(!first.contains("q="));- assert_ne!(- super::super::repeated_failure::failure_scope(- "desktop_click",- &serde_json::json!({"app":"Browser", "window_id": 1})- ),- super::super::repeated_failure::failure_scope(- "desktop_click",- &serde_json::json!({"app":"Browser", "window_id": 2})- ),- );-}--#[tokio::test]-async fn legitimate_wait_polling_does_not_consume_transient_budget() {- let handle = SteeringHandle::allow_all();- let mw = RepeatedToolFailureMiddleware::new(- handle.clone(),- 3,- std::sync::Arc::new(std::sync::Mutex::new(None)),- );- for id in 0..5 {- let mut result = failing_result("wait_subagent", "timed out waiting for child");- mw.after_tool(- &mut ctx(),- &(),- &invocation(format!("wait-{id}"), "wait_subagent"),- &mut result,- )- .await- .unwrap();- }- assert_eq!(drain_pause_count(&handle), 0);-}-#[tokio::test]async fn sampling_tool_output_still_hits_the_byte_budget_backstop() {// Unlike the proposal tools, sampling tools are deliberately NOTdiff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rsindex 2126897d5d..5798eb9769 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs@@ -480,6 +480,8 @@ fn embedder_hook_mw(#[path = "middleware_approval_guard_tests.rs"]mod approval_guard_tests;+#[path = "middleware_classified_failure_tests.rs"]+mod classified_failure_tests;#[path = "middleware_loop_guard_tests.rs"]mod loop_guard_tests;#[path = "middleware_prompt_cache_tests.rs"]