The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(agent): add turn guards for web chat sessions
Steven Enamakele28b5a37f07b
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rsindex ced685c839..630c58eca0 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs@@ -614,8 +614,12 @@ impl OpenHumanTurnPrelude {);run_context.dispatch = Some(Arc::new(crate::agent::tinyagents::host::TurnDispatchState::new(- crate::agent::tinyagents::agent_turn_wall_clock_ms()- .map(std::time::Duration::from_millis),+ crate::agent::tinyagents::agent_turn_wall_clock_ms_for(+ self.runtime_config+ .as_deref()+ .is_some_and(crate::agent::tinyagents::chat_provider_is_local),+ )+ .map(std::time::Duration::from_millis),),));run_context.sandbox_mode = Some(self.sandbox_mode);diff --git a/crates/openhuman-core/src/agent/tinyagents/mod.rs b/crates/openhuman-core/src/agent/tinyagents/mod.rsindex 8e5e1a7858..1b5901ec7f 100644--- a/crates/openhuman-core/src/agent/tinyagents/mod.rs+++ b/crates/openhuman-core/src/agent/tinyagents/mod.rs@@ -90,7 +90,10 @@ pub(crate) use turn_outcome::{};#[cfg(test)]pub(crate) use turn_policy::is_subagent_spawn_or_delegate_tool;-pub(crate) use turn_policy::{agent_turn_wall_clock_ms, ToolPolicyEnforcement};+pub(crate) use turn_policy::{+ agent_turn_wall_clock_ms, agent_turn_wall_clock_ms_for, chat_provider_is_local,+ local_web_turn_backstop_secs, ToolPolicyEnforcement,+};pub(crate) use turn_runner::{run_root_turn_via_hosted_agent, run_turn_via_tinyagents_shared};// Test-only glue so `tinyagents_tests.rs`'s `use super::*;` sees thediff --git a/crates/openhuman-core/src/web_chat/ops/turn_guards.rs b/crates/openhuman-core/src/web_chat/ops/turn_guards.rsindex 1fe830f4f8..2858f63016 100644--- a/crates/openhuman-core/src/web_chat/ops/turn_guards.rs+++ b/crates/openhuman-core/src/web_chat/ops/turn_guards.rs@@ -32,6 +32,30 @@ fn web_turn_deadline() -> Option<Duration> {(secs > 0).then(|| Duration::from_secs(secs))}+/// The backstop for a turn that has to be allowed to run long: one on a local /+/// self-hosted provider (#6042), whose prefill alone can take many minutes. The+/// explicit `OPENHUMAN_WEB_TURN_TIMEOUT_SECS` override still wins; otherwise the+/// default is the local turn ceiling plus a grace period, never the hosted 900s,+/// which sat below the harness's own ceilings and pre-empted them.+async fn resolve_web_turn_deadline() -> Option<Duration> {+ if std::env::var("OPENHUMAN_WEB_TURN_TIMEOUT_SECS").is_ok() {+ return web_turn_deadline();+ }+ let local = match crate::config::rpc::load_config_with_timeout().await {+ Ok(config) => crate::agent::tinyagents::chat_provider_is_local(&config),+ Err(error) => {+ log::debug!("[web-channel] backstop locality probe skipped: {error}");+ false+ }+ };+ if local {+ let secs = crate::agent::tinyagents::local_web_turn_backstop_secs();+ log::debug!("[web-channel] local provider: turn backstop {secs:?}s (#6042)");+ return secs.map(Duration::from_secs);+ }+ web_turn_deadline()+}+/// Drive a chat-turn future under the wall-clock backstop.////// On elapse the inner future is dropped (cooperative teardown at its next@@ -89,7 +113,7 @@ wherebiased;_ = cancel_token.cancelled() => None,res = drive_turn_with_deadline(- web_turn_deadline(),+ resolve_web_turn_deadline().await,crate::agent::turn_origin::with_origin(origin,crate::security::approval::APPROVAL_CHAT_CONTEXT.scope(approval_ctx, fut),