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(browser): send the Chrome path and persistent profile with each task
Shanu02a5be979ab2
diff --git a/crates/openhuman-core/src/modules/README.md b/crates/openhuman-core/src/modules/README.mdindex f9224d9b74..288671f64b 100644--- a/crates/openhuman-core/src/modules/README.md+++ b/crates/openhuman-core/src/modules/README.md@@ -217,7 +217,8 @@ download, its `dlopen`, or its resident memory.| [`computer_config.rs`](computer_config.rs) | `tinycomputer` | The private configuration: `jev` (decision model), `planner` (planner, rescue and output models), `browser` (Chrome path), `trace_path`. Rebuilt from `[computer]` and stored credentials on every call; `OPENHUMAN_COMPUTER_TRACE` turns tracing on. || [`computer.rs`](computer.rs) | `tinycomputer` | `status` for the Computer settings page: lifecycle state, configured routes, and optionally what the module reports through `Describe`. || [`browser.rs`](browser.rs) | `tinycomputer` | `BrowserClient` for the `Browser*` members, over the desktop proxy, plus the shared website policy: "Allow all" (the list's `*`) lets the browser open any public site, private and local addresses still refused. |-| [`browser_task.rs`](browser_task.rs) | `tinycomputer` | Browser tasks over `StartTask` / `AwaitTask` / `ContinueTask`: `start`, `wait`, `resume`, `cancel`, `report`. The host keeps the policy (surfaces, origins, action budget, approvals). |+| [`browser_task.rs`](browser_task.rs) | `tinycomputer` | Browser tasks over `StartTask` / `AwaitTask` / `ContinueTask`: `start`, `wait`, `resume`, `cancel`, `report`. The host keeps the policy (surfaces, origins, action budget, approvals) and sends Browser Control's Chrome path, and in persistent mode its profile folder, with every task, read from the settings each time. |+| [`browser_profile.rs`](browser_profile.rs) | `tinycomputer` | Whether a running Chrome holds the persistent profile folder, by the lock Chrome keeps there (`SingletonLock`, or `lockfile` on Windows). Chrome lets one browser at a time use a profile, so a task waits up to 5 s for one closing on it, then runs in a fresh profile. || [`browser_task_report.rs`](browser_task_report.rs) | `tinycomputer` | What is kept when a task stops: a content-free log summary, and with tracing on the full report under `<workspace>/state/computer/tasks/`. || [`browser_sites.rs`](browser_sites.rs), [`browser_sites/store.rs`](browser_sites/store.rs) | `tinycomputer` | Per-site memory of plans and elements learned by finished tasks, in `<workspace>/state/computer/sites/<site>.json`, with 30-day expiry. Fed back on `StartTask`; never reaches the agent's memory or prompts. || [`connectors.rs`](connectors.rs) | `tinyconnectors` | `proxy`, `call`, `call_stateless`, `call_bare`, `reconcile_route_if_loaded`. Builds the route configuration (signed-in backend or the user's own Composio key) and reconciles it on every call so sign-out reaches the module. |diff --git a/crates/openhuman-core/src/modules/browser_profile.rs b/crates/openhuman-core/src/modules/browser_profile.rsnew file mode 100644index 0000000000..f1b76602f5--- /dev/null+++ b/crates/openhuman-core/src/modules/browser_profile.rs@@ -0,0 +1,77 @@+//! Whether a running Chrome holds a profile folder, and waiting a moment for+//! one that is closing to let it go.+//!+//! Chrome lets one browser at a time use a profile folder: a second one+//! started on it hands its window to the first and exits, so a browser task+//! given the persistent profile while another Chrome holds it could not+//! start its browser. A task waits up to [`PROFILE_WAIT`] for a Chrome that+//! is closing (the one the task before it closes as it ends), and otherwise+//! runs in a fresh profile.++use std::path::Path;+use std::time::Duration;++/// How long a task waits for the Chrome holding its persistent profile to+/// let it go before it runs in a fresh profile instead.+pub(crate) const PROFILE_WAIT: Duration = Duration::from_secs(5);++/// How often the profile is looked at while waiting.+const PROFILE_POLL: Duration = Duration::from_millis(250);++/// Whether a running Chrome holds the profile folder `path`, by the lock it+/// keeps there: on macOS and Linux a `SingletonLock` link naming the host and+/// the process holding it, on Windows a `lockfile` held open. A link naming+/// another host is taken as held, as Chrome takes it; one naming a process+/// that is gone is a lock left by a crash, and free.+pub(crate) fn in_use(path: &Path) -> bool {+ #[cfg(windows)]+ {+ let lock = path.join("lockfile");+ lock.exists() && std::fs::OpenOptions::new().write(true).open(&lock).is_err()+ }+ #[cfg(not(windows))]+ {+ let Ok(target) = std::fs::read_link(path.join("SingletonLock")) else {+ return false;+ };+ held_by(&target.to_string_lossy())+ }+}++/// Whether a `SingletonLock` link's target, `<host>-<pid>`, names a live+/// process on this host, or another host.+#[cfg(not(windows))]+fn held_by(target: &str) -> bool {+ let Some((host, pid)) = target.rsplit_once('-') else {+ return false;+ };+ let Ok(pid) = pid.parse::<u32>() else {+ return false;+ };+ if sysinfo::System::host_name().is_some_and(|here| here != host) {+ return true;+ }+ let pid = sysinfo::Pid::from_u32(pid);+ let mut system = sysinfo::System::new();+ system.refresh_processes(sysinfo::ProcessesToUpdate::Some(&[pid]), true);+ system.process(pid).is_some()+}++/// Waits up to `wait` for no Chrome to hold the profile folder `path`;+/// whether it is free.+pub(crate) async fn free_within(path: &Path, wait: Duration) -> bool {+ let deadline = tokio::time::Instant::now() + wait;+ loop {+ if !in_use(path) {+ return true;+ }+ if tokio::time::Instant::now() >= deadline {+ return false;+ }+ tokio::time::sleep(PROFILE_POLL).await;+ }+}++#[cfg(test)]+#[path = "browser_profile_tests.rs"]+mod tests;diff --git a/crates/openhuman-core/src/modules/browser_profile_tests.rs b/crates/openhuman-core/src/modules/browser_profile_tests.rsnew file mode 100644index 0000000000..84cc3ed4c9--- /dev/null+++ b/crates/openhuman-core/src/modules/browser_profile_tests.rs@@ -0,0 +1,78 @@+use super::*;++/// A fresh profile folder under the system temporary directory.+fn folder(name: &str) -> std::path::PathBuf {+ let path = std::env::temp_dir().join(format!(+ "openhuman-browser-profile-{}-{name}",+ std::process::id()+ ));+ let _ = std::fs::remove_dir_all(&path);+ std::fs::create_dir_all(&path).unwrap();+ path+}++#[test]+fn a_folder_no_chrome_has_locked_is_free() {+ let path = folder("unlocked");+ assert!(!in_use(&path));+ assert!(!in_use(&path.join("missing")));+ let _ = std::fs::remove_dir_all(&path);+}++#[cfg(not(windows))]+#[test]+fn a_lock_naming_a_live_process_here_holds_the_folder() {+ let here = sysinfo::System::host_name().unwrap_or_default();+ let path = folder("live");+ std::os::unix::fs::symlink(+ format!("{here}-{}", std::process::id()),+ path.join("SingletonLock"),+ )+ .unwrap();+ assert!(in_use(&path));+ let _ = std::fs::remove_dir_all(&path);+}++#[cfg(not(windows))]+#[test]+fn a_lock_a_crashed_chrome_left_behind_is_free_and_another_hosts_is_held() {+ let here = sysinfo::System::host_name().unwrap_or_default();+ // No process has this id: the lock outlived its Chrome.+ let path = folder("stale");+ std::os::unix::fs::symlink(format!("{here}-4294967"), path.join("SingletonLock")).unwrap();+ assert!(!in_use(&path));+ let _ = std::fs::remove_dir_all(&path);++ let path = folder("elsewhere");+ std::os::unix::fs::symlink(+ format!("not-{here}-{}", std::process::id()),+ path.join("SingletonLock"),+ )+ .unwrap();+ assert!(in_use(&path), "a profile another computer holds is held");+ let _ = std::fs::remove_dir_all(&path);++ // A link with no process in it is no lock Chrome wrote.+ assert!(!held_by("no-number-here"));+ assert!(!held_by("nodash"));+}++#[cfg(not(windows))]+#[tokio::test]+async fn waiting_ends_as_soon_as_the_folder_is_let_go() {+ let here = sysinfo::System::host_name().unwrap_or_default();+ let path = folder("closing");+ let lock = path.join("SingletonLock");+ std::os::unix::fs::symlink(format!("{here}-{}", std::process::id()), &lock).unwrap();+ assert!(!free_within(&path, Duration::from_millis(300)).await);+ let letting_go = {+ let lock = lock.clone();+ tokio::spawn(async move {+ tokio::time::sleep(Duration::from_millis(300)).await;+ std::fs::remove_file(lock).unwrap();+ })+ };+ assert!(free_within(&path, PROFILE_WAIT).await);+ letting_go.await.unwrap();+ let _ = std::fs::remove_dir_all(&path);+}diff --git a/crates/openhuman-core/src/modules/browser_task.rs b/crates/openhuman-core/src/modules/browser_task.rsindex 9b8da19b0d..da4da23ce3 100644--- a/crates/openhuman-core/src/modules/browser_task.rs+++ b/crates/openhuman-core/src/modules/browser_task.rs@@ -69,8 +69,12 @@ pub fn start_request(config: &Config, task: &BrowserTask) -> StartTaskRequest {allow_destructive: false,browser_endpoint: None,headed: !config.browser.headless,- browser_executable: None,- browser_profile: None,+ // Read from the settings for every task, so a saved Chrome path+ // or profile applies without restarting the app.+ browser_executable: config.browser.chrome_path.clone(),+ browser_profile: (config.browser.profile_mode == "persistent")+ .then(|| config.browser.profile_path.clone())+ .flatten(),},budget: TaskBudget {max_actions: Some(task.max_actions),@@ -114,6 +118,7 @@ pub(crate) async fn begin<'a>(return Err("a browser task needs at least one allowed origin".to_owned());}let mut request = start_request(config, task);+ free_profile(&mut request, super::browser_profile::PROFILE_WAIT).await;let mut following = super::browser_sites::apply(config, task, &mut request).await;tracing::debug!(origins = task.origins.len(),@@ -281,6 +286,23 @@ fn refused_flow(error: &str) -> bool {))}+/// Leaves `request` its persistent profile only when no other Chrome holds+/// it within `wait`. Chrome lets one browser at a time use a profile folder,+/// so a task waits a moment for one closing on it (the browser of the task+/// before it, which closes as it ends), and otherwise runs in a fresh profile+/// rather than fail to start its browser.+async fn free_profile(request: &mut StartTaskRequest, wait: Duration) {+ let Some(profile) = request.constraints.browser_profile.clone() else {+ return;+ };+ if !super::browser_profile::free_within(std::path::Path::new(&profile), wait).await {+ tracing::warn!(+ "[browser-task] another Chrome holds the persistent profile; this task runs in a fresh profile"+ );+ request.constraints.browser_profile = None;+ }+}+fn unwrap_response<Reply>(member: &str, response: AgentResponse<Reply>) -> Result<Reply, String> {match (response.ok, response.data, response.error) {(true, Some(data), _) => Ok(data),diff --git a/crates/openhuman-core/src/modules/browser_task_tests.rs b/crates/openhuman-core/src/modules/browser_task_tests.rsindex 67f7d974fd..89a3356962 100644--- a/crates/openhuman-core/src/modules/browser_task_tests.rs+++ b/crates/openhuman-core/src/modules/browser_task_tests.rs@@ -34,6 +34,34 @@ fn start_request_confines_the_task_to_the_browser_under_host_policy() {assert_eq!(request.budget.max_rescues, Some(2));}+#[test]+fn a_task_carries_the_chrome_path_and_the_persistent_profile_from_settings() {+ let mut config = Config::default();+ config.browser.chrome_path =+ Some("/Users/asha/Desktop/Google Chrome.app/Contents/MacOS/Google Chrome".into());+ config.browser.profile_mode = "persistent".into();+ config.browser.profile_path = Some("/Users/asha/.openhuman/chrome".into());+ let request = start_request(&config, &task());+ assert_eq!(+ request.constraints.browser_executable.as_deref(),+ Some("/Users/asha/Desktop/Google Chrome.app/Contents/MacOS/Google Chrome")+ );+ assert_eq!(+ request.constraints.browser_profile.as_deref(),+ Some("/Users/asha/.openhuman/chrome")+ );+ // A fresh profile is the module's own temporary one.+ config.browser.profile_mode = "fresh".into();+ assert!(start_request(&config, &task())+ .constraints+ .browser_profile+ .is_none());+ assert!(start_request(&Config::default(), &task())+ .constraints+ .browser_executable+ .is_none());+}+#[test]fn a_traced_host_asks_the_module_to_record_every_decision() {let mut config = Config::default();@@ -123,6 +151,45 @@ fn unwrap_response_returns_data_or_the_structured_error() {.contains("no result"));}+#[tokio::test]+async fn a_task_keeps_the_persistent_profile_only_while_no_other_chrome_holds_it() {+ let mut config = Config::default();+ config.browser.profile_mode = "persistent".into();+ let profile =+ std::env::temp_dir().join(format!("openhuman-task-profile-{}", std::process::id()));+ let _ = std::fs::remove_dir_all(&profile);+ std::fs::create_dir_all(&profile).unwrap();+ config.browser.profile_path = Some(profile.to_string_lossy().into_owned());++ // Free: the task keeps it.+ let mut request = start_request(&config, &task());+ free_profile(&mut request, Duration::from_millis(50)).await;+ assert_eq!(+ request.constraints.browser_profile.as_deref(),+ config.browser.profile_path.as_deref()+ );++ // Held by a running Chrome (here, this process): a fresh profile instead.+ #[cfg(not(windows))]+ {+ let here = sysinfo::System::host_name().unwrap_or_default();+ std::os::unix::fs::symlink(+ format!("{here}-{}", std::process::id()),+ profile.join("SingletonLock"),+ )+ .unwrap();+ let mut request = start_request(&config, &task());+ free_profile(&mut request, Duration::from_millis(50)).await;+ assert!(request.constraints.browser_profile.is_none());+ }+ let _ = std::fs::remove_dir_all(&profile);++ // No persistent profile: nothing to wait for.+ let mut request = start_request(&Config::default(), &task());+ free_profile(&mut request, Duration::from_millis(50)).await;+ assert!(request.constraints.browser_profile.is_none());+}+#[test]fn a_saved_flow_is_run_instead_of_planned() {let flow: tinycomputer_bus::Flow = serde_json::from_value(serde_json::json!({diff --git a/crates/openhuman-core/src/modules/mod.rs b/crates/openhuman-core/src/modules/mod.rsindex ac524919db..c6bfec1930 100644--- a/crates/openhuman-core/src/modules/mod.rs+++ b/crates/openhuman-core/src/modules/mod.rs@@ -30,7 +30,8 @@//! - [`documents`] — the host half of the `tinydocs` module's three operations.//! - [`browser`] and [`browser_task`] — TinyComputer browser members and tasks//! without linking the browser engine into the core; [`browser_sites`] keeps-//! what finished tasks learned about each site for the next task there.+//! what finished tasks learned about each site for the next task there, and+//! [`browser_profile`] tells whether a Chrome holds the persistent profile.//! - [`wallet`] — the host half of the `tinywallet` module, which builds and//! assembles transactions while the signing key stays in this process.//! - [`host`] — the module broker, connection and loader.@@ -44,6 +45,8 @@ pub mod boot;#[cfg(feature = "modules")]pub mod browser;#[cfg(feature = "modules")]+pub(crate) mod browser_profile;+#[cfg(feature = "modules")]pub(crate) mod browser_sites;#[cfg(feature = "modules")]pub mod browser_task;diff --git a/crates/openhuman-core/src/tools/impl/browser/browser.rs b/crates/openhuman-core/src/tools/impl/browser/browser.rsindex 8d2c827756..2f6ec71c46 100644--- a/crates/openhuman-core/src/tools/impl/browser/browser.rs+++ b/crates/openhuman-core/src/tools/impl/browser/browser.rs@@ -284,6 +284,16 @@ impl BrowserTool {flow,site,};+ // The browser this conversation keeps open holds the persistent+ // profile, which the task's own browser needs: it is let go first.+ if self.client.config().browser.profile_mode == "persistent" {+ if let Err(error) = self.close().await {+ tracing::debug!(+ error = %error,+ "[tool.browser] could not close this conversation's browser before a task"+ );+ }+ }let view = crate::modules::browser_task::start(self.client.config(), &task).await.map_err(anyhow::Error::msg)?;