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(flows): deliver bus events to subscribers when triggers fire
Steven Enamakel57fd9590b81e
diff --git a/crates/openhuman-core/src/desktop/notifications/bus_tests_2_tests.rs b/crates/openhuman-core/src/desktop/notifications/bus_tests_2_tests.rsindex 79d2e2bd22..f8d3af1b85 100644--- a/crates/openhuman-core/src/desktop/notifications/bus_tests_2_tests.rs+++ b/crates/openhuman-core/src/desktop/notifications/bus_tests_2_tests.rs@@ -553,12 +553,12 @@ async fn a_noted_cron_completion_names_its_agent() {success: true,output: String::new(),};- let owner = event_owner(&crate::config::Config::default(), &event).await;+ let owner = event_owner(&crate::core::runtime::DispatchCtx::host_default(), &crate::config::Config::default(), &event).await;assert_eq!(owner, Ok(Some("notif-owner-agent".to_string())));// Taken: asked again, the job is no one's (no backend installed here).if crate::storage::installed().is_none() {assert_eq!(- event_owner(&crate::config::Config::default(), &event).await,+ event_owner(&crate::core::runtime::DispatchCtx::host_default(), &crate::config::Config::default(), &event).await,Ok(None));}diff --git a/crates/openhuman-core/src/flows/bus/owner_tests.rs b/crates/openhuman-core/src/flows/bus/owner_tests.rsindex 84f13fe4ef..e4c8beb3db 100644--- a/crates/openhuman-core/src/flows/bus/owner_tests.rs+++ b/crates/openhuman-core/src/flows/bus/owner_tests.rs@@ -51,18 +51,18 @@ async fn a_cached_owner_is_dropped_once_its_scope_loses_the_flow() {crate::flows::store::upsert_flow(&config, &local_flow("owner-test-revalidate")).unwrap();// Found in `local`, and remembered there.- assert_eq!(resolve(&config, "owner-test-revalidate").await, Ok(None));+ assert_eq!(resolve(&DispatchCtx::unbound(), &config, "owner-test-revalidate").await, Ok(None));assert_eq!(OWNERS.lock().unwrap().get("owner-test-revalidate"),Some(&None));// Still there: the cached answer stands.- assert_eq!(resolve(&config, "owner-test-revalidate").await, Ok(None));+ assert_eq!(resolve(&DispatchCtx::unbound(), &config, "owner-test-revalidate").await, Ok(None));assert!(OWNERS.lock().unwrap().contains_key("owner-test-revalidate"));// Gone: the cache entry is dropped and nothing is found.crate::flows::store::remove_flow(&config, "owner-test-revalidate").unwrap();- assert_eq!(resolve(&config, "owner-test-revalidate").await, Ok(None));+ assert_eq!(resolve(&DispatchCtx::unbound(), &config, "owner-test-revalidate").await, Ok(None));assert!(!OWNERS.lock().unwrap().contains_key("owner-test-revalidate"));}diff --git a/crates/openhuman-core/src/flows/bus/trigger.rs b/crates/openhuman-core/src/flows/bus/trigger.rsindex 1242010d96..66e14071ac 100644--- a/crates/openhuman-core/src/flows/bus/trigger.rs+++ b/crates/openhuman-core/src/flows/bus/trigger.rs@@ -279,6 +279,9 @@ impl EventHandler<DomainEvent> for FlowTriggerSubscriber {}async fn handle(&self, event: &DomainEvent) {+ // Trigger events arrive over the host's socket or its own scheduler:+ // the host's own tenant, and in SaaS none.+ let host = crate::core::runtime::DispatchCtx::host_default();match event {// Every scope's flows may listen for this trigger: match them in// each, so each run starts as its flow's owner.diff --git a/crates/openhuman-core/src/flows/bus_subscriber_tests.rs b/crates/openhuman-core/src/flows/bus_subscriber_tests.rsindex 33aa0c542a..58be8c1b7c 100644--- a/crates/openhuman-core/src/flows/bus_subscriber_tests.rs+++ b/crates/openhuman-core/src/flows/bus_subscriber_tests.rs@@ -65,7 +65,7 @@ async fn handle_does_not_panic_on_arbitrary_events() {job_type: "shell".into(),}).await;- sub.dispatch_schedule_tick("missing-flow").await;+ sub.dispatch_schedule_tick(&crate::core::runtime::DispatchCtx::host_default(), "missing-flow").await;}#[test]@@ -160,7 +160,7 @@ async fn handle_schedule_tick_ignores_disabled_flow() {// Must not panic and must not spawn a run for a disabled flow — we// can't directly observe "no run happened" without a full flows_run// fixture, but this exercises the early-return path without error.- sub.dispatch_schedule_tick("sched-flow").await;+ sub.dispatch_schedule_tick(&crate::core::runtime::DispatchCtx::host_default(), "sched-flow").await;}// ── in-flight dedupe (CodeRabbit finding B) ─────────────────────diff --git a/crates/openhuman-core/src/integrations/task_sources/bus.rs b/crates/openhuman-core/src/integrations/task_sources/bus.rsindex c6a1b7c7c6..ebf8fb70df 100644--- a/crates/openhuman-core/src/integrations/task_sources/bus.rs+++ b/crates/openhuman-core/src/integrations/task_sources/bus.rs@@ -39,11 +39,16 @@ impl EventHandler<DomainEvent> for TaskSourcesConnectionSubscriber {let DomainEvent::ComposioConnectionCreated {toolkit,connection_id,+ tenant,..} = eventelse {return;};+ let Some(ctx) = DispatchCtx::for_event(tenant.as_ref()) else {+ tracing::debug!(toolkit = %toolkit, "[task_sources:bus] connection_created has no tenant; skipped");+ return;+ };// Only act for toolkits we model as task sources.let Ok(provider) = ProviderSlug::parse(toolkit) else {diff --git a/crates/openhuman-core/src/storage/agents_tests.rs b/crates/openhuman-core/src/storage/agents_tests.rsindex 76da4da77b..d8ec5ced5f 100644--- a/crates/openhuman-core/src/storage/agents_tests.rs+++ b/crates/openhuman-core/src/storage/agents_tests.rs@@ -132,7 +132,7 @@ async fn without_a_backend_only_the_local_scope_runs() {return;}let agent = live_agent("agents-test-unvisited");- let runs = for_each_scope("test", |_| async {+ let runs = for_each_scope(&crate::core::runtime::DispatchCtx::host_default(), "test", |_| async {CoreContext::current().and_then(|c| c.session_agent().map(str::to_string))}).await;@@ -140,26 +140,26 @@ async fn without_a_backend_only_the_local_scope_runs() {assert_eq!(runs[0].0, None);assert!(for_each_agent("test", |_| async {}).await.is_empty());assert_eq!(- find_owner("test", |_| async { Ok(false) }).await,+ find_owner(&crate::core::runtime::DispatchCtx::host_default(), "test", |_| async { Ok(false) }).await,Ok(None),"nothing anywhere");assert_eq!(- find_owner("test", |_| async { Ok(true) }).await,+ find_owner(&crate::core::runtime::DispatchCtx::host_default(), "test", |_| async { Ok(true) }).await,Ok(Some(None)));assert!(- find_owner("test", |_| async { Err("down".to_string()) })+ find_owner(&crate::core::runtime::DispatchCtx::host_default(), "test", |_| async { Err("down".to_string()) }).await.is_err(),"a failed lookup with no match fails closed");- let inside = within_agent(Some("agents-test-unvisited"), async {+ let inside = within_agent(&crate::core::runtime::DispatchCtx::host_default(), Some("agents-test-unvisited"), async {CoreContext::current().and_then(|c| c.session_agent().map(str::to_string))}).await;assert_eq!(inside.flatten().as_deref(), Some("agents-test-unvisited"));- assert_eq!(within_agent(None, async { 7 }).await, Some(7));+ assert_eq!(within_agent(&crate::core::runtime::DispatchCtx::host_default(), None, async { 7 }).await, Some(7));AgentContextRegistry::deregister("agents-test-unvisited", &agent);}@@ -169,7 +169,7 @@ async fn without_a_backend_the_live_pass_runs_only_local() {return;}let agent = live_agent("agents-test-live-pass");- let runs = for_each_live_scope("test", |_| async { 1 }).await;+ let runs = for_each_live_scope(&crate::core::runtime::DispatchCtx::host_default(), "test", |_| async { 1 }).await;assert_eq!(runs, vec![(None, 1)]);AgentContextRegistry::deregister("agents-test-live-pass", &agent);}@@ -199,7 +199,7 @@ async fn the_local_pass_runs_outside_the_callers_agent() {}let agent = live_agent("agents-test-caller");let seen = CoreContext::scope(Arc::clone(&agent), async {- for_each_scope("test", |_| async {+ for_each_scope(&crate::core::runtime::DispatchCtx::host_default(), "test", |_| async {CoreContext::current().and_then(|c| c.session_agent().map(str::to_string))}).await