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
Merge remote-tracking branch 'upstream/main' into saas-phase4b
Steven Enamakel2963eed02ddc
diff --cc crates/openhuman-core/src/user_agents/host_tests.rsindex 183ac49454,abc430b4cb..73487ed0f8--- a/crates/openhuman-core/src/user_agents/host_tests.rs+++ b/crates/openhuman-core/src/user_agents/host_tests.rs@@@ -138,25 -138,49 +138,72 @@@ fn list_reports_provisioned_agents_onlyassert_eq!(open, vec![&b]);}+#[test]+fn a_reprovisioned_agent_does_not_inherit_the_old_credential() {+ let tmp = tempfile::tempdir().unwrap();+ let host = host(&tmp, 4, 60);+ let id = agent(&format!("returning-{}", uuid::Uuid::new_v4()));+ host.provision(&id).unwrap();+ let config = host.open(&id).unwrap().config.clone();+ super::super::credentials::store(+ &config,+ super::super::credentials::UserCredentialKind::Session,+ "old-session",+ None,+ )+ .unwrap();+ assert!(host.summary(&id).unwrap().unwrap().has_credential);+ host.deprovision(&id).unwrap();+ host.provision(&id).unwrap();+ assert!(+ !host.summary(&id).unwrap().unwrap().has_credential,+ "deprovisioning must forget the credential"+ );+}+++ #[test]+ fn an_agent_in_use_is_not_archived_from_under_it() {+ let tmp = tempfile::tempdir().unwrap();+ let host = host(&tmp, 4, 60);+ let id = agent("alice");+ host.provision(&id).unwrap();+ let state = host.open(&id).unwrap();+ let err = host.deprovision(&id).unwrap_err();+ assert!(err.contains("in use"), "{err}");+ assert!(host.is_open(&id), "a refused deprovision leaves it open");+ drop(state);+ assert!(host.deprovision(&id).unwrap());+ assert!(!host.is_open(&id));+ }++ #[test]+ fn deprovisioning_twice_in_a_second_archives_twice() {+ let tmp = tempfile::tempdir().unwrap();+ let host = host(&tmp, 4, 60);+ let id = agent("alice");+ for _ in 0..2 {+ host.provision(&id).unwrap();+ assert!(host.deprovision(&id).unwrap());+ }+ let archived = std::fs::read_dir(layout::archive_dir(tmp.path()))+ .unwrap()+ .count();+ assert_eq!(archived, 2);+ }++ #[test]+ fn opening_an_open_agent_sweeps_the_idle_ones() {+ let tmp = tempfile::tempdir().unwrap();+ // Everything is idle the moment it is released.+ let host = host(&tmp, 4, 0);+ let (a, b) = (agent("alice"), agent("bob"));+ host.provision(&a).unwrap();+ host.provision(&b).unwrap();+ drop(host.open(&a).unwrap());+ let held = host.open(&b).unwrap();+ // Re-opening bob (already open) closes idle alice.+ let again = host.open(&b).unwrap();+ assert!(!host.is_open(&a), "alice was idle and is closed");+ assert!(host.is_open(&b), "bob is in use and stays");+ drop((held, again));+ }diff --cc crates/openhuman-core/src/user_agents/surface_tests.rsindex e7a85fe700,37e9802a02..816c59b052--- a/crates/openhuman-core/src/user_agents/surface_tests.rs+++ b/crates/openhuman-core/src/user_agents/surface_tests.rs@@@ -39,20 -42,13 +42,20 @@@ fn the_saas_planes_never_overlap()}#[test]-fn turn_starting_thread_methods_stay_closed_for_now() {- for method in [- "openhuman.threads_generate_title",- "openhuman.threads_edit_message",+fn chat_is_open_but_other_channel_methods_are_not() {+ assert!(visible_in(true, true, "openhuman.channel_web_chat", false));+ assert!(visible_in(+ true,+ true,"openhuman.threads_regenerate",+ false+ ));+ for method in [+ "openhuman.channels_list",+ "openhuman.channels_connect",+ "openhuman.config_update_autonomy_settings",] {- assert!(!visible_in(true, true, method, false), "{method}");+ assert!(!visible_in(true, Scope::User, method, false), "{method}");}}diff --cc crates/openhuman-core/src/web_chat/ops/channel_ops.rsindex 461fc79cca,461fc79cca..83e726e4d1--- a/crates/openhuman-core/src/web_chat/ops/channel_ops.rs+++ b/crates/openhuman-core/src/web_chat/ops/channel_ops.rs@@@ -182,6 -182,6 +182,9 @@@ pub async fn channel_web_chatrun_mode: Option<String>,metadata: ChatRequestMetadata,) -> Result<Outcome<Value>, String> {++ // A SaaS user chooses the thread id; the same rules as `threads_upsert`++ // apply (no reserved prefixes, no path-like ids). No-op outside SaaS.++ crate::user_agents::surface::check_thread_id(thread_id.trim())?;// Mirrors the socket `chat:start` payload's `run_mode` handling// (`openhuman_rpc::server::socketio`): apply it before starting the turn so// `plan_mode_middleware` sees the requested mode from the first tooldiff --cc crates/openhuman-core/src/web_chat/ops/state.rsindex a830e32fa0,e9cce3b44a..445e96e1b0--- a/crates/openhuman-core/src/web_chat/ops/state.rs+++ b/crates/openhuman-core/src/web_chat/ops/state.rs@@@ -39,23 -39,16 +39,30 @@@ pub(crate) fn key_for(thread_id: &str)scoped_key(agent.as_deref(), thread_id)}+/// `key` with the calling scope's agent prefix removed: the id the caller+/// chose, for handing back to it.+pub(crate) fn unscope(key: &str) -> String {+ let agent = crate::core::runtime::CoreContext::current()+ .and_then(|context| context.session_agent().map(str::to_owned));+ match agent {+ Some(agent) => key- .strip_prefix(&format!("{agent}::"))++ .strip_prefix(&scoped_key(Some(&agent), ""))+ .unwrap_or(key)+ .to_string(),+ None => key.to_string(),+ }+}++ /// Injective encoding of `(session_agent, thread_id)`. Both parts are caller+ /// controlled, so a plain `agent::thread` join would let `("a", "b::c")` and+ /// `("a::b", "c")` (or an unscoped `"a::b"`) share one slot. A scoped key is+ /// `\x1f<agent byte length>:<agent><thread>`; an unscoped key is the bare+ /// thread id, except that an id starting with `\x1f` gets a second `\x1f`+ /// prepended so it can never look like a scoped key.pub(crate) fn scoped_key(session_agent: Option<&str>, thread_id: &str) -> String {match session_agent {- Some(agent) => format!("{agent}::{thread_id}"),+ Some(agent) => format!("\u{1f}{}:{agent}{thread_id}", agent.len()),+ None if thread_id.starts_with('\u{1f}') => format!("\u{1f}{thread_id}"),None => thread_id.to_string(),}}diff --cc crates/openhuman-rpc/src/server/saas_gateway.rsindex 2ab368818f,eea050e85f..47377b82c3--- a/crates/openhuman-rpc/src/server/saas_gateway.rs+++ b/crates/openhuman-rpc/src/server/saas_gateway.rs@@@ -75,13 -67,21 +75,25 @@@ pub(crate) async fn saas_gateway(operatreturn refuse(404, "not found");}- let Some(user) = header_str(&req, USER_HEADER).map(str::to_owned) else {+ // Absent means the operator plane. Present but unreadable, or present+ // twice, is refused: falling back to the operator would skip the user+ // signature check.+ let mut user_headers = req.headers().get_all(USER_HEADER).iter();+ let Some(first) = user_headers.next() else {+ // The chat event stream is a user's; the operator has none.+ if path == "/events" {+ return refuse(404, "not found");+ }return CoreContext::scope(operator, next.run(req)).await;};+ if user_headers.next().is_some() {+ log::debug!("[rpc:saas] refusing a request with more than one {USER_HEADER}");+ return refuse(400, "more than one user header");+ }+ let Ok(user) = first.to_str().map(str::to_owned) else {+ log::debug!("[rpc:saas] refusing an unreadable {USER_HEADER}");+ return refuse(400, "unreadable user header");+ };let Some(secret) = openhuman_core::core::auth::get_rpc_token() else {return refuse(503, "the core is not ready");diff --cc tests/agent_harness_e2e.rsindex a1b73c7aed,9829b034d0..d770a7b3dd--- a/tests/agent_harness_e2e.rs+++ b/tests/agent_harness_e2e.rs@@@ -945,8 -945,8 +945,8 @@@ fn subagent_delegation_happy_path()async fn subagent_delegation_happy_path_inner() {let _lock = env_lock();-- let fixture_path = Path::new(env!("CARGO_MANIFEST_DIR"))- .join("../../scripts/life-scenarios/fixtures/drafts/images/handoff-hero.png");- .join("../../tests/fixtures/images/handoff-hero.png");++ let fixture_path =++ Path::new(env!("CARGO_MANIFEST_DIR")).join("../../tests/fixtures/images/handoff-hero.png");let stack = boot_stack().await;let image_path = Path::new(&std::env::var("HOME").expect("test HOME")).join("OpenHuman/projects/delegation-vision.png");@@@ -2159,8 -2159,8 +2159,8 @@@ fn multi_hop_delegation_chain()async fn multi_hop_delegation_chain_inner() {let _lock = env_lock();-- let fixture_path = Path::new(env!("CARGO_MANIFEST_DIR"))- .join("../../scripts/life-scenarios/fixtures/drafts/images/handoff-hero.png");- .join("../../tests/fixtures/images/handoff-hero.png");++ let fixture_path =++ Path::new(env!("CARGO_MANIFEST_DIR")).join("../../tests/fixtures/images/handoff-hero.png");let stack = boot_stack().await;let image_path = Path::new(&std::env::var("HOME").expect("test HOME")).join("OpenHuman/projects/delegation-vision.png");diff --cc tests/saas_mode_e2e.rsindex a5ac558001,7f7702e163..6ad1f28d2c--- a/tests/saas_mode_e2e.rs+++ b/tests/saas_mode_e2e.rs@@@ -510,127 -545,38 +545,175 @@@ fn each_user_sees_only_their_own_threaddrop(server);}+/// Open `/events?client_id=` for `user` and forward each SSE `data:` line.+fn user_events(base: &str, user: &str, client_id: &str) -> std::sync::mpsc::Receiver<String> {+ use openhuman_core::user_agents::gateway::{sign, USER_HEADER, USER_SIG_HEADER};+ use std::io::BufRead;+ let (tx, rx) = std::sync::mpsc::channel();+ let url = format!("{base}/events?client_id={client_id}");+ let user = user.to_string();+ std::thread::spawn(move || {+ let client = reqwest::blocking::Client::builder()+ .timeout(None)+ .build()+ .unwrap();+ let Ok(response) = client+ .get(&url)+ .bearer_auth(BEARER)+ .header(USER_HEADER, &user)+ .header(USER_SIG_HEADER, sign(BEARER, &user, now()))+ .send()+ else {+ return;+ };+ let _ = tx.send(format!("status:{}", response.status().as_u16()));+ for line in std::io::BufReader::new(response).lines() {+ let Ok(line) = line else { break };+ if let Some(data) = line.strip_prefix("data:") {+ if tx.send(data.trim().to_string()).is_err() {+ break;+ }+ }+ }+ });+ rx+}++#[test]+fn chat_events_reach_only_the_user_whose_turn_produced_them() {+ let d = deployment(true);+ // Point the backend at a closed port so the turn fails fast — the failure+ // is itself an event on the owner's stream, without any real inference.+ let port = free_port();+ let child = core_command(&d, &["--port", &port.to_string()])+ .env("BACKEND_URL", "http://127.0.0.1:9")+ .stdout(Stdio::null())+ .stderr(Stdio::null())+ .spawn()+ .expect("spawn openhuman-core");+ let server = Server(child);+ let base = format!("http://127.0.0.1:{port}");+ let client = reqwest::blocking::Client::builder()+ .timeout(Duration::from_secs(10))+ .build()+ .unwrap();+ let deadline = Instant::now() + Duration::from_secs(120);+ while !client+ .get(format!("{base}/health"))+ .send()+ .is_ok_and(|r| r.status().is_success())+ {+ assert!(Instant::now() < deadline, "SaaS core never became healthy");+ std::thread::sleep(Duration::from_millis(250));+ }+ provision(&client, &base, "alice");+ provision(&client, &base, "bob");++ // The operator has no chat stream.+ let status = client+ .get(format!("{base}/events?client_id=c1"))+ .bearer_auth(BEARER)+ .send()+ .unwrap()+ .status()+ .as_u16();+ assert_eq!(status, 404);++ // Both users listen on the same client id.+ let alice_events = user_events(&base, "alice", "c1");+ let bob_events = user_events(&base, "bob", "c1");+ for (who, rx) in [("alice", &alice_events), ("bob", &bob_events)] {+ let first = rx.recv_timeout(Duration::from_secs(10)).unwrap();+ assert_eq!(first, "status:200", "{who}'s stream opens");+ }+++ // A reserved thread id is refused before any turn starts.++ let (_, body) = user_rpc_with(++ &client,++ &base,++ BEARER,++ "alice",++ None,++ "openhuman.channel_web_chat",++ json!({ "client_id": "c1", "thread_id": "channel:slack:x", "message": "hello" }),++ );++ assert!(body.get("error").is_some(), "{body}");+++ let (status, body) = user_rpc_with(+ &client,+ &base,+ BEARER,+ "alice",+ None,+ "openhuman.channel_web_chat",+ json!({ "client_id": "c1", "thread_id": "chat-1", "message": "hello" }),+ );+ assert_eq!(status, 200, "{body}");++ let mut alice_got = Vec::new();+ let until = Instant::now() + Duration::from_secs(30);+ while Instant::now() < until {+ match alice_events.recv_timeout(Duration::from_millis(500)) {+ Ok(data) if data.contains("chat-1") => {+ alice_got.push(data);+ if alice_got+ .iter()+ .any(|e| e.contains("error") || e.contains("done"))+ {+ break;+ }+ }+ Ok(_) | Err(std::sync::mpsc::RecvTimeoutError::Timeout) => {}+ Err(e) => panic!("alice's stream closed: {e}"),+ }+ }+ assert!(!alice_got.is_empty(), "alice receives her turn's events");+ assert!(+ alice_got.iter().all(|e| !e.contains("\"agent\"")),+ "the routing stamp is not on the wire: {alice_got:?}"+ );++ std::thread::sleep(Duration::from_secs(1));+ let leaked: Vec<String> = bob_events.try_iter().collect();+ assert!(+ leaked.is_empty(),+ "bob shares the client id but must see none of alice's events: {leaked:?}"+ );+ drop(server);+}+++ #[test]+ fn a_duplicate_or_unreadable_user_header_is_refused() {+ use openhuman_core::user_agents::gateway::USER_HEADER;+ let d = deployment(true);+ let (server, base, client) = start(&d);+ let body =+ json!({ "jsonrpc": "2.0", "id": 1, "method": "openhuman.user_agents_list", "params": {} });++ // Two user headers: refused, never run as the operator.+ let status = client+ .post(format!("{base}/rpc"))+ .bearer_auth(BEARER)+ .header(USER_HEADER, "alice")+ .header(USER_HEADER, "bob")+ .json(&body)+ .send()+ .unwrap()+ .status()+ .as_u16();+ assert_eq!(status, 400);++ // A header value that is valid HTTP but not text: refused too.+ let unreadable = reqwest::header::HeaderValue::from_bytes(b"alice\xff").unwrap();+ let status = client+ .post(format!("{base}/rpc"))+ .bearer_auth(BEARER)+ .header(USER_HEADER, unreadable)+ .json(&body)+ .send()+ .unwrap()+ .status()+ .as_u16();+ assert_eq!(status, 400);+ drop(server);+ }diff --cc vendor/tinyagentsindex 05e4a18019,d54a85368a..1df6ad019c--- a/vendor/tinyagents+++ b/vendor/tinyagents@@@ -1,1 -1,1 +1,1 @@@- Subproject commit 05e4a180194f7b44161a9ac1fa437ac14e4e6099-Subproject commit d54a85368a6e6fbc3f21d2e8613b31b31ec74629++Subproject commit 1df6ad019ca02681cbfb26276d734b1723dbc708diff --cc vendor/tinyflowsindex 18977d58db,f9df351f2c..a48f7c57b5--- a/vendor/tinyflows+++ b/vendor/tinyflows@@@ -1,1 -1,1 +1,1 @@@- Subproject commit 18977d58dba4ac0bacbf8c3331fc27246e65431e-Subproject commit f9df351f2cd73db99dd9ea19560001a4c35a12bc++Subproject commit a48f7c57b535cdd2af3951594cb5a2ca7a91eb6c