Skip to content

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

fix(session_host): narrow turn iteration counts to u32

Steven Enamakel30315f2bb947
diff --git a/crates/openhuman-core/src/agent/session_host/runtime/run_loop.rs b/crates/openhuman-core/src/agent/session_host/runtime/run_loop.rs
index 0784df2f27..b1e29c8d7c 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime/run_loop.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime/run_loop.rs
@@ -110,7 +110,7 @@ impl OpenHumanSessionHost {
BUS.publish(DomainEvent::AgentTurnCompleted {
session_id: self.event_session_id().to_string(),
text_chars: response.chars().count(),
- iterations: self.last_turn_iterations(),
+ iterations: self.last_turn_iterations() as usize,
});
drop(busy);
Ok(response)
diff --git a/crates/openhuman-core/src/agent/session_host/runtime/turn_results.rs b/crates/openhuman-core/src/agent/session_host/runtime/turn_results.rs
index 36e265dfdf..024f659272 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime/turn_results.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime/turn_results.rs
@@ -6,7 +6,7 @@ use super::super::types::OpenHumanSessionHost;
impl OpenHumanSessionHost {
/// Iterations from the latest durable receipt, used by the legacy
/// `AgentTurnCompleted` projection after the session turn returns.
- pub(crate) fn last_turn_iterations(&self) -> usize {
+ pub(crate) fn last_turn_iterations(&self) -> u32 {
self.runtime_state
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner())
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 302fec42dc..cf37acb366 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -51,7 +51,7 @@ pub(super) struct OpenHumanSessionState {
terminals: Vec<SessionTerminal>,
pub(super) last_turn_hit_cap: bool,
pub(super) last_turn_usage: Option<crate::agent::tinyagents::host::LastTurnUsage>,
- pub(super) last_turn_iterations: usize,
+ pub(super) last_turn_iterations: u32,
pub(super) context_middleware: Option<TurnContextMiddleware>,
required_output: Option<tinyagents_harness::config::RequiredOutput>,
pub(crate) pending_turn_overrides: super::types::TurnOverrides,
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/post_commit.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/post_commit.rs
index 35603fd5d2..70ba649083 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session/post_commit.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/post_commit.rs
@@ -41,7 +41,7 @@ pub(super) const PENDING_POST_COMMIT_WAIT: Duration = Duration::from_secs(10);
/// iterations. When the sidecar is empty (a driver that does not fill it),
/// this falls back to the assistant rows after the last user row, which is
/// this turn's exchange. Never reports zero.
-pub(super) fn turn_iterations(sidecar_model_calls: usize, history: &[Message]) -> usize {
+pub(super) fn turn_iterations(sidecar_model_calls: usize, history: &[Message]) -> u32 {
let calls = if sidecar_model_calls > 0 {
sidecar_model_calls
} else {
@@ -54,7 +54,7 @@ pub(super) fn turn_iterations(sidecar_model_calls: usize, history: &[Message]) -
.filter(|message| matches!(message, Message::Assistant(_)))
.count()
};
- calls.max(1)
+ calls.clamp(1, u32::MAX as usize) as u32
}
/// Await `publish` (the completion), then spawn `tail` (deferred work) and