Skip to content

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

refactor(channels): update channel message handling and logging

Steven Enamakela8ee43b8fcbd
diff --git a/crates/openhuman-core/src/channels/host/channel_events.rs b/crates/openhuman-core/src/channels/host/channel_events.rs
index c57e596df0..a652e810d9 100644
--- a/crates/openhuman-core/src/channels/host/channel_events.rs
+++ b/crates/openhuman-core/src/channels/host/channel_events.rs
@@ -6,9 +6,9 @@ use async_trait::async_trait;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
-use tinybus::EventHandler;
use tinybus::module::ModuleClient;
-use tinychannels_bus::{ChannelMessage, approvals::ReplyContext};
+use tinybus::EventHandler;
+use tinychannels_bus::{approvals::ReplyContext, ChannelMessage};
/// Captures the account configuration and reply addresses used by approvals.
pub struct ChannelApprovalSurfaceSubscriber {
diff --git a/crates/openhuman-core/src/channels/module_fixture_tests.rs b/crates/openhuman-core/src/channels/module_fixture_tests.rs
index 5081d1ba3e..8ddaefba14 100644
--- a/crates/openhuman-core/src/channels/module_fixture_tests.rs
+++ b/crates/openhuman-core/src/channels/module_fixture_tests.rs
@@ -8,8 +8,8 @@
//! on a process-lifetime runtime, so it outlives the short Tokio runtimes of
//! individual tests.
-use crate::config::Config;
use crate::config::schema::ModuleSourceMode;
+use crate::config::Config;
use crate::modules::linked::register_linked;
use crate::modules::{ops, runtime};
use std::sync::Arc;
@@ -140,10 +140,10 @@ async fn linked_module_prepares_runtime_limits_over_confidential_bus_call() {
#[cfg(feature = "e2e-test-support")]
async fn linked_module_prepares_legacy_inbound_facts_over_confidential_bus_call() {
let _storage = install_memory_storage();
- use tinychannels_bus::ChannelMessage;
use tinychannels_bus::module_inbound::{
ChannelInboundSource, PrepareChannelInboundRequest, PreparedChannelInbound,
};
+ use tinychannels_bus::ChannelMessage;
let message = ChannelMessage {
id: "message-1".into(),
diff --git a/crates/openhuman-core/src/channels/providers/relay/ops.rs b/crates/openhuman-core/src/channels/providers/relay/ops.rs
index 568a5e99bc..0b7c493972 100644
--- a/crates/openhuman-core/src/channels/providers/relay/ops.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/ops.rs
@@ -4,15 +4,15 @@ use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
-use serde_json::{Value, json};
+use serde_json::{json, Value};
use super::channel::RelayChannel;
use super::params::RelayInboundParams;
use super::store::{self, Recorded};
use crate::channels::context::MAX_CHANNEL_HISTORY;
use crate::channels::runtime::{
- PromptToolDescs, build_channel_turn_parts, prepare_runtime_limits,
- process_channel_runtime_message, runtime_context,
+ build_channel_turn_parts, prepare_runtime_limits, process_channel_runtime_message,
+ runtime_context, PromptToolDescs,
};
use crate::config::Config;
use crate::core::Outcome;
diff --git a/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs b/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs
index be727ffd1c..c93bd4a10d 100644
--- a/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs
@@ -1,6 +1,6 @@
use super::super::channel::CHANNEL_OUTBOUND_EVENT;
use super::*;
-use crate::agent::bus::{AgentTurnRequest, AgentTurnResponse, mock_agent_run_turn};
+use crate::agent::bus::{mock_agent_run_turn, AgentTurnRequest, AgentTurnResponse};
use crate::agent::turn_origin::AgentTurnOrigin;
use crate::core::runtime::{ContextOverlay, CoreContext, DomainSet};
use std::sync::Mutex;
@@ -212,16 +212,12 @@ async fn a_relayed_turn_runs_as_an_external_channel_and_keeps_its_thread() {
}
}
assert_eq!(outbound.len(), 2, "one channel_outbound per reply");
- assert!(
- outbound
- .iter()
- .all(|event| event.event_name() == CHANNEL_OUTBOUND_EVENT)
- );
- assert!(
- outbound
- .iter()
- .all(|event| event.context().thread_id == thread)
- );
+ assert!(outbound
+ .iter()
+ .all(|event| event.event_name() == CHANNEL_OUTBOUND_EVENT));
+ assert!(outbound
+ .iter()
+ .all(|event| event.context().thread_id == thread));
assert_eq!(outbound[0].context().request_id, "req-m1");
assert!(matches!(
outbound[0].wire_event(),
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/progressive.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/progressive.rs
index 9bc4121757..adc4ab98f2 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/progressive.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/progressive.rs
@@ -36,11 +36,10 @@ impl NativeProgressiveTarget {
turn_id: &str,
) -> anyhow::Result<std::sync::Arc<NativeProgressiveReply>> {
tracing::debug!(
- provider_matches_account = self
- .channel
- .account_id
- .as_deref()
- .is_some_and(|account| tinychannels_bus::provider_id(account) == self.channel.id),
+ provider_matches_account =
+ self.channel.account_id.as_deref().is_some_and(|account| {
+ tinychannels_bus::provider_id(account) == self.channel.id
+ }),
account_present = self
.channel
.account_id
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 bdee54fa99..0b68b13a7e 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
@@ -1,7 +1,7 @@
//! The per-message pipeline: typing indicator, ACK reaction, durable-session
//! dispatch through the shared runner, and final reply delivery.
-use crate::channels::context::{ChannelRuntimeContext, is_context_window_overflow_error};
+use crate::channels::context::{is_context_window_overflow_error, ChannelRuntimeContext};
#[cfg(test)]
use crate::channels::routes::get_or_create_turn_model_source;
use crate::channels::routes::{get_route_selection, handle_runtime_command_with_reset};
@@ -15,12 +15,12 @@ use tokio_util::sync::CancellationToken;
use tokio_util::task::AbortOnDropHandle;
use super::super::helpers::{
- REPLY_LOG_TRUNCATE_CHARS, build_channel_context_block, log_worker_join_result,
- spawn_typing_task,
+ build_channel_context_block, log_worker_join_result, spawn_typing_task,
+ REPLY_LOG_TRUNCATE_CHARS,
};
use super::super::host_agent::{self, HostRoute};
-use super::RuntimeChannelMessage;
use super::approval::{channel_has_approval_surface, try_route_approval_reply};
+use super::RuntimeChannelMessage;
fn inbound_console_preview(
envelope: &tinychannels_bus::ChannelInboundEnvelope,
diff --git a/crates/openhuman-core/src/channels/runtime/startup/callback.rs b/crates/openhuman-core/src/channels/runtime/startup/callback.rs
index 9284cec561..9d2ffee3c4 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/callback.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/callback.rs
@@ -268,7 +268,10 @@ impl ChannelHostCallbacks {
"scoped channel voice media callback entered"
);
if serialized_len > MAX_VOICE_MEDIA_BYTES {
- tracing::debug!(reason = "serialized_size", "scoped channel voice media rejected");
+ tracing::debug!(
+ reason = "serialized_size",
+ "scoped channel voice media rejected"
+ );
return Err(Error::failed("voice media callback exceeds its limit"));
}
let decoded = base64::Engine::decode(
@@ -276,11 +279,17 @@ impl ChannelHostCallbacks {
&request.audio_base64,
)
.map_err(|_| {
- tracing::debug!(reason = "invalid_base64", "scoped channel voice media rejected");
+ tracing::debug!(
+ reason = "invalid_base64",
+ "scoped channel voice media rejected"
+ );
Error::failed("voice media payload is invalid")
})?;
if decoded.is_empty() || decoded.len() > MAX_VOICE_MEDIA_DECODED_BYTES {
- tracing::debug!(reason = "decoded_size", "scoped channel voice media rejected");
+ tracing::debug!(
+ reason = "decoded_size",
+ "scoped channel voice media rejected"
+ );
return Err(Error::failed("voice media exceeds its size limit"));
}
let scope = &request.scope;
@@ -288,11 +297,12 @@ impl ChannelHostCallbacks {
let Some(channel) = context.channels_by_name.get(&scope.configured_instance) else {
tracing::debug!(
reason = "configured_instance_not_registered",
- provider_adapter_registered = context.channels_by_name.contains_key(&scope.channel.id),
- provider_matches_instance = scope.channel.id
- == tinychannels_bus::provider_id(&scope.configured_instance),
- account_matches_instance = scope.channel.account_id.as_deref()
- == Some(scope.configured_instance.as_str()),
+ provider_adapter_registered =
+ context.channels_by_name.contains_key(&scope.channel.id),
+ provider_matches_instance =
+ scope.channel.id == tinychannels_bus::provider_id(&scope.configured_instance),
+ account_matches_instance =
+ scope.channel.account_id.as_deref() == Some(scope.configured_instance.as_str()),
"scoped channel voice media rejected"
);
return Err(Error::failed("voice media account is not configured"));
@@ -306,12 +316,12 @@ impl ChannelHostCallbacks {
{
tracing::debug!(
reason = "scope_mismatch",
- provider_matches_instance = scope.channel.id
- == tinychannels_bus::provider_id(&scope.configured_instance),
- account_matches_instance = scope.channel.account_id.as_deref()
- == Some(scope.configured_instance.as_str()),
- adapter_matches_provider = tinychannels_bus::provider_id(channel.name())
- == scope.channel.id,
+ provider_matches_instance =
+ scope.channel.id == tinychannels_bus::provider_id(&scope.configured_instance),
+ account_matches_instance =
+ scope.channel.account_id.as_deref() == Some(scope.configured_instance.as_str()),
+ adapter_matches_provider =
+ tinychannels_bus::provider_id(channel.name()) == scope.channel.id,
conversation_present = !scope.conversation.id.trim().is_empty(),
turn_present = !scope.turn_id.trim().is_empty(),
"scoped channel voice media rejected"
@@ -329,7 +339,10 @@ impl ChannelHostCallbacks {
.is_some_and(|id| id.starts_with("tinychannels_media_v1_"))
})
.ok_or_else(|| {
- tracing::debug!(reason = "opaque_reference", "scoped channel voice media rejected");
+ tracing::debug!(
+ reason = "opaque_reference",
+ "scoped channel voice media rejected"
+ );
Error::failed("voice media has no durable scoped reference")
})?;
tracing::debug!("scoped channel voice media accepted");
diff --git a/crates/openhuman-core/src/threads/store/bus.rs b/crates/openhuman-core/src/threads/store/bus.rs
index 70a68b4bc2..45044ac3b4 100644
--- a/crates/openhuman-core/src/threads/store/bus.rs
+++ b/crates/openhuman-core/src/threads/store/bus.rs
@@ -36,7 +36,7 @@ use tinychannels_bus::ChannelMessage;
use tinychannels_runtime::context::conversation_history_key;
use super::{
- ConversationMessage, CreateConversationThread, append_message, ensure_thread, get_messages,
+ append_message, ensure_thread, get_messages, ConversationMessage, CreateConversationThread,
};
static CONVERSATION_PERSISTENCE_HANDLE: OnceLock<SubscriptionHandle> = OnceLock::new();