Skip to content

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

feat(events): carry tenant on proactive message events

Steven Enamakelaf3478922305
diff --git a/crates/openhuman-core/src/channels/proactive_tests.rs b/crates/openhuman-core/src/channels/proactive_tests.rs
index 71206ca7e2..579ae6e9be 100644
--- a/crates/openhuman-core/src/channels/proactive_tests.rs
+++ b/crates/openhuman-core/src/channels/proactive_tests.rs
@@ -75,6 +75,7 @@ fn proactive_event() -> DomainEvent {
source: "cron:test".into(),
message: "Hello!".into(),
job_name: Some("test".into()),
+ tenant: None,
}
}
diff --git a/crates/openhuman-core/src/core/events.rs b/crates/openhuman-core/src/core/events.rs
index 38f968d1b6..4402e0e335 100644
--- a/crates/openhuman-core/src/core/events.rs
+++ b/crates/openhuman-core/src/core/events.rs
@@ -403,6 +403,10 @@ pub enum DomainEvent {
message: String,
/// Optional job name for display/threading purposes.
job_name: Option<String>,
+ /// Tenant whose work produced this delivery; bus subscribers run on a
+ /// separate task and cannot inherit the publisher's dispatch context.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ tenant: Option<crate::core::runtime::Tenant>,
},
/// A host-owned system cron job came due (a `flow`-type row whose command
/// is `system:<job>`, see `cron::system_jobs`). The owning domain runs it.
diff --git a/crates/openhuman-core/src/core/events_tests.rs b/crates/openhuman-core/src/core/events_tests.rs
index a9de36216e..3de26878da 100644
--- a/crates/openhuman-core/src/core/events_tests.rs
+++ b/crates/openhuman-core/src/core/events_tests.rs
@@ -219,6 +219,7 @@ fn all_variants_have_correct_domain() {
source: "cron:morning_briefing".into(),
message: "Good morning!".into(),
job_name: Some("morning_briefing".into()),
+ tenant: None,
},
"cron",
),
diff --git a/crates/openhuman-core/src/core/runtime/subscribers_tests.rs b/crates/openhuman-core/src/core/runtime/subscribers_tests.rs
index 5d7480fa1b..7f522621df 100644
--- a/crates/openhuman-core/src/core/runtime/subscribers_tests.rs
+++ b/crates/openhuman-core/src/core/runtime/subscribers_tests.rs
@@ -224,17 +224,35 @@ fn proactive_message_reaches_web_on_channelless_core_boot() {
.build()
.expect("test runtime")
.block_on(async {
+ crate::core::runtime::lock_mode(crate::core::runtime::Mode::Saas)
+ .expect("lock isolated test process in SaaS mode");
crate::core::bus::init().await.expect("bus init");
let mut web_events = crate::web_chat::subscribe_web_channel_events();
let config = crate::config::Config::default();
assert!(config.channels_config.active_channel.is_none());
+ let root = tempfile::tempdir().expect("profile root");
+ let id = crate::profiles::ProfileId::parse("proactive-test").unwrap();
+ let profile_host = std::sync::Arc::new(crate::profiles::ProfileHost::new(
+ crate::profiles::SaasConfig::new(root.path()),
+ crate::core::runtime::CoreContext::for_test(
+ crate::core::runtime::DomainSet::full(),
+ None,
+ ),
+ ));
+ profile_host.provision(&id).await.expect("provision profile");
+ let profile = profile_host.open(&id).await.expect("open profile");
+ crate::profiles::host::install(profile_host);
+ let ctx = crate::core::runtime::DispatchCtx::new(profile.context());
+ let tenant = ctx.event_tenant();
+ assert_eq!(tenant.as_ref().and_then(|tenant| tenant.profile.as_deref()), Some("proactive-test"));
+
super::register_domain_subscribers(
std::env::temp_dir(),
config,
true,
crate::core::runtime::DomainSet::none(),
- &crate::core::runtime::DispatchCtx::ambient(),
+ &ctx,
);
crate::core::bus::BUS.publish(
@@ -242,6 +260,7 @@ fn proactive_message_reaches_web_on_channelless_core_boot() {
source: "cron:test".into(),
message: "Your morning briefing is ready.".into(),
job_name: Some("morning-briefing".into()),
+ tenant,
},
);
@@ -266,6 +285,8 @@ fn proactive_message_reaches_web_on_channelless_core_boot() {
event.full_response.as_deref(),
Some("Your morning briefing is ready.")
);
+ assert!(event.belongs_to_profile("proactive-test"));
+ assert!(!event.belongs_to_profile("another-profile"));
});
return;
}
diff --git a/crates/openhuman-core/src/cron/scheduler/delivery.rs b/crates/openhuman-core/src/cron/scheduler/delivery.rs
index b41952cb2f..d77db3ba51 100644
--- a/crates/openhuman-core/src/cron/scheduler/delivery.rs
+++ b/crates/openhuman-core/src/cron/scheduler/delivery.rs
@@ -209,6 +209,7 @@ pub(super) async fn deliver_run(
source,
message: output.to_string(),
job_name: job.name.clone(),
+ tenant: ctx.event_tenant(),
});
status = DeliveryStatus::Delivered;
}