Skip to content

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

Merge upstream/main into tiny-dep-tinyagents-2

Steven Enamakel354c5a65a9b3
diff --cc crates/openhuman-core/src/agent/session_host/driver.rs
index 9469be05b6,b14d1d3cb5..e37d2816d4
--- a/crates/openhuman-core/src/agent/session_host/driver.rs
+++ b/crates/openhuman-core/src/agent/session_host/driver.rs
@@@ -251,6 -251,12 +251,12 @@@ impl SessionDriver<OpenHumanRunContext
outcome.wrap_up_injected = false;
}
+ // When the close (and any required-output repair after it) must be
+ // done by, so the turn commits before the backstop drops it.
+ let close_by = request.run_context.data.turn_deadline.map(|deadline| {
+ let now = Instant::now();
- now + deadline.close_budget(now)
++ now + crate::agent::turn_deadline::close_budget(&deadline, now)
+ });
let close = grounded_close::close_if_needed(
&self.turn_model_source,
&self.model_name,
diff --cc crates/openhuman-core/src/agent/turn_deadline.rs
index 685bc073d3,aadc7704c2..cb1ec2895e
--- a/crates/openhuman-core/src/agent/turn_deadline.rs
+++ b/crates/openhuman-core/src/agent/turn_deadline.rs
@@@ -38,6 -38,27 +38,20 @@@ use tinyagents_harness::turn_deadline::
/// Environment override for the backstop, in seconds; `0` disables it.
pub const TURN_BACKSTOP_ENV: &str = "OPENHUMAN_WEB_TURN_TIMEOUT_SECS";
-/// Upper bound on the gap between wind-down and the backstop. It has to cover
-/// the tool round already in flight plus the grounded close (one model call,
-/// its verification, and at most one repair).
-const WIND_DOWN_MARGIN: Duration = Duration::from_secs(120);
-
-/// Upper bound on the gap between the harness hard stop and the backstop.
-const HARD_STOP_MARGIN: Duration = Duration::from_secs(60);
-
+ /// Time kept back from the post-loop grounded close so the turn can commit and
+ /// emit its reply before the backstop drops it.
+ const CLOSE_RESERVE: Duration = Duration::from_secs(10);
+
-/// Pure core of [`configured_backstop`]: an absent or unparseable value falls
-/// back to [`DEFAULT_TURN_BACKSTOP_SECS`]. `0` disables the backstop (`None`).
-pub fn parse_backstop(env_value: Option<&str>) -> Option<Duration> {
- let secs = env_value
- .and_then(|v| v.trim().parse::<u64>().ok())
- .unwrap_or(DEFAULT_TURN_BACKSTOP_SECS);
- (secs > 0).then(|| Duration::from_secs(secs))
++/// How long the post-loop grounded close may run as of `now`: the backstop
++/// remainder minus [`CLOSE_RESERVE`], zero once that has passed (#7716).
++/// Host-side until the harness `TurnDeadline` grows the same accessor.
++pub fn close_budget(deadline: &TurnDeadline, now: std::time::Instant) -> Duration {
++ deadline
++ .backstop()
++ .saturating_sub(deadline.elapsed_at(now))
++ .saturating_sub(CLOSE_RESERVE)
+ }
+
/// The backstop in force for this process (env [`TURN_BACKSTOP_ENV`]).
pub fn configured_backstop() -> Option<Duration> {
parse_backstop(std::env::var(TURN_BACKSTOP_ENV).ok().as_deref())
diff --cc crates/openhuman-core/src/agent/turn_deadline_tests.rs
index 17dd9ca306,93fc384161..c85ab32f47
--- a/crates/openhuman-core/src/agent/turn_deadline_tests.rs
+++ b/crates/openhuman-core/src/agent/turn_deadline_tests.rs
@@@ -25,3 -107,17 +25,17 @@@ async fn task_local_scope_is_visible_in
.await
.is_none());
}
+
+ /// The grounded close gets what is left of the backstop minus the commit
+ /// reserve, and nothing once the reserve itself is reached (#7716).
+ #[test]
+ fn close_budget_is_backstop_remainder_minus_reserve() {
+ let now = Instant::now();
+ let backstop = Duration::from_secs(900);
+ 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);
++ assert_eq!(close_budget(&at(780), now), Duration::from_secs(110));
++ assert_eq!(close_budget(&at(889), now), Duration::from_secs(1));
++ assert_eq!(close_budget(&at(890), now), Duration::ZERO);
++ assert_eq!(close_budget(&at(950), now), Duration::ZERO);
+ }