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(security): add approval gate for tool calls
Steven Enamakel49694a193dca
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rsindex 7480c2382a..0772427c63 100644--- a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs+++ b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs@@ -194,8 +194,6 @@ pub(super) fn assemble_turn_harness("[models] assembling turn harness with SDK retry/fallback policy");harness.with_policy(policy);- // Per-tool deadlines (`ToolTimeout` policies) are enforced only when the- // host installs the shared settings; see `install_harness_tool_timeouts`.crate::tools::timeout::install_harness_tool_timeouts(&mut harness);// Deterministic internal runs (summarizer/triage/memory-scoring style) may// reuse a prior identical model response; attach an in-memory response cachediff --git a/crates/openhuman-core/src/channels/host/channel_events_tests.rs b/crates/openhuman-core/src/channels/host/channel_events_tests.rsindex 958bfdb4a4..f2f5ec1079 100644--- a/crates/openhuman-core/src/channels/host/channel_events_tests.rs+++ b/crates/openhuman-core/src/channels/host/channel_events_tests.rs@@ -82,7 +82,6 @@ fn approval(thread_id: Option<&str>, client_id: Option<&str>) -> DomainEvent {tool_call_id: None,expires_at: None,agent_id: None,- detached: false,}}diff --git a/crates/openhuman-core/src/core/events.rs b/crates/openhuman-core/src/core/events.rsindex ce856f337a..edfe2e3608 100644--- a/crates/openhuman-core/src/core/events.rs+++ b/crates/openhuman-core/src/core/events.rs@@ -568,12 +568,6 @@ pub enum DomainEvent {/// The embedded agent whose turn parked this call, if any.#[serde(default, skip_serializing_if = "Option::is_none")]agent_id: Option<String>,- /// The park runs on a task detached from the chat turn it is routed- /// to (an async-delegated sub-agent, #5499), so it can outlive that- /// turn. The chat surface keeps a detached card across the turn's- /// `chat_done` and clears it on `ApprovalDecided` instead.- #[serde(default, skip_serializing_if = "std::ops::Not::not")]- detached: bool,},/// User decided a pending approval. Published by `approval_decide`/// RPC handler after the gate's parked future resolves.diff --git a/crates/openhuman-core/src/core/events_tests.rs b/crates/openhuman-core/src/core/events_tests.rsindex e30583051b..87845498e3 100644--- a/crates/openhuman-core/src/core/events_tests.rs+++ b/crates/openhuman-core/src/core/events_tests.rs@@ -549,7 +549,6 @@ fn approval_requested_does_not_surface_session_id() {tool_call_id: None,expires_at: None,agent_id: None,- detached: false,};let dbg = format!("{event:?}");assert!(diff --git a/crates/openhuman-core/src/security/approval/gate.rs b/crates/openhuman-core/src/security/approval/gate.rsindex cf9d7e88fb..c2b8c7cc00 100644--- a/crates/openhuman-core/src/security/approval/gate.rs+++ b/crates/openhuman-core/src/security/approval/gate.rs@@ -112,6 +112,15 @@ const SUBAGENT_APPROVAL_TTL: Duration = Duration::from_secs(180);/// [`is_unanswered_approval_reason`].pub const APPROVAL_UNANSWERED_PHRASE: &str = "nobody answered the approval prompt";+/// Whether the parked `request_id` was routed to its chat thread from a task+/// detached from that turn (an async-delegated sub-agent, #5499), so its card+/// can outlive the turn. Read by the web-channel surface when it bridges+/// `ApprovalRequested` (the route is recorded before the event is published);+/// `false` when no gate is installed or the request is unknown.+pub fn is_detached_request(request_id: &str) -> bool {+ ApprovalGate::try_global().is_some_and(|gate| gate.request_is_detached(request_id))+}+/// Whether a [`GateOutcome::Deny`] reason is a TTL expiry (the prompt went/// unanswered) rather than a refusal.pub fn is_unanswered_approval_reason(reason: &str) -> bool {diff --git a/crates/openhuman-core/src/security/approval/gate_intercept.rs b/crates/openhuman-core/src/security/approval/gate_intercept.rsindex 718dee0c19..fef23fdac9 100644--- a/crates/openhuman-core/src/security/approval/gate_intercept.rs+++ b/crates/openhuman-core/src/security/approval/gate_intercept.rs@@ -254,7 +254,8 @@ impl ApprovalGate {// from the chat turn that shows it — an async-delegated sub-agent. Such// a park can outlive that turn (the parent replies "I've asked the// image agent…" and its `chat_done` fires while the child still waits- // here), so the surface is told the card is `detached`: the frontend+ // here), so the route records it as `detached` and the web surface+ // (`is_detached_request`) marks the card: the frontend// keeps it across the parent's turn end instead of clearing it as a// park that "cannot outlive its turn" — the clear that left every// async `image_agent` / `video_agent` approval invisible until it@@ -537,7 +538,6 @@ impl ApprovalGate {tool_call_id: tool_call_id.map(str::to_string),expires_at: expires_at.map(|t| t.to_rfc3339()),agent_id: agent_id.clone(),- detached,});// Flow-origin surface bridge (flow-approval-surface, PR3): a flow rundiff --git a/crates/openhuman-core/src/security/approval/mod.rs b/crates/openhuman-core/src/security/approval/mod.rsindex 6e0eff6d69..bbe7a890ea 100644--- a/crates/openhuman-core/src/security/approval/mod.rs+++ b/crates/openhuman-core/src/security/approval/mod.rs@@ -22,7 +22,7 @@ mod store_documents;pub mod types;pub use gate::{- is_unanswered_approval_reason, parse_approval_reply, ApprovalChatContext, ApprovalError,+ is_detached_request, is_unanswered_approval_reason, parse_approval_reply, ApprovalChatContext, ApprovalError,ApprovalGate, FlowRunContext, APPROVAL_CHAT_CONTEXT, APPROVAL_COPILOT_STREAM_CONTEXT,APPROVAL_FLOW_RUN_CONTEXT, APPROVAL_UNANSWERED_PHRASE,};diff --git a/crates/openhuman-core/src/web_chat/event_bus.rs b/crates/openhuman-core/src/web_chat/event_bus.rsindex cf26e606c8..e2c7bcee63 100644--- a/crates/openhuman-core/src/web_chat/event_bus.rs+++ b/crates/openhuman-core/src/web_chat/event_bus.rs@@ -621,11 +621,10 @@ impl EventHandler<DomainEvent> for ApprovalSurfaceSubscriber {tool_call_id,expires_at,agent_id: _,- detached,} => match (thread_id, client_id) {(Some(thread_id), Some(client_id)) => {log::info!(- "[web-channel] approval-surface emitting approval_request request_id={request_id} thread_id={thread_id} client_id={client_id} tool={tool_name} detached={detached}"+ "[web-channel] approval-surface emitting approval_request request_id={request_id} thread_id={thread_id} client_id={client_id} tool={tool_name}");publish_web_channel_event(approval_request_event(request_id,@@ -636,7 +635,7 @@ impl EventHandler<DomainEvent> for ApprovalSurfaceSubscriber {client_id,tool_call_id.as_deref(),expires_at.as_deref(),- *detached,+ crate::security::approval::is_detached_request(request_id),));}_ => {