Skip to content

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

fix(notifications): store cron completion notifications under the job's owning agent

Steven Enamakele90d95732b74
diff --git a/crates/openhuman-core/src/desktop/notifications/bus.rs b/crates/openhuman-core/src/desktop/notifications/bus.rs
index 242fbdb767..d8ce148038 100644
--- a/crates/openhuman-core/src/desktop/notifications/bus.rs
+++ b/crates/openhuman-core/src/desktop/notifications/bus.rs
@@ -469,6 +469,24 @@ fn translate(event: &DomainEvent) -> Option<CoreNotificationEvent> {
}
}
+/// The agent whose storage scope a notification raised by `event` belongs
+/// in: the owner of the cron job a `CronJobCompleted` names, when a storage
+/// backend is installed and an agent's scope holds the job; `None` (`local`)
+/// otherwise.
+async fn event_owner(config: &crate::config::Config, event: &DomainEvent) -> Option<String> {
+ let DomainEvent::CronJobCompleted { job_id, .. } = event else {
+ return None;
+ };
+ if crate::storage::installed().is_none() {
+ return None;
+ }
+ crate::storage::agents::find_owner("notification owner", || async {
+ crate::cron::get_job(config, job_id).is_ok()
+ })
+ .await
+ .flatten()
+}
+
#[async_trait]
impl EventHandler<DomainEvent> for NotificationBridgeSubscriber {
fn name(&self) -> &str {
@@ -491,7 +509,15 @@ impl EventHandler<DomainEvent> for NotificationBridgeSubscriber {
// A workspace-bound event is stored in ITS OWN workspace, not
// whichever one this bridge was registered with (#5931).
let config = self.store_target(config, event);
- match super::store::insert_core_notification(&config, &notification) {
+ // Stored with the record that raised it: a cron job's
+ // completion goes to the agent the job belongs to
+ // (`crate::storage`), `local` otherwise.
+ let owner = event_owner(&config, event).await;
+ let stored = crate::storage::agents::within_agent(owner.as_deref(), async {
+ super::store::insert_core_notification(&config, &notification)
+ })
+ .await;
+ match stored {
Ok(true) => log::debug!(
"{LOG_PREFIX} persisted core notification id={}",
notification.id
diff --git a/crates/openhuman-core/src/integrations/task_sources/bus.rs b/crates/openhuman-core/src/integrations/task_sources/bus.rs
index 4dfc92e51d..7e7435b98c 100644
--- a/crates/openhuman-core/src/integrations/task_sources/bus.rs
+++ b/crates/openhuman-core/src/integrations/task_sources/bus.rs
@@ -77,7 +77,7 @@ async fn fire_for_connection(
toolkit: &str,
connection_id: &str,
) {
- let sources = match store::list_sources(&config) {
+ let sources = match store::list_sources(config) {
Ok(sources) => sources,
Err(e) => {
tracing::debug!(error = %e, "[task_sources:bus] list_sources failed, skipping");