Skip to content

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

fix(channels): project v22 envelopes into legacy route messages

Steven Enamakel33363dd4ee71
diff --git a/crates/openhuman-core/src/channels/routes.rs b/crates/openhuman-core/src/channels/routes.rs
index 22e5fae376..6c36445d76 100644
--- a/crates/openhuman-core/src/channels/routes.rs
+++ b/crates/openhuman-core/src/channels/routes.rs
@@ -1,7 +1,7 @@
//! Per-sender routing and runtime command handling.
-use super::context::{clear_sender_history, ChannelRouteSelection, ChannelRuntimeContext};
-use super::{outbound::text_message, Channel};
+use super::context::{ChannelRouteSelection, ChannelRuntimeContext, clear_sender_history};
+use super::{Channel, outbound::text_message};
use crate::inference::provider;
use std::sync::Arc;
use tinychannels_bus as traits;
@@ -83,6 +83,27 @@ struct RouteCallbacks {
cancellation: tokio_util::sync::CancellationToken,
}
+/// Project the v22 envelope into the legacy shape still required by the
+/// module's `ChannelControlRequest::Route` contract.
+#[allow(
+ deprecated,
+ reason = "TinyChannels v22 Route requests still declare ChannelMessage"
+)]
+fn route_compat_message(msg: &traits::ChannelInboundEnvelope) -> traits::ChannelMessage {
+ traits::ChannelMessage {
+ id: msg.message_id.clone(),
+ sender: msg.sender.id.clone(),
+ reply_target: msg.conversation.id.clone(),
+ content: msg.text.clone(),
+ channel: msg.channel.id.clone(),
+ timestamp: msg.timestamp_unix_ms.unwrap_or_default(),
+ thread_ts: msg.conversation.thread_id.clone(),
+ reply_to_id: msg.reply_to_id.clone(),
+ topic_id: msg.conversation.topic_id.clone(),
+ sender_name: msg.sender.name.clone(),
+ }
+}
+
impl RouteCallbacks {
fn new(
context: ChannelRuntimeContext,
@@ -175,7 +196,7 @@ pub(crate) async fn handle_runtime_command_if_needed(
tinychannels_bus::methods::PREPARE_CHANNEL_CONTROL,
(ChannelControlRequest::Route {
workspace_dir: ctx.workspace_dir.to_string_lossy().into_owned(),
- message: Box::new(msg.clone()),
+ message: Box::new(route_compat_message(msg)),
capabilities: target_channel.map(|channel| Box::new(channel.capabilities())),
route: tinychannels_bus::module_remote::RemoteRoute {
provider: current.provider,
diff --git a/crates/openhuman-core/src/channels/routes_tests.rs b/crates/openhuman-core/src/channels/routes_tests.rs
index b940c6a6b1..34b67d8ed5 100644
--- a/crates/openhuman-core/src/channels/routes_tests.rs
+++ b/crates/openhuman-core/src/channels/routes_tests.rs
@@ -1,6 +1,6 @@
use super::*;
use crate::channels::context::{
- conversation_history_key, ChannelRuntimeContext, RouteSelectionMap, TurnModelSourceCacheMap,
+ ChannelRuntimeContext, RouteSelectionMap, TurnModelSourceCacheMap, conversation_history_key,
};
use crate::channels::host::ChannelTurnStateSubscriber;
use crate::core::events::DomainEvent;
@@ -47,6 +47,38 @@ fn inbound(
}
}
+#[test]
+#[allow(
+ deprecated,
+ reason = "The route contract still requires the v21 ChannelMessage projection"
+)]
+fn route_compat_message_preserves_legacy_addressing_and_sender_metadata() {
+ let mut message = inbound(
+ "message-1",
+ "sender-1",
+ "conversation-1",
+ "/status",
+ "telegram",
+ Some("thread-1".into()),
+ );
+ message.timestamp_unix_ms = Some(123);
+ message.reply_to_id = Some("reply-1".into());
+ message.conversation.topic_id = Some("topic-1".into());
+ message.sender.name = Some("Alice".into());
+
+ let legacy = super::route_compat_message(&message);
+ assert_eq!(legacy.id, "message-1");
+ assert_eq!(legacy.sender, "sender-1");
+ assert_eq!(legacy.reply_target, "conversation-1");
+ assert_eq!(legacy.content, "/status");
+ assert_eq!(legacy.channel, "telegram");
+ assert_eq!(legacy.timestamp, 123);
+ assert_eq!(legacy.thread_ts.as_deref(), Some("thread-1"));
+ assert_eq!(legacy.reply_to_id.as_deref(), Some("reply-1"));
+ assert_eq!(legacy.topic_id.as_deref(), Some("topic-1"));
+ assert_eq!(legacy.sender_name.as_deref(), Some("Alice"));
+}
+
struct DummyTool;
#[async_trait]
@@ -420,12 +452,13 @@ async fn handle_runtime_command_set_model_clears_sender_history_and_persists_rou
.await;
assert!(handled);
- assert!(ctx
- .conversation_histories
- .lock()
- .unwrap()
- .get(key)
- .is_none());
+ assert!(
+ ctx.conversation_histories
+ .lock()
+ .unwrap()
+ .get(key)
+ .is_none()
+ );
assert_eq!(
get_route_selection(&ctx, key),
ChannelRouteSelection {
@@ -547,7 +580,9 @@ async fn handle_runtime_command_telegram_sessions_reports_empty_store() {
let sent = channel_impl.sent.lock().unwrap();
assert_eq!(sent.len(), 1);
- assert!(sent_text(&sent[0]).contains("No conversation threads yet. Send `/new` to create one."));
+ assert!(
+ sent_text(&sent[0]).contains("No conversation threads yet. Send `/new` to create one.")
+ );
assert_eq!(sent[0].thread_id.as_deref(), Some("42"));
}
@@ -582,12 +617,13 @@ async fn handle_runtime_command_telegram_new_status_and_sessions_round_trip() {
)
.await
);
- assert!(ctx
- .conversation_histories
- .lock()
- .unwrap()
- .get(sender_key)
- .is_none());
+ assert!(
+ ctx.conversation_histories
+ .lock()
+ .unwrap()
+ .get(sender_key)
+ .is_none()
+ );
ctx.conversation_histories
.lock()
@@ -666,9 +702,10 @@ async fn handle_runtime_command_telegram_new_status_and_sessions_round_trip() {
assert!(sent_text(&sent[2]).contains("**Recent sessions**"));
assert!(sent_text(&sent[2]).contains("→ `Telegram"));
- assert!(sent
- .iter()
- .all(|message| message.thread_ts.as_deref() == Some("42")));
+ assert!(
+ sent.iter()
+ .all(|message| message.thread_ts.as_deref() == Some("42"))
+ );
}
#[tokio::test]