Skip to content

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

fix(session-host): prefer typed failure cause over stop note

Steven Enamakeld4cd4eb336ec
diff --git a/crates/openhuman-core/src/agent/session_host/driver/grounded_close.rs b/crates/openhuman-core/src/agent/session_host/driver/grounded_close.rs
index ef2f7ac37f..2db2f74251 100644
--- a/crates/openhuman-core/src/agent/session_host/driver/grounded_close.rs
+++ b/crates/openhuman-core/src/agent/session_host/driver/grounded_close.rs
@@ -18,6 +18,7 @@ use tinyagents_harness::middleware::wrap_harness_instruction;
use crate::agent::{
session_host::turn_checkpoint::{
self, build_deterministic_checkpoint, build_deterministic_final_summary,
+ build_deterministic_final_summary_with_cause,
close_verification_prompt, final_answer_instruction, harness_instruction_needles,
render_tool_results, results_from_tool_outcomes,
},
@@ -234,12 +235,16 @@ pub(super) struct GroundedClose {
/// additional provider calls once its recovery budget is exhausted.
fn classified_halt_close(outcome: &TinyagentsTurnOutcome) -> Option<GroundedClose> {
let reason = outcome.breaker_halt.as_deref()?;
- if !reason.starts_with("Stopping after ") {
+ if outcome.failure_cause.is_none() && !reason.starts_with("Stopping after ") {
return None;
}
let records = results_from_tool_outcomes(&outcome.tool_outcomes);
Some(GroundedClose {
- output: build_deterministic_final_summary(&records, Some(reason)),
+ output: build_deterministic_final_summary_with_cause(
+ &records,
+ Some(reason),
+ outcome.failure_cause.as_ref(),
+ ),
usage: RepairUsage::default(),
})
}
@@ -398,7 +403,11 @@ pub(super) async fn close_if_needed(
if needs_cap_close {
build_deterministic_checkpoint(&records, outcome.model_calls)
} else {
- build_deterministic_final_summary(&records, stop_reason)
+ build_deterministic_final_summary_with_cause(
+ &records,
+ stop_reason,
+ outcome.failure_cause.as_ref(),
+ )
}
};
diff --git a/crates/openhuman-core/src/agent/session_host/driver/grounded_close_tests.rs b/crates/openhuman-core/src/agent/session_host/driver/grounded_close_tests.rs
index fd9639740b..bc60c4bf2c 100644
--- a/crates/openhuman-core/src/agent/session_host/driver/grounded_close_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/driver/grounded_close_tests.rs
@@ -4,6 +4,34 @@ use std::sync::Arc;
const RECORDS: &str = "\n- `list_directory` — ok\n > three crates\n";
const CLEAN_REPLY: &str = "The workspace holds three crates; the build is green.";
+fn classified_halt(note: &str, class: &str) -> TinyagentsTurnOutcome {
+ TinyagentsTurnOutcome {
+ deferred_terminal: None,
+ text: String::new(),
+ resolved_route: None,
+ history: Vec::new(),
+ conversation: Vec::new(),
+ model_calls: 1,
+ tool_calls: 1,
+ input_tokens: 0,
+ output_tokens: 0,
+ cached_input_tokens: 0,
+ cost: tinyagents_harness::cost::CostTally::default(),
+ early_exit_tool: None,
+ hit_cap: false,
+ wrap_up_injected: false,
+ truncated: false,
+ breaker_halt: Some(note.into()),
+ failure_cause: Some(tinyagents_harness::no_progress::ClassifiedStopCause {
+ class: class.into(),
+ operation: "search".into(),
+ summary: note.into(),
+ }),
+ tool_outcomes: vec![],
+ compaction: None,
+ }
+}
+
#[test]
fn classified_halt_returns_partial_work_without_provider_usage() {
use tinyagents_harness::turn_outcome::ToolCallOutcome;
@@ -101,6 +129,34 @@ fn classified_halt_summary_uses_typed_cause_when_halt_copy_conflicts() {
);
}
+#[test]
+fn classified_halt_summary_uses_typed_class_for_translated_notes() {
+ let note = "Interrompo aqui: bloqueado por política de segurança, orçamento esgotado.";
+ let cases = [
+ ("out_of_credits", "inference budget"),
+ ("provider_config", "configured correctly"),
+ ("transient", "temporary service issues"),
+ ("blocked_by_policy", "security settings"),
+ ];
+
+ for (class, expected_copy) in cases {
+ let outcome = classified_halt(note, class);
+ let close = classified_halt_close(&outcome)
+ .unwrap_or_else(|| panic!("typed `{class}` cause must close the turn"));
+ assert!(
+ close.output.contains(expected_copy),
+ "typed `{class}` cause must select its summary copy: {}",
+ close.output
+ );
+ assert!(
+ !close.output.contains("security settings") || class == "blocked_by_policy",
+ "translated prose must not override typed `{class}` cause: {}",
+ close.output
+ );
+ assert_eq!(close.usage.model_calls, 0);
+ }
+}
+
/// The host adapter delegates generation and verification to TinyAgents while
/// retaining its selected model, temperature, output cap and billing gauge.
#[tokio::test]
diff --git a/crates/openhuman-core/src/agent/session_host/stop_summary.rs b/crates/openhuman-core/src/agent/session_host/stop_summary.rs
index 0baadea0f3..2a5ba971fb 100644
--- a/crates/openhuman-core/src/agent/session_host/stop_summary.rs
+++ b/crates/openhuman-core/src/agent/session_host/stop_summary.rs
@@ -212,6 +212,8 @@ impl StopReasonKind {
"validation" | "invalid_arguments" => Self::InvalidCalls,
"unavailable" | "service_refused" => Self::Unavailable,
"site_refused" => Self::SiteRefused,
+ "out_of_credits" => Self::OutOfCredits,
+ "provider_config" => Self::ProviderConfig,
_ => Self::Generic,
}
}
@@ -262,7 +264,19 @@ fn times(count: usize) -> String {
/// The user-facing reply for a turn the breaker stopped with `stop_note`.
pub(crate) fn render_stop_summary(results: &[CheckpointToolResult], stop_note: &str) -> String {
- let kind = StopReasonKind::from_stop_note(stop_note);
+ render_stop_summary_with_cause(results, stop_note, None)
+}
+
+/// Render a stopped-turn summary from its typed cause when the harness has
+/// one. The note is only a compatibility source for old, untyped stops.
+pub(crate) fn render_stop_summary_with_cause(
+ results: &[CheckpointToolResult],
+ stop_note: &str,
+ failure_cause: Option<&tinyagents_harness::no_progress::ClassifiedStopCause>,
+) -> String {
+ let kind = failure_cause
+ .map(|cause| StopReasonKind::from_failure_class(&cause.class))
+ .unwrap_or_else(|| StopReasonKind::from_stop_note(stop_note));
tracing::debug!(
reason = kind.key(),
results = results.len(),
diff --git a/crates/openhuman-core/src/agent/session_host/turn_checkpoint.rs b/crates/openhuman-core/src/agent/session_host/turn_checkpoint.rs
index 3d33e2a080..1523d5d67d 100644
--- a/crates/openhuman-core/src/agent/session_host/turn_checkpoint.rs
+++ b/crates/openhuman-core/src/agent/session_host/turn_checkpoint.rs
@@ -508,12 +508,26 @@ pub(crate) fn close_verification_prompt(user_request: &str, records: &str, reply
pub(crate) fn build_deterministic_final_summary(
results: &[CheckpointToolResult],
stop_reason: Option<&str>,
+) -> String {
+ build_deterministic_final_summary_with_cause(results, stop_reason, None)
+}
+
+/// Build the deterministic final summary using a typed breaker cause when
+/// available. The note remains a legacy fallback for persisted untyped stops.
+pub(crate) fn build_deterministic_final_summary_with_cause(
+ results: &[CheckpointToolResult],
+ stop_reason: Option<&str>,
+ failure_cause: Option<&tinyagents_harness::no_progress::ClassifiedStopCause>,
) -> String {
if results.is_empty() && stop_reason.is_none() {
return "I finished this turn but produced no result to report.".to_string();
}
if let Some(reason) = stop_reason {
- return super::stop_summary::render_stop_summary(results, reason);
+ return super::stop_summary::render_stop_summary_with_cause(
+ results,
+ reason,
+ failure_cause,
+ );
}
let mut out = String::from(
"I finished this turn without writing up a result. Here is what each tool call returned:\n",