Skip to content

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

test(agent): pin the terminal-inference halt for an out-of-credits tool error

M3gA-Mind7739d0150a34
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_terminal_inference_halt_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_terminal_inference_halt_tests.rs
new file mode 100644
index 0000000000..26150d8c8c
--- /dev/null
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_terminal_inference_halt_tests.rs
@@ -0,0 +1,45 @@
+use super::*;
+use crate::agent::tinyagents::middleware::repeated_failure::RepeatedToolFailureMiddleware;
+
+// A tool that fails because inference itself could not run (out of credits, a
+// rejected provider config) halts the turn on the first failure with a typed
+// cause, quoting the raw error only up to the halt bound.
+
+#[tokio::test]
+async fn an_out_of_credits_tool_failure_halts_with_bounded_copy_and_a_typed_cause() {
+ 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 mut context = ctx();
+ let padding = "x".repeat(5_000);
+ let error = format!(
+ "Sub-agent inference failed and did not complete: 402 Insufficient budget {padding}"
+ );
+
+ let mut call = TaToolCall::new("credits-1", "delegate_task", serde_json::json!({}));
+ mw.before_tool(&mut context, &(), &mut call).await.unwrap();
+ let mut result = failing_result("delegate_task", &error);
+ mw.after_tool(
+ &mut context,
+ &(),
+ &invocation("credits-1", "delegate_task"),
+ &mut result,
+ )
+ .await
+ .unwrap();
+
+ assert_eq!(drain_pause_count(&handle), 1, "halts on the first failure");
+ let summary = slot.lock().unwrap().clone().expect("a halt summary");
+ assert!(
+ summary.contains("[truncated]") && !summary.contains(&"x".repeat(601)),
+ "the quoted error is not cut to the halt bound: {} chars",
+ summary.chars().count()
+ );
+
+ assert_eq!(
+ context
+ .take_halted_by_guard_cause()
+ .map(|cause| cause.class),
+ Some("out_of_credits".to_string())
+ );
+}
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs
index c029317edf..30ba29b768 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs
@@ -370,6 +370,8 @@ mod command_exit_failure_tests;
mod failure_effect_tests;
#[path = "middleware_failure_policy_class_tests.rs"]
mod failure_policy_class_tests;
+#[path = "middleware_terminal_inference_halt_tests.rs"]
+mod terminal_inference_halt_tests;
#[path = "middleware_loop_guard_tests.rs"]
mod loop_guard_tests;
#[path = "middleware_memory_budget_tests.rs"]