Skip to content

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

feat(relay): bind hosted relay turns to a tenant-scoped progressive target

Steven Enamakel7db6f510d703
diff --git a/crates/openhuman-core/src/channels/providers/relay/mod.rs b/crates/openhuman-core/src/channels/providers/relay/mod.rs
index 921de5e7f6..3788f23a2b 100644
--- a/crates/openhuman-core/src/channels/providers/relay/mod.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/mod.rs
@@ -23,7 +23,7 @@
mod channel;
mod ops;
mod params;
-mod progressive;
+pub(crate) mod progressive;
mod schemas;
mod store;
diff --git a/crates/openhuman-core/src/channels/providers/relay/ops.rs b/crates/openhuman-core/src/channels/providers/relay/ops.rs
index 01b3dd4785..1ff46e4a55 100644
--- a/crates/openhuman-core/src/channels/providers/relay/ops.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/ops.rs
@@ -267,6 +267,29 @@ pub(crate) async fn run_relay_turn(
}
};
+ let tenant = match dispatch_ctx.tenant() {
+ Ok(tenant) => tenant,
+ Err(error) => {
+ tracing::warn!("relayed channel turn lost its tenant scope: {error}");
+ return channel.sent();
+ }
+ };
+ let mut channel_ref = prepared.envelope.channel.clone();
+ channel_ref.id = params.channel.clone();
+ // A hosted relay has no local provider account. Bind the host callback to
+ // an account scope derived from the trusted tenant and provider instead;
+ // this value is never accepted from relay parameters or model metadata.
+ channel_ref.account_id = Some(crate::core::runtime::tenant::tenant_key(
+ &tenant,
+ &format!("hosted-channel:{}", params.channel),
+ ));
+ let progressive_target = Arc::new(crate::channels::runtime::dispatch::processor::progressive::hosted_relay_target(
+ &config,
+ Arc::clone(&channel),
+ channel_ref,
+ prepared.envelope.conversation.clone(),
+ ));
+
tracing::debug!(
channel = %params.channel,
thread_id = %thread_id,
@@ -276,6 +299,7 @@ pub(crate) async fn run_relay_turn(
let mut runtime_message = crate::channels::runtime::RuntimeChannelMessage::from(message);
runtime_message.prepared_inbound = Some(prepared);
runtime_message.imported_history = imported_history;
+ runtime_message.progressive_target = Some(progressive_target);
let turn = process_channel_runtime_message(ctx, runtime_message);
if let Some(context) = dispatch_ctx.core() {
crate::core::runtime::CoreContext::scope(
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 b4ef5c7f74..3393766c04 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/progressive.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/progressive.rs
@@ -20,7 +20,7 @@ enum ProgressiveTargetKind {
Configured(tinybus::module::ModuleObjectClient),
HostedRelay {
client: tinybus::module::ModuleClient,
- channel: std::sync::Arc<super::super::super::providers::relay::channel::RelayChannel>,
+ channel: std::sync::Arc<crate::channels::providers::relay::RelayChannel>,
},
}
@@ -69,7 +69,7 @@ impl NativeProgressiveTarget {
pub(crate) fn hosted_relay_target(
config: &crate::config::Config,
- channel: std::sync::Arc<super::super::super::providers::relay::channel::RelayChannel>,
+ channel: std::sync::Arc<crate::channels::providers::relay::RelayChannel>,
channel_ref: tinychannels_bus::channel::ChannelRef,
conversation: tinychannels_bus::channel::ConversationRef,
) -> NativeProgressiveTarget {