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/repeat_loop_stop.rs,crate

Steven Enamakel873399c7fcb1
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/repeat_loop_stop.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/repeat_loop_stop.rs
index 53b16ab977..cb8e8d5b9c 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/repeat_loop_stop.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/repeat_loop_stop.rs
@@ -13,6 +13,7 @@
//! instead.
use std::collections::HashSet;
+use std::hash::{Hash, Hasher};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Mutex;
@@ -41,7 +42,8 @@ pub(super) fn is_correctable_class(class: &str) -> bool {
/// failing calls in the current run.
#[derive(Default)]
pub(super) struct RepeatLoopWitness {
- /// `tool\u{1f}argument-fingerprint` of every call that failed so far.
+ /// `tool\u{1f}argument-fingerprint\u{1f}outcome-hash` of every failure so
+ /// far.
failed_calls: Mutex<HashSet<String>>,
/// Calls the repeat guard refused since the last successful call.
refusals_since_progress: AtomicUsize,
@@ -64,10 +66,21 @@ impl RepeatLoopWitness {
self.refusals_since_progress.load(Ordering::SeqCst)
}
- /// A call failed. Returns whether the same tool already failed with the
- /// same arguments earlier in this run (an identical re-issue).
- pub(super) fn record_failure(&self, tool: &str, arg_fingerprint: &str) -> bool {
- let key = format!("{tool}\u{1f}{arg_fingerprint}");
+ /// A call failed with `failure_text`. Returns whether the same tool
+ /// already failed with the same arguments and the same outcome earlier
+ /// in this run (an identical re-issue). The outcome is compared with its
+ /// volatile spans (timestamps, durations, request ids) normalised away; a
+ /// retry that fails differently (a task that got further, a different
+ /// error) is new evidence, not a repeat.
+ pub(super) fn record_failure(
+ &self,
+ tool: &str,
+ arg_fingerprint: &str,
+ failure_text: &str,
+ ) -> bool {
+ let mut hasher = std::collections::hash_map::DefaultHasher::new();
+ tinyagents_harness::no_progress::normalize_volatile(failure_text).hash(&mut hasher);
+ let key = format!("{tool}\u{1f}{arg_fingerprint}\u{1f}{:x}", hasher.finish());
let Ok(mut failed) = self.failed_calls.lock() else {
return false;
};
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/repeat_loop_stop_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/repeat_loop_stop_tests.rs
index b47476e88c..a38c898281 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/repeat_loop_stop_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/repeat_loop_stop_tests.rs
@@ -4,10 +4,20 @@ use crate::agent::session_host::stop_summary::StopReasonKind;
#[test]
fn only_an_identical_re_issue_counts_as_a_repeated_failure() {
let witness = RepeatLoopWitness::default();
- assert!(!witness.record_failure("file_read", "a"));
- assert!(!witness.record_failure("file_read", "b"));
- assert!(!witness.record_failure("grep", "a"));
- assert!(witness.record_failure("file_read", "a"));
+ assert!(!witness.record_failure("file_read", "a", "No such file"));
+ assert!(!witness.record_failure("file_read", "b", "No such file"));
+ assert!(!witness.record_failure("grep", "a", "No such file"));
+ assert!(witness.record_failure("file_read", "a", "No such file"));
+}
+
+#[test]
+fn a_retry_that_fails_differently_is_not_a_repeat() {
+ let witness = RepeatLoopWitness::default();
+ assert!(!witness.record_failure("browser_task", "a", "Task ended at step 2"));
+ assert!(!witness.record_failure("browser_task", "a", "Task ended at step 5"));
+ // Only volatile spans differ: still the same outcome.
+ assert!(!witness.record_failure("fetch", "u", "timed out after 31s"));
+ assert!(witness.record_failure("fetch", "u", "timed out after 47s"));
}
#[test]
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 fb1e9742d0..a13f1e28fe 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs
@@ -426,7 +426,11 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
};
let heuristic_failure_text = heuristic_text(tool_name, &failure_text);
let failed = result.is_error || body_level_failure;
- let repeated_failure = failed && self.stop.witness().record_failure(tool_name, &arg_fp);
+ let repeated_failure = failed
+ && self
+ .stop
+ .witness()
+ .record_failure(tool_name, &arg_fp, &failure_text);
if !failed {
self.stop.record_success();