Skip to content

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

refactor(channels): clean up channel context and test code

Steven Enamakeld08e7c5936b1
diff --git a/crates/openhuman-core/src/channels/bus.rs b/crates/openhuman-core/src/channels/bus.rs
index 5f729a827a..4d98d1913b 100644
--- a/crates/openhuman-core/src/channels/bus.rs
+++ b/crates/openhuman-core/src/channels/bus.rs
@@ -10,7 +10,6 @@ mod subscriber;
pub(crate) use delivery::NativeProgressiveReply;
pub use subscriber::ChannelInboundSubscriber;
-
#[cfg(test)]
#[path = "bus_tests.rs"]
mod tests;
diff --git a/crates/openhuman-core/src/channels/context.rs b/crates/openhuman-core/src/channels/context.rs
index 41e2e985dc..23ef1977bd 100644
--- a/crates/openhuman-core/src/channels/context.rs
+++ b/crates/openhuman-core/src/channels/context.rs
@@ -12,8 +12,8 @@ use tinytools::Tool;
pub(crate) use tinychannels_bus::context::ChannelRouteSelection;
pub(crate) use tinychannels_bus::{
- CHANNEL_TYPING_REFRESH_INTERVAL_SECS, DEFAULT_CHANNEL_INITIAL_BACKOFF_SECS,
- DEFAULT_CHANNEL_MAX_BACKOFF_SECS, MAX_CHANNEL_HISTORY, CHANNEL_MESSAGE_TIMEOUT_SECS,
+ CHANNEL_MESSAGE_TIMEOUT_SECS, CHANNEL_TYPING_REFRESH_INTERVAL_SECS,
+ DEFAULT_CHANNEL_INITIAL_BACKOFF_SECS, DEFAULT_CHANNEL_MAX_BACKOFF_SECS, MAX_CHANNEL_HISTORY,
MIN_CHANNEL_MESSAGE_TIMEOUT_SECS,
};
@@ -22,11 +22,15 @@ pub(crate) use tinychannels_bus::{
// `history_key` directly; provider identity derivation stays in TinyChannels.
#[cfg(test)]
pub(crate) fn conversation_history_key(msg: &tinychannels_bus::ChannelMessage) -> String {
- let mut key = [msg.channel.as_str(), msg.sender.as_str(), msg.reply_target.as_str()]
- .iter()
- .map(|part| part.replace('%', "%25").replace('_', "%5F"))
- .collect::<Vec<_>>()
- .join("_");
+ let mut key = [
+ msg.channel.as_str(),
+ msg.sender.as_str(),
+ msg.reply_target.as_str(),
+ ]
+ .iter()
+ .map(|part| part.replace('%', "%25").replace('_', "%5F"))
+ .collect::<Vec<_>>()
+ .join("_");
if !crate::channels::capabilities::capabilities_for(&msg.channel).history_key_ignores_thread {
if let Some(thread) = msg.thread_ts.as_deref() {
key.push_str("_thread:");
diff --git a/crates/openhuman-core/src/channels/providers/relay/params.rs b/crates/openhuman-core/src/channels/providers/relay/params.rs
index f570667582..6504ac87d8 100644
--- a/crates/openhuman-core/src/channels/providers/relay/params.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/params.rs
@@ -51,7 +51,10 @@ impl RelayInboundParams {
/// Production callers obtain this from `PrepareChannelIdentity`.
#[cfg(test)]
pub(crate) fn thread_id(&self) -> String {
- format!("channel:{}/{}/{}", self.channel, self.sender_id, self.chat_id)
+ format!(
+ "channel:{}/{}/{}",
+ self.channel, self.sender_id, self.chat_id
+ )
}
/// A message with the five required facts and nothing optional: no
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/mod.rs b/crates/openhuman-core/src/channels/runtime/dispatch/mod.rs
index 9ef36eadef..4f31890b03 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/mod.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/mod.rs
@@ -21,8 +21,8 @@ pub(crate) use processor::progressive::{
};
pub(crate) use processor::{
- process_channel_message, process_channel_runtime_message, reset_durable_channel_session, run_message_dispatch_loop,
- RuntimeChannelMessage,
+ process_channel_message, process_channel_runtime_message, reset_durable_channel_session,
+ run_message_dispatch_loop, RuntimeChannelMessage,
};
// `channel_has_approval_surface` stays pub(crate) on processor; re-export so
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 96775a2893..1c4827b34f 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs
@@ -257,9 +257,7 @@ async fn native_progressive_transport_dispatches_typed_content_through_configure
let channels: HashMap<String, Arc<ChannelHandle>> = HashMap::from([
(
other_account.name().to_owned(),
- Arc::new(ChannelHandle::test(TestChannel::new(
- other_account.name(),
- ))),
+ Arc::new(ChannelHandle::test(TestChannel::new(other_account.name()))),
),
(
selected_account.name().to_owned(),
@@ -378,15 +376,11 @@ async fn native_progressive_transport_rejects_unconfigured_account_without_provi
let channels: HashMap<String, Arc<ChannelHandle>> = HashMap::from([
(
"telegram:bot-a".into(),
- Arc::new(ChannelHandle::test(TestChannel::new(
- first_account.name(),
- ))),
+ Arc::new(ChannelHandle::test(TestChannel::new(first_account.name()))),
),
(
"telegram:bot-b".into(),
- Arc::new(ChannelHandle::test(TestChannel::new(
- second_account.name(),
- ))),
+ Arc::new(ChannelHandle::test(TestChannel::new(second_account.name()))),
),
]);
let progressive_channels: HashMap<String, Arc<dyn ProgressiveChannelTransport>> =
@@ -444,9 +438,7 @@ async fn native_progressive_output_event_is_acknowledged_by_optional_host_observ
let (callback, _context) = callback_for_channels(
HashMap::from([(
"telegram:bot-b".into(),
- Arc::new(ChannelHandle::test(TestChannel::new(
- "telegram:bot-b",
- ))),
+ Arc::new(ChannelHandle::test(TestChannel::new("telegram:bot-b"))),
)]),
HashMap::from([(
"telegram:bot-b".into(),
@@ -525,9 +517,7 @@ async fn native_progressive_output_event_validates_scope_without_observer() {
let (callback, _context) = callback_for_channels(
HashMap::from([(
"telegram:bot-b".into(),
- Arc::new(ChannelHandle::test(TestChannel::new(
- "telegram:bot-b",
- ))),
+ Arc::new(ChannelHandle::test(TestChannel::new("telegram:bot-b"))),
)]),
HashMap::from([(
"telegram:bot-b".into(),
@@ -568,9 +558,7 @@ async fn native_progressive_output_event_validates_scope_before_observer() {
let (callback, _) = callback_for_channels(
HashMap::from([(
"telegram:bot-b".into(),
- Arc::new(ChannelHandle::test(TestChannel::new(
- "telegram:bot-b",
- ))),
+ Arc::new(ChannelHandle::test(TestChannel::new("telegram:bot-b"))),
)]),
HashMap::from([(
"telegram:bot-b".into(),
@@ -598,9 +586,7 @@ async fn native_progressive_callbacks_stop_after_channel_session_cancellation()
let (callback, _context) = callback_for_channels(
HashMap::from([(
"telegram:bot-b".into(),
- Arc::new(ChannelHandle::test(TestChannel::new(
- "telegram:bot-b",
- ))),
+ Arc::new(ChannelHandle::test(TestChannel::new("telegram:bot-b"))),
)]),
HashMap::from([(
"telegram:bot-b".into(),
@@ -627,9 +613,7 @@ async fn native_progressive_callbacks_fail_closed_after_transport_owner_drops()
let (callback, context) = callback_for_channels(
HashMap::from([(
"telegram:bot-b".into(),
- Arc::new(ChannelHandle::test(TestChannel::new(
- "telegram:bot-b",
- ))),
+ Arc::new(ChannelHandle::test(TestChannel::new("telegram:bot-b"))),
)]),
HashMap::from([(
"telegram:bot-b".into(),
diff --git a/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs b/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs
index 49368e8792..fb62b504f6 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs
@@ -8,7 +8,6 @@ use crate::modules::channel_runtime::ChannelRuntimeLease;
use anyhow::{Context, Result};
use std::collections::HashMap;
use std::sync::{Arc, OnceLock, Weak};
-use tokio::sync::mpsc;
use tinybus::module::{ModuleCallError, ModuleClient, ModuleObjectClient};
use tinychannels_bus::module_runtime::{
ChannelIngressKind, ChannelMessagePreparation, ConfiguredChannelInfo,
@@ -16,6 +15,7 @@ use tinychannels_bus::module_runtime::{
use tinychannels_bus::module_supervision::ChannelSupervisionPolicy;
use tinychannels_bus::SendMessage;
use tinychannels_bus::{ChannelInteraction, ChannelInteractionResult};
+use tokio::sync::mpsc;
/// Channel objects sharing one captured config, callback object and module lease.
pub(super) struct ModuleChannelRuntime {
diff --git a/crates/openhuman-core/src/channels/runtime/test_support.rs b/crates/openhuman-core/src/channels/runtime/test_support.rs
index 4cd6bdb941..44d8635109 100644
--- a/crates/openhuman-core/src/channels/runtime/test_support.rs
+++ b/crates/openhuman-core/src/channels/runtime/test_support.rs
@@ -5,7 +5,6 @@ use super::dispatch::{
process_channel_message, process_channel_runtime_message, RuntimeChannelMessage,
};
use crate::channels::context::ChannelRuntimeContext;
-use tinychannels_bus::CHANNEL_MESSAGE_TIMEOUT_SECS;
use crate::channels::ChannelSystemPrompt;
use crate::config::{MultimodalConfig, MultimodalFileConfig, ReliabilityConfig};
use crate::core::events::DomainEvent;
@@ -18,6 +17,7 @@ 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 tinyinference_llm::model::{ChatModel, ModelRequest, ModelResponse};
use tinytools::{Tool, ToolResult};
use wiremock::matchers::{method, path};