Skip to content

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

feat(agent): propagate turn deadline into tinyagents harness

Steven Enamakel632ad0c9c40c
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 5abbc911c8..16a734970f 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
@@ -20,6 +20,9 @@ impl OpenHumanSessionHost {
context.progress = self.on_progress.clone();
context.thread_id = self.thread_id.clone();
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();
let cancellation = context.cancellation.clone();
let root_config = context.root_run_config("openhuman-session");
let options = TurnOptions {
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 abcee0de49..314ce3755b 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
@@ -247,6 +247,11 @@ pub struct OpenHumanRunContext {
pub progress: Option<Sender<AgentProgress>>,
/// Stop policies evaluated after each model call.
pub stop_hooks: Vec<Arc<dyn StopHook>>,
+ /// Wall-clock deadline of the top-level turn this run belongs to, set
+ /// 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>,
/// Parent runtime snapshot used by canonical recursive tool dispatch.
pub parent: Option<ParentExecutionContext>,
/// Context-preparation sources already consumed in this turn.
@@ -353,6 +358,7 @@ impl OpenHumanRunContext {
origin: None,
progress: None,
stop_hooks: crate::agent::stop_hooks::current_stop_hooks(),
+ turn_deadline: None,
parent: None,
prepared_context_sources: Arc::new(Vec::new()),
file_state_agent_id: None,
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_runner.rs b/crates/openhuman-core/src/agent/tinyagents/turn_runner.rs
index c16a7200d6..a162b0b0d9 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_runner.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_runner.rs
@@ -299,6 +299,14 @@ pub(super) async fn run_turn_via_tinyagents_body(
run_context.tool_rules.clone(),
);
super::response_shape::install(&mut harness, hosted_root.is_some());
+ // Wind down before the outer web backstop and clamp the harness wall clock
+ // below it (`agent::turn_deadline`); a no-op for turns without a deadline.
+ let _deadline_wind_down = super::deadline_wind_down::install(
+ &mut harness,
+ handle.as_ref(),
+ run_context.turn_deadline,
+ subagent_scope.is_some(),
+ );
// Fail-closed registry validation gate (issue #4249, Workstream 10 — registry).
// The projected `CapabilityRegistry` produced these diagnostics during