Skip to content

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

fix(agent): report the iteration cap only on a real cap

M3gA-Mind1668d6896709
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 fbc0cfb090..c6bda8ccf4 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
@@ -201,7 +201,6 @@ pub(super) async fn finalize_committed_turn(
"[session-runtime] post-commit: durable commit done; finalizing turn"
);
let usage = super::holistic_last_turn_usage(&sidecar);
- let interrupted = sidecar.hit_cap || receipt.outcome.interrupted;
// This hook runs only after the runtime durably appended the turn. Emit
// OpenHuman's classified stop before the terminal journal flush, so native
// completion cannot overwrite a cancellation/timeout/stop or hide commit
@@ -216,7 +215,10 @@ pub(super) async fn finalize_committed_turn(
let mut state = state
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner());
- state.last_turn_hit_cap = interrupted;
+ // Only the cap: a turn that ended on an early-exit tool
+ // (`ask_user_clarification`) is also `interrupted`, but it is waiting on
+ // the user's answer, not paused at its iteration limit.
+ state.last_turn_hit_cap = sidecar.hit_cap;
state.last_turn_usage = Some(usage.clone());
state.last_turn_iterations = iterations;
state.prelude.clone()
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session_post_commit_tests.rs b/crates/openhuman-core/src/agent/session_host/runtime_session_post_commit_tests.rs
new file mode 100644
index 0000000000..53e2c35e98
--- /dev/null
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session_post_commit_tests.rs
@@ -0,0 +1,59 @@
+//! `finalize_committed_turn` reports the iteration cap only when the turn hit it.
+
+use tinyagents_runtime::{CommitReceipt, ResumeMode, SessionTurnOutcome, TranscriptTurnOptions};
+
+use crate::agent::session_host::runtime_session::post_commit::{
+ finalize_committed_turn, TurnIdentity,
+};
+use crate::agent::session_host::runtime_session::OpenHumanSessionState;
+
+/// Commits one turn whose outcome is `interrupted` and returns the
+/// `last_turn_hit_cap` it leaves on the session.
+async fn hit_cap_after_interrupted_turn(sidecar_hit_cap: bool) -> bool {
+ let context = crate::agent::tinyagents::host::OpenHumanRunContext::new();
+ context.session_sidecar.lock().unwrap().hit_cap = sidecar_hit_cap;
+ let receipt = CommitReceipt {
+ outcome: SessionTurnOutcome {
+ history: Vec::new(),
+ output: Some("Which city do you mean?".into()),
+ // The driver marks a turn interrupted on an early-exit tool
+ // (`ask_user_clarification`) as well as on the cap.
+ interrupted: true,
+ },
+ options: TranscriptTurnOptions {
+ request_id: None,
+ thread_id: None,
+ stream: true,
+ resume: ResumeMode::Never,
+ context,
+ },
+ transcript: None,
+ };
+ let state = std::sync::Mutex::new(OpenHumanSessionState::default());
+ finalize_committed_turn(
+ &state,
+ &[],
+ TurnIdentity {
+ session_id: "post-commit-hit-cap".into(),
+ agent_id: "orchestrator".into(),
+ channel: "web".into(),
+ },
+ receipt,
+ )
+ .await;
+ let hit_cap = state.lock().unwrap().last_turn_hit_cap;
+ hit_cap
+}
+
+#[tokio::test]
+async fn a_clarification_early_exit_is_not_reported_as_hitting_the_cap() {
+ assert!(
+ !hit_cap_after_interrupted_turn(false).await,
+ "a turn that ended by asking the user a question was reported as an iteration-cap pause"
+ );
+}
+
+#[tokio::test]
+async fn a_turn_that_hit_the_cap_is_reported_as_hitting_it() {
+ assert!(hit_cap_after_interrupted_turn(true).await);
+}
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 b1a5adfbfd..1db988173f 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
@@ -10,6 +10,8 @@ use tinytools::ToolSpec;
mod flow_prompt_tests;
#[path = "runtime_session_terminal_tests.rs"]
mod terminal_tests;
+#[path = "runtime_session_post_commit_tests.rs"]
+mod post_commit_tests;
fn synthesized_tool_names(
prelude: &super::OpenHumanTurnPrelude,