Skip to content

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

refactor(channels): route channel service spawn through session helper

Steven Enamakel35e14cad4749
diff --git a/crates/openhuman-core/src/channels/runtime/session.rs b/crates/openhuman-core/src/channels/runtime/session.rs
index 2d9a37cc76..cde70bdc60 100644
--- a/crates/openhuman-core/src/channels/runtime/session.rs
+++ b/crates/openhuman-core/src/channels/runtime/session.rs
@@ -112,6 +112,14 @@ where
tokio::spawn(run(controller.current()))
}
+pub(crate) fn spawn_current_channel_service_with<F, Fut>(run: F) -> tokio::task::JoinHandle<()>
+where
+ F: FnOnce(CancellationToken) -> Fut + Send + 'static,
+ Fut: Future<Output = ()> + Send + 'static,
+{
+ spawn_channel_service_with(SESSION.clone(), run)
+}
+
/// Stop the host dispatch generation on logout, even with independent model auth.
pub(super) async fn run_in_session(
session: CancellationToken,
diff --git a/crates/openhuman-core/src/core/runtime/services.rs b/crates/openhuman-core/src/core/runtime/services.rs
index 2a73402bb7..b385664a64 100644
--- a/crates/openhuman-core/src/core/runtime/services.rs
+++ b/crates/openhuman-core/src/core/runtime/services.rs
@@ -292,28 +292,33 @@ pub fn spawn_channels_service() -> Option<tokio::task::JoinHandle<()>> {
{
// Capture before loading config: logout during that await must also
// invalidate a listener that has not finished starting yet.
- let channel_session = crate::channels::session::channel_session();
- return Some(tokio::spawn(async move {
- let config = match crate::config::Config::load_or_init().await {
- Ok(c) => c,
- Err(e) => {
- log::warn!("[channels] could not load config for listeners: {e}");
- return;
- }
- };
- if !crate::channels::has_listener_configuration(&config) {
- log::debug!(
- "[channels] no channel integrations configured; not spawning listeners"
- );
- return;
- }
- log::info!("[channels] spawning in-process realtime listeners (Telegram, Discord, …)");
- if let Err(e) =
- crate::channels::start_channels_with_session(config, channel_session).await
- {
- log::error!("[channels] start_channels ended with error: {e}");
- }
- }));
+ return Some(
+ crate::channels::session::spawn_current_channel_service_with(
+ |channel_session| async move {
+ let config = match crate::config::Config::load_or_init().await {
+ Ok(c) => c,
+ Err(e) => {
+ log::warn!("[channels] could not load config for listeners: {e}");
+ return;
+ }
+ };
+ if !crate::channels::has_listener_configuration(&config) {
+ log::debug!(
+ "[channels] no channel integrations configured; not spawning listeners"
+ );
+ return;
+ }
+ log::info!(
+ "[channels] spawning in-process realtime listeners (Telegram, Discord, …)"
+ );
+ if let Err(e) =
+ crate::channels::start_channels_with_session(config, channel_session).await
+ {
+ log::error!("[channels] start_channels ended with error: {e}");
+ }
+ },
+ ),
+ );
}
#[cfg(feature = "channels")]
{