Skip to content

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

refactor(ops): make builder repair helpers public and move tests

Steven Enamakel2282dd5dd999
diff --git a/crates/openhuman-core/src/flows/ops/builder.rs b/crates/openhuman-core/src/flows/ops/builder.rs
index d02af147ce..20d2cb35fa 100644
--- a/crates/openhuman-core/src/flows/ops/builder.rs
+++ b/crates/openhuman-core/src/flows/ops/builder.rs
@@ -494,7 +494,7 @@ pub(crate) fn start_builder_turn_clean(agent: &mut crate::agent::OpenHumanSessio
});
}
-fn is_backend_or_infrastructure_failure(error: &str) -> bool {
+pub(super) fn is_backend_or_infrastructure_failure(error: &str) -> bool {
let error = error.to_ascii_lowercase();
[
"backend returned",
@@ -504,10 +504,8 @@ fn is_backend_or_infrastructure_failure(error: &str) -> bool {
"gateway timeout",
"connection refused",
"connection reset",
- "connection timed out",
- "timed out",
- "timeout",
- "transport error",
+ "connection timed out while calling",
+ "transport error while calling",
"bucket does not exist",
"http 5",
"status 5",
@@ -517,37 +515,10 @@ fn is_backend_or_infrastructure_failure(error: &str) -> bool {
.any(|marker| error.contains(marker))
}
-fn backend_repair_message(error: &str) -> Option<String> {
+pub(super) fn backend_repair_message(error: &str) -> Option<String> {
is_backend_or_infrastructure_failure(error).then(|| {
format!(
"The workflow was not changed because this run failed in an external service.\n\n{error}"
)
})
}
-
-#[cfg(test)]
-mod tests {
- use super::{backend_repair_message, is_backend_or_infrastructure_failure};
-
- #[test]
- fn classifies_backend_failure_without_classifying_graph_errors() {
- assert!(is_backend_or_infrastructure_failure(
- "File upload failed: Backend returned 500 Internal Server Error"
- ));
- assert!(is_backend_or_infrastructure_failure(
- "connection timed out while calling file storage"
- ));
- assert!(!is_backend_or_infrastructure_failure(
- "required argument resolved null: nodes.get_link.item.json.url"
- ));
- }
-
- #[test]
- fn backend_repair_message_explains_why_the_graph_was_preserved() {
- let message = backend_repair_message("HTTP 503 from file storage").unwrap();
-
- assert!(message.contains("workflow was not changed"));
- assert!(message.contains("HTTP 503 from file storage"));
- assert!(backend_repair_message("required argument resolved null").is_none());
- }
-}
diff --git a/crates/openhuman-core/src/flows/ops_builder_repair_tests.rs b/crates/openhuman-core/src/flows/ops_builder_repair_tests.rs
new file mode 100644
index 0000000000..d3697d31b8
--- /dev/null
+++ b/crates/openhuman-core/src/flows/ops_builder_repair_tests.rs
@@ -0,0 +1,64 @@
+use super::*;
+use crate::{
+ config::Config,
+ flows::{
+ agents::workflow_builder::builder_prompt::{BuildMode, BuilderRequest},
+ ops::{
+ builder::{backend_repair_message, is_backend_or_infrastructure_failure},
+ flows_build_with_extra_hidden_tools,
+ },
+ },
+};
+
+#[test]
+fn classifies_backend_failures_without_classifying_graph_timeouts() {
+ assert!(is_backend_or_infrastructure_failure(
+ "File upload failed: Backend returned 500 Internal Server Error"
+ ));
+ assert!(is_backend_or_infrastructure_failure(
+ "connection timed out while calling file storage"
+ ));
+ assert!(!is_backend_or_infrastructure_failure(
+ "agent node fetch_profile timed out after 30 seconds"
+ ));
+ assert!(!is_backend_or_infrastructure_failure(
+ "required argument resolved null: nodes.get_link.item.json.url"
+ ));
+}
+
+#[test]
+fn backend_repair_message_explains_why_the_graph_was_preserved() {
+ let message = backend_repair_message("HTTP 503 from file storage").unwrap();
+
+ assert!(message.contains("workflow was not changed"));
+ assert!(message.contains("HTTP 503 from file storage"));
+ assert!(
+ backend_repair_message("agent node fetch_profile timed out after 30 seconds").is_none()
+ );
+}
+
+#[tokio::test]
+async fn repair_backend_failure_returns_no_proposal_before_starting_the_builder() {
+ let req = BuilderRequest {
+ mode: BuildMode::Repair,
+ instruction: "repair the failed workflow".to_string(),
+ graph: Some(json!({"nodes": [], "edges": []})),
+ flow_id: Some("flow-1".to_string()),
+ run_id: Some("run-1".to_string()),
+ error: Some("Backend returned 503 Service Unavailable".to_string()),
+ failing_node_ids: vec!["fetch".to_string()],
+ };
+
+ let outcome = flows_build_with_extra_hidden_tools(&Config::default(), req, None, &[])
+ .await
+ .expect("backend failure should short-circuit before the builder starts");
+
+ assert_eq!(outcome.value["proposal"], Value::Null);
+ assert_eq!(outcome.value["error"], Value::Null);
+ assert!(
+ outcome.value["assistant_text"]
+ .as_str()
+ .expect("assistant text")
+ .contains("workflow was not changed")
+ );
+}
diff --git a/crates/openhuman-core/src/flows/ops_tests.rs b/crates/openhuman-core/src/flows/ops_tests.rs
index 9ce8619747..6a04bfc276 100644
--- a/crates/openhuman-core/src/flows/ops_tests.rs
+++ b/crates/openhuman-core/src/flows/ops_tests.rs
@@ -335,7 +335,7 @@ fn graph(value: Value) -> WorkflowGraph {
fn seed_app_session_for_gate_test(tmp: &TempDir) {
use crate::security::credentials::{
- AuthService, APP_SESSION_PROVIDER, DEFAULT_AUTH_PROFILE_NAME,
+ APP_SESSION_PROVIDER, AuthService, DEFAULT_AUTH_PROFILE_NAME,
};
// `verify_session_active` reads from `config.config_path.parent()`, which
// `test_config` sets to `tmp.path()` itself (distinct from
@@ -358,7 +358,7 @@ fn seed_app_session_for_gate_test(tmp: &TempDir) {
// so none of this touches a live Composio backend.
use crate::flows::tinyflows::caps::{
- seed_live_catalog_cache, seed_probe_cache, ProbedOutputSample, ToolContract,
+ ProbedOutputSample, ToolContract, seed_live_catalog_cache, seed_probe_cache,
};
fn seeded_slack_send_contract() -> ToolContract {
@@ -697,6 +697,8 @@ use support_tests::*;
mod agent_binding_tests;
#[path = "ops_approval_manifest_and_catalog_tests.rs"]
mod approval_manifest_and_catalog_tests;
+#[path = "ops_builder_repair_tests.rs"]
+mod builder_repair_tests;
#[path = "ops_builder_trail_off_tests.rs"]
mod builder_trail_off_tests;
#[path = "ops_connection_ref_gate_tests.rs"]