The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(channels): thread dispatch context through remote control callbacks
Steven Enamakelc61682068633
diff --git a/crates/openhuman-core/src/channels/host/adapters.rs b/crates/openhuman-core/src/channels/host/adapters.rsindex 9fcb28610e..b050d70e85 100644--- a/crates/openhuman-core/src/channels/host/adapters.rs+++ b/crates/openhuman-core/src/channels/host/adapters.rs@@ -209,8 +209,9 @@ impl ConversationStore for ConversationHistoryStore {session_key: &str,limit: usize,) -> anyhow::Result<Vec<ConversationMessage>> {+ let ctx = DispatchCtx::ambient();let messages = crate::threads::store::get_messages(- &DispatchCtx::ambient(),+ &ctx,self.workspace_dir.clone(),session_key,)@@ -227,10 +228,11 @@ impl ConversationStore for ConversationHistoryStore {}async fn append(&self, session_key: &str, message: ConversationMessage) -> anyhow::Result<()> {+ let ctx = DispatchCtx::ambient();let now = chrono::Utc::now().to_rfc3339();// `append_message` requires the thread to exist; create-or-noop first.crate::threads::store::ensure_thread(- &DispatchCtx::ambient(),+ &ctx,self.workspace_dir.clone(),crate::threads::store::CreateConversationThread {id: session_key.to_string(),@@ -252,7 +254,7 @@ impl ConversationStore for ConversationHistoryStore {created_at: now,};crate::threads::store::append_message(- &DispatchCtx::ambient(),+ &ctx,self.workspace_dir.clone(),session_key,stored,diff --git a/crates/openhuman-core/src/channels/host/remote_control.rs b/crates/openhuman-core/src/channels/host/remote_control.rsindex 91103ecc76..181790bff7 100644--- a/crates/openhuman-core/src/channels/host/remote_control.rs+++ b/crates/openhuman-core/src/channels/host/remote_control.rs@@ -6,6 +6,7 @@ use crate::threads::store::{self as conversations, CreateConversationThread};/// Serves product-owned conversation state to the captured module runtime.pub(crate) async fn dispatch_callback(+ dispatch: &DispatchCtx,ctx: &ChannelRuntimeContext,tenant: &crate::core::runtime::Tenant,cancellation: &tokio_util::sync::CancellationToken,@@ -20,7 +21,7 @@ pub(crate) async fn dispatch_callback(match request {Request::ListThreads => {let threads = conversations::list_threads(- &DispatchCtx::ambient(),+ dispatch,ctx.workspace_dir.to_path_buf(),).map_err(|_| tinybus::Error::failed("conversation state unavailable"))?;@@ -43,7 +44,7 @@ pub(crate) async fn dispatch_callback(return Err(tinybus::Error::failed("channel session ended"));}conversations::ensure_thread(- &DispatchCtx::ambient(),+ dispatch,ctx.workspace_dir.to_path_buf(),CreateConversationThread {id: thread.id,@@ -67,7 +68,7 @@ pub(crate) async fn dispatch_callback(}Request::InvalidateThread { thread_id } => {let _removed = crate::web_chat::invalidate_thread_sessions_for_tenant(- &DispatchCtx::ambient(),+ dispatch,tenant,&thread_id,cancellation,diff --git a/crates/openhuman-core/src/channels/routes.rs b/crates/openhuman-core/src/channels/routes.rsindex 7834fc2214..416d69a919 100644--- a/crates/openhuman-core/src/channels/routes.rs+++ b/crates/openhuman-core/src/channels/routes.rs@@ -107,6 +107,12 @@ impl RouteCallbacks {) -> tinybus::Result<tinychannels_bus::ChannelBackendResult> {match request {tinychannels_bus::ChannelBackendRequest::RemoteControl(request) => {+ // The captured context is the carrier; without one the caller's+ // own ambient context is what the handlers read before.+ let dispatch_ctx = match &self.core_context {+ Some(core) => crate::core::runtime::DispatchCtx::new(Arc::clone(core)),+ None => crate::core::runtime::DispatchCtx::ambient(),+ };let dispatch = async {tokio::select! {biased;@@ -114,6 +120,7 @@ impl RouteCallbacks {Err(tinybus::Error::failed("channel session ended"))}result = super::host::remote_control::dispatch_callback(+ &dispatch_ctx,&self.context,&self.tenant,&self.cancellation,diff --git a/crates/openhuman-core/src/channels/runtime/startup/callback.rs b/crates/openhuman-core/src/channels/runtime/startup/callback.rsindex ef877ddcd4..8295438425 100644--- a/crates/openhuman-core/src/channels/runtime/startup/callback.rs+++ b/crates/openhuman-core/src/channels/runtime/startup/callback.rs@@ -159,6 +159,12 @@ impl ChannelHostCallbacks {let context = self.context()?;let tenant = &self.tenant;let cancellation = &self.cancellation;+ // The captured context is the carrier; without one the caller's+ // own ambient context is what the handlers read before.+ let dispatch_ctx = match &self.core_context {+ Some(core) => crate::core::runtime::DispatchCtx::new(Arc::clone(core)),+ None => crate::core::runtime::DispatchCtx::ambient(),+ };let dispatch = async {tokio::select! {biased;@@ -166,6 +172,7 @@ impl ChannelHostCallbacks {Err(Error::failed("channel session ended"))}result = crate::channels::host::remote_control::dispatch_callback(+ &dispatch_ctx,context.as_ref(),tenant,cancellation,