Skip to content

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

refactor(channels): extract channel reply wait into helper

Steven Enamakel04a142f763c6
diff --git a/crates/openhuman-core/src/channels/bus/subscriber.rs b/crates/openhuman-core/src/channels/bus/subscriber.rs
index 060f8a3048..4071dac8d6 100644
--- a/crates/openhuman-core/src/channels/bus/subscriber.rs
+++ b/crates/openhuman-core/src/channels/bus/subscriber.rs
@@ -140,8 +140,7 @@ impl EventHandler<DomainEvent> for ChannelInboundSubscriber {
};
let timeout = tokio::time::Duration::from_secs(180);
- let deadline = tokio::time::Instant::now() + timeout;
-
+ let wait = run_channel_reply_loop(async {
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);
@@ -155,11 +154,6 @@ impl EventHandler<DomainEvent> for ChannelInboundSubscriber {
return;
}
}
- _ = tokio::time::sleep_until(deadline) => {
- tracing::error!("[channel-inbound] agent timed out after {}s", timeout.as_secs());
- let _ = reply.finalize("Sorry, the request timed out.").await;
- return;
- }
event = event_rx.recv() => {
match event {
Ok(ev) if ev.context().request_id == request_id => {
@@ -270,9 +264,23 @@ impl EventHandler<DomainEvent> for ChannelInboundSubscriber {
}
}
+ }).await;
+ if wait.is_err() {
+ tracing::error!("[channel-inbound] agent timed out after {}s", timeout.as_secs());
+ let _ = reply.finalize("Sorry, the request timed out.").await;
+ }
}
}
+/// The backend socket path's legacy fixed deadline around its shared-runner
+/// event stream. Kept separate so the same wait policy can be exercised with
+/// Tokio's virtual clock and later replaced by the runner's own lifecycle.
+async fn run_channel_reply_loop(
+ event_loop: impl std::future::Future<Output = ()>,
+) -> Result<(), tokio::time::error::Elapsed> {
+ tokio::time::timeout(tokio::time::Duration::from_secs(180), event_loop).await
+}
+
async fn flush_events(
reply: &ModuleProgressiveReply,
pending: &mut Vec<ProgressiveEvent>,
@@ -282,3 +290,7 @@ async fn flush_events(
}
reply.feed(std::mem::take(pending)).await
}
+
+#[cfg(test)]
+#[path = "subscriber_tests.rs"]
+mod tests;