Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

chore: files changed crates/openhuman-core/src/tools/impl/browser/browser.rs,crates/openhuman-core/s

Steven Enamakel77bb85285b30
diff --git a/crates/openhuman-core/src/tools/impl/browser/browser.rs b/crates/openhuman-core/src/tools/impl/browser/browser.rs
index 1bee928ddb..5a10118251 100644
--- a/crates/openhuman-core/src/tools/impl/browser/browser.rs
+++ b/crates/openhuman-core/src/tools/impl/browser/browser.rs
@@ -9,6 +9,7 @@ mod session_pool;
mod task_actions;
#[path = "browser_unattended.rs"]
mod unattended;
+use crate::agent::turn_origin::AgentTurnOrigin;
use crate::modules::browser::BrowserClient;
use crate::security::approval::{ApprovalGate, GateOutcome};
use crate::security::SecurityPolicy;
@@ -42,6 +43,7 @@ async fn approve_browser_action(
session: &SessionId,
action: &Action,
force: bool,
+ origin: Option<&AgentTurnOrigin>,
) -> anyhow::Result<()> {
if !force && !needs_host_confirmation(action) {
return Ok(());
@@ -50,7 +52,7 @@ async fn approve_browser_action(
let kind = action_json["action"].as_str().unwrap_or("action");
// Nobody waits on an unattended approval, so the page needs no binding.
let action_digest = format!("{:x}", Sha256::digest(serde_json::to_vec(&action_json)?));
- if unattended::allow_current(&client.config().browser, kind, &action_digest) {
+ if unattended::allow(origin, &client.config().browser, kind, &action_digest) {
return Ok(());
}
let gate = ApprovalGate::try_global().ok_or_else(|| {
@@ -337,7 +339,11 @@ impl BrowserTool {
Ok(output)
}
- async fn confirm_pending(&self, args: &Value) -> anyhow::Result<Value> {
+ async fn confirm_pending(
+ &self,
+ args: &Value,
+ origin: Option<&AgentTurnOrigin>,
+ ) -> anyhow::Result<Value> {
let mut slot = self.pending.lock().await;
let held = slot
.as_ref()
@@ -347,7 +353,7 @@ impl BrowserTool {
}
let pending = slot.take().expect("pending checked above");
drop(slot);
- let approved = approve_task_action(&pending, &self.client.config().browser).await?;
+ let approved = approve_task_action(&pending, &self.client.config().browser, origin).await?;
let view = crate::modules::browser_task::resume(
self.client.config(),
ContinueTaskRequest {
@@ -365,13 +371,15 @@ impl BrowserTool {
Ok(output)
}
- async fn run(&self, args: &Value) -> anyhow::Result<Value> {
+ /// `origin` is the turn this call runs under; it decides only whether an
+ /// allow-listed action may skip the forced approval gate.
+ async fn run(&self, args: &Value, origin: Option<&AgentTurnOrigin>) -> anyhow::Result<Value> {
let verb = required(args, "action")?;
if verb == "close" {
return self.close().await;
}
match verb {
- "confirm_pending" => return self.confirm_pending(args).await,
+ "confirm_pending" => return self.confirm_pending(args, origin).await,
"task" => return self.task(args).await,
"task_continue" => return self.task_continue(args).await,
"task_cancel" => return self.task_cancel(args).await,
@@ -458,7 +466,7 @@ impl BrowserTool {
}
_ => {
let action = parse_action(args)?;
- approve_browser_action(&self.client, &id, &action, false).await?;
+ approve_browser_action(&self.client, &id, &action, false, origin).await?;
Ok(serde_json::to_value(
self.client.perform(&id, action).await?,
)?)
@@ -517,7 +525,10 @@ impl Tool for BrowserTool {
if !self.security.record_action() {
return Ok(ToolResult::error("Action blocked: rate limit exceeded"));
}
- match self.run(&args).await {
+ // The typed origin bound to this turn's immutable CoreContext by its
+ // entry point (cron, background job, workflow, chat).
+ let origin = crate::core::runtime::CoreContext::current_turn_origin();
+ match self.run(&args, origin.as_ref()).await {
Ok(v) => Ok(ToolResult::success(serde_json::to_string_pretty(&v)?)),
Err(e) => Ok(ToolResult::error(e.to_string())),
}
diff --git a/crates/openhuman-core/src/tools/impl/browser/browser_task_actions.rs b/crates/openhuman-core/src/tools/impl/browser/browser_task_actions.rs
index 1e64eafd27..b9d37cd73a 100644
--- a/crates/openhuman-core/src/tools/impl/browser/browser_task_actions.rs
+++ b/crates/openhuman-core/src/tools/impl/browser/browser_task_actions.rs
@@ -48,6 +48,7 @@ pub(super) fn task_inputs(args: &Value) -> anyhow::Result<BTreeMap<String, Strin
pub(super) async fn approve_task_action(
pending: &Pending,
browser: &crate::config::BrowserConfig,
+ origin: Option<&crate::agent::turn_origin::AgentTurnOrigin>,
) -> anyhow::Result<bool> {
let clean = |raw: &str| {
let cleaned = raw.chars().filter(|c| !c.is_control()).collect::<String>();
@@ -61,7 +62,7 @@ pub(super) async fn approve_task_action(
"task": pending.task, "action": pending.action, "target": pending.target
}))?);
let digest_hex = format!("{digest:x}");
- if super::unattended::allow_current(browser, "task_step", &digest_hex) {
+ if super::unattended::allow(origin, browser, "task_step", &digest_hex) {
return Ok(true);
}
let gate = ApprovalGate::try_global().ok_or_else(|| {
diff --git a/crates/openhuman-core/src/tools/impl/browser/browser_unattended.rs b/crates/openhuman-core/src/tools/impl/browser/browser_unattended.rs
index d4ec0f67d3..3288a0e0ef 100644
--- a/crates/openhuman-core/src/tools/impl/browser/browser_unattended.rs
+++ b/crates/openhuman-core/src/tools/impl/browser/browser_unattended.rs
@@ -7,7 +7,7 @@
//! unattended_actions` names the gated kinds such a turn may take without
//! asking; every other origin keeps the forced gate exactly as it was.
-use crate::agent::turn_origin::{self, AgentTurnOrigin, TrustedAutomationSource};
+use crate::agent::turn_origin::{AgentTurnOrigin, TrustedAutomationSource};
use crate::config::BrowserConfig;
/// A turn the user authorized ahead of time and nobody is watching live.
@@ -35,16 +35,22 @@ pub(super) fn allowed_for(
origin.is_some_and(is_unattended) && browser.allows_unattended(kind)
}
-/// Decide for the current turn, logging an allowed action by kind and digest
-/// only: no selector, typed value or page content reaches the log.
-pub(super) fn allow_current(browser: &BrowserConfig, kind: &str, digest_hex: &str) -> bool {
- let origin = turn_origin::current();
- let allowed = allowed_for(origin.as_ref(), browser, kind);
+/// Decide for the turn `origin` the tool was called under (read once from the
+/// per-turn `CoreContext` in `BrowserTool::execute`), logging an allowed
+/// action by kind and digest only: no selector, typed value or page content
+/// reaches the log.
+pub(super) fn allow(
+ origin: Option<&AgentTurnOrigin>,
+ browser: &BrowserConfig,
+ kind: &str,
+ digest_hex: &str,
+) -> bool {
+ let allowed = allowed_for(origin, browser, kind);
if allowed {
tracing::info!(
action = kind,
action_digest = %digest_hex.get(..12).unwrap_or(digest_hex),
- origin = %origin.as_ref().map(AgentTurnOrigin::class).unwrap_or_default(),
+ origin = %origin.map(AgentTurnOrigin::class).unwrap_or_default(),
"[browser] unattended action allowed by [browser] unattended_actions"
);
}