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
chore: files changed crates/openhuman-core/src/cron/bus_host.rs,crates/openhuman-core/src/cron/bus_h
Steven Enamakel6413a0569863
diff --git a/crates/openhuman-core/src/cron/bus_host.rs b/crates/openhuman-core/src/cron/bus_host.rsindex 43e6c6184c..ff03ddeffd 100644--- a/crates/openhuman-core/src/cron/bus_host.rs+++ b/crates/openhuman-core/src/cron/bus_host.rs@@ -25,8 +25,8 @@//! thread that delivered the callback: an agent turn is deep and long, and the//! bus runtime is for serving. The binding's context is re-entered around it.-use std::future::Future;use std::collections::HashSet;+use std::future::Future;use std::sync::{Arc, RwLock, Weak};use tinybus::Result as BusResult;@@ -171,12 +171,9 @@ impl Binding {/// holds the per-flow in-flight dedupe across ticks.#[cfg(feature = "flows")]pub(crate) fn flows(&self) -> &crate::flows::bus::FlowTriggerSubscriber {- self.flows- .get_or_init(|| {- crate::flows::bus::FlowTriggerSubscriber::with_config_source(- Arc::clone(&self.config),- )- })+ self.flows.get_or_init(|| {+ crate::flows::bus::FlowTriggerSubscriber::with_config_source(Arc::clone(&self.config))+ })}}diff --git a/crates/openhuman-core/src/cron/bus_host_tests.rs b/crates/openhuman-core/src/cron/bus_host_tests.rsindex 66560dbf61..9668953d9d 100644--- a/crates/openhuman-core/src/cron/bus_host_tests.rs+++ b/crates/openhuman-core/src/cron/bus_host_tests.rs@@ -334,13 +334,23 @@ async fn refreshing_binding_config_updates_existing_flow_subscriber() {}},);- binding.flows.set(subscriber).ok().expect("subscriber initialized once");+ binding+ .flows+ .set(subscriber)+ .ok()+ .expect("subscriber initialized once");let ctx = DispatchCtx::ambient();- binding.flows().dispatch_test_app_event(&ctx, "refresh-flow", serde_json::json!({"event": "first"})).await;+ binding+ .flows()+ .dispatch_test_app_event(&ctx, "refresh-flow", serde_json::json!({"event": "first"}))+ .await;started_rx.await.unwrap();binding.set_config(&refreshed);- binding.flows().dispatch_test_app_event(&ctx, "refresh-flow", serde_json::json!({"event": "second"})).await;+ binding+ .flows()+ .dispatch_test_app_event(&ctx, "refresh-flow", serde_json::json!({"event": "second"}))+ .await;release_tx.send(()).unwrap();assert_eq!(seen_rx.recv().await, Some(initial.action_dir.clone()));assert_eq!(seen_rx.recv().await, Some(refreshed.action_dir));@@ -350,20 +360,24 @@ async fn refreshing_binding_config_updates_existing_flow_subscriber() {#[tokio::test]async fn a_scheduled_flow_run_publishes_a_trigger_before_completion() {use crate::core::events::DomainEvent;- use tokio::sync::mpsc;use tinybus::EventHandler;+ use tokio::sync::mpsc;struct CronEvents(String, mpsc::UnboundedSender<&'static str>);#[async_trait]impl EventHandler<DomainEvent> for CronEvents {- fn name(&self) -> &str { "test::cron::flow_event_pair" }+ fn name(&self) -> &str {+ "test::cron::flow_event_pair"+ }async fn handle(&self, event: &DomainEvent) {let (job_id, name) = match event {DomainEvent::CronJobTriggered { job_id, .. } => (job_id, "triggered"),DomainEvent::CronJobCompleted { job_id, .. } => (job_id, "completed"),_ => return,};- if job_id == &self.0 { let _ = self.1.send(name); }+ if job_id == &self.0 {+ let _ = self.1.send(name);+ }}}@@ -374,37 +388,69 @@ async fn a_scheduled_flow_run_publishes_a_trigger_before_completion() {let job = crate::cron::add_flow_schedule_job(&config,"flow-event-pair",- Schedule::Every { every_ms: 3_600_000 },- ).unwrap();+ Schedule::Every {+ every_ms: 3_600_000,+ },+ )+ .unwrap();let (events_tx, mut events_rx) = mpsc::unbounded_channel();let _subscription = crate::core::bus::BUS.subscribe(Arc::new(CronEvents(job.id.clone(), events_tx))).unwrap();let run_id = format!("flow-event-{}", uuid::Uuid::new_v4());- let _: Attempt = proxy.call(callbacks::EXECUTE, (&job, &run_id)).await.unwrap();- let _: Attempt = proxy.call(callbacks::SCHEDULE_TRIGGER, ("flow-event-pair", &run_id)).await.unwrap();- let _: Attempt = proxy.call(callbacks::SCHEDULE_TRIGGER, ("flow-event-pair", &run_id)).await.unwrap();- let _: String = proxy.call(callbacks::DELIVER, (&job, &run_id, &Attempt {- success: true,- output: "done".into(),- retryable: false,- })).await.unwrap();+ let _: Attempt = proxy+ .call(callbacks::EXECUTE, (&job, &run_id))+ .await+ .unwrap();+ let _: Attempt = proxy+ .call(callbacks::SCHEDULE_TRIGGER, ("flow-event-pair", &run_id))+ .await+ .unwrap();+ let _: Attempt = proxy+ .call(callbacks::SCHEDULE_TRIGGER, ("flow-event-pair", &run_id))+ .await+ .unwrap();+ let _: String = proxy+ .call(+ callbacks::DELIVER,+ (+ &job,+ &run_id,+ &Attempt {+ success: true,+ output: "done".into(),+ retryable: false,+ },+ ),+ )+ .await+ .unwrap();let completion = tokio::time::timeout(std::time::Duration::from_secs(2), async {let mut seen = Vec::new();loop {- let event = events_rx.recv().await.expect("event subscriber remains open");+ let event = events_rx+ .recv()+ .await+ .expect("event subscriber remains open");seen.push(event);- if event == "completed" { break; }+ if event == "completed" {+ break;+ }}seen- }).await.expect("completion event arrives");+ })+ .await+ .expect("completion event arrives");assert_eq!(completion, vec!["triggered", "completed"]);let refused_job = crate::cron::add_flow_schedule_job(&config,"flow-event-refused",- Schedule::Every { every_ms: 3_600_000 },- ).unwrap();+ Schedule::Every {+ every_ms: 3_600_000,+ },+ )+ .unwrap();let (_refusing_host, refusing_proxy) = host(&config, true).await;let (refused_tx, mut refused_rx) = mpsc::unbounded_channel();let _refused_subscription = crate::core::bus::BUS@@ -412,31 +458,47 @@ async fn a_scheduled_flow_run_publishes_a_trigger_before_completion() {.unwrap();let refused_run = format!("flow-refused-{}", uuid::Uuid::new_v4());let refused_attempt: Attempt = refusing_proxy- .call(callbacks::SCHEDULE_TRIGGER, ("flow-event-refused", &refused_run))+ .call(+ callbacks::SCHEDULE_TRIGGER,+ ("flow-event-refused", &refused_run),+ ).await.unwrap();assert!(!refused_attempt.success);let _: String = refusing_proxy- .call(callbacks::DELIVER, (&refused_job, &refused_run, &refused_attempt))+ .call(+ callbacks::DELIVER,+ (&refused_job, &refused_run, &refused_attempt),+ ).await.unwrap();let refused_pair = tokio::time::timeout(std::time::Duration::from_secs(2), async {let mut seen = Vec::new();loop {- let event = refused_rx.recv().await.expect("refusal event subscriber remains open");+ let event = refused_rx+ .recv()+ .await+ .expect("refusal event subscriber remains open");seen.push(event);- if event == "completed" { break; }+ if event == "completed" {+ break;+ }}seen- }).await.expect("refused run completion event arrives");+ })+ .await+ .expect("refused run completion event arrives");assert_eq!(refused_pair, vec!["triggered", "completed"]);let (system_tx, mut system_rx) = mpsc::unbounded_channel();let system_job = crate::cron::system_jobs::ensure_system_job(&config,"issue57-event-pair",- Schedule::Every { every_ms: 3_600_000 },- ).unwrap();+ Schedule::Every {+ every_ms: 3_600_000,+ },+ )+ .unwrap();let _system_handler = crate::cron::system_job_handlers::register("issue57-event-pair",Arc::new(|_| Box::pin(async { Ok(()) })),@@ -451,18 +513,28 @@ async fn a_scheduled_flow_run_publishes_a_trigger_before_completion() {.unwrap();assert!(system_attempt.success);let _: String = proxy- .call(callbacks::DELIVER, (&system_job, &system_run, &system_attempt))+ .call(+ callbacks::DELIVER,+ (&system_job, &system_run, &system_attempt),+ ).await.unwrap();let system_pair = tokio::time::timeout(std::time::Duration::from_secs(2), async {let mut seen = Vec::new();loop {- let event = system_rx.recv().await.expect("system event subscriber remains open");+ let event = system_rx+ .recv()+ .await+ .expect("system event subscriber remains open");seen.push(event);- if event == "completed" { break; }+ if event == "completed" {+ break;+ }}seen- }).await.expect("system completion event arrives");+ })+ .await+ .expect("system completion event arrives");assert_eq!(system_pair, vec!["triggered", "completed"]);}diff --git a/crates/openhuman-core/src/cron/ops_delivery_tests.rs b/crates/openhuman-core/src/cron/ops_delivery_tests.rsindex 21091be66b..9d4a3ca970 100644--- a/crates/openhuman-core/src/cron/ops_delivery_tests.rs+++ b/crates/openhuman-core/src/cron/ops_delivery_tests.rs@@ -96,14 +96,18 @@ async fn run_job_now_pairs_trigger_and_completion_after_delivery() {struct Events(String, mpsc::UnboundedSender<&'static str>);#[async_trait]impl EventHandler<DomainEvent> for Events {- fn name(&self) -> &str { "test::cron::run_now_event_pair" }+ fn name(&self) -> &str {+ "test::cron::run_now_event_pair"+ }async fn handle(&self, event: &DomainEvent) {let (job_id, label) = match event {DomainEvent::CronJobTriggered { job_id, .. } => (job_id, "triggered"),DomainEvent::CronJobCompleted { job_id, .. } => (job_id, "completed"),_ => return,};- if job_id == &self.0 { let _ = self.1.send(label); }+ if job_id == &self.0 {+ let _ = self.1.send(label);+ }}}@@ -111,10 +115,8 @@ async fn run_job_now_pairs_trigger_and_completion_after_delivery() {let tmp = TempDir::new().unwrap();let config = tests::test_config(&tmp);let name = "ops-run-now-event-pair";- let _handler = crate::cron::system_job_handlers::register(- name,- Arc::new(|_| Box::pin(async { Ok(()) })),- );+ let _handler =+ crate::cron::system_job_handlers::register(name, Arc::new(|_| Box::pin(async { Ok(()) })));let job = tests::single_flight_system_job(&config, name);let (tx, mut rx) = mpsc::unbounded_channel();let _subscription = crate::core::bus::BUS@@ -134,10 +136,14 @@ async fn run_job_now_pairs_trigger_and_completion_after_delivery() {loop {let event = rx.recv().await.expect("cron event subscriber remains open");seen.push(event);- if event == "completed" { break; }+ if event == "completed" {+ break;+ }}seen- }).await.expect("Run Now completion event arrives");+ })+ .await+ .expect("Run Now completion event arrives");assert_eq!(pair, vec!["triggered", "completed"]);let runs = cron::list_runs(&config, &job.id, 10).unwrap();assert_eq!(runs[0].delivery_status, Some(DeliveryStatus::NotRequested));diff --git a/crates/openhuman-core/src/cron/store_tests.rs b/crates/openhuman-core/src/cron/store_tests.rsindex a157fe17b4..7a0e0fea0e 100644--- a/crates/openhuman-core/src/cron/store_tests.rs+++ b/crates/openhuman-core/src/cron/store_tests.rs@@ -31,7 +31,11 @@ fn remove_job_does_not_write_to_stdout() {println!("BEGIN_CRON_REMOVE_CAPTURE");use std::io::Write;std::io::stdout().flush().unwrap();- remove_job(&config, &std::env::var("OPENHUMAN_CRON_REMOVE_JOB").unwrap()).unwrap();+ remove_job(+ &config,+ &std::env::var("OPENHUMAN_CRON_REMOVE_JOB").unwrap(),+ )+ .unwrap();println!("END_CRON_REMOVE_CAPTURE");std::io::stdout().flush().unwrap();return;@@ -41,12 +45,20 @@ fn remove_job_does_not_write_to_stdout() {let config = test_config(&tmp);let job = add_job(&config, "*/5 * * * *", "echo remove").unwrap();let output = Command::new(std::env::current_exe().unwrap())- .args(["--exact", "cron::store::tests::remove_job_does_not_write_to_stdout", "--nocapture"])+ .args([+ "--exact",+ "cron::store::tests::remove_job_does_not_write_to_stdout",+ "--nocapture",+ ]).env(CHILD, &config.workspace_dir).env("OPENHUMAN_CRON_REMOVE_JOB", &job.id).output().unwrap();- assert!(output.status.success(), "{}", String::from_utf8_lossy(&output.stderr));+ assert!(+ output.status.success(),+ "{}",+ String::from_utf8_lossy(&output.stderr)+ );let stdout = String::from_utf8_lossy(&output.stdout);let captured = stdout.split("BEGIN_CRON_REMOVE_CAPTURE\n").nth(1).unwrap();let captured = captured.split("END_CRON_REMOVE_CAPTURE\n").next().unwrap();diff --git a/crates/openhuman-core/src/cron/tools/run.rs b/crates/openhuman-core/src/cron/tools/run.rsindex d156627ab2..a1dfba31f3 100644--- a/crates/openhuman-core/src/cron/tools/run.rs+++ b/crates/openhuman-core/src/cron/tools/run.rs@@ -131,12 +131,7 @@ impl Tool for CronRunTool {Some(delivery_status),);let _ = cron::record_last_run(&self.config, &job.id, finished_at, success, &output);- crate::cron::scheduler::run_delivery::publish_completion(- &dispatch,- &job,- success,- &output,- );+ crate::cron::scheduler::run_delivery::publish_completion(&dispatch, &job, success, &output);let payload = json!({"job_id": job.id,diff --git a/crates/openhuman-core/src/cron/tools/run_tests.rs b/crates/openhuman-core/src/cron/tools/run_tests.rsindex efa23ad593..b9151dba01 100644--- a/crates/openhuman-core/src/cron/tools/run_tests.rs+++ b/crates/openhuman-core/src/cron/tools/run_tests.rs@@ -86,14 +86,18 @@ async fn cron_run_tool_pairs_start_and_completion_without_requesting_delivery()struct Events(String, mpsc::UnboundedSender<&'static str>);#[async_trait::async_trait]impl EventHandler<DomainEvent> for Events {- fn name(&self) -> &str { "test::cron::run_tool_event_pair" }+ fn name(&self) -> &str {+ "test::cron::run_tool_event_pair"+ }async fn handle(&self, event: &DomainEvent) {let (job_id, label) = match event {DomainEvent::CronJobTriggered { job_id, .. } => (job_id, "triggered"),DomainEvent::CronJobCompleted { job_id, .. } => (job_id, "completed"),_ => return,};- if job_id == &self.0 { let _ = self.1.send(label); }+ if job_id == &self.0 {+ let _ = self.1.send(label);+ }}}@@ -103,8 +107,11 @@ async fn cron_run_tool_pairs_start_and_completion_without_requesting_delivery()let job = crate::cron::system_jobs::ensure_system_job(&cfg,"cron-run-tool-event-pair",- tinyflows_bus::schedule::types::Schedule::Every { every_ms: 3_600_000 },- ).unwrap();+ tinyflows_bus::schedule::types::Schedule::Every {+ every_ms: 3_600_000,+ },+ )+ .unwrap();let _handler = crate::cron::system_job_handlers::register("cron-run-tool-event-pair",Arc::new(|_| Box::pin(async { Ok(()) })),@@ -124,13 +131,20 @@ async fn cron_run_tool_pairs_start_and_completion_without_requesting_delivery()loop {let event = rx.recv().await.expect("cron event subscriber remains open");seen.push(event);- if event == "completed" { break; }+ if event == "completed" {+ break;+ }}seen- }).await.expect("cron_run completion event arrives");+ })+ .await+ .expect("cron_run completion event arrives");assert_eq!(pair, vec!["triggered", "completed"]);let runs = cron::list_runs(&cfg, &job.id, 10).unwrap();- assert_eq!(runs[0].delivery_status, Some(cron::DeliveryStatus::NotRequested));+ assert_eq!(+ runs[0].delivery_status,+ Some(cron::DeliveryStatus::NotRequested)+ );}// ── GHSA-f46p-6vf9-64mm: approval gate must fire for cron_run ────diff --git a/crates/openhuman-core/src/flows/bus/trigger.rs b/crates/openhuman-core/src/flows/bus/trigger.rsindex 34bb83ec45..026cef6122 100644--- a/crates/openhuman-core/src/flows/bus/trigger.rs+++ b/crates/openhuman-core/src/flows/bus/trigger.rs@@ -206,7 +206,11 @@ impl FlowTriggerSubscriber {+ 'static,Fut: Future<Output = ()> + Send + 'static,{- Self::with_executor(Arc::new(RwLock::new((*config).clone())), queue_capacity, runner)+ Self::with_executor(+ Arc::new(RwLock::new((*config).clone())),+ queue_capacity,+ runner,+ )}#[cfg(test)]diff --git a/crates/openhuman-core/src/flows/bus_trigger_queue_tests.rs b/crates/openhuman-core/src/flows/bus_trigger_queue_tests.rsindex 6f84ab157e..2ccd2c50bf 100644--- a/crates/openhuman-core/src/flows/bus_trigger_queue_tests.rs+++ b/crates/openhuman-core/src/flows/bus_trigger_queue_tests.rs@@ -41,7 +41,6 @@ async fn schedule_tick_is_coalesced_while_a_trigger_run_is_active() {);}-#[tokio::test]async fn app_event_runs_queue_fifo_per_tenant_while_other_tenants_progress() {use crate::core::runtime::{ContextOverlay, CoreContext, DispatchCtx, DomainSet};