Skip to content

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

fix: bound committed progress send when bridge stalls

Steven Enamakeld376a58794a7
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
index 0f1265d288..1a3eb4c396 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -28,6 +28,10 @@ use super::announcement_notes::{
};
use super::types::OpenHumanSessionHost;
+/// Preserve the response path if a progress receiver stays open but stops
+/// consuming events. The web bridge has its own bounded drain wait afterward.
+const COMMITTED_TURN_PROGRESS_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(3);
+
/// The terminal event is the progress bridge's drain fence. Unlike content
/// capture, it must wait for space in a busy channel so the response cannot
/// overtake queued tool events on the web socket.
@@ -36,21 +40,33 @@ async fn send_committed_turn_progress(
input: &str,
output: &str,
iterations: u32,
-) {
+) -> bool {
use crate::agent::progress::AgentProgress;
let _ = progress.try_send(AgentProgress::TurnContent {
input: Some(input.to_string()),
output: Some(output.to_string()),
});
- if progress
- .send(AgentProgress::TurnCompleted { iterations })
- .await
- .is_err()
+ match tokio::time::timeout(
+ COMMITTED_TURN_PROGRESS_TIMEOUT,
+ progress.send(AgentProgress::TurnCompleted { iterations }),
+ )
+ .await
{
- log::warn!(
- "[agent_session] committed turn completion not delivered: progress receiver closed"
- );
+ Ok(Ok(())) => true,
+ Ok(Err(_)) => {
+ log::warn!(
+ "[agent_session] committed turn completion not delivered: progress receiver closed"
+ );
+ false
+ }
+ Err(_) => {
+ log::warn!(
+ "[agent_session] committed turn completion not delivered within {:?}: progress receiver stalled",
+ COMMITTED_TURN_PROGRESS_TIMEOUT
+ );
+ false
+ }
}
}
@@ -1811,8 +1827,9 @@ impl OpenHumanSessionHost {
state.last_turn_citations = citations;
}
if let Some(progress) = &progress {
- send_committed_turn_progress(progress, &input, &output, iterations)
- .await;
+ let _ =
+ send_committed_turn_progress(progress, &input, &output, iterations)
+ .await;
}
crate::agent::hooks::fire_hooks(
&post_turn_hooks,
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session_tests.rs b/crates/openhuman-core/src/agent/session_host/runtime_session_tests.rs
index f208d075ad..1aaf4c35b8 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session_tests.rs
@@ -22,7 +22,7 @@ async fn committed_turn_completion_waits_for_a_full_progress_channel() {
));
assert!(matches!(rx.recv().await, Some(AgentProgress::TurnStarted)));
- send.await;
+ assert!(send.await);
assert!(matches!(
tokio::time::timeout(std::time::Duration::from_secs(1), rx.recv())
.await
@@ -31,6 +31,20 @@ async fn committed_turn_completion_waits_for_a_full_progress_channel() {
));
}
+/// A receiver can remain alive while its bridge is stalled. Once the send
+/// deadline passes, the committed chat response must still be able to return.
+#[tokio::test(start_paused = true)]
+async fn committed_turn_completion_is_bounded_when_progress_stalls() {
+ use crate::agent::progress::AgentProgress;
+
+ let (tx, mut rx) = tokio::sync::mpsc::channel(1);
+ tx.send(AgentProgress::TurnStarted).await.unwrap();
+
+ assert!(!super::send_committed_turn_progress(&tx, "question", "answer", 2).await);
+ assert!(matches!(rx.recv().await, Some(AgentProgress::TurnStarted)));
+ assert!(rx.try_recv().is_err(), "timed-out send must be cancelled");
+}
+
fn spec(name: &str) -> ToolSpec {
ToolSpec {
name: name.into(),