Skip to content

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

fix(agent): report answered model calls as a failed run's iteration

M3gA-Mind8f332c312eba
diff --git a/crates/openhuman-core/src/agent/harness/session/turn/core/failed_turn.rs b/crates/openhuman-core/src/agent/harness/session/turn/core/failed_turn.rs
index c4ab25ccd5..f138180a5a 100644
--- a/crates/openhuman-core/src/agent/harness/session/turn/core/failed_turn.rs
+++ b/crates/openhuman-core/src/agent/harness/session/turn/core/failed_turn.rs
@@ -125,7 +125,7 @@ impl Agent {
ts: chrono::Utc::now().to_rfc3339(),
reasoning_content: None,
tool_calls: Vec::new(),
- iteration: 0,
+ iteration: snapshot.model_calls,
};
self.persist_session_transcript(
&persisted,
diff --git a/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph/dispatch.rs b/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph/dispatch.rs
index 904cb6ecb7..15d6567573 100644
--- a/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph/dispatch.rs
+++ b/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph/dispatch.rs
@@ -340,7 +340,7 @@ pub(in super::super) async fn run_subagent_via_graph(
// snapshot's own seed is the provider-bound copy with rehydrated
// images. The unanswered suffix rides the failure marker as text
// (#6281).
- let (recovered, unanswered_steps, recovered_usage) = {
+ let (recovered, unanswered_steps, recovered_usage, completed_rounds) = {
let snapshot = transcript_snapshot
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner);
@@ -357,7 +357,7 @@ pub(in super::super) async fn run_subagent_via_graph(
snapshot.cached_input_tokens,
),
};
- (recovered, unanswered, usage)
+ (recovered, unanswered, usage, snapshot.model_calls)
};
tracing::warn!(
agent_id,
@@ -377,6 +377,7 @@ pub(in super::super) async fn run_subagent_via_graph(
&recovered,
&recovered_usage,
unanswered_steps.as_deref(),
+ completed_rounds,
context_window.unwrap_or(0),
if native_tools { "native" } else { "xml" },
worker_thread_id.as_deref(),
diff --git a/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph/transcript.rs b/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph/transcript.rs
index 1b2fb6dbe2..26b6cf6660 100644
--- a/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph/transcript.rs
+++ b/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph/transcript.rs
@@ -115,8 +115,8 @@ pub(super) fn persist_subagent_transcript(
/// append a trailing failure marker so the record is self-describing. `recovered`
/// holds only what a provider accepted; steps only the failing request carried
/// arrive as `unanswered_steps` text and are appended to the marker (#6281).
-/// `usage` is what the answered calls reported, and the iteration count is the
-/// number of completed rounds recovered.
+/// `usage` is what the answered calls reported, and `completed_rounds` is the
+/// number of model calls a provider answered.
#[allow(clippy::too_many_arguments)]
pub(super) fn persist_failed_run(
workspace_dir: &std::path::Path,
@@ -128,6 +128,7 @@ pub(super) fn persist_failed_run(
recovered: &[ChatMessage],
usage: &AggregatedUsage,
unanswered_steps: Option<&str>,
+ completed_rounds: u32,
context_window: u64,
dispatcher: &str,
worker_thread_id: Option<&str>,
@@ -151,7 +152,7 @@ pub(super) fn persist_failed_run(
usage,
context_window,
dispatcher,
- recovered.len() as u32,
+ completed_rounds,
);
if let Some(thread_id) = worker_thread_id {
diff --git a/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph_failed_run_tests.rs b/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph_failed_run_tests.rs
index 332b8f4477..d35b24ffa6 100644
--- a/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph_failed_run_tests.rs
+++ b/crates/openhuman-core/src/agent/harness/subagent_runner/ops/graph_failed_run_tests.rs
@@ -101,6 +101,21 @@ async fn failed_subagent_run_keeps_its_unanswered_round_out_of_history() {
&& marker.contains("round-1"),
"the marker carries the cause and the unanswered round as text, got: {marker}"
);
+
+ // Two model calls were answered before the rejection; the recorded
+ // iteration must say so rather than count persisted messages.
+ let raw = std::fs::read_to_string(&path).expect("raw transcript");
+ let marker_line = raw
+ .lines()
+ .filter_map(|line| serde_json::from_str::<serde_json::Value>(line).ok())
+ .filter(|line| line.get("role").and_then(|role| role.as_str()) == Some("assistant"))
+ .last()
+ .expect("failure marker line");
+ assert_eq!(
+ marker_line.get("iteration").and_then(|n| n.as_u64()),
+ Some(2),
+ "the failed run reports the model calls a provider answered: {marker_line}"
+ );
}
/// #6281 review: a failed run recovers the caller's original history, not the
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs
index 368e422b7a..32e6712f2d 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context.rs
@@ -89,6 +89,9 @@ pub(crate) struct TranscriptSnapshot {
pub(crate) input_tokens: u64,
pub(crate) output_tokens: u64,
pub(crate) cached_input_tokens: u64,
+ /// Model calls the provider answered, so a failed run reports its real
+ /// iteration count rather than one derived from message counts.
+ pub(crate) model_calls: u32,
}
/// Display cap for one unanswered step in a failure note, matching the cap
@@ -199,6 +202,7 @@ impl Middleware<()> for TranscriptSnapshotMiddleware {
) -> TaResult<()> {
if let Ok(mut guard) = self.sink.lock() {
guard.accepted_len = guard.messages.len();
+ guard.model_calls += 1;
// The response has not been sent back to a provider yet, so it sits
// past `accepted_len`; an error before the next request still keeps
// it, as text.