The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(cron): simplify channel bridge registration and delivery logic
Steven Enamakela0c985a69194
diff --git a/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs b/crates/openhuman-core/src/channels/runtime/startup/start_channels.rsindex d8a1521dba..0073b73aed 100644--- a/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs+++ b/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs@@ -252,9 +252,7 @@ async fn start_channels_inner(mut config: Config, session: CancellationToken) ->.map_err(|_| anyhow::anyhow!("channel callback context was already initialized"))?;// Cron channel context and replies use the durable agent transcript; this// bridge retains only the live channel transport adapters.- crate::cron::channel_bridge::register_channel_bridge(Arc::clone(- &runtime_ctx.module_objects,- ));+ crate::cron::channel_bridge::register_channel_bridge(Arc::clone(&runtime_ctx.module_objects));let startup = module_runtime.as_mut()diff --git a/crates/openhuman-core/src/cron/channel_bridge.rs b/crates/openhuman-core/src/cron/channel_bridge.rsindex 358c53a639..23ab02510d 100644--- a/crates/openhuman-core/src/cron/channel_bridge.rs+++ b/crates/openhuman-core/src/cron/channel_bridge.rs@@ -80,12 +80,12 @@ pub async fn send_to_channel(.map_err(|_| "channel progressive output could not be opened".to_string())?;match reply.finish(text).await {Ok(result) if crate::channels::runtime::dispatch::delivery_succeeded(&result) => Ok(()),- Ok(ProgressiveResult::DeliveryBatch { .. }- | ProgressiveResult::DeliveryOutcome { .. }- | ProgressiveResult::DeliveryOutcomes { .. }- | ProgressiveResult::DeliveryUnsupported { .. }) => {- Err("channel provider did not confirm complete delivery".into())- }+ Ok(+ ProgressiveResult::DeliveryBatch { .. }+ | ProgressiveResult::DeliveryOutcome { .. }+ | ProgressiveResult::DeliveryOutcomes { .. }+ | ProgressiveResult::DeliveryUnsupported { .. },+ ) => Err("channel provider did not confirm complete delivery".into()),Ok(_) => Err("channel provider returned an invalid delivery result".into()),Err(_) => Err("channel progressive delivery failed".into()),}diff --git a/crates/openhuman-core/src/cron/channel_bridge_tests.rs b/crates/openhuman-core/src/cron/channel_bridge_tests.rsindex 4d5f59ea80..6d9aa98232 100644--- a/crates/openhuman-core/src/cron/channel_bridge_tests.rs+++ b/crates/openhuman-core/src/cron/channel_bridge_tests.rs@@ -1,56 +1,34 @@use super::*;-use async_trait::async_trait;-use std::sync::atomic::{AtomicUsize, Ordering};-use std::sync::Mutex;-use tinychannels_bus::ChannelMessage;-use tokio::sync::mpsc;+use tinyflows_bus::schedule::types::ChannelConversationIdentity;-struct MockChannel {- sends: Arc<AtomicUsize>,- last_target: Arc<Mutex<String>>,+#[test]+fn conversation_ref_preserves_full_provider_scope() {+ let identity = ChannelConversationIdentity {+ kind: "group".into(),+ id: "room-1".into(),+ scope_id: Some("account-scope".into()),+ parent_id: Some("parent-1".into()),+ thread_id: Some("thread-2".into()),+ topic_id: Some("topic-3".into()),+ };+ let conversation = conversation_ref(&identity).unwrap();+ assert_eq!(conversation.kind, ConversationKind::Group);+ assert_eq!(conversation.id, "room-1");+ assert_eq!(conversation.scope_id.as_deref(), Some("account-scope"));+ assert_eq!(conversation.parent_id.as_deref(), Some("parent-1"));+ assert_eq!(conversation.thread_id.as_deref(), Some("thread-2"));+ assert_eq!(conversation.topic_id.as_deref(), Some("topic-3"));}-#[async_trait]-impl Channel for MockChannel {- fn name(&self) -> &str {- "telegram"- }- async fn send(&self, message: &SendMessage) -> anyhow::Result<()> {- self.sends.fetch_add(1, Ordering::SeqCst);- *self.last_target.lock().unwrap() = format!(- "{}|{}",- message.recipient,- message.idempotency_key.clone().unwrap_or_default()- );- Ok(())- }- async fn listen(&self, _tx: mpsc::Sender<ChannelMessage>) -> anyhow::Result<()> {- Ok(())- }-}--// One test: the bridge is process-global, so keep its steps sequential.-#[tokio::test]-async fn bridge_sends_with_a_run_specific_idempotency_key() {- let sends = Arc::new(AtomicUsize::new(0));- let last_target = Arc::new(Mutex::new(String::new()));- let ch: Arc<dyn Channel> = Arc::new(MockChannel {- sends: Arc::clone(&sends),- last_target: Arc::clone(&last_target),- });- let channels = Arc::new(HashMap::from([("telegram".to_string(), ch)]));- register_channel_bridge(channels);-- send_to_channel("Telegram", "42", None, "hi", "cron:j:r1")- .await- .unwrap();- assert_eq!(sends.load(Ordering::SeqCst), 1);- assert_eq!(- *last_target.lock().unwrap(),- "42|cron:j:r1",- "the send carries the run-specific idempotency key"- );- assert!(send_to_channel("slack", "42", None, "hi", "k")- .await- .is_err());+#[test]+fn conversation_ref_rejects_unknown_kind_claims() {+ let identity = ChannelConversationIdentity {+ kind: "invented".into(),+ id: "room-1".into(),+ scope_id: None,+ parent_id: None,+ thread_id: None,+ topic_id: None,+ };+ assert!(conversation_ref(&identity).is_err());}diff --git a/crates/openhuman-core/src/cron/scheduler/origin_delivery.rs b/crates/openhuman-core/src/cron/scheduler/origin_delivery.rsindex 8bc685df7e..4cf76f7707 100644--- a/crates/openhuman-core/src/cron/scheduler/origin_delivery.rs+++ b/crates/openhuman-core/src/cron/scheduler/origin_delivery.rs@@ -235,7 +235,6 @@ pub(crate) async fn deliver_to_origin(channel,reply_target,channel_session,- thread_id,..} => {let identity = channel_session@@ -247,8 +246,8 @@ pub(crate) async fn deliver_to_origin(let text = strip_openhuman_link_markup(text);channel_bridge::send_to_channel(channel,+ identity,reply_target,- thread_id.as_deref(),&text,&origin_request_id(&job.id, run_id),)