Skip to content

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

chore: files changed crates/openhuman-core/src/channels/bus/subscriber.rs,crates/openhuman-core/src/

Steven Enamakeld616a91ba467
diff --git a/crates/openhuman-core/src/channels/bus/subscriber.rs b/crates/openhuman-core/src/channels/bus/subscriber.rs
index 71a436dabe..6a3767f8ea 100644
--- a/crates/openhuman-core/src/channels/bus/subscriber.rs
+++ b/crates/openhuman-core/src/channels/bus/subscriber.rs
@@ -137,6 +137,9 @@ impl EventHandler<DomainEvent> for ChannelInboundSubscriber {
let timeout = tokio::time::Duration::from_secs(180);
let deadline = tokio::time::Instant::now() + timeout;
+ let mut pending = Vec::with_capacity(32);
+ let mut batch_timer = tokio::time::interval(tokio::time::Duration::from_millis(20));
+ batch_timer.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Delay);
loop {
tokio::select! {
event = event_rx.recv() => {
@@ -145,25 +148,29 @@ impl EventHandler<DomainEvent> for ChannelInboundSubscriber {
match ev.event.as_str() {
"text_delta" => {
if let Some(delta) = ev.delta.as_ref() {
- if let Err(error) = reply.feed(vec![ProgressiveEvent::TextDelta(delta.clone())]).await { tracing::error!("[channel-inbound] delivery failed: {error}"); return; }
+ pending.push(ProgressiveEvent::TextDelta(delta.clone()));
}
}
"tool_call" => {
if let Some(ref name) = ev.tool_name {
- if let Err(error) = reply.feed(vec![ProgressiveEvent::ToolCall(name.clone())]).await { tracing::error!("[channel-inbound] delivery failed: {error}"); return; }
+ pending.push(ProgressiveEvent::ToolCall(name.clone()));
}
}
"tool_result" => {
if let Some(ref name) = ev.tool_name {
- if let Err(error) = reply.feed(vec![ProgressiveEvent::ToolResult { tool_name: name.clone(), success: ev.success.unwrap_or(true) }]).await { tracing::error!("[channel-inbound] delivery failed: {error}"); return; }
+ pending.push(ProgressiveEvent::ToolResult { tool_name: name.clone(), success: ev.success.unwrap_or(true) });
}
}
"thinking_delta" => {
if let Some(delta) = ev.delta.as_ref() {
- if let Err(error) = reply.feed(vec![ProgressiveEvent::ThinkingDelta(delta.clone())]).await { tracing::error!("[channel-inbound] delivery failed: {error}"); return; }
+ pending.push(ProgressiveEvent::ThinkingDelta(delta.clone()));
}
}
"chat_done" | "chat:done" => {
+ if let Err(error) = flush_events(&reply, &mut pending).await {
+ tracing::error!("[channel-inbound] delivery failed: {error}");
+ return;
+ }
let full_response = ev.full_response.unwrap_or_default();
// Even when the agent produced no visible
// text, we must close out any draft we
@@ -190,6 +197,10 @@ impl EventHandler<DomainEvent> for ChannelInboundSubscriber {
return;
}
"chat_error" | "chat:error" => {
+ if let Err(error) = flush_events(&reply, &mut pending).await {
+ tracing::error!("[channel-inbound] delivery failed: {error}");
+ return;
+ }
let err_msg = ev.message.unwrap_or_else(|| "unknown error".to_string());
tracing::error!("[channel-inbound] agent error: {}", err_msg);
let _ = reply.finalize(&format!("Sorry, I encountered an error: {err_msg}")).await;
@@ -207,6 +218,10 @@ impl EventHandler<DomainEvent> for ChannelInboundSubscriber {
// cooperative-cancel path) and never double-ends
// a turn already finalized by `chat_error`.
"chat_cancelled" => {
+ if let Err(error) = flush_events(&reply, &mut pending).await {
+ tracing::error!("[channel-inbound] delivery failed: {error}");
+ return;
+ }
tracing::info!(
"[channel-inbound] turn cancelled reason={:?}",
ev.cancel_reason
@@ -226,6 +241,18 @@ impl EventHandler<DomainEvent> for ChannelInboundSubscriber {
return;
}
}
+ if pending.len() >= 32 {
+ if let Err(error) = flush_events(&reply, &mut pending).await {
+ tracing::error!("[channel-inbound] delivery failed: {error}");
+ return;
+ }
+ }
+ }
+ _ = batch_timer.tick(), if !pending.is_empty() => {
+ if let Err(error) = flush_events(&reply, &mut pending).await {
+ tracing::error!("[channel-inbound] delivery failed: {error}");
+ return;
+ }
}
_ = tokio::time::sleep_until(deadline) => {
tracing::error!("[channel-inbound] agent timed out after {}s", timeout.as_secs());
@@ -236,3 +263,9 @@ impl EventHandler<DomainEvent> for ChannelInboundSubscriber {
}
}
}
+
+
+async fn flush_events(reply: &ModuleProgressiveReply, pending: &mut Vec<ProgressiveEvent>) -> Result<(), crate::modules::client::ModuleCallError> {
+ if pending.is_empty() { return Ok(()); }
+ reply.feed(std::mem::take(pending)).await
+}
diff --git a/crates/openhuman-core/src/modules/channel_runtime_tests.rs b/crates/openhuman-core/src/modules/channel_runtime_tests.rs
index 49f8847abb..c86cdd2433 100644
--- a/crates/openhuman-core/src/modules/channel_runtime_tests.rs
+++ b/crates/openhuman-core/src/modules/channel_runtime_tests.rs
@@ -120,7 +120,7 @@ async fn released_runtime_scopes_callbacks_and_replays_one_final_send() {
let artifact = std::env::var("OPENHUMAN_CHANNELS_TEST_ARTIFACT").expect("verified artifact path");
let mut config = crate::config::Config::default();
config.modules.allow_download = false;
- config.modules.overrides = vec![crate::config::ModuleOverride { id: "tinychannels".into(), path: artifact }];
+ config.modules.overrides = vec![crate::config::schema::ModuleOverride { id: "tinychannels".into(), path: artifact }];
let first_sends = Arc::new(std::sync::atomic::AtomicUsize::new(0));
let second_sends = Arc::new(std::sync::atomic::AtomicUsize::new(0));
let first = ChannelRuntimeLease::open(ModuleClient::new(config.clone()), TransportFixture(first_sends.clone())).await.unwrap();