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
fix(session_host): enforce tool rules and turn guards in run loop
Steven Enamakele1d8f1978ae5
diff --git a/crates/openhuman-core/src/agent/session_host/runtime/run_loop.rs b/crates/openhuman-core/src/agent/session_host/runtime/run_loop.rsindex 49a79d1008..5b0a20e592 100644--- a/crates/openhuman-core/src/agent/session_host/runtime/run_loop.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime/run_loop.rs@@ -44,8 +44,10 @@ impl OpenHumanSessionHost {origin: Option<crate::agent::turn_origin::AgentTurnOrigin>,approval: crate::security::approval::ApprovalTurnContext,) -> Result<String> {- let origin =- origin.or_else(|| crate::core::runtime::DispatchCtx::ambient_turn().turn_origin());+ let origin = origin.or_else(|| {+ crate::core::runtime::DispatchCtx::from_weak(self.host_env.core.as_ref())+ .turn_origin_or_scoped()+ });let guard = enforce_prompt_input(message,PromptEnforcementContext {diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rsindex 6282ffc4cf..b1cd7352b3 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs@@ -840,7 +840,7 @@ impl OpenHumanSessionHost {.unwrap_or_else(std::sync::PoisonError::into_inner).context_window = context_window;let original_user_message = user_text_with_markers(&request.input);- prelude.begin_user_effects(request);+ prelude.begin_user_effects(request, &options.run_context.data);let turn = state.lock().unwrap_or_else(|poisoned| poisoned.into_inner())diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/tool_rules.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/tool_rules.rsindex 38ebbe9299..3854095822 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session/tool_rules.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/tool_rules.rs@@ -60,9 +60,14 @@ impl OpenHumanTurnPrelude {}/// Records the user text a turn begins with, for its user-side effects.- pub(super) fn begin_user_effects(&self, request: &SessionTurnRequest) {- let user_text = crate::core::runtime::DispatchCtx::ambient_turn()- .turn_origin()+ pub(super) fn begin_user_effects(+ &self,+ request: &SessionTurnRequest,+ run_context: &OpenHumanRunContext,+ ) {+ let user_text = run_context+ .dispatch_ctx()+ .turn_origin_or_scoped().is_some_and(|origin| origin.is_user_authored()).then(|| request.input.text());self.mutablediff --git a/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs b/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rsindex 0e0103ae09..8e8a0db94e 100644--- a/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs+++ b/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs@@ -232,9 +232,7 @@ impl OpenHumanSecurityGate {/// The origin of the turn this gate authorizes for: the run's own context/// when it carries one, else the calling task's turn scope.fn turn_origin(&self) -> Option<crate::agent::turn_origin::AgentTurnOrigin> {- DispatchCtx::from_weak(self.dispatch.as_ref())- .turn_origin()- .or_else(|| DispatchCtx::ambient_turn().turn_origin())+ DispatchCtx::from_weak(self.dispatch.as_ref()).turn_origin_or_scoped()}/// Finds the registered [`Tool`] named `name`, if any.diff --git a/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs b/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rsindex 8038323c95..a903ce482a 100644--- a/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs+++ b/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs@@ -589,7 +589,7 @@ pub async fn agent_chat_reply_for(// trust statement and hand every such turn the blanket CLI allowance// instead of the narrower one it asked for.let run = crate::agent::turn_origin::with_origin(- effective_agent_chat_origin(),+ effective_agent_chat_origin(&turn_ctx),agent.run_single_with_approval(message, None, approval),);// `untrusted_input` was set on the session above; the turn's run contextdiff --git a/crates/openhuman-core/src/inference/host_runtime/ops/turn_guards.rs b/crates/openhuman-core/src/inference/host_runtime/ops/turn_guards.rsindex b911df6406..290253665e 100644--- a/crates/openhuman-core/src/inference/host_runtime/ops/turn_guards.rs+++ b/crates/openhuman-core/src/inference/host_runtime/ops/turn_guards.rs@@ -130,8 +130,9 @@ pub(super) fn grant_turn_cwd(config: &mut Config, root: &std::path::Path) {/// [`is_user_authored`](crate::agent::turn_origin::AgentTurnOrigin::is_user_authored)/// reads `false` for it and the conversation autosave would silently drop a/// real user message.-pub(super) fn effective_agent_chat_origin() -> crate::agent::turn_origin::AgentTurnOrigin {- crate::core::runtime::DispatchCtx::ambient_turn()- .turn_origin()+pub(super) fn effective_agent_chat_origin(+ ctx: &crate::core::runtime::DispatchCtx,+) -> crate::agent::turn_origin::AgentTurnOrigin {+ ctx.turn_origin_or_scoped().unwrap_or(crate::agent::turn_origin::AgentTurnOrigin::DirectChat)}