Skip to content

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

feat(task_sources): fire connection fetches per storage scope

Steven Enamakel2eacd3624e8e
diff --git a/crates/openhuman-core/src/integrations/task_sources/bus.rs b/crates/openhuman-core/src/integrations/task_sources/bus.rs
index d380df792d..07f1225df2 100644
--- a/crates/openhuman-core/src/integrations/task_sources/bus.rs
+++ b/crates/openhuman-core/src/integrations/task_sources/bus.rs
@@ -60,6 +60,25 @@ impl EventHandler<DomainEvent> for TaskSourcesConnectionSubscriber {
return;
}
+ // Every scope may hold sources for this toolkit (`crate::storage`):
+ // fire each scope's under its own agent.
+ crate::storage::agents::for_each_scope("task_sources connection", || {
+ fire_for_connection(&config, provider, toolkit, connection_id)
+ })
+ .await;
+ }
+}
+
+/// Starts a one-shot fetch for every enabled source of `provider` in the
+/// current storage scope that the new connection serves.
+async fn fire_for_connection(
+ config: &crate::config::Config,
+ provider: ProviderSlug,
+ toolkit: &str,
+ connection_id: &str,
+) {
+ {
+ let config = config.clone();
let sources = match store::list_sources(&config) {
Ok(sources) => sources,
Err(e) => {
@@ -88,7 +107,8 @@ impl EventHandler<DomainEvent> for TaskSourcesConnectionSubscriber {
// pattern as the periodic poll). Each fetch captures its own
// owned config + source.
let config = config.clone();
- tokio::spawn(async move {
+ // Scoped: the fetch keeps the scope's agent context.
+ crate::core::runtime::spawn_scoped(async move {
let _ = pipeline::run_source_once(&config, &source, FetchReason::ConnectionCreated)
.await;
});