Skip to content

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

fix(composio): keep a connector failure reason on one line

Shanu84582fab84c8
diff --git a/crates/openhuman-core/src/integrations/composio/ops/pass_failure.rs b/crates/openhuman-core/src/integrations/composio/ops/pass_failure.rs
index f42f0cd803..a20e9d3040 100644
--- a/crates/openhuman-core/src/integrations/composio/ops/pass_failure.rs
+++ b/crates/openhuman-core/src/integrations/composio/ops/pass_failure.rs
@@ -30,7 +30,7 @@ pub(crate) const MAX_FAILED_ATTEMPTS: u32 = 3;
/// the call site and are not retried: repeating them cannot help, and a timed
/// out call may still be running.
///
-/// The reason is the connector's message, trimmed and cut to
+/// The reason is the connector's message on one line, cut to
/// [`MAX_REASON_CHARS`]. A failure that gave no message is still named, so a
/// row never reads "Sync failed:" with nothing after it.
pub(crate) fn failure_reason(
@@ -43,7 +43,7 @@ pub(crate) fn failure_reason(
}
Some(
message
- .map(str::trim)
+ .map(one_line)
.filter(|message| !message.is_empty())
.map(clip)
.unwrap_or_else(|| format!("the {toolkit} connector stopped without saying why")),
@@ -72,11 +72,18 @@ pub(crate) fn pass_failure(
Some(reason)
}
+/// `message` with every run of whitespace, line breaks included, made one
+/// space. A provider error can span lines (the complaint, then the fields it
+/// wanted), and the reason is shown as one row and logged as one line.
+fn one_line(message: &str) -> String {
+ message.split_whitespace().collect::<Vec<_>>().join(" ")
+}
+
/// `message` cut to [`MAX_REASON_CHARS`] characters, on a character boundary.
-fn clip(message: &str) -> String {
+fn clip(message: String) -> String {
match message.char_indices().nth(MAX_REASON_CHARS) {
Some((cut, _)) => format!("{}…", message[..cut].trim_end()),
- None => message.to_string(),
+ None => message,
}
}
diff --git a/crates/openhuman-core/src/integrations/composio/ops/pass_failure_tests.rs b/crates/openhuman-core/src/integrations/composio/ops/pass_failure_tests.rs
index f32c80fbff..427a186f5c 100644
--- a/crates/openhuman-core/src/integrations/composio/ops/pass_failure_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/ops/pass_failure_tests.rs
@@ -37,9 +37,32 @@ fn a_failure_carries_the_connectors_reason_trimmed() {
);
}
+#[test]
+fn a_reason_that_spans_lines_is_kept_on_one_line() {
+ // The shape of the GitHub error seen on staging (tinyhumansai/tinyconnectors#20).
+ assert_eq!(
+ failure_reason(
+ SyncStage::Failed,
+ Some("`GITHUB_SEARCH_ISSUES_AND_PULL_REQUESTS` failed: Invalid request data provided\n- Following fields are missing: {'q'}\n"),
+ "github"
+ )
+ .as_deref(),
+ Some("`GITHUB_SEARCH_ISSUES_AND_PULL_REQUESTS` failed: Invalid request data provided - Following fields are missing: {'q'}")
+ );
+ assert_eq!(
+ failure_reason(
+ SyncStage::Failed,
+ Some("rate limited\r\n\t retry later"),
+ "notion"
+ )
+ .as_deref(),
+ Some("rate limited retry later")
+ );
+}
+
#[test]
fn a_failure_without_a_reason_is_still_named() {
- for message in [None, Some(""), Some(" ")] {
+ for message in [None, Some(""), Some(" "), Some("\n\t")] {
assert_eq!(
failure_reason(SyncStage::Failed, message, "github").as_deref(),
Some("the github connector stopped without saying why"),