Skip to content

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

test(session_host): cover driver progress tracing and cost rollup

Steven Enamakel28f16345b2f4
diff --git a/crates/openhuman-core/src/agent/progress_tracing/journal_projection_cost_rollup_tests.rs b/crates/openhuman-core/src/agent/progress_tracing/journal_projection_cost_rollup_tests.rs
index f2a5948613..3e84e59a07 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/journal_projection_cost_rollup_tests.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/journal_projection_cost_rollup_tests.rs
@@ -52,6 +52,7 @@ fn turn_with_usage(usages: &[Usage]) -> Vec<AgentObservation> {
1_010 + offset * 10,
AgentEvent::RunCompleted {
run_id: RunId::new("run-1"),
+ outcome: None,
},
));
events
@@ -220,6 +221,7 @@ fn subagent_usage_does_not_roll_into_the_parent_turn() {
1_070,
AgentEvent::RunCompleted {
run_id: RunId::new("run-1"),
+ outcome: None,
},
),
];
@@ -297,6 +299,7 @@ fn unknown_tool_call_projects_a_failed_tool_span() {
1_030,
AgentEvent::RunCompleted {
run_id: RunId::new("run-1"),
+ outcome: None,
},
),
];
@@ -364,6 +367,7 @@ fn unknown_tool_call_inside_a_subagent_projects_a_child_tool_span() {
1_050,
AgentEvent::RunCompleted {
run_id: RunId::new("run-1"),
+ outcome: None,
},
),
];
diff --git a/crates/openhuman-core/src/agent/progress_tracing/journal_projection_tests.rs b/crates/openhuman-core/src/agent/progress_tracing/journal_projection_tests.rs
index a88b95679a..2d9a6931d3 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/journal_projection_tests.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/journal_projection_tests.rs
@@ -78,6 +78,7 @@ fn single_turn(tool_error: Option<&str>) -> Vec<AgentObservation> {
1_070,
AgentEvent::RunCompleted {
run_id: RunId::new("run-1"),
+ outcome: None,
},
),
]
@@ -144,6 +145,7 @@ fn subagent_turn() -> Vec<AgentObservation> {
1_100,
AgentEvent::RunCompleted {
run_id: RunId::new("run-1"),
+ outcome: None,
},
),
]
@@ -257,6 +259,7 @@ fn projects_failed_subagent_from_child_run_failed() {
AgentEvent::RunFailed {
run_id: RunId::new("run-1"),
error: "provider unavailable".to_string(),
+ outcome: None,
},
),
obs(
@@ -264,6 +267,7 @@ fn projects_failed_subagent_from_child_run_failed() {
1_030,
AgentEvent::RunCompleted {
run_id: RunId::new("run-1"),
+ outcome: None,
},
),
];
@@ -319,6 +323,7 @@ fn projects_turn_content_from_root_model_io() {
1_030,
AgentEvent::RunCompleted {
run_id: RunId::new("run-1"),
+ outcome: None,
},
),
];
diff --git a/crates/openhuman-core/src/agent/session_host/driver.rs b/crates/openhuman-core/src/agent/session_host/driver.rs
index d06b671591..264d972800 100644
--- a/crates/openhuman-core/src/agent/session_host/driver.rs
+++ b/crates/openhuman-core/src/agent/session_host/driver.rs
@@ -414,6 +414,8 @@ impl SessionDriver<OpenHumanRunContext> for OpenHumanSessionDriver {
output: Some(output),
partial: None,
interrupted: outcome.early_exit_tool.is_some() || outcome.hit_cap,
+ // `None` lets the runtime derive the outcome from `interrupted`.
+ outcome: None,
})
}
}
@@ -450,6 +452,7 @@ fn driver_failure(error: impl std::fmt::Display) -> DriverFailure {
DriverFailure {
error: RuntimeError::Driver(error.to_string()),
partial: None,
+ outcome: None,
}
}
@@ -482,7 +485,7 @@ fn ensure_snapshot_tools_are_executable(
}
fn driver_error_with_snapshot(
- error: impl std::fmt::Display,
+ error: anyhow::Error,
snapshot: &crate::agent::tinyagents::TranscriptSnapshotSink,
sidecar: &std::sync::Arc<
std::sync::Mutex<crate::agent::tinyagents::host::run_context::SessionTurnSidecar>,
@@ -490,6 +493,21 @@ fn driver_error_with_snapshot(
elapsed: std::time::Duration,
fallback_model: &str,
) -> DriverFailure {
+ // Classify from the typed harness error when the chain carries one, rather
+ // than matching on its rendered text.
+ let typed = error
+ .chain()
+ .find_map(|cause| cause.downcast_ref::<tinyagents_harness::TinyAgentsError>());
+ let stalled = matches!(
+ typed,
+ Some(tinyagents_harness::TinyAgentsError::GenerationStalled)
+ );
+ let terminal = typed.map(|typed| {
+ tinyagents_harness::terminal::TerminalOutcome::from_error(
+ typed,
+ tinyagents_harness::terminal::TimeoutPhase::AfterTurn,
+ )
+ });
let error = error.to_string();
let guard = snapshot
.lock()
@@ -531,15 +549,15 @@ fn driver_error_with_snapshot(
observed.resolved_route = guard.resolved_route.clone();
}
if guard.messages.is_empty() {
- return driver_failure(error);
+ let mut failure = driver_failure(error);
+ failure.outcome = terminal;
+ return failure;
}
let accepted_end = guard.accepted_end();
let history = guard.messages[..accepted_end].to_vec();
let unanswered =
crate::agent::tinyagents::render_unanswered_steps(&guard.messages[accepted_end..]);
- let display = if error
- .contains(&tinyagents_harness::TinyAgentsError::GenerationStalled.to_string())
- {
+ let display = if stalled {
// The model's streamed narration was stopped before it could repeat
// indefinitely. Preserve the completed tools as a useful, bounded
// partial rather than showing only the failed model's process text.
@@ -566,7 +584,9 @@ fn driver_error_with_snapshot(
output: None,
partial: Some(TranscriptPartial::new(display)),
interrupted: true,
+ outcome: terminal.clone(),
}),
+ outcome: terminal,
}
}
diff --git a/crates/openhuman-core/src/agent/session_host/driver_tests.rs b/crates/openhuman-core/src/agent/session_host/driver_tests.rs
index af235f8f6c..43add5510e 100644
--- a/crates/openhuman-core/src/agent/session_host/driver_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/driver_tests.rs
@@ -23,7 +23,7 @@ fn graph_failure_persists_only_accepted_snapshot_history() {
},
));
let failure = driver_error_with_snapshot(
- "provider rejected follow-up",
+ anyhow::anyhow!("provider rejected follow-up"),
&snapshot,
&sidecar(),
std::time::Duration::from_millis(1),
@@ -59,7 +59,7 @@ fn stalled_model_stream_reports_completed_evidence_instead_of_its_narration() {
},
));
let failure = driver_error_with_snapshot(
- tinyagents_harness::TinyAgentsError::GenerationStalled,
+ anyhow::Error::new(tinyagents_harness::TinyAgentsError::GenerationStalled),
&snapshot,
&sidecar(),
std::time::Duration::from_millis(1),
@@ -102,7 +102,7 @@ fn graph_failure_copies_snapshot_usage_and_failed_tool_outcome_to_sidecar() {
));
let sidecar = sidecar();
let failure = driver_error_with_snapshot(
- "tool follow-up was rejected",
+ anyhow::anyhow!("tool follow-up was rejected"),
&snapshot,
&sidecar,
std::time::Duration::from_millis(25),
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_adapter_tests.rs b/crates/openhuman-core/src/agent/session_host/runtime_adapter_tests.rs
index 2a0f63199f..fb04b6d347 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_adapter_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_adapter_tests.rs
@@ -56,6 +56,7 @@ impl SessionDriver<OpenHumanRunContext> for RecordingDriver {
output: Some("done".into()),
partial: None,
interrupted: false,
+ outcome: None,
})
}
}