Skip to content

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

fix(middleware): prevent body excerpt from masking ordinary site failures

Steven Enamakelc5313e52117c
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs
index 7944ad8f25..7aa42913a2 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs
@@ -476,6 +476,16 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
false if body_level_failure => content.clone(),
false => String::new(),
};
+ // For an ordinary fetched-site status (404, 410, etc.), the response
+ // body is untrusted excerpt text. It must not turn the site failure
+ // into a terminal inference or transient tool failure. Keep the full
+ // text below for the exact-repeat tracker and its user-facing summary.
+ let heuristic_failure_text = if fetched_site_policy(tool_name, &failure_text) == Some(None)
+ {
+ failure_text.lines().next().unwrap_or(&failure_text)
+ } else {
+ &failure_text
+ };
if !result.is_error && !body_level_failure {
// Only a successful observation against this operation and scope
@@ -559,7 +569,7 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
// a provider error (a script calling an API) without the agent's own
// inference having failed.
if result.is_error && !is_command_exit_report(&failure_text) {
- if let Some(kind) = terminal_inference_failure_kind(&failure_text) {
+ if let Some(kind) = terminal_inference_failure_kind(heuristic_failure_text) {
tracing::warn!(
tool = tool_name,
kind = ?kind,
@@ -605,9 +615,9 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
let recoverable = result.is_error
&& !hard_reject
&& !is_command_exit_report(&failure_text)
- && (is_recoverable_tool_failure(&failure_text)
+ && (is_recoverable_tool_failure(heuristic_failure_text)
|| matches!(
- crate::tools::status::classify(&failure_text, false).class,
+ crate::tools::status::classify(heuristic_failure_text, false).class,
crate::tools::status::ToolFailureClass::Timeout
| crate::tools::status::ToolFailureClass::ServiceUnavailable
| crate::tools::status::ToolFailureClass::ModelConnection
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 29d937e3a2..7543d469a1 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
@@ -143,6 +143,53 @@ async fn repeated_tool_failure_pauses_only_after_the_threshold() {
);
}
+#[tokio::test]
+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 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(),
+ &(),
+ &invocation(format!("fetch-{index}"), "web_fetch"),
+ &mut result,
+ )
+ .await
+ .unwrap();
+ }
+ assert_eq!(
+ drain_pause_count(&handle),
+ 0,
+ "the ordinary site failure should remain below the exact-repeat halt threshold"
+ );
+
+ let mut result = failing_result("web_fetch", error);
+ mw.after_tool(
+ &mut ctx(),
+ &(),
+ &invocation("fetch-2", "web_fetch"),
+ &mut result,
+ )
+ .await
+ .unwrap();
+
+ assert_eq!(
+ drain_pause_count(&handle),
+ 1,
+ "the body excerpt must not divert an ordinary site error into transient-failure handling"
+ );
+ let summary = slot
+ .lock()
+ .unwrap()
+ .clone()
+ .expect("exact-repeat halt summary");
+ assert!(summary.contains("404") && summary.contains("timed out"));
+}
+
#[tokio::test]
async fn repeated_tool_failure_resets_on_a_success() {
let handle = SteeringHandle::allow_all();