Skip to content

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

feat(status): classify web_fetch HTTP errors as site failures, not credential issues

Steven Enamakel35cbd9d8c1c9
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 f4f3322e45..e1b7d725db 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
@@ -338,3 +338,210 @@ fn a_mistyped_file_path_is_a_correctable_call_not_a_missing_program() {
Some(("unsupported", 0))
);
}
+
+// ── 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", &not_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"))
+ );
+}
diff --git a/crates/openhuman-core/src/tools/status/mod.rs b/crates/openhuman-core/src/tools/status/mod.rs
index 76bc7a363e..e166705f7f 100644
--- a/crates/openhuman-core/src/tools/status/mod.rs
+++ b/crates/openhuman-core/src/tools/status/mod.rs
@@ -16,7 +16,7 @@
mod ops;
mod types;
-pub use ops::{classify, describe, tool_execution_error};
+pub use ops::{classify, describe, fetched_site_status, tool_execution_error};
pub use types::{
ClassifiedFailure, FailureCategory, ToolFailureClass, ToolLifecycleState, MODULE_FAULT_MARKER,
NOT_FOUND_MARKER, UNSUPPORTED_MARKER,
diff --git a/crates/openhuman-core/src/tools/status/ops.rs b/crates/openhuman-core/src/tools/status/ops.rs
index 400940346d..36d315da55 100644
--- a/crates/openhuman-core/src/tools/status/ops.rs
+++ b/crates/openhuman-core/src/tools/status/ops.rs
@@ -25,6 +25,11 @@ pub fn classify(error_text: &str, timed_out: bool) -> ClassifiedFailure {
describe(class)
}
+/// Stub (RED step).
+pub fn fetched_site_status(_text: &str) -> Option<u16> {
+ None
+}
+
/// The prefix the agent tool adapter puts on an error a tool returned as `Err`.
/// [`tool_execution_error`] is its only producer, so the classifier and the
/// adapter cannot drift apart.
diff --git a/crates/openhuman-core/src/tools/status/ops_tests.rs b/crates/openhuman-core/src/tools/status/ops_tests.rs
index 58f7508b2a..22aff800e5 100644
--- a/crates/openhuman-core/src/tools/status/ops_tests.rs
+++ b/crates/openhuman-core/src/tools/status/ops_tests.rs
@@ -260,3 +260,69 @@ fn recoverable_flag_matches_category() {
assert!(!classify("permission denied (os error 13)", false).recoverable);
assert!(!classify("blocked by policy", false).recoverable);
}
+
+// ── A public site's HTTP status is not OpenHuman's credential (tinytools#47) ──
+//
+// `web_fetch` reports a 4xx/5xx from the site it fetched as
+// `HTTP <code> <reason> from <host>; <guidance>`. The site refusing a request
+// says nothing about OpenHuman's own sign-in, so the bare-status keyword rules
+// must not claim it.
+
+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.";
+
+#[test]
+fn fetched_site_status_reads_the_web_fetch_error_shape() {
+ assert_eq!(fetched_site_status(FETCH_403), Some(403));
+ assert_eq!(fetched_site_status(FETCH_429), Some(429));
+ assert_eq!(fetched_site_status(FETCH_404), Some(404));
+ assert_eq!(fetched_site_status(FETCH_503), Some(503));
+ assert_eq!(
+ fetched_site_status(" HTTP 403 Forbidden from 127.0.0.1; the site refused it."),
+ Some(403)
+ );
+}
+
+#[test]
+fn fetched_site_status_ignores_text_that_only_resembles_the_shape() {
+ // Bare statuses, other tools' wording, and the shape buried mid-text.
+ assert_eq!(fetched_site_status("HTTP 403 Forbidden"), None);
+ assert_eq!(fetched_site_status("HTTP 403"), None);
+ assert_eq!(fetched_site_status("403 Forbidden"), None);
+ assert_eq!(
+ fetched_site_status("Gmail API error: 403 insufficient scopes"),
+ None
+ );
+ assert_eq!(
+ fetched_site_status("Command failed (exit 1)\nHTTP 403 Forbidden from example.test; x"),
+ None
+ );
+ assert_eq!(fetched_site_status("HTTP 2000 Weird from example.test; x"), None);
+ assert_eq!(fetched_site_status("HTTP 403 Forbidden from ; x"), None);
+}
+
+#[test]
+fn a_fetched_sites_403_is_not_a_credential_failure() {
+ assert_ne!(class_of(FETCH_403), ToolFailureClass::BadCredentials);
+ assert_ne!(class_of(FETCH_403), ToolFailureClass::BlockedByPolicy);
+ // Body excerpts quoted back by the tool must not steer the class either.
+ let with_excerpt = format!("{FETCH_403}\nResponse excerpt: unauthorized, invalid api key");
+ assert_ne!(class_of(&with_excerpt), ToolFailureClass::BadCredentials);
+}
+
+#[test]
+fn a_fetched_sites_other_statuses_keep_their_ordinary_classes() {
+ assert_eq!(class_of(FETCH_429), ToolFailureClass::ServiceUnavailable);
+ assert_eq!(class_of(FETCH_503), ToolFailureClass::ServiceUnavailable);
+ assert_eq!(class_of(FETCH_404), ToolFailureClass::NotFound);
+}
+
+#[test]
+fn bare_status_text_still_means_credentials() {
+ // The credentialed-API protection: no `from <host>;` shape, no exemption.
+ assert_eq!(class_of("HTTP 403 Forbidden"), ToolFailureClass::BadCredentials);
+ assert_eq!(class_of("403 Forbidden"), ToolFailureClass::BadCredentials);
+}