Skip to content

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

fix(channels): fail closed when progressive transport owner drops

Steven Enamakela9eb58ab4900
diff --git a/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs b/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs
index edc4609fdd..d7235191d4 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs
@@ -520,7 +520,7 @@ async fn native_progressive_output_event_validates_scope_before_observer() {
async fn native_progressive_callbacks_stop_after_channel_session_cancellation() {
let observer = Arc::new(RecordingOutputObserver::default());
let adapter = Arc::new(RecordingChannel::new("telegram:bot-b"));
- let (callback, _context) = callback_for_channels(
+ let (mut callback, _context) = callback_for_channels(
HashMap::from([("telegram:bot-b".into(), adapter.clone() as Arc<dyn Channel>)]),
HashMap::from([(
"telegram:bot-b".into(),
@@ -529,6 +529,7 @@ async fn native_progressive_callbacks_stop_after_channel_session_cancellation()
Some(observer.clone() as Arc<dyn ProgressiveOutputObserver>),
);
+ callback.cancellation = tokio_util::sync::CancellationToken::new();
callback.cancellation.cancel();
assert!(callback
.dispatch_controller_backend(output_event_request(
@@ -540,3 +541,27 @@ async fn native_progressive_callbacks_stop_after_channel_session_cancellation()
.is_err());
assert!(observer.seen.lock().await.is_empty());
}
+
+#[tokio::test]
+async fn native_progressive_callbacks_fail_closed_after_transport_owner_drops() {
+ let adapter = Arc::new(RecordingChannel::new("telegram:bot-b"));
+ let (callback, context) = callback_for_channels(
+ HashMap::from([("telegram:bot-b".into(), adapter.clone() as Arc<dyn Channel>)]),
+ HashMap::from([(
+ "telegram:bot-b".into(),
+ adapter.clone() as Arc<dyn ProgressiveChannelTransport>,
+ )]),
+ None,
+ );
+ drop(context);
+ drop(adapter);
+
+ assert!(callback
+ .dispatch_controller_backend(output_event_request(
+ Some("telegram:bot-b"),
+ Some("chat-42"),
+ Some("turn-16"),
+ ))
+ .await
+ .is_err());
+}
diff --git a/crates/openhuman-core/src/channels/runtime/startup/progressive_transport.rs b/crates/openhuman-core/src/channels/runtime/startup/progressive_transport.rs
index 9d0c29d1f7..c96694fc58 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/progressive_transport.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/progressive_transport.rs
@@ -227,14 +227,16 @@ fn receipt_matches_scope(
channel: Option<&tinychannels_bus::ChannelRef>,
conversation: Option<&tinychannels_bus::ConversationRef>,
) -> bool {
- receipt.channel.as_ref().is_some_and(|receipt_channel| {
- channel.is_some_and(|channel| receipt_channel == channel)
- }) && receipt
- .conversation
+ receipt
+ .channel
.as_ref()
- .is_some_and(|receipt_conversation| {
- conversation.is_some_and(|conversation| receipt_conversation == conversation)
- })
+ .is_some_and(|receipt_channel| channel.is_some_and(|channel| receipt_channel == channel))
+ && receipt
+ .conversation
+ .as_ref()
+ .is_some_and(|receipt_conversation| {
+ conversation.is_some_and(|conversation| receipt_conversation == conversation)
+ })
}
fn receipt_contains_message(receipt: &tinychannels_bus::channel::MessageReceipt, id: &str) -> bool {
diff --git a/crates/openhuman-core/src/channels/runtime/startup/progressive_transport_tests.rs b/crates/openhuman-core/src/channels/runtime/startup/progressive_transport_tests.rs
index 24f4fa1225..0d11e61dab 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/progressive_transport_tests.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/progressive_transport_tests.rs
@@ -24,3 +24,63 @@ fn forbidden_edit_error_is_preserved_instead_of_reported_as_unsupported() {
assert_eq!(error.message, "edit denied by account policy");
assert!(!error.unsupported);
}
+
+#[test]
+fn receipt_scope_requires_exact_channel_and_full_conversation_identity() {
+ use tinychannels_bus::channel::{types::ConversationKind, MessageReceipt};
+ use tinychannels_bus::{ChannelRef, ConversationRef};
+
+ let channel = ChannelRef {
+ id: "telegram".into(),
+ account_id: Some("telegram:bot-a".into()),
+ };
+ let conversation = ConversationRef {
+ kind: ConversationKind::Group,
+ id: "chat-42".into(),
+ scope_id: Some("tenant-1".into()),
+ parent_id: Some("group-7".into()),
+ thread_id: Some("thread-9".into()),
+ topic_id: Some("topic-5".into()),
+ };
+ let mut receipt = MessageReceipt {
+ channel: Some(channel.clone()),
+ conversation: Some(conversation.clone()),
+ ..Default::default()
+ };
+ assert!(receipt_matches_scope(
+ &receipt,
+ Some(&channel),
+ Some(&conversation)
+ ));
+ assert!(!receipt_matches_scope(&receipt, Some(&channel), None));
+ assert!(!receipt_matches_scope(
+ &MessageReceipt::default(),
+ Some(&channel),
+ Some(&conversation)
+ ));
+
+ let mut different_account = channel.clone();
+ different_account.account_id = Some("telegram:bot-b".into());
+ assert!(!receipt_matches_scope(
+ &receipt,
+ Some(&different_account),
+ Some(&conversation)
+ ));
+
+ let mut different_kind = conversation.clone();
+ different_kind.kind = ConversationKind::Dm;
+ assert!(!receipt_matches_scope(
+ &receipt,
+ Some(&channel),
+ Some(&different_kind)
+ ));
+ receipt.conversation = Some(ConversationRef {
+ thread_id: Some("different-thread".into()),
+ ..conversation.clone()
+ });
+ assert!(!receipt_matches_scope(
+ &receipt,
+ Some(&channel),
+ Some(&conversation)
+ ));
+}