Skip to content

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

refactor(session-host): move stop classification into stop_summary

Steven Enamakel2d365cd37c1c
diff --git a/crates/openhuman-core/src/agent/orchestration/spawn_parallel/collect.rs b/crates/openhuman-core/src/agent/orchestration/spawn_parallel/collect.rs
index abb83de780..29de3b63c5 100644
--- a/crates/openhuman-core/src/agent/orchestration/spawn_parallel/collect.rs
+++ b/crates/openhuman-core/src/agent/orchestration/spawn_parallel/collect.rs
@@ -117,7 +117,7 @@ pub(crate) async fn project_spawn_parallel_result(
// An incomplete worker was stopped early (breaker /
// cap); its span closes at WARNING with that stop.
stop: matches!(result.status, ParallelAgentStatus::Incomplete).then(|| {
- crate::agent::turn_projection::stop_from_incomplete(
+ crate::agent::session_host::stop_summary::stop_from_incomplete(
error.as_deref().unwrap_or(""),
)
}),
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/dispatch_outcomes.rs b/crates/openhuman-core/src/agent/orchestration/tools/dispatch_outcomes.rs
index a27e77e95e..f56286234a 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/dispatch_outcomes.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/dispatch_outcomes.rs
@@ -78,7 +78,7 @@ pub(crate) fn incomplete_envelope(
/// How a sub-agent handed back as `Incomplete { reason }` was stopped
/// (iteration cap or failure breaker), for its `SubagentCompleted` event.
pub(crate) fn incomplete_stop(reason: &str) -> Option<tinyagents_harness::turn_stop::TurnStop> {
- Some(crate::agent::turn_projection::stop_from_incomplete(reason))
+ Some(crate::agent::session_host::stop_summary::stop_from_incomplete(reason))
}
/// The parent's tool result for a sub-agent the harness stopped early: a
@@ -93,7 +93,7 @@ pub(crate) fn stopped_subagent_result(
reason: &str,
envelope: String,
) -> ToolResult {
- let stop = crate::agent::turn_projection::stop_from_incomplete(reason);
+ let stop = crate::agent::session_host::stop_summary::stop_from_incomplete(reason);
log::debug!(
"[subagent] {tool_name} child stopped early agent_id={agent_id} task_id={task_id} \
{}; returning a failed tool result",
diff --git a/crates/openhuman-core/src/agent/progress_tracing/progress_tracing_stop_tests.rs b/crates/openhuman-core/src/agent/progress_tracing/progress_tracing_stop_tests.rs
index 727656d92e..97c9cbc91f 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/progress_tracing_stop_tests.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/progress_tracing_stop_tests.rs
@@ -57,7 +57,7 @@ fn a_breaker_stopped_turn_closes_at_warning_with_stop_attributes() {
(
AgentProgress::TurnCompleted {
iterations: 4,
- stop: Some(crate::agent::turn_projection::breaker_stop(BREAKER_NOTE)),
+ stop: Some(crate::agent::session_host::stop_summary::breaker_stop(BREAKER_NOTE)),
},
50,
),
@@ -169,7 +169,7 @@ fn a_stopped_subagent_span_closes_at_warning_with_stop_attributes() {
(
subagent_completed(
"t-stop",
- Some(crate::agent::turn_projection::breaker_stop(BREAKER_NOTE)),
+ Some(crate::agent::session_host::stop_summary::breaker_stop(BREAKER_NOTE)),
),
40,
),
diff --git a/crates/openhuman-core/src/agent/session_host/driver.rs b/crates/openhuman-core/src/agent/session_host/driver.rs
index e9f2f2778d..c08f041458 100644
--- a/crates/openhuman-core/src/agent/session_host/driver.rs
+++ b/crates/openhuman-core/src/agent/session_host/driver.rs
@@ -468,7 +468,7 @@ impl SessionDriver<OpenHumanRunContext> for OpenHumanSessionDriver {
observed.wrap_up_injected = outcome.wrap_up_injected;
// How the harness stopped the turn, if it did. The wind-down
// middleware marked the sidecar during the run.
- observed.stop = crate::agent::turn_projection::classify_stop(
+ observed.stop = crate::agent::session_host::stop_summary::classify_stop(
outcome.breaker_halt.as_deref(),
observed.wind_down,
outcome.hit_cap,
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 16927c36d3..5cc8ddd4a1 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
@@ -80,7 +80,7 @@ async fn committed_progress_carries_the_sidecar_stop_on_turn_completed() {
let mut context = crate::agent::tinyagents::host::OpenHumanRunContext::new();
context.progress = Some(tx);
context.session_sidecar.lock().unwrap().stop =
- Some(crate::agent::turn_projection::breaker_stop(
+ Some(crate::agent::session_host::stop_summary::breaker_stop(
"Stopping after 2 attempt(s): failure class `uncertain_side_effect` still blocks \
operation `web_answer_tool` on `x`. Resolve this blocker before retrying.",
));
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 e8285153ae..d387a29e2d 100644
--- a/crates/openhuman-core/src/agent/session_host/stop_summary.rs
+++ b/crates/openhuman-core/src/agent/session_host/stop_summary.rs
@@ -19,6 +19,7 @@
use std::fmt::Write as _;
use super::turn_checkpoint::CheckpointToolResult;
+use tinyagents_harness::turn_stop::TurnStop;
/// Longest error line shown for one tool, in characters.
const ERROR_LINE_CHARS: usize = 120;
@@ -26,6 +27,30 @@ const ERROR_LINE_CHARS: usize = 120;
/// Most result lines listed; the rest are counted.
const MAX_LISTED: usize = 8;
+/// Maps an unclassified breaker stop to the product's stable stop category.
+fn stop_fallback_class(note: &str) -> &'static str {
+ StopReasonKind::from_stop_note(note).key()
+}
+
+/// A breaker stop with the product-specific fallback category.
+pub(crate) fn breaker_stop(note: &str) -> TurnStop {
+ TurnStop::breaker(note, stop_fallback_class)
+}
+
+/// Classifies the terminal reason for a completed turn.
+pub(crate) fn classify_stop(
+ breaker_halt: Option<&str>,
+ wind_down: bool,
+ hit_cap: bool,
+) -> Option<TurnStop> {
+ TurnStop::classify(breaker_halt, wind_down, hit_cap, stop_fallback_class)
+}
+
+/// Projects an incomplete result reason through the product's stop categories.
+pub(crate) fn stop_from_incomplete(reason: &str) -> TurnStop {
+ TurnStop::from_incomplete_reason(reason, stop_fallback_class)
+}
+
/// Why the breaker stopped the turn, in terms a user can act on.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum StopReasonKind {
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 cb66dfa3ec..37babd04d5 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_run_finalize.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_run_finalize.rs
@@ -164,7 +164,7 @@ pub(super) async fn finalize_turn_outcome(
// clean completion. No deadline wind-down on this path: only the session
// turn carries one, and it records the stop through its sidecar.
let stop =
- crate::agent::turn_projection::classify_stop(breaker_halt.as_deref(), false, hit_cap);
+ crate::agent::session_host::stop_summary::classify_stop(breaker_halt.as_deref(), false, hit_cap);
if let Some(stop) = stop.as_ref().filter(|_| turn_completed_sink.is_some()) {
tracing::debug!(
model,