Skip to content

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

refactor: keep committed progress helper within Rust layout limit

Steven Enamakel5542ce9621a2
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 1a3eb4c396..d0d387b2bc 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -28,47 +28,8 @@ 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.
-async fn send_committed_turn_progress(
- progress: &tokio::sync::mpsc::Sender<crate::agent::progress::AgentProgress>,
- 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()),
- });
- match tokio::time::timeout(
- COMMITTED_TURN_PROGRESS_TIMEOUT,
- progress.send(AgentProgress::TurnCompleted { iterations }),
- )
- .await
- {
- 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
- }
- }
-}
+#[path = "runtime_session_progress.rs"]
+mod progress;
/// Mutable product state observed by the runtime hooks.
///
@@ -1827,9 +1788,10 @@ impl OpenHumanSessionHost {
state.last_turn_citations = citations;
}
if let Some(progress) = &progress {
- let _ =
- send_committed_turn_progress(progress, &input, &output, iterations)
- .await;
+ let _ = progress::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_progress.rs b/crates/openhuman-core/src/agent/session_host/runtime_session_progress.rs
new file mode 100644
index 0000000000..d73909f38c
--- /dev/null
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session_progress.rs
@@ -0,0 +1,43 @@
+//! Post-commit progress delivery for a chat turn.
+
+use crate::agent::progress::AgentProgress;
+
+/// 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);
+
+/// Send the terminal event as the progress bridge's drain fence. Content
+/// capture stays best effort; the completion waits for channel capacity, up to
+/// a deadline, so a healthy bridge can forward queued tool events first.
+pub(super) async fn send_committed_turn_progress(
+ progress: &tokio::sync::mpsc::Sender<AgentProgress>,
+ input: &str,
+ output: &str,
+ iterations: u32,
+) -> bool {
+ let _ = progress.try_send(AgentProgress::TurnContent {
+ input: Some(input.to_string()),
+ output: Some(output.to_string()),
+ });
+ match tokio::time::timeout(
+ COMMITTED_TURN_PROGRESS_TIMEOUT,
+ progress.send(AgentProgress::TurnCompleted { iterations }),
+ )
+ .await
+ {
+ 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
+ }
+ }
+}
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 1aaf4c35b8..90fe99b4cd 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
@@ -14,7 +14,7 @@ async fn committed_turn_completion_waits_for_a_full_progress_channel() {
let (tx, mut rx) = tokio::sync::mpsc::channel(1);
tx.send(AgentProgress::TurnStarted).await.unwrap();
- let send = super::send_committed_turn_progress(&tx, "question", "answer", 2);
+ let send = super::progress::send_committed_turn_progress(&tx, "question", "answer", 2);
tokio::pin!(send);
assert!(matches!(
futures::poll!(send.as_mut()),
@@ -40,7 +40,7 @@ async fn committed_turn_completion_is_bounded_when_progress_stalls() {
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!(!super::progress::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");
}