Skip to content

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

fix(subagent_host): restore failure cause for incomplete outcomes

Steven Enamakele80d7353a911
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs
index bb0a72dbbe..21bf218356 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs
@@ -349,6 +349,12 @@ pub(in crate::agent::subagent_host) fn outcome_to_host(
) -> SubagentRunOutcome {
let persistence_disposition = result.disposition;
let outcome = result.outcome;
+ let neutral_failure_cause = match &outcome.status {
+ SubagentOutcomeKind::Incomplete(_) => failure_cause_from_extensions(&outcome.extensions),
+ SubagentOutcomeKind::Completed
+ | SubagentOutcomeKind::AwaitingInput(_)
+ | SubagentOutcomeKind::Cancelled => None,
+ };
let elapsed_from_neutral = outcome
.extensions
.get("elapsed_ns")
@@ -393,7 +399,7 @@ pub(in crate::agent::subagent_host) fn outcome_to_host(
.unwrap_or_else(|| fallback_agent_id.to_owned()),
output: outcome.output.clone(),
iterations: outcome.usage.calls as usize,
- failure_cause: None,
+ failure_cause: neutral_failure_cause.clone(),
elapsed: std::time::Duration::from_millis(
durable_metadata
.map(|(_, elapsed_ms)| elapsed_ms)
@@ -445,6 +451,13 @@ pub(in crate::agent::subagent_host) fn outcome_to_host(
};
host.status = status;
host.persistence_disposition = persistence_disposition;
+ if matches!(host.status, SubagentRunStatus::Incomplete { .. }) {
+ if host.failure_cause.is_none() {
+ host.failure_cause = neutral_failure_cause;
+ }
+ } else {
+ host.failure_cause = None;
+ }
if is_awaiting_input {
host.status = SubagentRunStatus::AwaitingUser {
question: match host.status {
@@ -458,6 +471,17 @@ pub(in crate::agent::subagent_host) fn outcome_to_host(
host
}
+fn failure_cause_from_extensions(
+ extensions: &std::collections::BTreeMap<String, serde_json::Value>,
+) -> Option<tinyagents_harness::no_progress::ClassifiedStopCause> {
+ let cause = extensions.get("failure_cause")?.as_object()?;
+ Some(tinyagents_harness::no_progress::ClassifiedStopCause {
+ class: cause.get("class")?.as_str()?.to_owned(),
+ operation: cause.get("operation")?.as_str()?.to_owned(),
+ summary: cause.get("summary")?.as_str()?.to_owned(),
+ })
+}
+
pub(super) fn map_lifecycle_error(error: SubagentError) -> SubagentRunError {
SubagentRunError::Provider(anyhow::anyhow!(error.to_string()))
}
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter_tests.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter_tests.rs
index cc546d1cfb..fab8c27fc7 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter_tests.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter_tests.rs
@@ -93,10 +93,7 @@ fn durable_winner_cause_is_restored_without_a_host_cache() {
&persistence,
);
- assert_eq!(
- projected.failure_cause,
- Some(winner_cause)
- );
+ assert_eq!(projected.failure_cause, Some(winner_cause));
assert_eq!(projected.output, "durable winner");
}
@@ -123,10 +120,7 @@ fn a_losing_cached_cause_cannot_replace_the_durable_winner_cause() {
&persistence,
);
- assert_eq!(
- projected.failure_cause,
- Some(winner_cause)
- );
+ assert_eq!(projected.failure_cause, Some(winner_cause));
assert_eq!(projected.output, "durable winner");
}
@@ -162,10 +156,7 @@ fn non_incomplete_winners_discard_stale_typed_causes() {
let persistence = OpenHumanPersistence::new(directory.path().join("checkpoints"));
let stale = cause("not_found", "file_read", "stale cause");
let statuses = [
- (
- SubagentOutcomeKind::Completed,
- SubagentRunStatus::Completed,
- ),
+ (SubagentOutcomeKind::Completed, SubagentRunStatus::Completed),
(
SubagentOutcomeKind::AwaitingInput(SubagentPause {
reason: "question".into(),