Skip to content

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

feat(channels): route doctor health checks through module

Steven Enamakel8d2b5d535a69
diff --git a/crates/openhuman-core/src/channels/commands.rs b/crates/openhuman-core/src/channels/commands.rs
index 0017301c42..d5aa4a9789 100644
--- a/crates/openhuman-core/src/channels/commands.rs
+++ b/crates/openhuman-core/src/channels/commands.rs
@@ -1,22 +1,19 @@
//! `doctor channels`: health checks for every configured real-time channel.
//!
-//! Channels are built by `tinychannels::build_channels` from the same hydrated
-//! config the runtime uses, and checked by `tinychannels::runtime`; this module
-//! only prints the report.
+//! OpenHuman hydrates credentials and applies its proxy policy. Provider
+//! construction and bounded health checks execute in the TinyChannels module;
+//! this adapter formats the observations.
-use super::runtime::{hydrate_channel_credentials, RuntimeProxyClients};
+use super::runtime::hydrate_channel_credentials;
use crate::config::Config;
+use crate::modules::client::ModuleClient;
use anyhow::Result;
-use std::sync::Arc;
use std::time::Duration;
-use tinychannels::runtime::{check_channels_health, ChannelHealthState};
-
-/// Per-channel health-check budget.
-const HEALTH_CHECK_TIMEOUT: Duration = Duration::from_secs(10);
+use tinychannels_bus::{ChannelHealthState, HttpProxyPolicy};
/// Display label for a channel id (`telegram` → `Telegram`).
fn channel_label(channel: &str) -> String {
- tinychannels::controllers::find_channel_definition(channel)
+ tinychannels_bus::controllers::find_channel_definition(channel)
.map(|definition| definition.display_name.to_string())
.unwrap_or_else(|| channel.to_string())
}
@@ -32,12 +29,32 @@ fn report_line(label: &str, state: ChannelHealthState) -> String {
/// Run health checks for configured channels.
pub async fn doctor_channels(config: Config) -> Result<()> {
- let host: Arc<dyn tinychannels::ChannelHost> = Arc::new(tinychannels::NoopHost);
- let channels = tinychannels::build_channels(
- &hydrate_channel_credentials(&config),
- &host,
- &RuntimeProxyClients,
- );
+ let configured = configured_providers(&config);
+ if configured.is_empty() {
+ println!("No real-time channels configured. Configure channels in the web UI.");
+ return Ok(());
+ }
+ let selectors = configured
+ .iter()
+ .map(|channel| format!("channel.{channel}"))
+ .filter(|service| config.proxy.should_apply_to_service(service))
+ .collect::<Vec<_>>();
+ let proxy = if selectors.is_empty() {
+ HttpProxyPolicy::default()
+ } else {
+ HttpProxyPolicy {
+ http_proxy: config.proxy.http_proxy.clone(),
+ https_proxy: config.proxy.https_proxy.clone(),
+ all_proxy: config.proxy.all_proxy.clone(),
+ no_proxy: config.proxy.normalized_no_proxy(),
+ service_selectors: selectors,
+ }
+ };
+ let client = ModuleClient::new(config.clone())
+ .with_timeout(Duration::from_secs(configured.len() as u64 * 10 + 5));
+ let channels =
+ crate::modules::channel_health::check(&client, hydrate_channel_credentials(&config), proxy)
+ .await?;
if channels.is_empty() {
println!("No real-time channels configured. Configure channels in the web UI.");
@@ -48,13 +65,14 @@ pub async fn doctor_channels(config: Config) -> Result<()> {
println!();
let (mut healthy, mut unhealthy, mut timeout) = (0_u32, 0_u32, 0_u32);
- for (name, state) in check_channels_health(&channels, HEALTH_CHECK_TIMEOUT).await {
+ for report in channels {
+ let state = report.state;
match state {
ChannelHealthState::Healthy => healthy += 1,
ChannelHealthState::Unhealthy => unhealthy += 1,
ChannelHealthState::Timeout => timeout += 1,
}
- println!("{}", report_line(&channel_label(&name), state));
+ println!("{}", report_line(&channel_label(&report.channel), state));
}
if config.channels_config.webhook.is_some() {
@@ -66,6 +84,32 @@ pub async fn doctor_channels(config: Config) -> Result<()> {
Ok(())
}
+/// Selecting configured providers is host configuration orchestration. The
+/// module owns construction, platform support, health I/O and timeout handling.
+fn configured_providers(config: &Config) -> Vec<&'static str> {
+ let channels = &config.channels_config;
+ [
+ ("telegram", channels.telegram.is_some()),
+ ("discord", channels.discord.is_some()),
+ ("slack", channels.slack.is_some()),
+ ("mattermost", channels.mattermost.is_some()),
+ ("imessage", channels.imessage.is_some()),
+ ("matrix", channels.matrix.is_some()),
+ ("signal", channels.signal.is_some()),
+ ("whatsapp", channels.whatsapp.is_some()),
+ ("linq", channels.linq.is_some()),
+ ("email", channels.email.is_some()),
+ ("irc", channels.irc.is_some()),
+ ("lark", channels.lark.is_some()),
+ ("dingtalk", channels.dingtalk.is_some()),
+ ("qq", channels.qq.is_some()),
+ ("yuanbao", channels.yuanbao.is_some()),
+ ]
+ .into_iter()
+ .filter_map(|(channel, configured)| configured.then_some(channel))
+ .collect()
+}
+
#[cfg(test)]
#[path = "commands_tests.rs"]
mod tests;
diff --git a/crates/openhuman-core/src/channels/commands_tests.rs b/crates/openhuman-core/src/channels/commands_tests.rs
index cac0bb3b7b..d71c1c33db 100644
--- a/crates/openhuman-core/src/channels/commands_tests.rs
+++ b/crates/openhuman-core/src/channels/commands_tests.rs
@@ -20,3 +20,25 @@ fn channel_labels_use_definition_display_names() {
async fn doctor_with_no_channels_is_ok() {
doctor_channels(Config::default()).await.unwrap();
}
+
+#[tokio::test]
+async fn doctor_with_configured_provider_requires_the_module() {
+ let mut config = Config::default();
+ config.modules.enabled = false;
+ config.channels_config.imessage = Some(tinychannels_bus::config::IMessageConfig {
+ allowed_contacts: vec![],
+ });
+ let error = doctor_channels(config).await.unwrap_err();
+ assert!(error.to_string().contains("module unavailable"), "{error}");
+}
+
+#[test]
+fn doctor_provider_selection_ignores_cli_and_relay_only_configuration() {
+ let mut config = Config::default();
+ config.channels_config.relay = Some(Default::default());
+ assert!(configured_providers(&config).is_empty());
+ config.channels_config.imessage = Some(tinychannels_bus::config::IMessageConfig {
+ allowed_contacts: vec![],
+ });
+ assert_eq!(configured_providers(&config), vec!["imessage"]);
+}
diff --git a/crates/openhuman-core/src/modules/channel_health.rs b/crates/openhuman-core/src/modules/channel_health.rs
new file mode 100644
index 0000000000..512981d9a2
--- /dev/null
+++ b/crates/openhuman-core/src/modules/channel_health.rs
@@ -0,0 +1,17 @@
+//! Thin confidential adapter for TinyChannels' provider health checks.
+use super::client::{ModuleCallError, ModuleClient};
+use tinychannels_bus::{ChannelHealthReport, ChannelsConfig, HttpProxyPolicy};
+
+pub(crate) async fn check(
+ client: &ModuleClient,
+ config: ChannelsConfig,
+ proxy: HttpProxyPolicy,
+) -> Result<Vec<ChannelHealthReport>, ModuleCallError> {
+ client
+ .call_confidential(
+ "tinychannels",
+ tinychannels_bus::methods::CHECK_CHANNEL_HEALTH,
+ (config, proxy, 10_000_u64),
+ )
+ .await
+}
diff --git a/crates/openhuman-core/src/modules/mod.rs b/crates/openhuman-core/src/modules/mod.rs
index 2a27aaef1c..a7dc8ff070 100644
--- a/crates/openhuman-core/src/modules/mod.rs
+++ b/crates/openhuman-core/src/modules/mod.rs
@@ -53,6 +53,7 @@ mod browser_task_report;
pub(crate) mod channel_controller;
#[cfg(feature = "voice")]
pub mod channel_email;
+pub(crate) mod channel_health;
pub mod client;
#[cfg(feature = "modules")]
pub mod computer;