Skip to content

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

fix(progress_tracing): correct cost rollup and status reporting

Steven Enamakelb8d5ff4d4ab7
diff --git a/crates/openhuman-core/src/agent/progress_tracing/collector/events.rs b/crates/openhuman-core/src/agent/progress_tracing/collector/events.rs
index fb745eebb7..98a6fa61d8 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/collector/events.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/collector/events.rs
@@ -519,7 +519,10 @@ impl SpanCollector {
return;
};
if let Ok(serde_json::Value::String(class)) = serde_json::to_value(failure.class) {
- extra.insert("tool.failure_class".to_string(), serde_json::Value::String(class));
+ extra.insert(
+ "tool.failure_class".to_string(),
+ serde_json::Value::String(class),
+ );
}
if self.ctx.capture_content {
extra.insert(
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 219bfa5ced..d45b364d4a 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
@@ -262,7 +262,8 @@ fn cache_creation_tokens_reach_the_projected_generation_span() {
}
/// The answer the crate injects for an unknown tool (`unknown_tool_message`).
-const UNKNOWN_TOOL_ANSWER: &str = "unknown tool `send_fax` (arguments: {\"to\":\"1234\"}): no tool \
+const UNKNOWN_TOOL_ANSWER: &str =
+ "unknown tool `send_fax` (arguments: {\"to\":\"1234\"}): no tool \
with that name is available to you, and calling it again will fail the same way.";
/// The crate's recovered pair for an unknown tool (TOOL-11 `recover_tool_call`):
@@ -334,20 +335,22 @@ fn unknown_tool_call_projects_exactly_one_failed_tool_span() {
),
];
observations.extend(recovered_unknown_tool_pair(10, 1_021));
- observations.push(
- obs(
- 3,
- 1_030,
- AgentEvent::RunCompleted {
- run_id: RunId::new("run-1"),
- outcome: None,
- },
- ),
- );
+ observations.push(obs(
+ 3,
+ 1_030,
+ AgentEvent::RunCompleted {
+ run_id: RunId::new("run-1"),
+ outcome: None,
+ },
+ ));
let spans = spans_from_observations(ctx().with_capture_content(true), 10, &observations);
let tools: Vec<&TraceSpan> = spans.iter().filter(|s| s.kind == SpanKind::Tool).collect();
- assert_eq!(tools.len(), 1, "exactly one tool span per unknown-tool call");
+ assert_eq!(
+ tools.len(),
+ 1,
+ "exactly one tool span per unknown-tool call"
+ );
let tool = tools[0];
assert_eq!(tool.name, "tool.send_fax");
assert_eq!(tool.attributes["tool.success"], serde_json::json!(false));
diff --git a/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs b/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs
index 0b526380c3..bb326b5184 100644
--- a/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs
@@ -256,7 +256,8 @@ async fn tool_completed_projects_output_arguments_and_elapsed() {
}
/// The answer the crate injects for an unknown tool (`unknown_tool_message`).
-const UNKNOWN_TOOL_ANSWER: &str = "unknown tool `search_files` (arguments: {\"query\":\"config\"}): \
+const UNKNOWN_TOOL_ANSWER: &str =
+ "unknown tool `search_files` (arguments: {\"query\":\"config\"}): \
no tool with that name is available to you, and calling it again will fail the same way.";
/// Emit what the crate emits for an unknown-tool call since TOOL-11: the typed
@@ -335,7 +336,10 @@ async fn unknown_tool_call_projects_exactly_one_failed_timeline_row() {
let (tool_name, success, failure, output, label) = completed.remove(0);
assert_eq!(tool_name, "search_files");
assert!(!success, "the attempted tool is projected as a failed call");
- assert_eq!(output, UNKNOWN_TOOL_ANSWER, "the row carries the error text");
+ assert_eq!(
+ output, UNKNOWN_TOOL_ANSWER,
+ "the row carries the error text"
+ );
assert_eq!(label.as_deref(), Some("Search Files (unavailable)"));
// #6277: a tool the agent does not have fails identically on every retry,
// so the timeline must not tell the user to "try again / run diagnostics".
@@ -412,7 +416,10 @@ async fn unknown_tool_call_in_a_child_run_projects_one_subagent_row() {
}
}
assert_eq!((started, completed), (1, 1));
- assert_eq!(class, Some(crate::tools::status::ToolFailureClass::NotFound));
+ assert_eq!(
+ class,
+ Some(crate::tools::status::ToolFailureClass::NotFound)
+ );
}
/// W2-budget-dedupe: two `UsageRecorded` events for the *same* model call
diff --git a/crates/openhuman-core/src/tools/status/ops.rs b/crates/openhuman-core/src/tools/status/ops.rs
index 02ddc44023..3d14c3f962 100644
--- a/crates/openhuman-core/src/tools/status/ops.rs
+++ b/crates/openhuman-core/src/tools/status/ops.rs
@@ -65,7 +65,10 @@ fn classify_class(error_text: &str, timed_out: bool) -> ToolFailureClass {
// The `timed_out` flag is not consulted here: the only live caller
// derives it by sniffing the same text.
if let Some(class) = structural_class(&text) {
- tracing::debug!(?class, "[tool_status::classify] matched structural result shape");
+ tracing::debug!(
+ ?class,
+ "[tool_status::classify] matched structural result shape"
+ );
return class;
}
@@ -275,11 +278,7 @@ fn structural_class(text: &str) -> Option<ToolFailureClass> {
// The exit line is the renderer's own; 127 and 126 are the shell's
// codes for a missing program and a non-executable one, which the
// user can act on. Every other code is the program's verdict.
- let exit_line = text
- .trim_start()
- .lines()
- .next()
- .unwrap_or_default();
+ let exit_line = text.trim_start().lines().next().unwrap_or_default();
let code = exit_line
.split_once("exit code ")
.map(|(_, rest)| {
diff --git a/crates/openhuman-core/src/tools/status/ops_tests.rs b/crates/openhuman-core/src/tools/status/ops_tests.rs
index 8a948700b8..d8e136d760 100644
--- a/crates/openhuman-core/src/tools/status/ops_tests.rs
+++ b/crates/openhuman-core/src/tools/status/ops_tests.rs
@@ -390,7 +390,10 @@ fn structural_prefixes_only_count_where_the_producer_puts_them() {
#[test]
fn structural_classes_carry_their_own_copy() {
- let invalid = classify("invalid arguments for tool `shell`: missing `command`", false);
+ let invalid = classify(
+ "invalid arguments for tool `shell`: missing `command`",
+ false,
+ );
assert_eq!(invalid.class, ToolFailureClass::InvalidArguments);
assert!(!invalid.recoverable);
assert!(!invalid.cause_plain.contains("took too long"));
diff --git a/crates/openhuman-core/src/web_chat/ops/turn_guards_tests.rs b/crates/openhuman-core/src/web_chat/ops/turn_guards_tests.rs
new file mode 100644
index 0000000000..662da9fc6a
--- /dev/null
+++ b/crates/openhuman-core/src/web_chat/ops/turn_guards_tests.rs
@@ -0,0 +1,58 @@
+use super::*;
+
+fn result(text: &str) -> WebChatTaskResult {
+ WebChatTaskResult {
+ full_response: text.to_string(),
+ citations: Vec::new(),
+ usage: None,
+ workspace_dir: std::path::PathBuf::from("/tmp/turn-guards"),
+ timing: None,
+ }
+}
+
+/// The guarded turn sees the backstop it runs under, so the session turn can
+/// hand the harness the deadline it must wind down before.
+#[tokio::test]
+async fn guarded_turn_sees_the_backstop_deadline() {
+ let backstop = Duration::from_secs(900);
+ let seen = std::sync::Arc::new(std::sync::Mutex::new(None));
+ let seen_in_turn = seen.clone();
+ let res = drive_turn_with_deadline(Some(backstop), async move {
+ *seen_in_turn.lock().unwrap() = crate::agent::turn_deadline::current();
+ Ok(result("answer"))
+ })
+ .await
+ .expect("turn completes");
+ assert_eq!(res.full_response, "answer");
+ let deadline = seen.lock().unwrap().expect("deadline scoped on the turn");
+ assert_eq!(deadline.backstop(), backstop);
+ assert_eq!(deadline.wind_down_after(), Duration::from_secs(780));
+ assert!(deadline.wind_down_after() < deadline.hard_stop_after());
+ assert!(deadline.hard_stop_after() < backstop);
+}
+
+#[tokio::test]
+async fn disabled_backstop_scopes_no_deadline() {
+ let res = drive_turn_with_deadline(None, async {
+ assert!(crate::agent::turn_deadline::current().is_none());
+ Ok(result("ok"))
+ })
+ .await;
+ assert!(res.is_ok());
+}
+
+/// If the backstop fires anyway, the caller gets the typed `turn_timeout`
+/// error, which is classified to user-facing copy, not silence.
+#[tokio::test(start_paused = true)]
+async fn backstop_firing_yields_a_classified_turn_timeout_error() {
+ let err = drive_turn_with_deadline(Some(Duration::from_secs(900)), async {
+ std::future::pending::<()>().await;
+ Ok(result("never"))
+ })
+ .await
+ .expect_err("backstop fires");
+ assert!(super::super::super::web_errors::is_outer_backstop_timeout(&err));
+ let classified = super::super::super::web_errors::classify_inference_error(&err);
+ assert_eq!(classified.error_type, "turn_timeout");
+ assert!(!classified.message.trim().is_empty());
+}