Skip to content

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

Merge remote-tracking branch 'upstream/main' into channels-provider-lease-bus

Steven Enamakela2d78073cb7f
diff --cc crates/openhuman-core/src/channels/providers/relay/mod.rs
index 2444809965,81756efc41..d2c9ebde8c
--- a/crates/openhuman-core/src/channels/providers/relay/mod.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/mod.rs
@@@ -26,24 -25,10 +26,10 @@@ mod params
mod schemas;
mod store;
--pub use channel::{RelayChannel, CHANNEL_OUTBOUND_EVENT};
++pub use channel::{CHANNEL_OUTBOUND_EVENT, RelayChannel};
pub use ops::channel_relay_inbound;
pub use params::{
-- validate_channel, validate_id, RelayInboundParams, DEFAULT_RELAY_CLIENT_ID, MAX_CHANNEL_LEN,
-- MAX_ID_LEN, MAX_SENDER_NAME_CHARS, MAX_TEXT_BYTES, RESERVED_CHANNELS,
++ DEFAULT_RELAY_CLIENT_ID, MAX_CHANNEL_LEN, MAX_ID_LEN, MAX_SENDER_NAME_CHARS, MAX_TEXT_BYTES,
++ RESERVED_CHANNELS, RelayInboundParams, validate_channel, validate_id,
};
pub use schemas::{all_relay_controller_schemas, all_relay_registered_controllers};
-
- // The durable conversation key belongs to this inbound relay call, not a
- // process-global last sender. The dispatch future carries it to session build.
- tokio::task_local! { static RELAY_THREAD: String; }
-
- pub(crate) fn current_thread_id() -> Option<String> {
- RELAY_THREAD.try_with(Clone::clone).ok()
- }
-
- pub(crate) async fn with_thread<F: std::future::Future>(thread: String, future: F) -> F::Output {
- // Keep the dispatch future on the heap through task-local wrappers;
- // embedding it multiplies debug-build stack frames on ordinary worker threads.
- RELAY_THREAD.scope(thread, Box::pin(future)).await
- }
diff --cc crates/openhuman-core/src/channels/providers/relay/ops.rs
index 8aa3b143a9,f629fe0f9b..d4b38fb90b
--- a/crates/openhuman-core/src/channels/providers/relay/ops.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/ops.rs
@@@ -3,15 -3,14 +3,15 @@@
use std::collections::HashMap;
use std::sync::Arc;
--use serde_json::{json, Value};
++use serde_json::{Value, json};
use super::channel::RelayChannel;
use super::params::RelayInboundParams;
use super::store::{self, Recorded};
-use crate::channels::context::{conversation_history_key, MAX_CHANNEL_HISTORY};
+use crate::channels::context::MAX_CHANNEL_HISTORY;
use crate::channels::runtime::{
- build_channel_turn_parts, prepare_runtime_limits, process_channel_runtime_message,
- runtime_context, PromptToolDescs,
- build_channel_turn_parts, process_channel_message, runtime_context, PromptToolDescs,
++ PromptToolDescs, build_channel_turn_parts, prepare_runtime_limits,
++ process_channel_runtime_message, runtime_context,
};
use crate::config::Config;
use crate::core::Outcome;
@@@ -161,12 -130,9 +161,14 @@@ pub(crate) async fn run_relay_turn
let mut channels_by_name: HashMap<String, Arc<dyn crate::channels::Channel>> = HashMap::new();
channels_by_name.insert(params.channel.clone(), channel.clone());
- let ctx = Arc::new(runtime_context(
- let mut runtime = runtime_context(&config, parts, Arc::new(channels_by_name));
++ let mut runtime = runtime_context(
+ &config,
+ parts,
+ Arc::new(channels_by_name),
+ message_timeout_secs,
- ));
++ );
+ runtime.relay_thread = Some(thread_id.clone());
+ let ctx = Arc::new(runtime);
// The thread is the conversation's memory: seed the pipeline's per-chat
// history from it, since this runtime context lives for one message.
@@@ -218,13 -165,16 +220,18 @@@
request_id = %request_id,
"[channels::relay] dispatching relayed turn"
);
- let turn = process_channel_message(ctx, message);
+ let mut runtime_message = crate::channels::runtime::RuntimeChannelMessage::from(message);
+ runtime_message.prepared_inbound = Some(prepared);
- super::with_thread(
- thread_id.clone(),
- process_channel_runtime_message(ctx, runtime_message),
- )
- .await;
++ let turn = process_channel_runtime_message(ctx, runtime_message);
+ if let Some(context) = crate::core::runtime::CoreContext::scoped() {
+ crate::core::runtime::CoreContext::scope(
+ context.derive_channel_turn(Some(thread_id.clone()), None),
+ Box::pin(turn),
+ )
+ .await;
+ } else {
+ turn.await;
+ }
let replies = channel.sent();
record(&workspace_dir, &params, &thread_id, &replies).await;
diff --cc crates/openhuman-core/src/channels/runtime/startup/turn_parts.rs
index bdc11af74c,72a186f33e..44a1ef12fd
--- a/crates/openhuman-core/src/channels/runtime/startup/turn_parts.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/turn_parts.rs
@@@ -232,9 -232,9 +232,10 @@@ pub(crate) fn runtime_context
config: &Config,
parts: ChannelTurnParts,
channels_by_name: Arc<HashMap<String, Arc<dyn crate::channels::Channel>>>,
+ message_timeout_secs: u64,
) -> ChannelRuntimeContext {
ChannelRuntimeContext {
+ relay_thread: None,
channels_by_name,
turn_model_source: None,
default_provider: Arc::new(parts.provider_name),