Skip to content

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

refactor(channels): update runtime dispatch logic and tests

Steven Enamakelfb5b91731d97
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
index f3b84ce188..242db4488d 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
@@ -1,11 +1,11 @@
//! The per-message pipeline: typing indicator, ACK reaction, durable-session
//! dispatch through the shared runner, and final reply delivery.
-use crate::channels::context::{is_context_window_overflow_error, ChannelRuntimeContext};
+use crate::channels::SendMessage;
+use crate::channels::context::{ChannelRuntimeContext, is_context_window_overflow_error};
#[cfg(test)]
use crate::channels::routes::get_or_create_turn_model_source;
use crate::channels::routes::{get_route_selection, handle_runtime_command_with_reset};
-use crate::channels::SendMessage;
use crate::core::bus::BUS;
use crate::core::events::DomainEvent;
use crate::util::truncate_with_ellipsis;
@@ -15,12 +15,12 @@ use tokio_util::sync::CancellationToken;
use tokio_util::task::AbortOnDropHandle;
use super::super::helpers::{
- build_channel_context_block, log_worker_join_result, spawn_typing_task,
- REPLY_LOG_TRUNCATE_CHARS,
+ REPLY_LOG_TRUNCATE_CHARS, build_channel_context_block, log_worker_join_result,
+ spawn_typing_task,
};
use super::super::host_agent::{self, HostRoute};
-use super::approval::{channel_has_approval_surface, try_route_approval_reply};
use super::RuntimeChannelMessage;
+use super::approval::{channel_has_approval_surface, try_route_approval_reply};
fn inbound_console_preview(
envelope: &tinychannels_bus::ChannelInboundEnvelope,
diff --git a/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs b/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs
index 8bfd7e1b5b..c06e22d40a 100644
--- a/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs
+++ b/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs
@@ -1,12 +1,12 @@
-use super::super::context::{ChannelRuntimeContext, CHANNEL_MESSAGE_TIMEOUT_SECS};
+use super::super::context::{CHANNEL_MESSAGE_TIMEOUT_SECS, ChannelRuntimeContext};
use super::super::runtime::test_support::{
- linked_telegram_runtime, run_dispatch_harness, DispatchHarnessOptions,
+ DispatchHarnessOptions, linked_telegram_runtime, run_dispatch_harness,
};
use super::super::runtime::{
- process_channel_message, run_message_dispatch_loop, RuntimeChannelMessage,
+ RuntimeChannelMessage, process_channel_message, run_message_dispatch_loop,
};
-use super::common::{use_real_agent_handler, RecordingChannel, SlowModel};
-use crate::agent::bus::{mock_agent_run_turn, AgentTurnRequest, AgentTurnResponse};
+use super::common::{RecordingChannel, SlowModel, use_real_agent_handler};
+use crate::agent::bus::{AgentTurnRequest, AgentTurnResponse, mock_agent_run_turn};
use crate::channels::runtime::ChannelHandle;
use crate::core::events::DomainEvent;
use crate::inference::provider;
@@ -362,7 +362,9 @@ fn unrelated_processed_event(n: usize) -> DomainEvent {
}
}
-async fn resolved_route_ctx(send_error: Option<&str>) -> (Arc<ChannelRuntimeContext>, Arc<RecordingChannel>) {
+async fn resolved_route_ctx(
+ send_error: Option<&str>,
+) -> (Arc<ChannelRuntimeContext>, Arc<RecordingChannel>) {
let mut channel_state = RecordingChannel::default();
channel_state.send_error = send_error.map(str::to_owned);
let channel_impl = Arc::new(channel_state);
@@ -370,32 +372,35 @@ async fn resolved_route_ctx(send_error: Option<&str>) -> (Arc<ChannelRuntimeCont
let mut channels_by_name = HashMap::new();
channels_by_name.insert(channel.name().to_string(), channel);
- (Arc::new(ChannelRuntimeContext {
- relay_thread: None,
- channels_by_name: Arc::new(channels_by_name),
- module_objects: Arc::new(HashMap::new()),
- turn_model_source: Some(crate::agent::tinyagents::TurnModelSource::from_model(
- Arc::new(super::common::DummyModel),
- )),
- default_provider: Arc::new("requested-provider".to_string()),
- tools_registry: Arc::new(vec![]),
- system_prompt: crate::channels::ChannelSystemPrompt::fixed("test-system-prompt"),
- model: Arc::new("requested-model".to_string()),
- temperature: 0.0,
- max_tool_iterations: 10,
- turn_model_source_cache: Arc::new(Mutex::new(HashMap::new())),
- route_overrides: Arc::new(Mutex::new(HashMap::new())),
- api_url: None,
- inference_url: None,
- reliability: Arc::new(crate::config::ReliabilityConfig::default()),
- provider_runtime_options: provider::ProviderRuntimeOptions::default(),
- workspace_dir: Arc::new(std::env::temp_dir()),
- message_timeout_secs: CHANNEL_MESSAGE_TIMEOUT_SECS,
- multimodal: crate::config::MultimodalConfig::default(),
- multimodal_files: crate::config::MultimodalFileConfig::default(),
- config: None,
- core: None,
- }), channel_impl)
+ (
+ Arc::new(ChannelRuntimeContext {
+ relay_thread: None,
+ channels_by_name: Arc::new(channels_by_name),
+ module_objects: Arc::new(HashMap::new()),
+ turn_model_source: Some(crate::agent::tinyagents::TurnModelSource::from_model(
+ Arc::new(super::common::DummyModel),
+ )),
+ default_provider: Arc::new("requested-provider".to_string()),
+ tools_registry: Arc::new(vec![]),
+ system_prompt: crate::channels::ChannelSystemPrompt::fixed("test-system-prompt"),
+ model: Arc::new("requested-model".to_string()),
+ temperature: 0.0,
+ max_tool_iterations: 10,
+ turn_model_source_cache: Arc::new(Mutex::new(HashMap::new())),
+ route_overrides: Arc::new(Mutex::new(HashMap::new())),
+ api_url: None,
+ inference_url: None,
+ reliability: Arc::new(crate::config::ReliabilityConfig::default()),
+ provider_runtime_options: provider::ProviderRuntimeOptions::default(),
+ workspace_dir: Arc::new(std::env::temp_dir()),
+ message_timeout_secs: CHANNEL_MESSAGE_TIMEOUT_SECS,
+ multimodal: crate::config::MultimodalConfig::default(),
+ multimodal_files: crate::config::MultimodalFileConfig::default(),
+ config: None,
+ core: None,
+ }),
+ channel_impl,
+ )
}
async fn run_resolved_route_message(
@@ -462,7 +467,10 @@ async fn run_resolved_route_message(
assert_eq!(model, "actual-model");
let sends = channel.sent.lock().expect("test sends lock");
if send_error.is_some() {
- assert!(sends.is_empty(), "a failed send must not be recorded as delivered");
+ assert!(
+ sends.is_empty(),
+ "a failed send must not be recorded as delivered"
+ );
} else {
assert_eq!(sends.len(), 1, "successful reply delivery must be recorded");
}
@@ -672,8 +680,10 @@ async fn dispatch_replies_with_timeout_notice_when_handler_exceeds_deadline() {
..Default::default()
})
.await;
- assert!(timed_out
- .sends
- .iter()
- .any(|send| send.content.contains("Request timed out")));
+ assert!(
+ timed_out
+ .sends
+ .iter()
+ .any(|send| send.content.contains("Request timed out"))
+ );
}