Skip to content

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

feat(agent): wind down turns before the deadline expires

Steven Enamakele118d6e3c3b7
diff --git a/crates/openhuman-core/src/agent/tinyagents/budget_stop_turn_tests.rs b/crates/openhuman-core/src/agent/tinyagents/budget_stop_turn_tests.rs
index 532bd13e35..7f48729b43 100644
--- a/crates/openhuman-core/src/agent/tinyagents/budget_stop_turn_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/budget_stop_turn_tests.rs
@@ -226,7 +226,7 @@ async fn deadline_wind_down_pauses_the_hosted_turn_inner() {
let (tx, _rx) = tokio::sync::mpsc::channel(64);
let mut context = root_context("deadline-wind-down", "/tmp/deadline-wind-down", tx);
let now = std::time::Instant::now();
- context.turn_deadline = Some(crate::agent::turn_deadline::TurnDeadline::new(
+ context.turn_deadline = Some(tinyagents_harness::turn_deadline::TurnDeadline::new(
now - std::time::Duration::from_secs(800),
std::time::Duration::from_secs(900),
));
@@ -298,7 +298,7 @@ fn a_turn_before_its_wind_down_point_runs_to_its_final_answer() {
let (tx, _rx) = tokio::sync::mpsc::channel(64);
let mut context = root_context("deadline-fresh", "/tmp/deadline-fresh", tx);
context.turn_deadline =
- Some(crate::agent::turn_deadline::TurnDeadline::starting_now(
+ Some(tinyagents_harness::turn_deadline::TurnDeadline::starting_now(
std::time::Duration::from_secs(900),
));
let outcome = run_root_turn_via_hosted_agent(
diff --git a/crates/openhuman-core/src/agent/tinyagents/deadline_wind_down.rs b/crates/openhuman-core/src/agent/tinyagents/deadline_wind_down.rs
index 1c00f45eac..324e9198e5 100644
--- a/crates/openhuman-core/src/agent/tinyagents/deadline_wind_down.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/deadline_wind_down.rs
@@ -1,184 +1,45 @@
-//! Wind a top-level turn down before the outer backstop drops it.
+//! Host adapter over `tinyagents_harness::middleware::library::install_wind_down`.
//!
-//! [`TurnDeadline`] puts the wind-down point at 780s under the default 900s
-//! web backstop. Once that point has passed, [`DeadlineWindDownMiddleware`]
-//! sends [`SteeringCommand::Pause`] at the next safe checkpoint: after a model
-//! call (that call's tool round still runs) or after a tool result (so a long
-//! sub-agent call is not followed by yet another model call). The loop drains
-//! the pause at the top of its next iteration, before any provider call. That
-//! is the same mechanism as the goal-budget and cap pauses
-//! ([`super::stop_hooks`]).
-//!
-//! A paused run has no final response, so the session driver's grounded close
-//! (`session_host::driver::grounded_close`) writes the user's answer from the
-//! completed tool results. The turn then commits like any other, and the user
-//! gets an answer instead of a dropped turn.
-//!
-//! [`install`] also clamps the harness `max_wall_clock_ms` to the deadline's
-//! hard stop. A single tool call that runs past the wind-down point is then
-//! ended by the harness's own typed `Timeout`, before the backstop drops the
-//! turn with nothing recorded.
+//! The harness owns the mechanism (pause once the turn's `TurnDeadline`
+//! wind-down point passes, clamp `max_wall_clock_ms` to the hard stop). The
+//! host contributes only the callback that records the pause on the turn's
+//! session sidecar, so the driver reports the turn as wound down rather than
+//! completed (`session_host::driver::grounded_close` then writes the answer).
-use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
-use std::time::Instant;
-use async_trait::async_trait;
-use tinyagents_harness::context::RunContext;
-use tinyagents_harness::middleware::{Middleware, ToolInvocationIdentity};
+use tinyagents_harness::middleware::library::{install_wind_down, WindDownMiddleware};
use tinyagents_harness::runtime::AgentHarness;
-use tinyagents_harness::steering::{SteeringCommand, SteeringHandle};
-use tinyinference_llm::model::ModelResponse;
-use tinytools::ToolResult;
+use tinyagents_harness::steering::SteeringHandle;
-use crate::agent::tinyagents::host::{OpenHumanRunContext, SessionTurnSidecar};
+use crate::agent::tinyagents::host::OpenHumanRunContext;
use crate::agent::tinyagents::observability::SubagentScope;
-use crate::agent::turn_deadline::TurnDeadline;
-
-/// Pauses the run once its turn deadline's wind-down point has passed.
-pub(crate) struct DeadlineWindDownMiddleware {
- handle: SteeringHandle,
- deadline: TurnDeadline,
- /// Latched on the first pause, so `Pause` is sent exactly once.
- fired: Arc<AtomicBool>,
- /// The turn's session sidecar; the pause is recorded there so the driver
- /// can report the turn as wound down rather than completed.
- sidecar: std::sync::OnceLock<Arc<std::sync::Mutex<SessionTurnSidecar>>>,
-}
-
-impl DeadlineWindDownMiddleware {
- pub(crate) fn new(handle: SteeringHandle, deadline: TurnDeadline) -> Self {
- Self {
- handle,
- deadline,
- fired: Arc::new(AtomicBool::new(false)),
- sidecar: std::sync::OnceLock::new(),
- }
- }
-
- /// Record the pause on `sidecar` (the turn's run-context sidecar). Set
- /// once, before the run starts.
- pub(crate) fn set_sidecar(&self, sidecar: Arc<std::sync::Mutex<SessionTurnSidecar>>) {
- let _ = self.sidecar.set(sidecar);
- }
-
- /// Whether this middleware has paused the run.
- pub(crate) fn fired(&self) -> bool {
- self.fired.load(Ordering::SeqCst)
- }
-
- /// Pause the run if the wind-down point has passed as of `now`. Returns
- /// whether this call sent the pause.
- pub(crate) fn maybe_pause(&self, checkpoint: &'static str, now: Instant) -> bool {
- if !self.deadline.should_wind_down(now) || self.fired.swap(true, Ordering::SeqCst) {
- return false;
- }
- tracing::warn!(
- target: "turn_deadline",
- checkpoint,
- elapsed_ms = self.deadline.elapsed_at(now).as_millis() as u64,
- wind_down_ms = self.deadline.wind_down_after().as_millis() as u64,
- backstop_ms = self.deadline.backstop().as_millis() as u64,
- "[turn_deadline] wind-down point passed; pausing the run so the turn closes with an answer before the backstop"
- );
- self.handle.send(SteeringCommand::Pause);
- if let Some(sidecar) = self.sidecar.get() {
- sidecar
- .lock()
- .unwrap_or_else(std::sync::PoisonError::into_inner)
- .wind_down = true;
- tracing::debug!(
- target: "turn_deadline",
- "[turn_deadline] wind-down recorded on the turn sidecar; the turn will be reported as stopped"
- );
- }
- true
- }
-}
-#[async_trait]
-impl<State, Ctx> Middleware<State, Ctx> for DeadlineWindDownMiddleware
-where
- State: Send + Sync,
- Ctx: Send + Sync,
-{
- fn name(&self) -> &str {
- "openhuman.deadline_wind_down"
- }
-
- async fn after_model(
- &self,
- _ctx: &mut RunContext<Ctx>,
- _state: &State,
- _response: &mut ModelResponse,
- ) -> tinyagents_harness::Result<()> {
- self.maybe_pause("after_model", Instant::now());
- Ok(())
- }
-
- async fn after_tool(
- &self,
- _ctx: &mut RunContext<Ctx>,
- _state: &State,
- _invocation: &ToolInvocationIdentity,
- _result: &mut ToolResult,
- ) -> tinyagents_harness::Result<()> {
- self.maybe_pause("after_tool", Instant::now());
- Ok(())
- }
-}
-
-/// Install the wind-down for a run that carries a turn deadline, and clamp the
-/// harness wall-clock ceiling to its hard stop.
-///
-/// Children and runs without a deadline are left untouched. A synchronous
-/// child is bounded by its parent's tool-call budget, which the clamp already
-/// ends at the hard stop. Detached children must not inherit the deadline of
-/// the turn that spawned them.
+/// Install the harness wind-down for a top-level turn that carries a deadline
+/// and record its pause on the turn sidecar.
pub(super) fn install(
harness: &mut AgentHarness<(), OpenHumanRunContext>,
handle: &Option<SteeringHandle>,
run_context: &OpenHumanRunContext,
subagent_scope: &Option<SubagentScope>,
-) -> Option<Arc<DeadlineWindDownMiddleware>> {
- let middleware = install_for(
+) -> Option<Arc<WindDownMiddleware>> {
+ let middleware = install_wind_down(
harness,
handle.as_ref(),
run_context.turn_deadline,
subagent_scope.is_some(),
)?;
- // `install_for` hands back the instance it registered; record the pause
- // on the turn's sidecar through that same shared state.
- middleware.set_sidecar(run_context.session_sidecar.clone());
- Some(middleware)
-}
-
-/// [`install`] over plain values, for tests.
-pub(super) fn install_for(
- harness: &mut AgentHarness<(), OpenHumanRunContext>,
- handle: Option<&SteeringHandle>,
- deadline: Option<TurnDeadline>,
- is_subagent: bool,
-) -> Option<Arc<DeadlineWindDownMiddleware>> {
- let deadline = deadline.filter(|_| !is_subagent)?;
- let now = Instant::now();
- let mut policy = harness.policy().clone();
- let configured = policy.limits.max_wall_clock_ms;
- policy.limits.max_wall_clock_ms = deadline.clamp_wall_clock_ms(configured, now);
- tracing::debug!(
- target: "turn_deadline",
- configured_ms = ?configured,
- clamped_ms = ?policy.limits.max_wall_clock_ms,
- elapsed_ms = deadline.elapsed_at(now).as_millis() as u64,
- wind_down_ms = deadline.wind_down_after().as_millis() as u64,
- hard_stop_ms = deadline.hard_stop_after().as_millis() as u64,
- backstop_ms = deadline.backstop().as_millis() as u64,
- "[turn_deadline] clamped harness wall clock to the turn's hard stop"
- );
- harness.with_policy(policy);
- let handle = handle?;
- let middleware = Arc::new(DeadlineWindDownMiddleware::new(handle.clone(), deadline));
- harness.push_middleware(middleware.clone());
+ let sidecar = run_context.session_sidecar.clone();
+ middleware.set_on_pause(Arc::new(move || {
+ sidecar
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .wind_down = true;
+ tracing::debug!(
+ target: "turn_deadline",
+ "[turn_deadline] wind-down recorded on the turn sidecar; the turn will be reported as stopped"
+ );
+ }));
Some(middleware)
}
diff --git a/crates/openhuman-core/src/agent/tinyagents/deadline_wind_down_tests.rs b/crates/openhuman-core/src/agent/tinyagents/deadline_wind_down_tests.rs
index 6763598166..8e76a41459 100644
--- a/crates/openhuman-core/src/agent/tinyagents/deadline_wind_down_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/deadline_wind_down_tests.rs
@@ -1,5 +1,6 @@
use super::*;
-use std::time::Duration;
+use std::time::{Duration, Instant};
+use tinyagents_harness::turn_deadline::TurnDeadline;
fn handle() -> SteeringHandle {
crate::agent::tinyagents::host::steering::openhuman_steering_handle(
@@ -7,37 +8,9 @@ fn handle() -> SteeringHandle {
)
}
-#[test]
-fn does_not_pause_before_the_wind_down_point() {
- let now = Instant::now();
- let deadline = TurnDeadline::new(now - Duration::from_secs(100), Duration::from_secs(900));
- let mw = DeadlineWindDownMiddleware::new(handle(), deadline);
- assert!(!mw.maybe_pause("after_model", now));
- assert!(!mw.fired());
-}
-
-#[test]
-fn pauses_once_after_the_wind_down_point() {
- let now = Instant::now();
- let deadline = TurnDeadline::new(now - Duration::from_secs(781), Duration::from_secs(900));
- let mw = DeadlineWindDownMiddleware::new(handle(), deadline);
- assert!(
- mw.maybe_pause("after_tool", now),
- "first checkpoint past wind-down pauses"
- );
- assert!(mw.fired());
- assert!(
- !mw.maybe_pause("after_model", now),
- "the pause is latched and sent exactly once"
- );
-}
-
-/// The harness's own default turn ceiling is later than the web backstop.
-/// That ordering is what dropped long turns. The clamp must therefore always
-/// bring it below the backstop.
#[test]
fn the_default_harness_ceiling_is_clamped_below_the_backstop() {
- let backstop = Duration::from_secs(crate::agent::turn_deadline::DEFAULT_TURN_BACKSTOP_SECS);
+ let backstop = Duration::from_secs(tinyagents_harness::turn_deadline::DEFAULT_TURN_BACKSTOP_SECS);
let default_ms = crate::agent::tinyagents::DEFAULT_AGENT_TURN_TIMEOUT_SECS * 1_000;
assert!(
default_ms > backstop.as_millis() as u64,
@@ -50,51 +23,6 @@ fn the_default_harness_ceiling_is_clamped_below_the_backstop() {
assert!(clamped < backstop.as_millis() as u64);
}
-#[test]
-fn install_clamps_the_policy_and_adds_the_middleware_for_a_root_turn() {
- let mut harness: AgentHarness<(), OpenHumanRunContext> = AgentHarness::new();
- harness.with_policy(crate::agent::tinyagents::run_policy_for(200, false));
- let now = Instant::now();
- let deadline = TurnDeadline::new(now, Duration::from_secs(900));
- let h = handle();
- let mw = install_for(&mut harness, Some(&h), Some(deadline), false);
- assert!(mw.is_some());
- let clamped = harness
- .policy()
- .limits
- .max_wall_clock_ms
- .expect("bounded wall clock");
- assert!(
- clamped <= 840_000,
- "clamped to the hard stop, got {clamped}"
- );
- assert!(
- clamped > 830_000,
- "measured from the deadline start, got {clamped}"
- );
-}
-
-#[test]
-fn install_leaves_children_and_unbounded_turns_alone() {
- let h = handle();
- let deadline = TurnDeadline::starting_now(Duration::from_secs(900));
-
- let mut child: AgentHarness<(), OpenHumanRunContext> = AgentHarness::new();
- child.with_policy(crate::agent::tinyagents::run_policy_for(10, false));
- let before = child.policy().limits.max_wall_clock_ms;
- assert!(install_for(&mut child, Some(&h), Some(deadline), true).is_none());
- assert_eq!(child.policy().limits.max_wall_clock_ms, before);
-
- let mut plain: AgentHarness<(), OpenHumanRunContext> = AgentHarness::new();
- plain.with_policy(crate::agent::tinyagents::run_policy_for(10, false));
- let before = plain.policy().limits.max_wall_clock_ms;
- assert!(install_for(&mut plain, Some(&h), None, false).is_none());
- assert_eq!(plain.policy().limits.max_wall_clock_ms, before);
-}
-
-/// The wind-down pause is how the turn ended, so it must reach the session
-/// sidecar the driver classifies the turn's stop from. Before, the middleware
-/// only paused, and a wound-down turn was traced as a clean completion.
#[test]
fn a_wind_down_pause_is_recorded_on_the_turn_sidecar() {
let mut harness: AgentHarness<(), OpenHumanRunContext> = AgentHarness::new();
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
index fe6f13c964..ac7dee62f9 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
@@ -284,7 +284,7 @@ pub struct OpenHumanRunContext {
/// only by the session turn entry point from the web backstop
/// (`agent::turn_deadline`). The harness winds the run down and clamps
/// its wall clock against it. `None` for turns without a backstop.
- pub turn_deadline: Option<crate::agent::turn_deadline::TurnDeadline>,
+ pub turn_deadline: Option<tinyagents_harness::turn_deadline::TurnDeadline>,
/// Parent runtime snapshot used by canonical recursive tool dispatch.
pub parent: Option<ParentExecutionContext>,
/// Context-preparation sources already consumed in this turn.
diff --git a/crates/openhuman-core/src/agent/turn_deadline.rs b/crates/openhuman-core/src/agent/turn_deadline.rs
index e75e45f081..685bc073d3 100644
--- a/crates/openhuman-core/src/agent/turn_deadline.rs
+++ b/crates/openhuman-core/src/agent/turn_deadline.rs
@@ -8,8 +8,9 @@
//! `tinyagents::turn_policy`) was later than the backstop, so the harness
//! never got the chance to stop the turn itself.
//!
-//! This module is the single source of truth for the backstop and for the two
-//! points the harness derives from it:
+//! The deadline value (`tinyagents_harness::turn_deadline::TurnDeadline`)
+//! owns the two points the harness derives from the backstop; this module
+//! keeps the host side (env override, task-local scope):
//!
//! * **wind-down** (`backstop - min(120s, backstop/5)`, 780s by default): the
//! harness pauses the run at the next safe point, after a model call or a
@@ -30,105 +31,18 @@
//! `None` and keep their previous behaviour.
use std::future::Future;
-use std::time::{Duration, Instant};
+use std::time::Duration;
-/// Default outer wall-clock backstop for one web-chat turn, in seconds.
-pub const DEFAULT_TURN_BACKSTOP_SECS: u64 = 900;
+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";
-/// 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);
-
-/// 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))
-}
-
/// 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())
}
-/// One turn's backstop, anchored at the instant the backstop started counting.
-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
-pub struct TurnDeadline {
- started: Instant,
- backstop: Duration,
-}
-
-impl TurnDeadline {
- /// A deadline whose backstop started at `started`.
- pub fn new(started: Instant, backstop: Duration) -> Self {
- Self { started, backstop }
- }
-
- /// A deadline whose backstop starts counting now.
- pub fn starting_now(backstop: Duration) -> Self {
- Self::new(Instant::now(), backstop)
- }
-
- /// The outer backstop, measured from [`Self::started`].
- pub fn backstop(&self) -> Duration {
- self.backstop
- }
-
- /// When the backstop started counting.
- pub fn started(&self) -> Instant {
- self.started
- }
-
- /// Elapsed budget after which the harness winds the turn down.
- pub fn wind_down_after(&self) -> Duration {
- self.backstop
- .saturating_sub(WIND_DOWN_MARGIN.min(self.backstop / 5))
- }
-
- /// Elapsed budget at which the harness stops the turn itself.
- pub fn hard_stop_after(&self) -> Duration {
- self.backstop
- .saturating_sub(HARD_STOP_MARGIN.min(self.backstop / 10))
- }
-
- /// Time spent since the backstop started, as of `now`.
- pub fn elapsed_at(&self, now: Instant) -> Duration {
- now.saturating_duration_since(self.started)
- }
-
- /// Whether the wind-down point has passed as of `now`.
- pub fn should_wind_down(&self, now: Instant) -> bool {
- self.elapsed_at(now) >= self.wind_down_after()
- }
-
- /// Time left until the hard stop as of `now` (zero once it has passed).
- pub fn hard_stop_remaining(&self, now: Instant) -> Duration {
- self.hard_stop_after().saturating_sub(self.elapsed_at(now))
- }
-
- /// Clamp a configured harness wall-clock ceiling (`None` means unbounded)
- /// so it ends at the hard stop, never later. Never returns `None`: a turn
- /// under a backstop is bounded whether or not the ceiling is configured.
- /// Floors at 1 ms because a zero ceiling would read as "no time at all".
- pub fn clamp_wall_clock_ms(&self, configured_ms: Option<u64>, now: Instant) -> Option<u64> {
- let remaining_ms = self
- .hard_stop_remaining(now)
- .as_millis()
- .min(u128::from(u64::MAX)) as u64;
- let remaining_ms = remaining_ms.max(1);
- Some(configured_ms.map_or(remaining_ms, |ms| ms.min(remaining_ms)))
- }
-}
-
tokio::task_local! {
static CURRENT_TURN_DEADLINE: TurnDeadline;
}
diff --git a/crates/openhuman-core/src/agent/turn_deadline_tests.rs b/crates/openhuman-core/src/agent/turn_deadline_tests.rs
index 7c81f40ecd..17dd9ca306 100644
--- a/crates/openhuman-core/src/agent/turn_deadline_tests.rs
+++ b/crates/openhuman-core/src/agent/turn_deadline_tests.rs
@@ -1,87 +1,5 @@
use super::*;
-#[test]
-fn default_deadlines_are_780s_840s_900s() {
- let deadline = TurnDeadline::starting_now(Duration::from_secs(DEFAULT_TURN_BACKSTOP_SECS));
- assert_eq!(deadline.wind_down_after(), Duration::from_secs(780));
- assert_eq!(deadline.hard_stop_after(), Duration::from_secs(840));
- assert_eq!(deadline.backstop(), Duration::from_secs(900));
-}
-
-/// The ordering production was missing: the harness must stop (and before
-/// that wind down) strictly before the backstop drops the turn, for every
-/// backstop an operator can configure.
-#[test]
-fn wind_down_precedes_hard_stop_precedes_backstop_for_every_backstop() {
- for secs in [
- 1_u64, 2, 5, 10, 30, 60, 120, 300, 599, 600, 601, 900, 1_200, 3_600, 86_400,
- ] {
- let deadline = TurnDeadline::starting_now(Duration::from_secs(secs));
- assert!(
- deadline.wind_down_after() < deadline.hard_stop_after(),
- "backstop {secs}s: wind-down {:?} must precede hard stop {:?}",
- deadline.wind_down_after(),
- deadline.hard_stop_after()
- );
- assert!(
- deadline.hard_stop_after() < deadline.backstop(),
- "backstop {secs}s: hard stop {:?} must precede backstop",
- deadline.hard_stop_after()
- );
- }
-}
-
-/// The harness ceiling (default 3600s) is always clamped below the backstop,
-/// and so is an explicit opt-out (`None`).
-#[test]
-fn harness_wall_clock_is_always_clamped_below_the_backstop() {
- let backstop = Duration::from_secs(DEFAULT_TURN_BACKSTOP_SECS);
- let now = Instant::now();
- let deadline = TurnDeadline::new(now, backstop);
- let backstop_ms = backstop.as_millis() as u64;
- // The harness's default turn ceiling (`DEFAULT_AGENT_TURN_TIMEOUT_SECS`);
- // `deadline_wind_down_tests.rs` pins that constant against this module.
- let harness_default_ms = 3_600_000;
-
- let clamped = deadline
- .clamp_wall_clock_ms(Some(harness_default_ms), now)
- .expect("clamped ceiling");
- assert_eq!(clamped, 840_000);
- assert!(clamped < backstop_ms);
-
- let unbounded = deadline.clamp_wall_clock_ms(None, now).expect("bounded");
- assert_eq!(unbounded, 840_000);
-
- // A configured ceiling that is already tighter is kept.
- assert_eq!(
- deadline.clamp_wall_clock_ms(Some(10_000), now),
- Some(10_000)
- );
-}
-
-#[test]
-fn clamp_measures_the_remaining_budget_from_the_backstop_start() {
- let now = Instant::now();
- let started = now - Duration::from_secs(800);
- let deadline = TurnDeadline::new(started, Duration::from_secs(900));
- assert_eq!(
- deadline.clamp_wall_clock_ms(Some(3_600_000), now),
- Some(40_000)
- );
- // Past the hard stop the ceiling floors at 1 ms rather than 0.
- let late = TurnDeadline::new(now - Duration::from_secs(899), Duration::from_secs(900));
- assert_eq!(late.clamp_wall_clock_ms(Some(3_600_000), now), Some(1));
-}
-
-#[test]
-fn should_wind_down_flips_at_the_wind_down_point() {
- let now = Instant::now();
- let fresh = TurnDeadline::new(now - Duration::from_secs(779), Duration::from_secs(900));
- assert!(!fresh.should_wind_down(now));
- let due = TurnDeadline::new(now - Duration::from_secs(780), Duration::from_secs(900));
- assert!(due.should_wind_down(now));
-}
-
#[test]
fn parse_backstop_defaults_and_disables() {
assert_eq!(parse_backstop(None), Some(Duration::from_secs(900)));
diff --git a/crates/openhuman-core/src/web_chat/ops/turn_guards.rs b/crates/openhuman-core/src/web_chat/ops/turn_guards.rs
index cc1fd3a8ed..c5936273d2 100644
--- a/crates/openhuman-core/src/web_chat/ops/turn_guards.rs
+++ b/crates/openhuman-core/src/web_chat/ops/turn_guards.rs
@@ -83,7 +83,7 @@ where
Some(d) => match tokio::time::timeout(
d,
crate::agent::turn_deadline::with_turn_deadline(
- Some(crate::agent::turn_deadline::TurnDeadline::starting_now(d)),
+ Some(tinyagents_harness::turn_deadline::TurnDeadline::starting_now(d)),
Box::pin(fut),
),
)