Skip to content

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

test(agent): one table-shaped test for the close budget

M3gA-Mindad89e9a15c34
diff --git a/crates/openhuman-core/src/agent/session_host/driver/grounded_close.rs b/crates/openhuman-core/src/agent/session_host/driver/grounded_close.rs
index d4e7ce2160..600d331f76 100644
--- a/crates/openhuman-core/src/agent/session_host/driver/grounded_close.rs
+++ b/crates/openhuman-core/src/agent/session_host/driver/grounded_close.rs
@@ -272,13 +272,10 @@ pub(super) async fn close_if_needed(
Some(GroundedClose { output, usage })
}
-/// Run `close` within `budget` (the turn deadline's
-/// [`close_budget`](crate::agent::turn_deadline::TurnDeadline::close_budget)),
-/// or ship `fallback` when it runs out. `None` (no deadline) waits for `close`.
-///
-/// The fallback is the same deterministic summary a rejected close ships, so a
-/// slow or stalled provider costs the user the model's wording, not the answer.
-/// Usage of calls that finished before the timeout is not recorded.
+/// Run `close` within `budget`, else ship `fallback` (the deterministic summary
+/// a rejected close ships). `None` (no turn deadline) waits for `close`.
+/// ponytail: usage of calls finished before a timeout is dropped; thread a
+/// shared `RepairUsage` through if that spend must be billed.
async fn within_close_budget(
budget: Option<std::time::Duration>,
model: &str,
diff --git a/crates/openhuman-core/src/agent/session_host/driver/grounded_close_tests.rs b/crates/openhuman-core/src/agent/session_host/driver/grounded_close_tests.rs
index 56b35e79ef..8f0d85aa6a 100644
--- a/crates/openhuman-core/src/agent/session_host/driver/grounded_close_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/driver/grounded_close_tests.rs
@@ -249,44 +249,32 @@ fn a_capped_truncated_turn_gets_the_cap_checkpoint() {
assert!(out.contains("<tool_records>"), "{out}");
}
-/// The production failure (#7716): the close model never answered, and the
-/// backstop dropped the turn with no summary. Within its budget the close
-/// gives up and ships the deterministic summary instead.
+/// #7716: a close that never answers ships the fallback once the budget runs
+/// out; one that finishes in time, or runs without a deadline, ships its reply.
#[tokio::test]
-async fn stalled_close_model_ships_the_fallback_within_the_budget() {
- let instruction = final_answer_instruction(None, false, RECORDS);
- let ask = |_prompt: String| std::future::pending::<(String, Option<BilledUsage>)>();
- let verify = |_candidate: String| async { (None, None) };
+async fn close_budget_bounds_the_close_and_falls_back_on_expiry() {
+ use std::time::Duration;
let fallback = || FALLBACK.to_string();
+ let reply = || async {
+ (
+ CLEAN_REPLY.to_string(),
+ RepairUsage::for_model("test-model"),
+ )
+ };
- let started = std::time::Instant::now();
+ let stalled = std::future::pending::<(String, RepairUsage)>();
let (output, usage) = within_close_budget(
- Some(std::time::Duration::from_millis(20)),
+ Some(Duration::from_millis(20)),
"test-model",
- close_with_one_repair("test-model", instruction, None, ask, verify, &fallback),
- &fallback,
+ stalled,
+ fallback,
)
.await;
-
assert_eq!(output, FALLBACK);
assert_eq!(usage.model_calls, 0);
- assert!(
- started.elapsed() < std::time::Duration::from_secs(5),
- "the budget, not the stalled call, ended the close"
- );
-}
-#[tokio::test]
-async fn close_that_finishes_in_budget_or_without_one_ships_its_reply() {
- let closed = || async {
- (
- CLEAN_REPLY.to_string(),
- RepairUsage::for_model("test-model"),
- )
- };
- for budget in [Some(std::time::Duration::from_secs(60)), None] {
- let (output, _) =
- within_close_budget(budget, "test-model", closed(), || FALLBACK.to_string()).await;
+ for budget in [Some(Duration::from_secs(60)), None] {
+ let (output, _) = within_close_budget(budget, "test-model", reply(), fallback).await;
assert_eq!(output, CLEAN_REPLY, "budget {budget:?}");
}
}
diff --git a/crates/openhuman-core/src/agent/turn_deadline.rs b/crates/openhuman-core/src/agent/turn_deadline.rs
index 0c6d0bd587..aadc7704c2 100644
--- a/crates/openhuman-core/src/agent/turn_deadline.rs
+++ b/crates/openhuman-core/src/agent/turn_deadline.rs
@@ -114,10 +114,8 @@ impl TurnDeadline {
self.elapsed_at(now) >= self.wind_down_after()
}
- /// How long the post-loop grounded close may run as of `now`: what is left
- /// of the backstop minus [`CLOSE_RESERVE`], zero once that has passed. The
- /// close otherwise makes up to four model calls with no deadline, and a
- /// slow one let the backstop drop the turn with no summary (#7716).
+ /// How long the post-loop grounded close may run as of `now`: the backstop
+ /// remainder minus [`CLOSE_RESERVE`], zero once that has passed (#7716).
pub fn close_budget(&self, now: Instant) -> Duration {
self.backstop
.saturating_sub(self.elapsed_at(now))
diff --git a/crates/openhuman-core/src/agent/turn_deadline_tests.rs b/crates/openhuman-core/src/agent/turn_deadline_tests.rs
index dcb90d72f7..93fc384161 100644
--- a/crates/openhuman-core/src/agent/turn_deadline_tests.rs
+++ b/crates/openhuman-core/src/agent/turn_deadline_tests.rs
@@ -117,6 +117,7 @@ fn close_budget_is_backstop_remainder_minus_reserve() {
let at = |elapsed: u64| TurnDeadline::new(now - Duration::from_secs(elapsed), backstop);
// The wind-down point of a default turn leaves 120s, 110s of it for the close.
assert_eq!(at(780).close_budget(now), Duration::from_secs(110));
+ assert_eq!(at(889).close_budget(now), Duration::from_secs(1));
assert_eq!(at(890).close_budget(now), Duration::ZERO);
assert_eq!(at(950).close_budget(now), Duration::ZERO);
}