Skip to content

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

fix(channels): stop reusing telegram topic id as reply thread

Steven Enamakela0669f06555d
diff --git a/crates/openhuman-core/src/channels/routes.rs b/crates/openhuman-core/src/channels/routes.rs
index 63003ce146..5a49d092f1 100644
--- a/crates/openhuman-core/src/channels/routes.rs
+++ b/crates/openhuman-core/src/channels/routes.rs
@@ -168,7 +168,10 @@ where
return false;
}
let current = get_route_selection(ctx, sender_key);
- let reply_thread = msg.thread_ts.clone().or_else(|| msg.topic_id.clone());
+ // Telegram's legacy `thread_ts` is the inbound provider message id used
+ // for reply targeting; forum topic routing is already encoded in
+ // `reply_target` and must not be reused as a reply-to id.
+ let reply_thread = msg.thread_ts.clone();
let history_len =
durable_channel_history_len(ctx, &current, &msg.channel, durable_session_key.as_deref())
.await;
diff --git a/crates/openhuman-core/src/channels/routes_tests.rs b/crates/openhuman-core/src/channels/routes_tests.rs
index 786dbbd410..d176521dfe 100644
--- a/crates/openhuman-core/src/channels/routes_tests.rs
+++ b/crates/openhuman-core/src/channels/routes_tests.rs
@@ -140,7 +140,7 @@ async fn handle_linked_runtime_command(
reply_to_id: msg.reply_to_id.clone(),
conversation: tinychannels_bus::ConversationRef {
id: msg.reply_target.clone(),
- topic_id: msg.topic_id.clone().or_else(|| msg.thread_ts.clone()),
+ topic_id: msg.topic_id.clone(),
..Default::default()
},
sender: tinychannels_bus::SenderRef {
@@ -751,28 +751,53 @@ async fn handle_runtime_command_telegram_new_uses_module_storage() {
let linked = crate::channels::runtime::test_support::linked_telegram_runtime().await;
let workspace = linked.config().workspace_dir.clone();
let mut ctx = runtime_context(workspace);
- let channel_state = Arc::new(TestChannel::new("recording"));
- let channel = Arc::new(ChannelHandle::Test(Arc::clone(&channel_state)));
+ let channel = linked
+ .channels()
+ .into_iter()
+ .find(|(name, _)| tinychannels_bus::provider_id(name) == "telegram")
+ .map(|(_, channel)| channel)
+ .expect("linked runtime should expose its Telegram module handle");
let msg = ChannelMessage {
reply_to_id: None,
- topic_id: None,
- id: "1".into(),
+ topic_id: Some("42".into()),
+ id: "100".into(),
sender: "alice".into(),
- reply_target: "chat-remote".into(),
+ reply_target: "-200:42".into(),
content: "/new".into(),
channel: "telegram".into(),
timestamp: 0,
- thread_ts: Some("42".into()),
+ thread_ts: Some("100".into()),
sender_name: None,
};
assert!(handle_linked_runtime_command(&mut ctx, &msg, Some(&channel), &linked).await);
- let sent = channel_state.sent.lock().unwrap();
- assert_eq!(sent.len(), 1);
- assert!(sent[0].content.contains("Started new session"));
+ let topic_only_msg = ChannelMessage {
+ id: "101".into(),
+ thread_ts: None,
+ ..msg.clone()
+ };
assert!(
- sent[0]
- .content
+ handle_linked_runtime_command(&mut ctx, &topic_only_msg, Some(&channel), &linked).await
+ );
+ let sent = linked
+ .provider_request_bodies("/bottoken/sendMessage")
+ .await;
+ assert_eq!(sent.len(), 2);
+ assert_eq!(sent[0]["chat_id"], "-200");
+ assert_eq!(sent[0]["message_thread_id"], "42");
+ assert_eq!(sent[0]["reply_to_message_id"], 100);
+ assert!(
+ sent[0]["text"]
+ .as_str()
+ .unwrap()
+ .contains("Started new session")
+ );
+ assert!(
+ sent[0]["text"]
+ .as_str()
+ .unwrap()
.contains("Durable conversation history reset")
);
- assert_eq!(sent[0].thread_ts.as_deref(), Some("42"));
+ assert_eq!(sent[1]["chat_id"], "-200");
+ assert_eq!(sent[1]["message_thread_id"], "42");
+ assert!(sent[1].get("reply_to_message_id").is_none());
}
diff --git a/crates/openhuman-core/src/channels/runtime/test_support.rs b/crates/openhuman-core/src/channels/runtime/test_support.rs
index 65b5e60218..fd8c36581b 100644
--- a/crates/openhuman-core/src/channels/runtime/test_support.rs
+++ b/crates/openhuman-core/src/channels/runtime/test_support.rs
@@ -3,10 +3,10 @@
#[allow(unused_imports)] // Used by tests/raw_coverage outside the core unit-test crate.
pub use super::dispatch::test_support::build_channel_context_block_for_test;
use super::dispatch::{
- process_channel_message, process_channel_runtime_message, RuntimeChannelMessage,
+ RuntimeChannelMessage, process_channel_message, process_channel_runtime_message,
};
-use crate::channels::context::ChannelRuntimeContext;
use crate::channels::ChannelSystemPrompt;
+use crate::channels::context::ChannelRuntimeContext;
use crate::config::{MultimodalConfig, MultimodalFileConfig, ReliabilityConfig};
use crate::core::events::DomainEvent;
use crate::inference::provider::ProviderRuntimeOptions;
@@ -17,8 +17,8 @@ use std::path::PathBuf;
use std::sync::atomic::Ordering;
use std::sync::{Arc, Mutex};
use std::time::Duration;
-use tinychannels_bus::ChannelMessage;
use tinychannels_bus::CHANNEL_MESSAGE_TIMEOUT_SECS;
+use tinychannels_bus::ChannelMessage;
use tinyinference_llm::model::{ChatModel, ModelRequest, ModelResponse};
use tinytools::{Tool, ToolResult};
use wiremock::matchers::{method, path};
@@ -161,6 +161,19 @@ impl LinkedTelegramRuntime {
.map(|request| request.url.path().to_owned())
.collect()
}
+
+ pub(crate) async fn provider_request_bodies(&self, path: &str) -> Vec<serde_json::Value> {
+ self.server
+ .received_requests()
+ .await
+ .expect("mock provider should expose received requests")
+ .into_iter()
+ .filter(|request| request.url.path() == path)
+ .map(|request| {
+ serde_json::from_slice(&request.body).expect("provider request should be JSON")
+ })
+ .collect()
+ }
}
/// Prepare an actual linked TinyChannels module with mocked Telegram HTTP.