Skip to content

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

fix(channels): apply prepared message timeout to relayed turns

Steven Enamakel4c69d1ff24de
diff --git a/crates/openhuman-core/src/channels/context_tests.rs b/crates/openhuman-core/src/channels/context_tests.rs
index aa5fd547b7..d59c4b31b3 100644
--- a/crates/openhuman-core/src/channels/context_tests.rs
+++ b/crates/openhuman-core/src/channels/context_tests.rs
@@ -120,10 +120,10 @@ fn clear_and_compact_sender_history_update_cached_messages() {
#[tokio::test]
async fn overflow_detection_covers_edge_cases() {
let ctx = runtime_context();
- assert!(is_context_window_overflow_error(&anyhow::anyhow!(
+ assert!(is_context_window_overflow_error(&ctx, &anyhow::anyhow!(
"Maximum context length exceeded"
- )));
- assert!(!is_context_window_overflow_error(&anyhow::anyhow!(
+ )).await.unwrap());
+ assert!(!is_context_window_overflow_error(&ctx, &anyhow::anyhow!(
"network timeout"
- )));
+ )).await.unwrap());
}
diff --git a/crates/openhuman-core/src/channels/providers/relay/ops.rs b/crates/openhuman-core/src/channels/providers/relay/ops.rs
index 6f2a7fdc17..953820343e 100644
--- a/crates/openhuman-core/src/channels/providers/relay/ops.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/ops.rs
@@ -10,7 +10,8 @@ use super::params::RelayInboundParams;
use super::store::{self, Recorded};
use crate::channels::context::MAX_CHANNEL_HISTORY;
use crate::channels::runtime::{
- build_channel_turn_parts, process_channel_runtime_message, runtime_context, PromptToolDescs,
+ build_channel_turn_parts, prepare_runtime_limits, process_channel_runtime_message,
+ runtime_context, PromptToolDescs,
};
use crate::config::Config;
use crate::core::Outcome;
@@ -112,6 +113,29 @@ pub(crate) async fn run_relay_turn(
params.message_id.clone(),
));
+ let client = crate::modules::client::ModuleClient::new(config.clone());
+ let (message_timeout_secs, _) = match prepare_runtime_limits(
+ &client,
+ config.channels_config.message_timeout_secs,
+ 1,
+ )
+ .await
+ {
+ Ok(limits) => limits,
+ Err(error) => {
+ tracing::warn!("relayed channel runtime limits unavailable: {error}");
+ let reply =
+ "⚠️ This chat's assistant is not available right now. Please try again later.";
+ let _ = crate::channels::traits::Channel::send(
+ channel.as_ref(),
+ &crate::channels::SendMessage::new(reply, &params.chat_id),
+ )
+ .await;
+ record(&workspace_dir, &params, &thread_id, &channel.sent()).await;
+ return channel.sent();
+ }
+ };
+
let security = Arc::new(
SecurityPolicy::from_config(&config.autonomy, &config.workspace_dir, &config.action_dir)
.with_privacy_mode(config.privacy.mode),
@@ -143,7 +167,7 @@ pub(crate) async fn run_relay_turn(
&config,
parts,
Arc::new(channels_by_name),
- None,
+ message_timeout_secs,
));
// The thread is the conversation's memory: seed the pipeline's per-chat
diff --git a/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs b/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs
index 82c6c348ab..625700b8c6 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs
@@ -254,7 +254,7 @@ async fn start_channels_inner(mut config: Config, session: CancellationToken) ->
&config,
parts,
Arc::clone(&channels_by_name),
- Some(message_timeout_secs),
+ message_timeout_secs,
));
context_slot
.set(Arc::downgrade(&runtime_ctx))
diff --git a/crates/openhuman-core/src/channels/runtime/startup/turn_parts.rs b/crates/openhuman-core/src/channels/runtime/startup/turn_parts.rs
index 57eae582c6..792f6be474 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/turn_parts.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/turn_parts.rs
@@ -9,7 +9,7 @@
use super::chat_workload::{ChatWorkloadResolution, resolve_chat_workload};
use super::prompt::format_access_context;
use crate::agent::host_runtime;
-use crate::channels::context::{ChannelRuntimeContext, effective_channel_message_timeout_secs};
+use crate::channels::context::ChannelRuntimeContext;
use crate::channels::system_prompt::{ChannelPromptInputs, ChannelSystemPrompt};
use crate::config::Config;
use crate::inference::provider;
@@ -232,7 +232,7 @@ pub(crate) fn runtime_context(
config: &Config,
parts: ChannelTurnParts,
channels_by_name: Arc<HashMap<String, Arc<dyn crate::channels::Channel>>>,
- prepared_message_timeout_secs: Option<u64>,
+ message_timeout_secs: u64,
) -> ChannelRuntimeContext {
ChannelRuntimeContext {
channels_by_name,
@@ -251,9 +251,7 @@ pub(crate) fn runtime_context(
reliability: Arc::new(config.reliability.clone()),
provider_runtime_options: parts.provider_runtime_options,
workspace_dir: Arc::new(config.workspace_dir.clone()),
- message_timeout_secs: prepared_message_timeout_secs.unwrap_or_else(|| {
- effective_channel_message_timeout_secs(config.channels_config.message_timeout_secs)
- }),
+ message_timeout_secs,
multimodal: config.multimodal.clone(),
multimodal_files: config.multimodal_files.clone(),
// Crate-native turn models for the channel turn (Phase 3 P3-B).