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
Merge upstream/main into bench-6962-deepseek-cache
Steven Enamakel51d274dec5c2
diff --cc crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rsindex 2e1e99b7d8,6fce803e82..d2758f11cf--- a/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rs@@@ -339,98 -340,245 +340,341 @@@ fn a_mistyped_file_path_is_a_correctabl);}+/// Queue one validation/no-progress-style nudge the way a first shell timeout+/// does, and return the middleware holding it.+async fn middleware_with_one_pending_nudge() -> RepeatedToolFailureMiddleware {+ let handle = SteeringHandle::allow_all();+ let slot = std::sync::Arc::new(std::sync::Mutex::new(None));+ let mw = RepeatedToolFailureMiddleware::new(handle, 3, slot);+ let mut call = TaToolCall::new(+ "sh-1",+ "shell",+ serde_json::json!({ "command": "whois a.io" }),+ );+ mw.before_tool(&mut ctx(), &(), &mut call).await.unwrap();+ let mut result = failing_result("shell", "Command timed out after 60s and was killed");+ mw.after_tool(&mut ctx(), &(), &invocation("sh-1", "shell"), &mut result)+ .await+ .unwrap();+ mw+}++fn nudge_request(leading: &TaMessage) -> ModelRequest {+ ModelRequest {+ messages: vec![+ leading.clone(),+ TaMessage::user("look up a.io"),+ TaMessage::tool("sh-1", "Command timed out after 60s and was killed"),+ ],+ ..Default::default()+ }+}++fn system_messages(request: &ModelRequest) -> usize {+ request+ .messages+ .iter()+ .filter(|message| matches!(message, TaMessage::System(_)))+ .count()+}++/// #6962: DeepSeek moves every system turn to the prompt head, so a nudge sent+/// as a new system message reset its prompt cache to the static prefix. For a+/// model whose profile hoists system messages the nudge rides the tail tool+/// result instead, and the leading system message stays byte-identical.+#[tokio::test]+async fn nudges_for_a_hoisting_model_add_no_system_message() {+ let mw = middleware_with_one_pending_nudge().await;+ let mut run_ctx = ctx();+ run_ctx.model_profile = Some(tinyinference_llm::model::ModelProfile {+ hoists_system_messages: true,+ mid_conversation_system_messages: true,+ ..Default::default()+ });+ let leading = TaMessage::system("persona");+ let mut request = nudge_request(&leading);++ mw.nudge_injector()+ .before_model(&mut run_ctx, &(), &mut request)+ .await+ .unwrap();++ assert_eq!(request.messages.len(), 3, "no message added");+ assert_eq!(+ request.messages[0], leading,+ "leading system message untouched"+ );+ assert_eq!(system_messages(&request), 1, "no new system message");+ let tail = request.messages.last().unwrap().text();+ assert!(tail.starts_with("Command timed out"), "{tail}");+ assert!(tail.contains("smaller, bounded"), "nudge delivered: {tail}");+}++/// Other models keep the tail system message the nudge always used.+#[tokio::test]+async fn nudges_for_other_models_stay_tail_system_messages() {+ let mw = middleware_with_one_pending_nudge().await;+ let leading = TaMessage::system("persona");+ let mut request = nudge_request(&leading);++ mw.nudge_injector()+ .before_model(&mut ctx(), &(), &mut request)+ .await+ .unwrap();++ assert_eq!(request.messages.len(), 4);+ assert_eq!(request.messages[0], leading);+ assert!(matches!(+ request.messages.last(),+ Some(TaMessage::System(_))+ ));+ assert!(request+ .messages+ .last()+ .unwrap()+ .text()+ .contains("smaller, bounded"));+}+++ // ── A public site's HTTP status is not OpenHuman's credential (tinytools#47) ──+ //+ // The error strings below are the exact `web_fetch` renderings from+ // tinyhumansai/tinytools#47 (`http_error_message`).++ const FETCH_403: &str =+ "HTTP 403 Forbidden from example.test; the site refused the request. Try another source.";+ const FETCH_429: &str = "HTTP 429 Too Many Requests from example.test; the site is rate limiting requests. Retry-After: 30. Try another source, or retry later.";+ const FETCH_404: &str = "HTTP 404 Not Found from example.test; the page does not exist at this URL. Check the URL or try another source.";+ const FETCH_503: &str = "HTTP 503 Service Unavailable from example.test; the server failed to handle the request. Retry later or try another source.";++ /// Run one failing `tool` call with `url` and `error` through the breaker.+ async fn fail_call(+ mw: &RepeatedToolFailureMiddleware,+ id: &str,+ tool: &str,+ arguments: serde_json::Value,+ error: &str,+ ) {+ let mut call = TaToolCall::new(id, tool, arguments);+ mw.before_tool(&mut ctx(), &(), &mut call).await.unwrap();+ let mut result = failing_result(tool, error);+ mw.after_tool(&mut ctx(), &(), &invocation(id, tool), &mut result)+ .await+ .unwrap();+ }++ fn fetch_args(url: &str) -> serde_json::Value {+ serde_json::json!({ "url": url })+ }++ #[tokio::test]+ async fn one_blocked_website_does_not_stop_the_run() {+ 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());+ fail_call(+ &mw,+ "blocked-1",+ "web_fetch",+ fetch_args("https://example.test/a"),+ FETCH_403,+ )+ .await;+ assert_eq!(drain_pause_count(&handle), 0);+ assert!(slot.lock().unwrap().is_none());+ }++ #[tokio::test]+ async fn repeated_refusals_from_one_host_stop_the_run_after_the_budget() {+ 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());+ // Different pages of one host: a new path must not reset the count.+ for (id, path) in [("r1", "a"), ("r2", "b")] {+ fail_call(+ &mw,+ id,+ "web_fetch",+ fetch_args(&format!("https://example.test/{path}")),+ FETCH_403,+ )+ .await;+ }+ assert_eq!(drain_pause_count(&handle), 0);+ fail_call(+ &mw,+ "r3",+ "web_fetch",+ fetch_args("https://example.test/c?q=3"),+ FETCH_403,+ )+ .await;+ assert_eq!(drain_pause_count(&handle), 1);+ let summary = slot.lock().unwrap().clone().unwrap();+ assert!(summary.contains("site_refused"), "{summary}");+ assert!(summary.contains("example.test"), "{summary}");+ assert!(!summary.contains("authentication"), "{summary}");+ }++ #[tokio::test]+ async fn refusals_from_different_hosts_are_counted_separately() {+ 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, host) in [+ ("h1", "a.test"),+ ("h2", "b.test"),+ ("h3", "c.test"),+ ("h4", "d.test"),+ ] {+ fail_call(+ &mw,+ id,+ "web_fetch",+ fetch_args(&format!("https://{host}/page")),+ &FETCH_403.replace("example.test", host),+ )+ .await;+ }+ assert_eq!(drain_pause_count(&handle), 0);+ }++ #[tokio::test]+ async fn a_good_fetch_from_a_host_clears_its_refusal_count() {+ 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 ["c1", "c2"] {+ fail_call(+ &mw,+ id,+ "web_fetch",+ fetch_args("https://example.test/a"),+ FETCH_403,+ )+ .await;+ }+ let mut call = TaToolCall::new("c-ok", "web_fetch", fetch_args("https://example.test/open"));+ mw.before_tool(&mut ctx(), &(), &mut call).await.unwrap();+ let mut ok = tool_result(+ "web_fetch",+ "status=200 url=https://example.test/open\nhello",+ );+ mw.after_tool(&mut ctx(), &(), &invocation("c-ok", "web_fetch"), &mut ok)+ .await+ .unwrap();+ for id in ["c3", "c4"] {+ fail_call(+ &mw,+ id,+ "web_fetch",+ fetch_args("https://example.test/b"),+ FETCH_403,+ )+ .await;+ }+ assert_eq!(drain_pause_count(&handle), 0);+ }++ #[tokio::test]+ async fn a_credentialed_endpoint_still_stops_on_the_first_403() {+ // The site-refusal exemption is for `web_fetch` of a public URL. The same+ // wording from a tool that talks to an account-bound API is still a+ // credential failure with no retry budget.+ 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());+ fail_call(+ &mw,+ "cred-1",+ "composio_execute",+ serde_json::json!({"endpoint": "github/repos", "account_id": "acct-1"}),+ FETCH_403,+ )+ .await;+ assert_eq!(drain_pause_count(&handle), 1);+ let summary = slot.lock().unwrap().clone().unwrap();+ assert!(summary.contains("authentication"), "{summary}");+ }++ #[test]+ fn fetched_site_statuses_map_to_recovery_budgets() {+ let policy = super::super::repeated_failure::recovery_policy;+ assert_eq!(+ policy("web_fetch", FETCH_403, false),+ Some(("site_refused", 2))+ );+ assert_eq!(+ policy("web_fetch", FETCH_429, false),+ Some(("transient", 2))+ );+ assert_eq!(+ policy("web_fetch", FETCH_503, false),+ Some(("transient", 2))+ );+ // A missing page is an ordinary failure: the exact-repeat guard handles it.+ assert_eq!(policy("web_fetch", FETCH_404, false), None);+ // Bare statuses from web_fetch (no host shape) keep today's meaning.+ assert_eq!(+ policy("web_fetch", "403 Forbidden", false),+ Some(("authentication", 0))+ );+ // The same shape from another tool is not exempt.+ assert_eq!(+ policy("composio_execute", FETCH_403, false),+ Some(("authentication", 0))+ );+ }++ #[test]+ fn a_quoted_response_body_does_not_change_the_fetch_verdict() {+ let policy = super::super::repeated_failure::recovery_policy;+ let not_found = format!("{FETCH_404}\nResponse excerpt: 403 Forbidden unauthorized");+ assert_eq!(policy("web_fetch", ¬_found, false), None);+ let refused = format!("{FETCH_403}\nResponse excerpt: service unavailable, timed out");+ assert_eq!(+ policy("web_fetch", &refused, false),+ Some(("site_refused", 2))+ );+ }++ #[test]+ fn web_fetch_failure_scope_is_the_host_not_the_page() {+ let scope = super::super::repeated_failure::failure_scope;+ assert_eq!(+ scope("web_fetch", &fetch_args("https://example.test/a?q=1")),+ scope("web_fetch", &fetch_args("https://example.test/b/c"))+ );+ assert_ne!(+ scope("web_fetch", &fetch_args("https://example.test/a")),+ scope("web_fetch", &fetch_args("https://other.test/a"))+ );+ }++ #[test]+ fn fetched_site_status_reads_only_the_web_fetch_error_shape() {+ let status = super::super::fetched_site::fetched_site_status;+ assert_eq!(status(FETCH_403), Some(403));+ assert_eq!(status(FETCH_429), Some(429));+ assert_eq!(status(FETCH_404), Some(404));+ assert_eq!(status(FETCH_503), Some(503));+ assert_eq!(+ status(" HTTP 403 Forbidden from 127.0.0.1; the site refused it."),+ Some(403)+ );+ // Bare statuses, other tools' wording, success codes, and the shape+ // buried mid-text are not the shape.+ for text in [+ "HTTP 403 Forbidden",+ "HTTP 403",+ "403 Forbidden",+ "Gmail API error: 403 insufficient scopes",+ "Command failed (exit 1)\nHTTP 403 Forbidden from example.test; x",+ "HTTP 2000 Weird from example.test; x",+ "HTTP 200 OK from example.test; x",+ "HTTP 403 Forbidden from ; x",+ "HTTP 403 Forbidden from example.test no semicolon",+ ] {+ assert_eq!(status(text), None, "{text}");+ }+ }