Skip to content

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

feat(agent): add turn deadline and backstop for stalled turns

Steven Enamakel49f1f346544a
diff --git a/crates/openhuman-core/src/agent/mod.rs b/crates/openhuman-core/src/agent/mod.rs
index 2086308a81..e6c64cb47a 100644
--- a/crates/openhuman-core/src/agent/mod.rs
+++ b/crates/openhuman-core/src/agent/mod.rs
@@ -83,7 +83,6 @@ pub mod tools;
pub mod triage;
/// Wall-clock deadline of one top-level turn: the outer backstop and the
/// harness wind-down / hard-stop points derived from it.
-pub mod turn_deadline;
/// Turn-origin task-local — explicit trust/routing label scoped by every
/// entry point that invokes the agent (web chat, channel runtime, cron,
/// background jobs, CLI). Read by the approval gate to make
diff --git a/crates/openhuman-core/src/agent/turn_deadline.rs b/crates/openhuman-core/src/agent/session_host/turn_backstop.rs
similarity index 79%
rename from crates/openhuman-core/src/agent/turn_deadline.rs
rename to crates/openhuman-core/src/agent/session_host/turn_backstop.rs
index cb1ec2895e..c7bea3a7e3 100644
--- a/crates/openhuman-core/src/agent/turn_deadline.rs
+++ b/crates/openhuman-core/src/agent/session_host/turn_backstop.rs
@@ -1,4 +1,6 @@
-//! Wall-clock deadline of one top-level agent turn.
+//! Host side of the wall-clock deadline of one top-level agent turn: the env
+//! override and the task-local scope. The deadline itself (`close_budget`
+//! included) is `tinyagents_harness::turn_deadline::TurnDeadline`.
//!
//! A web-chat turn runs under an outer backstop (`web_chat::ops::turn_guards`)
//! that drops the turn future when it elapses. Dropping it discards
@@ -38,20 +40,6 @@ use tinyagents_harness::turn_deadline::{parse_backstop, TurnDeadline};
/// Environment override for the backstop, in seconds; `0` disables it.
pub const TURN_BACKSTOP_ENV: &str = "OPENHUMAN_WEB_TURN_TIMEOUT_SECS";
-/// 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);
-
-/// 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())
@@ -75,5 +63,5 @@ pub async fn with_turn_deadline<F: Future>(deadline: Option<TurnDeadline>, futur
}
#[cfg(test)]
-#[path = "turn_deadline_tests.rs"]
+#[path = "turn_backstop_tests.rs"]
mod tests;
diff --git a/crates/openhuman-core/src/agent/turn_deadline_tests.rs b/crates/openhuman-core/src/agent/session_host/turn_backstop_tests.rs
similarity index 52%
rename from crates/openhuman-core/src/agent/turn_deadline_tests.rs
rename to crates/openhuman-core/src/agent/session_host/turn_backstop_tests.rs
index c8e25996e9..17dd9ca306 100644
--- a/crates/openhuman-core/src/agent/turn_deadline_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/turn_backstop_tests.rs
@@ -1,5 +1,4 @@
use super::*;
-use std::time::Instant;
#[test]
fn parse_backstop_defaults_and_disables() {
@@ -26,17 +25,3 @@ async fn task_local_scope_is_visible_inside_and_absent_outside() {
.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!(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);
-}