Skip to content

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

feat(session_host): add turn guards for web chat sessions

Steven Enamakel2ef059fc8182
diff --git a/crates/openhuman-core/src/agent/session_host/driver.rs b/crates/openhuman-core/src/agent/session_host/driver.rs
index efb8fcd20e..26c315498b 100644
--- a/crates/openhuman-core/src/agent/session_host/driver.rs
+++ b/crates/openhuman-core/src/agent/session_host/driver.rs
@@ -267,7 +267,7 @@ impl SessionDriver<OpenHumanRunContext> for OpenHumanSessionDriver {
// 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 + crate::agent::turn_deadline::close_budget(&deadline, now)
+ now + deadline.close_budget(now)
});
// A Stop during the close or the repair after it hands back the
// accepted rounds like a Stop during the loop, instead of letting the
diff --git a/crates/openhuman-core/src/agent/session_host/mod.rs b/crates/openhuman-core/src/agent/session_host/mod.rs
index 7b68116664..a909b6eb62 100644
--- a/crates/openhuman-core/src/agent/session_host/mod.rs
+++ b/crates/openhuman-core/src/agent/session_host/mod.rs
@@ -56,6 +56,7 @@ mod turn;
// harness-assembly site has to name it. It stays the one definition — the whole
// point is that the in-loop conclusion and the out-of-band fallback ask for the
// same thing.
+pub(crate) mod turn_backstop;
pub(crate) mod turn_checkpoint;
mod types;
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session_turn.rs b/crates/openhuman-core/src/agent/session_host/runtime_session_turn.rs
index bba3d933b6..4d8c5a2ab4 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session_turn.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session_turn.rs
@@ -24,7 +24,7 @@ impl OpenHumanSessionHost {
context.workspace = self.workspace_descriptor.clone();
// The web backstop's deadline, when this turn runs under one: the
// harness winds down before it instead of being dropped by it.
- context.turn_deadline = crate::agent::turn_deadline::current();
+ context.turn_deadline = crate::agent::session_host::turn_backstop::current();
let cancellation = context.cancellation.clone();
let root_config = context.root_run_config("openhuman-session");
let mut options = TurnOptions {
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 cea02aa841..2e1cc0f2c4 100644
--- a/crates/openhuman-core/src/web_chat/ops/turn_guards.rs
+++ b/crates/openhuman-core/src/web_chat/ops/turn_guards.rs
@@ -12,7 +12,7 @@ use super::super::types::WebChatTaskResult;
/// (env `OPENHUMAN_WEB_TURN_TIMEOUT_SECS=0`).
///
/// This is the OUTER safety net (issue #4746), and the single source of truth
-/// for the turn's deadlines (`agent::turn_deadline`, default 900s). The
+/// for the turn's deadlines (`agent::session_host::turn_backstop`, default 900s). The
/// harness derives two earlier points from it:
///
/// * **wind-down** at backstop minus `min(120s, backstop/5)`, 780s by default.
@@ -34,7 +34,7 @@ use super::super::types::WebChatTaskResult;
/// nothing delivered. Override via `OPENHUMAN_WEB_TURN_TIMEOUT_SECS`; set it to
/// `0` to disable the backstop and the derived deadlines with it.
fn web_turn_deadline() -> Option<Duration> {
- crate::agent::turn_deadline::configured_backstop()
+ crate::agent::session_host::turn_backstop::configured_backstop()
}
/// The backstop for a turn that has to be allowed to run long: one on a local /
@@ -77,12 +77,12 @@ where
{
match deadline {
// Scope the deadline on the task so the session turn hands it to the
- // harness (`agent::turn_deadline`), which winds down before `d`. The
+ // harness (`agent::session_host::turn_backstop`), which winds down before `d`. The
// turn future is boxed: it is very large, and the scope wrapper would
// otherwise hold it inline a second time and overflow the worker stack.
Some(d) => match tokio::time::timeout(
d,
- crate::agent::turn_deadline::with_turn_deadline(
+ crate::agent::session_host::turn_backstop::with_turn_deadline(
Some(tinyagents_harness::turn_deadline::TurnDeadline::starting_now(d)),
Box::pin(fut),
),
diff --git a/crates/openhuman-core/src/web_chat/ops/turn_guards_tests.rs b/crates/openhuman-core/src/web_chat/ops/turn_guards_tests.rs
index 6dcc9c030c..eb29ba7eed 100644
--- a/crates/openhuman-core/src/web_chat/ops/turn_guards_tests.rs
+++ b/crates/openhuman-core/src/web_chat/ops/turn_guards_tests.rs
@@ -18,7 +18,7 @@ async fn guarded_turn_sees_the_backstop_deadline() {
let seen = std::sync::Arc::new(std::sync::Mutex::new(None));
let seen_in_turn = seen.clone();
let res = drive_turn_with_deadline(Some(backstop), async move {
- *seen_in_turn.lock().unwrap() = crate::agent::turn_deadline::current();
+ *seen_in_turn.lock().unwrap() = crate::agent::session_host::turn_backstop::current();
Ok(result("answer"))
})
.await
@@ -34,7 +34,7 @@ async fn guarded_turn_sees_the_backstop_deadline() {
#[tokio::test]
async fn disabled_backstop_scopes_no_deadline() {
let res = drive_turn_with_deadline(None, async {
- assert!(crate::agent::turn_deadline::current().is_none());
+ assert!(crate::agent::session_host::turn_backstop::current().is_none());
Ok(result("ok"))
})
.await;