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(security_gate): give a refused approval a reason the model can read
M3gA-Mind44c3028b6be4
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs b/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rsindex 385caeb4be..42364f82d8 100644--- a/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs+++ b/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs@@ -90,6 +90,7 @@ use crate::security::policy::{CommandClass, GateDecision as PolicyGateDecision,use crate::security::prompt_injection::{enforce_prompt_input, PromptEnforcementAction, PromptEnforcementContext,};+use crate::security::POLICY_DENIED_MARKER;use crate::tools::agent_policy::{ToolPolicyAction, ToolPolicySession};use tinytools::{PermissionLevel, Tool};@@ -305,11 +306,15 @@ impl OpenHumanSecurityGate {/// Parks the turn on the human approval flow and reports how it settled.///- /// Returns [`GateDecision::Prompted`] whichever way it resolves — including- /// the TTL timeout, which `ApprovalGate` itself renders as a `Deny`. That is- /// the whole point of the `Prompted` variant: the interactive flow stays- /// host-side and the runtime only sees the settled answer, never a hint that- /// a human was (or was not) at the keyboard.+ /// An approval returns [`GateDecision::Prompted`]; a refusal — a Deny, the+ /// TTL timeout, or a dropped channel, all of which `ApprovalGate` renders as+ /// a `Deny` — returns [`GateDecision::Deny`] via [`decision_for_outcome`].+ /// A `Prompted { approved: false }` carries no reason, so the harness fell+ /// back to a bare "tool call was not approved": the model then asked the+ /// user to approve, or reached the same result through `shell` instead.+ /// The Deny text gives it the parity `ApprovalSecurityMiddleware` already+ /// had, while still never hinting that a human was (or was not) at the+ /// keyboard.async fn park_for_approval(&self, call: &ToolCallRequest) -> GateDecision {let Some(gate) = ApprovalGate::try_global() else {// Parity with `ApprovalSecurityMiddleware`: no gate installed means@@ -340,31 +345,45 @@ impl OpenHumanSecurityGate {let (outcome, request_id) = gate.intercept_audited(&call.tool_name, &summary, redacted).await;- match outcome {- GateOutcome::Allow => {- // Only an approval that persisted a row yields an id; the- // session-allowlist shortcut returns `None` and has nothing to- // record. A call with no `call_id` cannot be correlated back,- // so the id is dropped rather than stored under a key no- // executor can ask for.- if let (Some(request_id), Some(call_id)) = (request_id, call.call_id.as_ref()) {- self.pending_audit- .lock()- .unwrap_or_else(|poisoned| poisoned.into_inner())- .insert(call_id.as_str().to_string(), request_id);- }- GateDecision::Prompted { approved: true }- }- GateOutcome::Deny { reason } => {- tracing::warn!(- target: "tinyagents",- tool = %call.tool_name,- reason = %reason,- "[tinyagents::host::security] approval flow declined the tool call"- );- GateDecision::Prompted { approved: false }+ if matches!(outcome, GateOutcome::Allow) {+ // Only an approval that persisted a row yields an id; the+ // session-allowlist shortcut returns `None` and has nothing to+ // record. A call with no `call_id` cannot be correlated back, so+ // the id is dropped rather than stored under a key no executor can+ // ask for.+ if let (Some(request_id), Some(call_id)) = (request_id, call.call_id.as_ref()) {+ self.pending_audit+ .lock()+ .unwrap_or_else(|poisoned| poisoned.into_inner())+ .insert(call_id.as_str().to_string(), request_id);}}+ decision_for_outcome(&call.tool_name, outcome)+ }+}++/// Maps how the approval flow settled to what the runtime is told.+///+/// A refusal is a `Deny` whose text names no human and no timeout — every+/// refusal reads the same — and rules out other routes explicitly, because+/// `shell` never prompts below the full tier and was used to redo a refused+/// call.+fn decision_for_outcome(tool_name: &str, outcome: GateOutcome) -> GateDecision {+ match outcome {+ GateOutcome::Allow => GateDecision::Prompted { approved: true },+ GateOutcome::Deny { reason } => {+ tracing::warn!(+ target: "tinyagents",+ tool = %tool_name,+ reason = %reason,+ "[tinyagents::host::security] approval flow declined the tool call"+ );+ GateDecision::deny(format!(+ "{POLICY_DENIED_MARKER} This action was refused and must not be performed this \+ turn — do not retry this call and do not achieve the same result another way \+ (shell, CLI, another tool). Tell the user it was not done."+ ))+ }}}diff --git a/crates/openhuman-core/src/agent/tinyagents/host/security_gate_tests.rs b/crates/openhuman-core/src/agent/tinyagents/host/security_gate_tests.rsindex 3420d99960..3012bd8e52 100644--- a/crates/openhuman-core/src/agent/tinyagents/host/security_gate_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/host/security_gate_tests.rs@@ -454,3 +454,44 @@ async fn screen_input_never_redacts_while_replayed_history_is_trusted() {}}}++/// A refused approval must reach the model as a Deny with a reason. Returned+/// as `Prompted { approved: false }` it carried none, and the harness fell back+/// to a bare "tool call was not approved" — after which the model redid the+/// call through `shell`.+#[test]+fn a_refused_approval_is_a_deny_the_model_can_read() {+ for gate_reason in [+ "[policy-denied] User denied 'write_file' execution.",+ "[policy-denied] Approval for 'write_file' timed out after 600s.",+ ] {+ let outcome = GateOutcome::Deny {+ reason: gate_reason.to_string(),+ };+ let decision = decision_for_outcome("write_file", outcome);+ assert!(!decision.is_allowed());+ let reason = decision+ .denial_reason()+ .expect("a refused approval carries a reason for the model");+ assert!(reason.starts_with(crate::security::POLICY_DENIED_MARKER));+ assert!(reason.contains("must not be performed"), "{reason}");+ assert!(reason.contains("another way"), "{reason}");+ let lower = reason.to_lowercase();+ assert!(+ !lower.contains("user denied")+ && !lower.contains("timed out")+ && !lower.contains("human"),+ "the text must not say who refused or how: {reason}"+ );+ }+}++#[test]+fn an_approved_park_is_still_prompted_and_allowed() {+ let decision = decision_for_outcome("write_file", GateOutcome::Allow);+ assert!(matches!(+ decision,+ GateDecision::Prompted { approved: true }+ ));+ assert!(decision.is_allowed());+}