Skip to content

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

refactor(runtime): update channel dispatch logic and tests

Steven Enamakel982ab9d1ccf6
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rs b/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rs
index 7229902079..152b054c02 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rs
@@ -7,13 +7,13 @@ use std::{
use async_trait::async_trait;
use tinyagents_harness::{
+ CancellationToken,
run_queue::RunQueue,
turn_runner::{
EventSink, FailureClassification, FailureClassifier, IngressDecision, IngressPolicy,
IngressStage, QueueDisposition, ReplyStore, ScopeKey, Summarizer, TerminalEvent, TurnHost,
TurnRequest, TurnResult, TurnRunner, TurnRunnerConfig, TurnSession, TurnSignal,
},
- CancellationToken,
};
use tokio::sync::mpsc;
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/native_runner_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch/native_runner_tests.rs
index f6774fb15c..b1ffd910ec 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/native_runner_tests.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/native_runner_tests.rs
@@ -152,11 +152,13 @@ async fn queued_terminal_delivery_does_not_leave_a_completion_entry() {
shared.with("queued-request", |_| {});
shared.record_delivery("queued-request", true);
- assert!(shared
- .slots
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner())
- .is_empty());
+ assert!(
+ shared
+ .slots
+ .lock()
+ .unwrap_or_else(|poisoned| poisoned.into_inner())
+ .is_empty()
+ );
}
#[tokio::test]
@@ -166,11 +168,13 @@ async fn active_terminal_delivery_is_returned_to_its_waiting_caller() {
shared.record_delivery("active-request", true);
assert_eq!(shared.take_delivery("active-request"), Some(true));
- assert!(shared
- .slots
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner())
- .is_empty());
+ assert!(
+ shared
+ .slots
+ .lock()
+ .unwrap_or_else(|poisoned| poisoned.into_inner())
+ .is_empty()
+ );
}
#[tokio::test]
diff --git a/crates/openhuman-core/src/channels/runtime/test_support.rs b/crates/openhuman-core/src/channels/runtime/test_support.rs
index 7b1582265a..d6a60eba90 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};
diff --git a/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs b/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs
index 238a30279d..423962fa9d 100644
--- a/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs
+++ b/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs
@@ -191,7 +191,7 @@ async fn process_channel_message_cancels_scoped_typing_task() {
.filter(|path| path.ends_with("/sendChatAction"))
.count(),
2,
- "the module-backed provider should receive one typing start and stop"
+ "the module-backed provider should receive one typing start and stop; got {requests:?}"
);
assert_eq!(
requests
@@ -199,7 +199,7 @@ async fn process_channel_message_cancels_scoped_typing_task() {
.filter(|path| path.ends_with("/sendMessage"))
.count(),
1,
- "the module-backed provider should receive the completed reply"
+ "the module-backed provider should receive the completed reply; got {requests:?}"
);
}
@@ -680,10 +680,8 @@ 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("time budget")
+ && send.content.contains("retry your question in this thread")
+ }));
}
diff --git a/crates/openhuman-core/src/channels/tests/runtime_tool_calls.rs b/crates/openhuman-core/src/channels/tests/runtime_tool_calls.rs
index 7c34d3d551..e93eeb43b1 100644
--- a/crates/openhuman-core/src/channels/tests/runtime_tool_calls.rs
+++ b/crates/openhuman-core/src/channels/tests/runtime_tool_calls.rs
@@ -1,6 +1,6 @@
use super::super::context::{
- conversation_history_key, ChannelRouteSelection, ChannelRuntimeContext,
- CHANNEL_MESSAGE_TIMEOUT_SECS,
+ CHANNEL_MESSAGE_TIMEOUT_SECS, ChannelRouteSelection, ChannelRuntimeContext,
+ conversation_history_key,
};
use super::super::runtime::process_channel_message;
use super::common::{
@@ -81,7 +81,8 @@ async fn process_channel_message_handles_models_command_without_llm_call() {
let _module_storage = crate::channels::module_fixture::install_memory_storage();
let _module_client = crate::channels::module_fixture::client().await;
crate::core::bus::init().await.expect("bus init");
- let _builtins = crate::agent::harness::host_definition::AgentDefinitionRegistry::init_global_builtins();
+ let _builtins =
+ crate::agent::harness::host_definition::AgentDefinitionRegistry::init_global_builtins();
let channel_impl = Arc::new(TestChannel::new("telegram"));
let channel = Arc::new(ChannelHandle::Test(channel_impl.clone()));
@@ -147,7 +148,10 @@ async fn process_channel_message_handles_models_command_without_llm_call() {
let sent = channel_impl.sent_messages.lock().await;
assert_eq!(sent.len(), 1);
- assert!(sent[0].contains("Provider switched to `openhuman`"));
+ assert!(
+ sent[0].contains("Provider switched to `openhuman`"),
+ "the module-handled command should confirm its route change: {sent:?}"
+ );
let route = runtime_ctx
.route_overrides