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
test(tinyagents): cover output stage planning and wire repeated-failure tests
Steven Enamakel1cfa0b9df5e7
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/failure_policy.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/failure_policy.rsindex f6abd04a0c..96db9ff82a 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware/failure_policy.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/failure_policy.rs@@ -2,12 +2,14 @@//! ([`recovery_policy_with_effect`]), split out of `repeated_failure.rs` so the breaker//! stays readable: the ladder driver lives there, the classification here.+use super::fetched_site::fetched_site_policy;use tinyagents_harness::middleware::{call_effect, CallEffect};-pub(super) use tinyagents_harness::no_progress::{is_command_exit_report, ARGUMENT_SCHEMA_RECOVERY};use tinyagents_harness::no_progress::{is_argument_rejection, is_pre_execution_failure, json_error_recovery,};-use super::fetched_site::fetched_site_policy;+pub(super) use tinyagents_harness::no_progress::{+ is_command_exit_report, ARGUMENT_SCHEMA_RECOVERY,+};use tinyinference_llm::failure::is_recoverable_failure_text as is_recoverable_tool_failure;/// Explicit recovery policy. Only recognised failures enter the classifieddiff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rsindex c872ef6e08..b2c239eb65 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs@@ -9,8 +9,8 @@ use async_trait::async_trait;use tinyagents_harness::context::RunContext;use tinyagents_harness::error::Result as TaResult;use tinyagents_harness::middleware::{- call_effect, dispatch_target, is_repeat_call_exempt, repeat_guard_marker, CallEffect, Middleware,- StopLatch, ToolFactsLookup, ToolInvocationIdentity,+ call_effect, dispatch_target, is_repeat_call_exempt, repeat_guard_marker, CallEffect,+ Middleware, StopLatch, ToolFactsLookup, ToolInvocationIdentity,};use tinyagents_harness::no_progress::{classified_step, clear_recovered, ClassifiedFailureTracker, ClassifiedStep, FailurePolicy,@@ -146,7 +146,6 @@ impl RepeatedToolFailureMiddleware {pub(crate) fn take_pending_nudges(&self) -> Vec<String> {self.pending_nudges.drain_all()}-}/// The halt wording for the recoverable ladder: OpenHuman's own copy.@@ -538,7 +537,10 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>if is_repeat_call_exempt(tool_name) {return Ok(());}- if let Some(summary) = self.recoverable.record(&HaltCopy, tool_name, &arg_fp, &failure_text) {+ if let Some(summary) =+ self.recoverable+ .record(&HaltCopy, tool_name, &arg_fp, &failure_text)+ {tracing::warn!(tool = tool_name,"[tinyagents::mw] recoverable-failure headroom exhausted — halting run so the root cause surfaces"@@ -648,3 +650,7 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>Ok(())}}++#[cfg(test)]+#[path = "repeated_failure_tests.rs"]+mod tests;diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure_tests.rsnew file mode 100644index 0000000000..f87865109d--- /dev/null+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure_tests.rs@@ -0,0 +1,55 @@+use super::*;++#[test]+fn identical_recoverable_halt_uses_openhuman_copy() {+ let ladder = RecoverableFailureLadder::default();+ let mut summary = None;+ for _ in 0..8 {+ summary = ladder.record(&HaltCopy, "web_fetch", "fp", "connection reset");+ ladder.reset_streak();+ }+ let summary = summary.expect("eighth identical failure halts");+ assert_eq!(+ summary,+ recoverable_identical_halt_summary("web_fetch", 8, "connection reset")+ );+}++#[test]+fn varied_recoverable_failures_halt_with_the_no_progress_copy() {+ let ladder = RecoverableFailureLadder::default();+ let mut summary = None;+ for i in 0..20 {+ summary = ladder.record(&HaltCopy, "web_fetch", &format!("fp{i}"), "timed out");+ if summary.is_some() {+ break;+ }+ }+ let summary = summary.expect("a long varied streak halts");+ assert!(summary.starts_with("Stopping: "));+ assert!(summary.contains("in a row with no successful progress"));+}++#[test]+fn first_error_line_is_scrubbed_before_it_reaches_a_summary() {+ let line = first_error_line("boom\nsecond line");+ assert_eq!(line, "boom");+}++#[test]+fn shell_missing_app_nudge_names_the_host_not_the_desktop_target() {+ let tracker = ClassifiedFailureTracker::default();+ let step = classified_step(+ &tracker,+ "missing_app",+ "shell",+ "shell",+ 1,+ "jq: not found",+ );+ let ClassifiedStep::Nudge(generic) = step else {+ panic!("missing_app within budget nudges");+ };+ assert!(generic.contains("desktop target"));+ assert!(missing_program_nudge("shell", "jq: not found").contains("not available on this host"));+}diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output.rsindex 35866e41b5..c5537925f1 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output.rs@@ -19,13 +19,13 @@ use crate::agent::harness::tool_result_artifacts::{artifact_read_target, page_artifact_read, TINYAGENTS_TOOL_RESULT_ARTIFACT_STORE,};use crate::agent::tinyagents::payload_summarizer::DynPayloadSummarizer;-use tinyagents_harness::middleware::library::{- disclose, plan_output_stages, should_compact, OutputCapPolicy,-};use crate::inference::tokenjuice::generate::GenerateTicket;use tinyagents_harness::artifacts::tool_results::{apply_per_result_persistence, ArtifactRead, ToolResultArtifactStore,};+use tinyagents_harness::middleware::library::{+ disclose, plan_output_stages, should_compact, OutputCapPolicy,+};use tinyjuice_bus::types::AgentTokenjuiceCompression;/// TinyJuice's own estimate: `ceil(characters / 4)`, not bytes. Multibytediff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output_tests.rsindex bcc85eaea6..acf56f0727 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output_tests.rs@@ -119,3 +119,58 @@ fn a_raw_fetch_wrapped_in_use_skill_is_still_a_raw_fetch() {));assert!(!is_raw_fetch("use_skill", &json!({"raw": true})));}++fn policy_mw(budget: usize, caps: &[(&str, usize)]) -> ToolOutputMiddleware {+ let mut tool_policies = HashMap::new();+ for (name, cap) in caps {+ let mut policy = TaToolPolicy::default();+ policy.runtime.max_result_bytes = Some(*cap);+ tool_policies.insert((*name).to_string(), policy);+ }+ ToolOutputMiddleware {+ budget_bytes: budget,+ payload_summarizer: None,+ artifact_store: None,+ tokenjuice_compaction_enabled: false,+ tokenjuice_compression: AgentTokenjuiceCompression::Full,+ runtime_config: None,+ tool_policies,+ artifact_reads: Default::default(),+ focus_by_call: Default::default(),+ summary_focus_tools: Default::default(),+ raw_fetches: Default::default(),+ file_reads: Default::default(),+ }+}++#[test]+fn a_tools_declared_cap_wins_over_the_shared_budget_in_the_stage_plan() {+ let mw = policy_mw(16_000, &[("web_fetch", 50_000)]);+ let declared = plan_output_stages(&mw, "web_fetch", 10, false);+ assert_eq!(declared.budget_bytes, 50_000);+ assert!(declared.tool_declared_cap);+ let shared = plan_output_stages(&mw, "shell", 10, false);+ assert_eq!(shared.budget_bytes, 16_000);+ assert!(!shared.tool_declared_cap);+}++#[test]+fn proposal_and_discovery_tools_are_exempt_from_the_byte_cap() {+ let mw = policy_mw(100, &[]);+ for tool in ["propose_workflow", "mcp_list_tools"] {+ assert!(plan_output_stages(&mw, tool, 10_000, true).truncation_exempt);+ }+ // A sampling tool skips compaction but stays under the byte cap.+ let sampling = plan_output_stages(&mw, "get_tool_contract", 10_000, true);+ assert!(sampling.compaction_exempt && !sampling.truncation_exempt);+}++#[test]+fn the_untouched_output_is_kept_only_when_it_could_spill_and_be_read_back() {+ let mw = policy_mw(100, &[]);+ assert!(plan_output_stages(&mw, "shell", 101, true).keep_full_output);+ assert!(!plan_output_stages(&mw, "shell", 101, false).keep_full_output);+ assert!(!plan_output_stages(&mw, "shell", 100, true).keep_full_output);+ let too_big = tinytools_std::filesystem::FileReadTool::MAX_FILE_SIZE_BYTES as usize + 1;+ assert!(!plan_output_stages(&mw, "shell", too_big, true).keep_full_output);+}