Skip to content

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

fix(flows): dedupe bus triggers by commit instead of run

Steven Enamakelabc8af7ead3f
diff --git a/crates/openhuman-core/src/cron/scheduler/run_delivery.rs b/crates/openhuman-core/src/cron/scheduler/run_delivery.rs
index a1279e449b..4378591774 100644
--- a/crates/openhuman-core/src/cron/scheduler/run_delivery.rs
+++ b/crates/openhuman-core/src/cron/scheduler/run_delivery.rs
@@ -132,7 +132,7 @@ impl TriggerSink for HostTriggers {
self.binding.config(),
))
})
- .dispatch_schedule_tick(flow_id)
+ .dispatch_schedule_tick(&self.binding.dispatch_ctx(), flow_id)
.await;
#[cfg(not(feature = "flows"))]
tracing::warn!(%flow_id, "[cron] built without `flows`; schedule trigger dropped");
diff --git a/crates/openhuman-core/src/flows/bus/dedup_commit.rs b/crates/openhuman-core/src/flows/bus/dedup_commit.rs
index 0884075f1d..8097ec1ef8 100644
--- a/crates/openhuman-core/src/flows/bus/dedup_commit.rs
+++ b/crates/openhuman-core/src/flows/bus/dedup_commit.rs
@@ -341,7 +341,10 @@ impl EventHandler<DomainEvent> for DedupCommitSubscriber {
} = event
{
// Settle the run as the agent its flow belongs to (`super::owner`).
- super::owner::as_owner(&self.config, flow_id, |ctx| {
+ // `FlowRunFinished` carries no tenant: the host's own, and in SaaS
+ // none (the run is then not settled here).
+ let host = crate::core::runtime::DispatchCtx::host_default();
+ super::owner::as_owner(&host, &self.config, flow_id, |ctx| {
self.handle_finished(ctx, flow_id, run_id, status)
})
.await;
diff --git a/crates/openhuman-core/src/flows/bus/owner_tests.rs b/crates/openhuman-core/src/flows/bus/owner_tests.rs
index c1baec0f9d..84f13fe4ef 100644
--- a/crates/openhuman-core/src/flows/bus/owner_tests.rs
+++ b/crates/openhuman-core/src/flows/bus/owner_tests.rs
@@ -11,7 +11,7 @@ async fn without_a_backend_every_flow_is_local() {
workspace_dir: dir.path().to_path_buf(),
..Config::default()
};
- assert_eq!(flow_owner(&config, "any-flow").await, Ok(None));
+ assert_eq!(flow_owner(&DispatchCtx::unbound(), &config, "any-flow").await, Ok(None));
}
#[test]
diff --git a/crates/openhuman-core/src/flows/bus/run_digest.rs b/crates/openhuman-core/src/flows/bus/run_digest.rs
index eec57ef230..5a122c7cf3 100644
--- a/crates/openhuman-core/src/flows/bus/run_digest.rs
+++ b/crates/openhuman-core/src/flows/bus/run_digest.rs
@@ -197,7 +197,10 @@ impl EventHandler<DomainEvent> for FlowRunDigestSubscriber {
} = event
{
// Settle the run as the agent its flow belongs to (`super::owner`).
- super::owner::as_owner(&self.config, flow_id, |ctx| {
+ // `FlowRunFinished` carries no tenant: the host's own, and in SaaS
+ // none (the run is then not settled here).
+ let host = crate::core::runtime::DispatchCtx::host_default();
+ super::owner::as_owner(&host, &self.config, flow_id, |ctx| {
self.handle_finished(ctx, flow_id, run_id, status)
})
.await;
diff --git a/crates/openhuman-core/src/flows/bus/trigger.rs b/crates/openhuman-core/src/flows/bus/trigger.rs
index fcea085775..1242010d96 100644
--- a/crates/openhuman-core/src/flows/bus/trigger.rs
+++ b/crates/openhuman-core/src/flows/bus/trigger.rs
@@ -125,8 +125,12 @@ impl FlowTriggerSubscriber {
/// enabled with a `schedule` trigger (it may have been disabled/edited
/// since the job was registered), and dispatches it with an empty trigger
/// payload.
- pub(crate) async fn dispatch_schedule_tick(&self, flow_id: &str) {
- super::owner::as_owner(&self.config, flow_id, |ctx| {
+ pub(crate) async fn dispatch_schedule_tick(
+ &self,
+ host: &crate::core::runtime::DispatchCtx,
+ flow_id: &str,
+ ) {
+ super::owner::as_owner(host, &self.config, flow_id, |ctx| {
self.handle_schedule_tick(ctx, flow_id)
})
.await
@@ -284,7 +288,7 @@ impl EventHandler<DomainEvent> for FlowTriggerSubscriber {
payload,
..
} => {
- crate::storage::agents::for_each_live_scope("flows app_event", |ctx| {
+ crate::storage::agents::for_each_live_scope(&host, "flows app_event", |ctx| {
self.handle_app_event(ctx, toolkit, trigger, payload)
})
.await;
diff --git a/crates/openhuman-core/src/integrations/task_sources/bus.rs b/crates/openhuman-core/src/integrations/task_sources/bus.rs
index a06d1645b4..c6a1b7c7c6 100644
--- a/crates/openhuman-core/src/integrations/task_sources/bus.rs
+++ b/crates/openhuman-core/src/integrations/task_sources/bus.rs
@@ -52,7 +52,7 @@ impl EventHandler<DomainEvent> for TaskSourcesConnectionSubscriber {
// Every scope may hold sources for this toolkit (`crate::storage`):
// handle each scope as its own agent, with that agent's config.
- crate::storage::agents::for_each_live_scope("task_sources connection", |scope_ctx| async move {
+ crate::storage::agents::for_each_live_scope(&ctx, "task_sources connection", |scope_ctx| async move {
fire_in_scope(&scope_ctx, provider, toolkit, connection_id).await
})
.await;