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(web_chat): add turn guards for parallel chat turns
Steven Enamakela6daae46d7f4
diff --git a/crates/openhuman-core/src/web_chat/ops/parallel_turn.rs b/crates/openhuman-core/src/web_chat/ops/parallel_turn.rsindex 3a38f8f7ad..76c3a12709 100644--- a/crates/openhuman-core/src/web_chat/ops/parallel_turn.rs+++ b/crates/openhuman-core/src/web_chat/ops/parallel_turn.rs@@ -67,7 +67,7 @@ pub(crate) async fn spawn_parallel_turn(task_cancel_token,origin.clone(),approval_ctx,- |host_env, activity| {+ |host_env, activity, approval| {run_chat_task(&client_id_task,&thread_id_task,@@ -82,6 +82,7 @@ pub(crate) async fn spawn_parallel_turn(/* fork */ true,host_env,activity,+ approval,)},)diff --git a/crates/openhuman-core/src/web_chat/ops/start_chat.rs b/crates/openhuman-core/src/web_chat/ops/start_chat.rsindex d5ebc1a689..98fba4977e 100644--- a/crates/openhuman-core/src/web_chat/ops/start_chat.rs+++ b/crates/openhuman-core/src/web_chat/ops/start_chat.rs@@ -510,7 +510,7 @@ async fn start_chat_inner(task_cancel_token,origin.clone(),approval_ctx,- |host_env, activity| {+ |host_env, activity, approval| {run_chat_task(&client_id_task,&thread_id_task,@@ -525,6 +525,7 @@ async fn start_chat_inner(/* fork */ false,host_env,activity,+ approval,)},)diff --git a/crates/openhuman-core/src/web_chat/ops/turn_guards.rs b/crates/openhuman-core/src/web_chat/ops/turn_guards.rsindex 38f1ed8e3a..5fa2448a1a 100644--- a/crates/openhuman-core/src/web_chat/ops/turn_guards.rs+++ b/crates/openhuman-core/src/web_chat/ops/turn_guards.rs@@ -216,8 +216,8 @@ fn turn_host_env(/// `run_chat_task` when building `fut`.////// `build_turn` receives the turn's [`HostTurnEnv`] -- its own cancellation-/// token (fired by a Stop) and the backstop's [`TurnDeadline`] -- and the guard's-/// [`TurnActivity`] record, and returns+/// token (fired by a Stop) and the backstop's [`TurnDeadline`] -- the guard's+/// [`TurnActivity`] record and the turn's [`ApprovalTurnContext`], and returns/// the turn future, which hands the env to the session it runs. The env is an/// explicit value, so it reaches the turn's whole run tree without any ambient/// scope.@@ -230,7 +230,7 @@ pub(crate) async fn run_turn_under_cancel_and_deadline<B, F>(build_turn: B,) -> Option<Result<WebChatTaskResult, String>>where- B: FnOnce(HostTurnEnv, TurnActivity) -> F,+ B: FnOnce(HostTurnEnv, TurnActivity, crate::security::approval::ApprovalTurnContext) -> F,F: std::future::Future<Output = Result<WebChatTaskResult, String>>,{let ids = approval_ctx.request_id.clone().map(|request_id| TurnIds {@@ -249,8 +249,11 @@ where|activity| {crate::agent::turn_origin::with_origin(origin,- crate::security::approval::APPROVAL_CHAT_CONTEXT- .scope(approval_ctx, build_turn(env, activity)),+ build_turn(+ env,+ activity,+ crate::security::approval::ApprovalTurnContext::chat(approval_ctx),+ ),)},),diff --git a/crates/openhuman-core/src/web_chat/run_task.rs b/crates/openhuman-core/src/web_chat/run_task.rsindex f437321ffc..8e37ddb187 100644--- a/crates/openhuman-core/src/web_chat/run_task.rs+++ b/crates/openhuman-core/src/web_chat/run_task.rs@@ -47,6 +47,8 @@ pub(crate) async fn run_chat_task(// The web-turn guard's activity record for this turn, passed explicitly by// `run_turn_under_cancel_and_deadline`.activity: super::turn_activity::TurnActivity,+ // Where this turn's parked approvals surface, handed to the turn itself.+ approval: crate::security::approval::ApprovalTurnContext,) -> Result<WebChatTaskResult, String> {// One turn at a time per profile: wait behind its relay and cron turns.let _turn = crate::profiles::turn_gate::acquire().await;@@ -203,7 +205,7 @@ pub(crate) async fn run_chat_task(// default test-thread stack — see the channels web-turn coverage tests).#[cfg(feature = "tinymemes")]let turn_started = std::time::Instant::now();- let turn = Box::pin(agent.run_single_with_origin(message, Some(origin)));+ let turn = Box::pin(agent.run_single_with_approval(message, Some(origin), approval));let mut result = match turn.await {Ok(response) => {// A successful turn proves the thread's balance is usable, so drop