Skip to content

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

refactor(tinyagents): simplify failure cause handling in turn execution

Steven Enamakeld5b022f1dbc5
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs
index 0d93f379b6..0bd5e62aa5 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs
@@ -302,8 +302,11 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
&self,
_ctx: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,
_state: &(),
- _run: &mut tinyagents_harness::middleware::AgentRun,
+ run: &mut tinyagents_harness::middleware::AgentRun,
) -> TaResult<()> {
+ if run.failure_cause.is_none() {
+ run.failure_cause = self.stop.current_classified_cause();
+ }
self.stop.finish_run();
Ok(())
}
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs b/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
index 72c94c6325..8483c5f23e 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
@@ -500,7 +500,6 @@ async fn drive_turn(
let candidate_names = prepared.tools().plan.candidates.clone();
let TurnWiring {
halt_summary,
- classified_cause,
wrap_up_fired,
compression_mw,
prompt_cache_guard,
@@ -686,7 +685,6 @@ async fn drive_turn(
Some(bridge),
early_exit,
&halt_summary,
- classified_cause(),
&wrap_up_fired,
run_instance_id,
&tool_outcome_sink,
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs b/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs
index 6389878c24..c4cfd879cd 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs
@@ -101,11 +101,6 @@ pub(super) struct TurnMiddlewareInputs {
pub(super) struct TurnWiring {
/// Root-cause summary recorded by the repeated-tool-failure breaker.
pub(super) halt_summary: HaltSummarySlot,
- /// Reads the repeated-failure latch's typed cause while it still owns the
- /// halt summary. `AgentRun.failure_cause` covers the harness guard path.
- pub(super) classified_cause: Arc<
- dyn Fn() -> Option<tinyagents_harness::no_progress::ClassifiedStopCause> + Send + Sync,
- >,
/// Set by `FinalCallWrapUpMiddleware` when it turned the last permitted
/// model call into the turn's conclusion (issue #6014). `None` when the
/// middleware is not installed (a run that does not pause at its cap).
@@ -596,12 +591,8 @@ pub(super) fn install_turn_middleware(
// compacted, trimmed or persisted (`memory::lifecycle::prefetch::pre_turn`).
harness.push_middleware(Arc::new(middleware::memory_pack::memory_pack_middleware()));
- let classified_cause = repeated_failure
- .map(|mw| Arc::new(move || mw.current_classified_cause()) as _)
- .unwrap_or_else(|| Arc::new(|| None));
TurnWiring {
halt_summary,
- classified_cause,
wrap_up_fired,
compression_mw,
prompt_cache_guard,
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_run_finalize.rs b/crates/openhuman-core/src/agent/tinyagents/turn_run_finalize.rs
index a274f4aace..7e880d58e3 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_run_finalize.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_run_finalize.rs
@@ -41,7 +41,6 @@ pub(super) async fn finalize_turn_outcome(
bridge: Option<Arc<OpenhumanEventBridge>>,
early_exit: Option<tinyagents_harness::tool::EarlyExit>,
halt_summary: &HaltSummarySlot,
- classified_cause: Option<tinyagents_harness::no_progress::ClassifiedStopCause>,
wrap_up_fired: &Option<Arc<tinyagents_harness::middleware::FinalCallWrapUpMiddleware>>,
run_instance_id: u64,
tool_outcome_sink: &ToolOutcomeSink,
@@ -164,7 +163,7 @@ pub(super) async fn finalize_turn_outcome(
// A run the harness stopped (breaker / cap) is traced as stopped, not as a
// clean completion. No deadline wind-down on this path: only the session
// turn carries one, and it records the stop through its sidecar.
- let failure_cause = run.failure_cause.clone().or(classified_cause);
+ let failure_cause = run.failure_cause.clone();
let stop = crate::agent::turn_projection::classify_stop_with_cause(
breaker_halt.as_deref(),
failure_cause.clone(),