Skip to content

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

fix(channels): route turn state through the configured module object

Steven Enamakel97f8852f25c3
diff --git a/crates/openhuman-core/src/channels/host/channel_events.rs b/crates/openhuman-core/src/channels/host/channel_events.rs
index 12a50a57f6..28ecdc79fb 100644
--- a/crates/openhuman-core/src/channels/host/channel_events.rs
+++ b/crates/openhuman-core/src/channels/host/channel_events.rs
@@ -7,7 +7,7 @@ use async_trait::async_trait;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
-use tinybus::module::ModuleClient;
+use tinybus::module::{ModuleClient, ModuleObjectClient};
use tinybus::EventHandler;
use tinychannels_bus::{approvals::ReplyContext, ChannelMessage};
@@ -175,16 +175,24 @@ impl EventHandler<DomainEvent> for ChannelApprovalSurfaceSubscriber {
}
/// Projects host turn lifecycle facts into module-owned remote status storage.
+///
+/// Turn state is written through the configured module object that owns the
+/// running providers. A process-wide client reaches a callback-only runtime
+/// with no running provider state, which would not report `remote_control` and
+/// so would silently drop every mark.
pub struct ChannelTurnStateSubscriber {
workspace_dir: PathBuf,
- config: Option<Arc<crate::config::Config>>,
+ objects: Option<Arc<HashMap<String, ModuleObjectClient>>>,
cancellation: tokio_util::sync::CancellationToken,
}
impl ChannelTurnStateSubscriber {
- pub fn with_config(config: Arc<crate::config::Config>) -> Self {
+ pub fn with_objects(
+ workspace_dir: PathBuf,
+ objects: Arc<HashMap<String, ModuleObjectClient>>,
+ ) -> Self {
Self {
- workspace_dir: config.workspace_dir.clone(),
- config: Some(config),
+ workspace_dir,
+ objects: Some(objects),
cancellation: super::super::runtime::session::channel_session(),
}
}
@@ -192,50 +200,54 @@ impl ChannelTurnStateSubscriber {
pub fn new(workspace_dir: PathBuf) -> Self {
Self {
workspace_dir,
- config: None,
+ objects: None,
cancellation: tokio_util::sync::CancellationToken::new(),
}
}
async fn mark(&self, channel: &str, reply_target: &str, event_ws: &PathBuf, busy: bool) {
- #[cfg(test)]
- eprintln!(
- "turn-state mark begin busy={busy} channel={channel:?} target={reply_target:?} cancelled={} remote={} event_ws={:?} subscriber_ws={:?} config={}",
- self.cancellation.is_cancelled(),
- capabilities_for(channel).remote_control,
- event_ws,
- self.workspace_dir,
- self.config.is_some(),
- );
if self.cancellation.is_cancelled()
|| !capabilities_for(channel).remote_control
|| *event_ws != self.workspace_dir
{
- #[cfg(test)]
- eprintln!("turn-state mark skipped");
return;
}
- #[cfg(test)]
- let client = if self.config.is_none() {
- crate::channels::module_fixture::client().await
- } else {
- crate::modules::client(self.config.as_deref().cloned().unwrap_or_default())
- };
- #[cfg(not(test))]
- let client = crate::modules::client(self.config.as_deref().cloned().unwrap_or_default());
- let result: Result<tinychannels_bus::module_remote::RemoteOperationResult, _> = client
- .call_confidential(
- "tinychannels",
- tinychannels_bus::methods::EXECUTE_REMOTE,
- (tinychannels_bus::module_remote::RemoteOperation::MarkTurn {
- workspace_dir: self.workspace_dir.to_string_lossy().into_owned(),
- channel: channel.into(),
- reply_target: reply_target.into(),
- busy,
- },),
- )
- .await;
- #[cfg(test)]
- eprintln!("turn-state mark result: {result:?}");
+ let args = (tinychannels_bus::module_remote::RemoteOperation::MarkTurn {
+ workspace_dir: self.workspace_dir.to_string_lossy().into_owned(),
+ channel: channel.into(),
+ reply_target: reply_target.into(),
+ busy,
+ },);
+ let result: Result<tinychannels_bus::module_remote::RemoteOperationResult, _> =
+ match &self.objects {
+ Some(objects) => {
+ let Some(object) = objects
+ .get(channel)
+ .or_else(|| objects.get(tinychannels_bus::provider_id(channel)))
+ else {
+ tracing::debug!(
+ channel,
+ "[channels] turn state skipped: no configured module object"
+ );
+ return;
+ };
+ object
+ .call_confidential(tinychannels_bus::methods::EXECUTE_REMOTE, args)
+ .await
+ }
+ None => {
+ #[cfg(test)]
+ {
+ crate::channels::module_fixture::client()
+ .await
+ .call_confidential("tinychannels", tinychannels_bus::methods::EXECUTE_REMOTE, args)
+ .await
+ }
+ #[cfg(not(test))]
+ {
+ return;
+ }
+ }
+ };
if result.is_err() {
tracing::debug!("channel turn status unavailable");
}
diff --git a/crates/openhuman-core/src/channels/routes_tests.rs b/crates/openhuman-core/src/channels/routes_tests.rs
index 3b7c5c52ee..08d7df6431 100644
--- a/crates/openhuman-core/src/channels/routes_tests.rs
+++ b/crates/openhuman-core/src/channels/routes_tests.rs
@@ -176,7 +176,6 @@ async fn handle_linked_runtime_command(
)
.await
.expect("linked TinyChannels should prepare the command's trusted scope");
- eprintln!("DIAG prepared channel={:?} reply_target={:?} running={:?}", prepared.message.channel, prepared.message.reply_target, ctx.channels_by_name.keys().collect::<Vec<_>>());
let session_key = prepared.session_key.clone();
let scope = RemoteSessionScope {
channel: prepared.envelope.channel,
diff --git a/crates/openhuman-core/src/channels/routes_tests_telegram.rs b/crates/openhuman-core/src/channels/routes_tests_telegram.rs
index 0e2809ffec..947db2cc8a 100644
--- a/crates/openhuman-core/src/channels/routes_tests_telegram.rs
+++ b/crates/openhuman-core/src/channels/routes_tests_telegram.rs
@@ -33,7 +33,7 @@ async fn handle_runtime_command_telegram_new_status_and_sessions_round_trip() {
},
);
- let subscriber = ChannelTurnStateSubscriber::with_config(Arc::new(linked.config().clone()));
+ let subscriber = ChannelTurnStateSubscriber::with_objects(workspace.clone(), linked.module_objects());
let event_core = ctx
.core
.as_ref()
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 0073b73aed..4727d976a8 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs
@@ -212,7 +212,13 @@ async fn start_channels_inner(mut config: Config, session: CancellationToken) ->
// Remote-control turn state (`/status` shows "in progress") for every
// channel with the `remote_control` capability.
let _turn_state_handle = bus.subscribe(Arc::new(
- crate::channels::host::ChannelTurnStateSubscriber::with_config(Arc::new(config.clone())),
+ crate::channels::host::ChannelTurnStateSubscriber::with_objects(
+ config.workspace_dir.clone(),
+ module_runtime
+ .as_ref()
+ .expect("runtime prepared when providers are configured")
+ .module_objects(),
+ ),
));
// In-chat approvals (sub-issue 2 of #3098) for every channel with the
// `chat_approvals` capability: `Prompt`-class tool calls are gated for the