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
fix(agent): fingerprint repeat results after every result rewrite
M3gA-Mind1893c52a7f81
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rsindex b70a8aa3a4..fa8497fa53 100644--- a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs+++ b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs@@ -267,17 +267,43 @@ pub(super) fn assemble_turn_harness(};let handle = Some(orchestration::openhuman_steering_handle(steering_run_class));+ // Shared by the two breakers below: whichever halts writes the root cause here.+ let halt_summary: HaltSummarySlot = std::sync::Arc::new(std::sync::Mutex::new(None));++ // Repeat-progress breaker (issue #4463, restoring #4088 / #4095): the failure+ // breaker below resets on every success, so a model looping on a *successful*+ // no-op tool or re-emitting an identical narration+call never trips it. This+ // guard halts on identical successful `(tool, args)` batches / identical+ // outputs, and on one call returning the identical result again with other+ // calls in between (#6275), sharing the same halt-summary slot + steering+ // handle. Polling tools (`wait_subagent`) stay exempt.+ //+ // Pushed first / outermost: `after_tool` runs in reverse registration order,+ // so this guard fingerprints a result only after every other middleware+ // (byte cap, summarizer, memory-protocol note) has finished rewriting it,+ // i.e. exactly what the model sees. Registered any later, a result whose+ // visible note changed between calls would count as identical.+ let repeat_progress = handle.as_ref().map(|handle| {+ Arc::new(middleware::RepeatProgressMiddleware::new(+ handle.clone(),+ halt_summary.clone(),+ ))+ });+ if let Some(mw) = &repeat_progress {+ harness.push_middleware(mw.clone());+ }+// Memory protocol (issue #4116): observe the read → dedupe → write →// update-index cycle and append a corrective note when a write skips the- // dedupe read or leaves the index stale. Pushed first / outermost so its- // `after_tool` runs *after* the byte-cap truncation, keeping the note.+ // dedupe read or leaves the index stale. Pushed ahead of every other+ // result-rewriting middleware so its `after_tool` runs *after* the byte-cap+ // truncation, keeping the note.harness.push_middleware(Arc::new(middleware::MemoryProtocolMiddleware::new()));// Repeated-failure circuit breaker: pause the run when a tool returns the same// error `REPEATED_TOOL_FAILURE_THRESHOLD` times in a row, so a deterministic// security/approval denial or terminal tool error surfaces its root cause// instead of burning the whole iteration budget (legacy ProgressGuard parity).- let halt_summary: HaltSummarySlot = std::sync::Arc::new(std::sync::Mutex::new(None));if let Some(handle) = &handle {harness.push_middleware(Arc::new(middleware::RepeatedToolFailureMiddleware::new(handle.clone(),@@ -286,22 +312,6 @@ pub(super) fn assemble_turn_harness()));}- // Repeat-progress breaker (issue #4463, restoring #4088 / #4095): the failure- // breaker above resets on every success, so a model looping on a *successful*- // no-op tool or re-emitting an identical narration+call never trips it. This- // guard halts on identical successful `(tool, args)` batches / identical- // outputs, sharing the same halt-summary slot + steering handle. Polling tools- // (`wait_subagent`) stay exempt.- let repeat_progress = handle.as_ref().map(|handle| {- Arc::new(middleware::RepeatProgressMiddleware::new(- handle.clone(),- halt_summary.clone(),- ))- });- if let Some(mw) = &repeat_progress {- harness.push_middleware(mw.clone());- }-// Policy-driven stop hooks (budget cap, thread-goal budget, ad-hoc iteration// ceiling): fire after each model call and pause the run on the first stop// vote. Replaces the legacy tool-call-loop firing point.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 9ceeb2d061..891ecc43cc 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@@ -528,142 +528,6 @@ async fn successful_repeat_tracker_resets_failed_and_exempt_batches() {);}-// ── #6275: repeats that are not back to back ────────────────────────────--/// One A, B round of two different successful calls, each returning the given-/// output. The adjacent-batch streak restarts on every step of such a cycle.-async fn run_alternating_round(mw: &RepeatProgressMiddleware, a_output: &str, b_output: &str) {- run_successful_repeat_cycle(mw, "use_skill", json!({"skill": "skills"}), a_output, None).await;- run_successful_repeat_cycle(- mw,- "use_skill",- json!({"skill": "skills", "tool": "skill_search"}),- b_output,- None,- )- .await;-}--#[tokio::test]-async fn alternating_identical_successful_calls_halt_on_recurrence() {- let handle = SteeringHandle::allow_all();- let summary = std::sync::Arc::new(std::sync::Mutex::new(None));- let mw = RepeatProgressMiddleware::new(handle.clone(), summary.clone());-- for _ in 0..DEFAULT_REPEAT_CALL_THRESHOLD - 1 {- run_alternating_round(&mw, "doc", "hits").await;- }- assert_eq!(drain_pause_count(&handle), 0);-- run_successful_repeat_cycle(&mw, "use_skill", json!({"skill": "skills"}), "doc", None).await;- assert_eq!(- drain_pause_count(&handle),- 1,- "an alternating call returning the identical result for the third time must halt the run"- );- assert!(- summary- .lock()- .unwrap()- .as_deref()- .is_some_and(|text| text.contains("identical result")),- "the recurrence halt summary should reach the host turn result"- );-}--#[tokio::test]-async fn alternating_calls_whose_output_changed_do_not_halt() {- let handle = SteeringHandle::allow_all();- let mw = RepeatProgressMiddleware::new(- handle.clone(),- std::sync::Arc::new(std::sync::Mutex::new(None)),- );- for i in 0..DEFAULT_REPEAT_CALL_THRESHOLD * 3 {- run_alternating_round(&mw, &format!("doc-{i}"), &format!("hits-{i}")).await;- }- assert_eq!(- drain_pause_count(&handle),- 0,- "a re-read with identical arguments whose output changed is progress, not a repeat"- );-}--#[tokio::test]-async fn alternating_exempt_polling_calls_do_not_halt() {- let handle = SteeringHandle::allow_all();- let mw = RepeatProgressMiddleware::new(- handle.clone(),- std::sync::Arc::new(std::sync::Mutex::new(None)),- );- for i in 0..DEFAULT_REPEAT_CALL_THRESHOLD * 3 {- run_successful_repeat_cycle(- &mw,- "wait_subagent",- json!({"task_id": "t"}),- "still running",- None,- )- .await;- let output = format!("status-{i}");- run_successful_repeat_cycle(&mw, "lookup", json!({"id": 1}), &output, None).await;- }- assert_eq!(- drain_pause_count(&handle),- 0,- "identical polling results must not feed the recurrence ledger"- );-}--#[tokio::test]-async fn evicting_a_recorded_result_resets_the_recurrence_ledger() {- // What the last `before_model` sees for the recorded result `repeat-1`:- // untouched, blanked by microcompact, or dropped by compression / trim.- let cases: [(Vec<TaMessage>, usize, &str); 3] = [- (- vec![TaMessage::tool("repeat-1", "doc")],- 1,- "a result still in context keeps counting",- ),- (- vec![TaMessage::tool("repeat-1", CLEARED_PLACEHOLDER)],- 0,- "a result blanked by compaction must not count toward a repeat",- ),- (- vec![],- 0,- "a result dropped by compaction must not count toward a repeat",- ),- ];- for (compacted, expected_pauses, why) in cases {- let handle = SteeringHandle::allow_all();- let mw = RepeatProgressMiddleware::new(- handle.clone(),- std::sync::Arc::new(std::sync::Mutex::new(None)),- );- let observer = mw.eviction_observer();- for _ in 0..DEFAULT_REPEAT_CALL_THRESHOLD - 1 {- run_alternating_round(&mw, "doc", "hits").await;- }-- // The next model call: the guard sees the request before the reduction- // steps run, the observer after them.- let mut request = ModelRequest::new(vec![TaMessage::tool("repeat-1", "doc")]);- mw.before_model(&mut ctx(), &(), &mut request)- .await- .unwrap();- let mut request = ModelRequest::new(compacted);- observer- .before_model(&mut ctx(), &(), &mut request)- .await- .unwrap();-- run_successful_repeat_cycle(&mw, "use_skill", json!({"skill": "skills"}), "doc", None)- .await;- assert_eq!(drain_pause_count(&handle), expected_pauses, "{why}");- }-}-// ── ApprovalSecurityMiddleware ──────────────────────────────────────────#[test]diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_repeat_progress_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_repeat_progress_tests.rsnew file mode 100644index 0000000000..078394a538--- /dev/null+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_repeat_progress_tests.rs@@ -0,0 +1,139 @@+//! Repeat-progress guard tests for repeats that are not back to back (#6275).++use super::*;++// ── #6275: repeats that are not back to back ────────────────────────────++/// One A, B round of two different successful calls, each returning the given+/// output. The adjacent-batch streak restarts on every step of such a cycle.+async fn run_alternating_round(mw: &RepeatProgressMiddleware, a_output: &str, b_output: &str) {+ run_successful_repeat_cycle(mw, "use_skill", json!({"skill": "skills"}), a_output, None).await;+ run_successful_repeat_cycle(+ mw,+ "use_skill",+ json!({"skill": "skills", "tool": "skill_search"}),+ b_output,+ None,+ )+ .await;+}++#[tokio::test]+async fn alternating_identical_successful_calls_halt_on_recurrence() {+ let handle = SteeringHandle::allow_all();+ let summary = std::sync::Arc::new(std::sync::Mutex::new(None));+ let mw = RepeatProgressMiddleware::new(handle.clone(), summary.clone());++ for _ in 0..DEFAULT_REPEAT_CALL_THRESHOLD - 1 {+ run_alternating_round(&mw, "doc", "hits").await;+ }+ assert_eq!(drain_pause_count(&handle), 0);++ run_successful_repeat_cycle(&mw, "use_skill", json!({"skill": "skills"}), "doc", None).await;+ assert_eq!(+ drain_pause_count(&handle),+ 1,+ "an alternating call returning the identical result for the third time must halt the run"+ );+ assert!(+ summary+ .lock()+ .unwrap()+ .as_deref()+ .is_some_and(|text| text.contains("identical result")),+ "the recurrence halt summary should reach the host turn result"+ );+}++#[tokio::test]+async fn alternating_calls_whose_output_changed_do_not_halt() {+ let handle = SteeringHandle::allow_all();+ let mw = RepeatProgressMiddleware::new(+ handle.clone(),+ std::sync::Arc::new(std::sync::Mutex::new(None)),+ );+ for i in 0..DEFAULT_REPEAT_CALL_THRESHOLD * 3 {+ run_alternating_round(&mw, &format!("doc-{i}"), &format!("hits-{i}")).await;+ }+ assert_eq!(+ drain_pause_count(&handle),+ 0,+ "a re-read with identical arguments whose output changed is progress, not a repeat"+ );+}++#[tokio::test]+async fn alternating_exempt_polling_calls_do_not_halt() {+ let handle = SteeringHandle::allow_all();+ let mw = RepeatProgressMiddleware::new(+ handle.clone(),+ std::sync::Arc::new(std::sync::Mutex::new(None)),+ );+ for i in 0..DEFAULT_REPEAT_CALL_THRESHOLD * 3 {+ run_successful_repeat_cycle(+ &mw,+ "wait_subagent",+ json!({"task_id": "t"}),+ "still running",+ None,+ )+ .await;+ let output = format!("status-{i}");+ run_successful_repeat_cycle(&mw, "lookup", json!({"id": 1}), &output, None).await;+ }+ assert_eq!(+ drain_pause_count(&handle),+ 0,+ "identical polling results must not feed the recurrence ledger"+ );+}++#[tokio::test]+async fn evicting_a_recorded_result_resets_the_recurrence_ledger() {+ // What the last `before_model` sees for the recorded result `repeat-1`:+ // untouched, blanked by microcompact, or dropped by compression / trim.+ let cases: [(Vec<TaMessage>, usize, &str); 3] = [+ (+ vec![TaMessage::tool("repeat-1", "doc")],+ 1,+ "a result still in context keeps counting",+ ),+ (+ vec![TaMessage::tool("repeat-1", CLEARED_PLACEHOLDER)],+ 0,+ "a result blanked by compaction must not count toward a repeat",+ ),+ (+ vec![],+ 0,+ "a result dropped by compaction must not count toward a repeat",+ ),+ ];+ for (compacted, expected_pauses, why) in cases {+ let handle = SteeringHandle::allow_all();+ let mw = RepeatProgressMiddleware::new(+ handle.clone(),+ std::sync::Arc::new(std::sync::Mutex::new(None)),+ );+ let observer = mw.eviction_observer();+ for _ in 0..DEFAULT_REPEAT_CALL_THRESHOLD - 1 {+ run_alternating_round(&mw, "doc", "hits").await;+ }++ // The next model call: the guard sees the request before the reduction+ // steps run, the observer after them.+ let mut request = ModelRequest::new(vec![TaMessage::tool("repeat-1", "doc")]);+ mw.before_model(&mut ctx(), &(), &mut request)+ .await+ .unwrap();+ let mut request = ModelRequest::new(compacted);+ observer+ .before_model(&mut ctx(), &(), &mut request)+ .await+ .unwrap();++ run_successful_repeat_cycle(&mw, "use_skill", json!({"skill": "skills"}), "doc", None)+ .await;+ assert_eq!(drain_pause_count(&handle), expected_pauses, "{why}");+ }+}diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rsindex 3c10facf24..dd5df05192 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs@@ -417,6 +417,8 @@ fn embedder_hook_mw(#[path = "middleware_loop_guard_tests.rs"]mod loop_guard_tests;+#[path = "middleware_repeat_progress_tests.rs"]+mod repeat_progress_tests;#[path = "middleware_tool_output_tests.rs"]mod tool_output_tests;#[path = "middleware_tool_policy_tests.rs"]