Skip to content

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

fix(composio): end a sync on a connector-reported failure instead of repeating it

Shanueecbbf52908f
diff --git a/crates/openhuman-core/src/integrations/composio/ops/mod.rs b/crates/openhuman-core/src/integrations/composio/ops/mod.rs
index edb4e22f2a..c1f9d6a76f 100644
--- a/crates/openhuman-core/src/integrations/composio/ops/mod.rs
+++ b/crates/openhuman-core/src/integrations/composio/ops/mod.rs
@@ -24,6 +24,7 @@
//! | `user_scopes` | per-toolkit agent scope prefs, over the bound memory driver |
//! | `connector_runs` | Sync History rows for Composio runs (openhuman#6257) |
//! | `source_rows` | which memory-sources row a Composio connection belongs to |
+//! | `pass_failure` | when a connector pass failed; the Sources-row retry schedule (openhuman#6255) |
mod connections;
mod connector_runs;
@@ -32,6 +33,7 @@ mod error_utils;
mod execute;
mod memory_cleanup;
mod pass_budget;
+mod pass_failure;
mod providers_ops;
mod source_rows;
mod toolkits;
diff --git a/crates/openhuman-core/src/integrations/composio/ops/pass_budget.rs b/crates/openhuman-core/src/integrations/composio/ops/pass_budget.rs
index 3e2cbd19ac..a1330ee7f8 100644
--- a/crates/openhuman-core/src/integrations/composio/ops/pass_budget.rs
+++ b/crates/openhuman-core/src/integrations/composio/ops/pass_budget.rs
@@ -38,7 +38,8 @@ const SINGLE_CALL_MAX_PASSES: usize = 50;
pub(crate) struct DrainFailure {
/// The failing pass's error.
pub error: String,
- /// Records written by the passes that finished before it.
+ /// Records written before the drain stopped: the passes before a failing
+ /// call, and a failed pass's own pages when the connector read some first.
pub written: u32,
}
@@ -49,9 +50,11 @@ pub(crate) struct DrainFailure {
/// The outcome sums `records_read` and `written` across passes, is
/// `already_ingested` only when every pass was a no-op, and carries the last
/// pass's `more_pending` and `message` — the same "last pass's word wins" rule
-/// the Sources-row loop applies. A pass error ends the run with a
-/// [`DrainFailure`] carrying that error and what the earlier passes wrote,
-/// which the driver has already committed.
+/// the Sources-row loop applies. A pass error, or a pass the connector reports
+/// as failed, ends the run with a [`DrainFailure`] carrying the reason and what
+/// the passes wrote, which the driver has already committed. Nothing here
+/// retries a failure: these entry points run again on their own schedule
+/// (openhuman#6255).
pub(crate) async fn run_passes_within_budget<F, Fut>(
budget: u32,
mut run_pass: F,
@@ -86,6 +89,14 @@ where
total.already_ingested = total.already_ingested && pass.already_ingested;
total.more_pending = pass.more_pending;
total.message = pass.message;
+ // Checked before the read-nothing stop below, which would otherwise end
+ // a failed pass as a quiet success.
+ if let Some(error) = pass.failure {
+ return Err(DrainFailure {
+ error,
+ written: total.written,
+ });
+ }
// A pass that read nothing cannot make progress; "more pending" from
// it would only be asked again for the same nothing.
if !pass.more_pending || pass.records_read == 0 {
diff --git a/crates/openhuman-core/src/integrations/composio/ops/pass_budget_tests.rs b/crates/openhuman-core/src/integrations/composio/ops/pass_budget_tests.rs
index 0f87615100..00b9b4e67a 100644
--- a/crates/openhuman-core/src/integrations/composio/ops/pass_budget_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/ops/pass_budget_tests.rs
@@ -17,6 +17,7 @@ fn pass(written: u32, more_pending: bool) -> SyncPassOutcome {
already_ingested: false,
more_pending,
message: None,
+ failure: None,
}
}
@@ -131,6 +132,7 @@ async fn already_ingested_holds_only_when_every_pass_was_a_no_op() {
already_ingested: true,
more_pending: true,
message: None,
+ failure: None,
};
let last = SyncPassOutcome {
more_pending: false,
@@ -197,6 +199,7 @@ async fn the_budget_counts_records_read_not_records_written() {
already_ingested: true,
more_pending: true,
message: None,
+ failure: None,
};
let (out, asked) = drive(
SINGLE_CALL_ITEM_BUDGET,
@@ -227,6 +230,7 @@ async fn a_pass_that_reads_nothing_ends_the_run() {
already_ingested: false,
more_pending: true,
message: None,
+ failure: None,
};
let (out, asked) = drive(SINGLE_CALL_ITEM_BUDGET, vec![Ok(empty)]).await;
let out = out.expect("the pass succeeds");
@@ -234,3 +238,49 @@ async fn a_pass_that_reads_nothing_ends_the_run() {
assert_eq!(out.records_read, 0);
assert!(out.more_pending, "the module's own word is still reported");
}
+
+#[tokio::test]
+async fn a_pass_the_connector_reports_as_failed_ends_the_run_with_its_reason() {
+ // openhuman#6255: a failed pass is not "more pending". The pages it read
+ // before its page failed are committed, so they count toward the written
+ // total, and the drain stops instead of asking the failing connector again.
+ let failed = SyncPassOutcome {
+ failure: Some("GITHUB_SEARCH_ISSUES_AND_PULL_REQUESTS failed".to_string()),
+ ..pass(40, false)
+ };
+ let (out, asked) = drive(
+ SINGLE_CALL_ITEM_BUDGET,
+ vec![Ok(pass(200, true)), Ok(failed)],
+ )
+ .await;
+ assert_eq!(
+ out.unwrap_err(),
+ DrainFailure {
+ error: "GITHUB_SEARCH_ISSUES_AND_PULL_REQUESTS failed".to_string(),
+ written: 240,
+ }
+ );
+ assert_eq!(
+ asked.len(),
+ 2,
+ "a failed pass is not retried within the call"
+ );
+}
+
+#[tokio::test]
+async fn a_failed_pass_that_read_nothing_is_still_a_failure() {
+ // The read-nothing stop would otherwise end this drain as a quiet success.
+ let failed = SyncPassOutcome {
+ failure: Some("the github connector stopped without saying why".to_string()),
+ ..SyncPassOutcome::default()
+ };
+ let (out, asked) = drive(SINGLE_CALL_ITEM_BUDGET, vec![Ok(failed)]).await;
+ assert_eq!(
+ out.unwrap_err(),
+ DrainFailure {
+ error: "the github connector stopped without saying why".to_string(),
+ written: 0,
+ }
+ );
+ assert_eq!(asked.len(), 1);
+}
diff --git a/crates/openhuman-core/src/integrations/composio/ops/pass_failure.rs b/crates/openhuman-core/src/integrations/composio/ops/pass_failure.rs
new file mode 100644
index 0000000000..f42f0cd803
--- /dev/null
+++ b/crates/openhuman-core/src/integrations/composio/ops/pass_failure.rs
@@ -0,0 +1,99 @@
+//! When a connector sync pass has failed, and how long a Sources-row run waits
+//! before asking again (openhuman#6255).
+//!
+//! The connector module reports a page it could not read as
+//! [`SyncStage::Failed`]: it keeps the pages it had already read, puts the
+//! reason in the response's `message`, and leaves the batch incomplete. An
+//! incomplete batch otherwise means "call again", so a connector that failed on
+//! its first page was asked again at once, up to fifty times a click, with the
+//! reason logged nowhere. These two decisions end that: a failed pass is a
+//! failure, and the only retries are a few spaced ones.
+
+use std::time::Duration;
+
+use tinyconnectors_bus::records::{ConnectorSyncResponse, SyncStage};
+
+/// Longest failure reason kept, in characters.
+///
+/// A provider error can carry a whole response body. The reason is shown on
+/// the source row and written to the log, so it is cut rather than kept whole.
+pub(crate) const MAX_REASON_CHARS: usize = 300;
+
+/// Attempts a Sources-row run makes at a pass the connector keeps failing:
+/// the first try and two retries.
+pub(crate) const MAX_FAILED_ATTEMPTS: u32 = 3;
+
+/// Why a pass failed, or `None` for a pass that did not.
+///
+/// Only the connector's own failed stage counts. Host-side errors (the module
+/// being unavailable, a timed-out call, an ingest error) are already `Err` at
+/// 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
+/// [`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(
+ stage: SyncStage,
+ message: Option<&str>,
+ toolkit: &str,
+) -> Option<String> {
+ if stage != SyncStage::Failed {
+ return None;
+ }
+ Some(
+ message
+ .map(str::trim)
+ .filter(|message| !message.is_empty())
+ .map(clip)
+ .unwrap_or_else(|| format!("the {toolkit} connector stopped without saying why")),
+ )
+}
+
+/// The failure the connector reported for one sync pass, logged once.
+///
+/// See [`failure_reason`] for what counts. Logged here, where a pass's response
+/// is read, so every caller gets the same line, with how far the pass got
+/// before it stopped.
+pub(crate) fn pass_failure(
+ response: &ConnectorSyncResponse,
+ toolkit: &str,
+ connection_id: &str,
+) -> Option<String> {
+ let reason = failure_reason(response.stage, response.message.as_deref(), toolkit)?;
+ tracing::warn!(
+ toolkit = %toolkit,
+ connection_id = %connection_id,
+ pages_read = response.pages_read,
+ records = response.batch.records.len(),
+ reason = %reason,
+ "[composio] connector sync pass failed"
+ );
+ Some(reason)
+}
+
+/// `message` cut to [`MAX_REASON_CHARS`] characters, on a character boundary.
+fn clip(message: &str) -> String {
+ match message.char_indices().nth(MAX_REASON_CHARS) {
+ Some((cut, _)) => format!("{}…", message[..cut].trim_end()),
+ None => message.to_string(),
+ }
+}
+
+/// How long to wait before asking again after `failed_attempts` consecutive
+/// failed passes, or `None` once the run should give up.
+///
+/// Five seconds after the first failure, ten after the second, and no third
+/// retry: a transient provider error still recovers, and a connector that is
+/// broken shows its failure within about fifteen seconds instead of holding
+/// the row on "Syncing".
+pub(crate) fn retry_delay(failed_attempts: u32) -> Option<Duration> {
+ if failed_attempts == 0 || failed_attempts >= MAX_FAILED_ATTEMPTS {
+ return None;
+ }
+ Some(Duration::from_secs(5 * 2_u64.pow(failed_attempts - 1)))
+}
+
+#[cfg(test)]
+#[path = "pass_failure_tests.rs"]
+mod tests;
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
new file mode 100644
index 0000000000..f32c80fbff
--- /dev/null
+++ b/crates/openhuman-core/src/integrations/composio/ops/pass_failure_tests.rs
@@ -0,0 +1,113 @@
+//! When a connector pass counts as failed, and the Sources-row retry schedule
+//! (openhuman#6255).
+
+use super::*;
+
+#[test]
+fn only_the_connectors_failed_stage_is_a_failure() {
+ for stage in [
+ SyncStage::Requested,
+ SyncStage::Fetching,
+ SyncStage::Stored,
+ SyncStage::Ingesting,
+ SyncStage::Completed,
+ ] {
+ assert_eq!(
+ failure_reason(
+ stage,
+ Some("today's provider request budget is spent"),
+ "gmail"
+ ),
+ None,
+ "{stage:?} is not a failure, whatever its message says"
+ );
+ }
+}
+
+#[test]
+fn a_failure_carries_the_connectors_reason_trimmed() {
+ assert_eq!(
+ failure_reason(
+ SyncStage::Failed,
+ Some(" action GITHUB_SEARCH_ISSUES_AND_PULL_REQUESTS failed "),
+ "github"
+ )
+ .as_deref(),
+ Some("action GITHUB_SEARCH_ISSUES_AND_PULL_REQUESTS failed")
+ );
+}
+
+#[test]
+fn a_failure_without_a_reason_is_still_named() {
+ for message in [None, Some(""), Some(" ")] {
+ assert_eq!(
+ failure_reason(SyncStage::Failed, message, "github").as_deref(),
+ Some("the github connector stopped without saying why"),
+ "message {message:?}"
+ );
+ }
+}
+
+#[test]
+fn a_long_reason_is_cut_to_the_limit() {
+ let long = "x".repeat(MAX_REASON_CHARS + 50);
+ let reason = failure_reason(SyncStage::Failed, Some(&long), "notion").expect("a failure");
+ assert_eq!(
+ reason.chars().count(),
+ MAX_REASON_CHARS + 1,
+ "the limit plus the ellipsis"
+ );
+ assert!(reason.ends_with('…'));
+
+ let exact = "y".repeat(MAX_REASON_CHARS);
+ assert_eq!(
+ failure_reason(SyncStage::Failed, Some(&exact), "notion"),
+ Some(exact),
+ "a reason at the limit is kept whole"
+ );
+}
+
+#[test]
+fn a_reason_is_cut_on_a_character_boundary() {
+ // Multi-byte characters: a byte-offset cut would panic or split one.
+ let long = "é".repeat(MAX_REASON_CHARS + 10);
+ let reason = failure_reason(SyncStage::Failed, Some(&long), "slack").expect("a failure");
+ assert_eq!(reason.chars().count(), MAX_REASON_CHARS + 1);
+ assert!(reason.starts_with('é') && reason.ends_with('…'));
+}
+
+#[test]
+fn the_retry_schedule_waits_five_then_ten_seconds_then_gives_up() {
+ assert_eq!(retry_delay(0), None, "nothing has failed yet");
+ assert_eq!(retry_delay(1), Some(Duration::from_secs(5)));
+ assert_eq!(retry_delay(2), Some(Duration::from_secs(10)));
+ assert_eq!(
+ retry_delay(MAX_FAILED_ATTEMPTS),
+ None,
+ "the third failure ends the run"
+ );
+ assert_eq!(retry_delay(MAX_FAILED_ATTEMPTS + 7), None);
+}
+
+#[test]
+fn a_failed_response_names_its_failure() {
+ let response = ConnectorSyncResponse {
+ stage: SyncStage::Failed,
+ message: Some("GITHUB_SEARCH_ISSUES_AND_PULL_REQUESTS failed".to_string()),
+ ..ConnectorSyncResponse::default()
+ };
+ assert_eq!(
+ pass_failure(&response, "github", "ca_1").as_deref(),
+ Some("GITHUB_SEARCH_ISSUES_AND_PULL_REQUESTS failed")
+ );
+}
+
+#[test]
+fn a_response_that_stopped_short_without_failing_is_not_a_failure() {
+ let response = ConnectorSyncResponse {
+ stage: SyncStage::Completed,
+ message: Some("today's provider request budget is spent".to_string()),
+ ..ConnectorSyncResponse::default()
+ };
+ assert_eq!(pass_failure(&response, "gmail", "ca_1"), None);
+}
diff --git a/crates/openhuman-core/src/integrations/composio/ops/providers_ops.rs b/crates/openhuman-core/src/integrations/composio/ops/providers_ops.rs
index d896d42ab7..507a0dcce9 100644
--- a/crates/openhuman-core/src/integrations/composio/ops/providers_ops.rs
+++ b/crates/openhuman-core/src/integrations/composio/ops/providers_ops.rs
@@ -23,6 +23,7 @@ use super::super::types::{
use super::connections::resolve_toolkit_for_connection;
use super::connector_runs::{self, ConnectorRun};
use super::error_utils::{report_composio_op_error, OpResult};
+use super::pass_failure::{pass_failure, retry_delay};
use super::source_rows::source_sync_depth_days;
use crate::memory::api::provider::types::SourceItem;
use crate::memory::api::types::MemoryTaint;
@@ -323,6 +324,9 @@ pub async fn composio_sync_budgeted(
// absent: it describes the state the run ended in, and a pass that
// completes cleanly must not inherit the note of an earlier one.
let mut stop_note: Option<String> = None;
+ // Consecutive passes the connector reported as failed (openhuman#6255).
+ // A clean pass resets it; `retry_delay` decides when to stop asking.
+ let mut failed_attempts = 0u32;
let outcome = loop {
passes += 1;
// The source's configured per-run cap wins over the pass ceiling:
@@ -343,6 +347,31 @@ pub async fn composio_sync_budgeted(
{
Ok(pass) => {
total_written = total_written.saturating_add(u64::from(pass.written));
+ // A failed pass keeps what it read (counted above); the run
+ // waits, then asks again a bounded number of times (openhuman#6255).
+ if let Some(reason) = pass.failure {
+ failed_attempts += 1;
+ let Some(delay) = retry_delay(failed_attempts) else {
+ break Err(reason);
+ };
+ tracing::info!(
+ toolkit = %toolkit_for_log,
+ connection_id = %connection_for_log,
+ attempt = failed_attempts,
+ retry_in_secs = delay.as_secs(),
+ "[composio] connector sync pass failed; retrying"
+ );
+ publish_stage(
+ "running",
+ Some(format!(
+ "attempt {failed_attempts} failed, retrying in {}s",
+ delay.as_secs()
+ )),
+ );
+ tokio::time::sleep(delay).await;
+ continue;
+ }
+ failed_attempts = 0;
more_pending = pass.more_pending;
stop_note = pass
.message
@@ -363,6 +392,11 @@ pub async fn composio_sync_budgeted(
if !pass.more_pending {
break Ok(());
}
+ // A pass that read nothing cannot make progress, whatever it
+ // says about more (the same rule as `pass_budget`'s drain).
+ if pass.records_read == 0 {
+ break Ok(());
+ }
if passes >= MAX_PASSES {
// The cap is pacing, not failure: everything fetched is
// ingested and the next click resumes from the cursor.
@@ -479,6 +513,10 @@ pub(crate) struct SyncPassOutcome {
/// budget being spent, above all. Carried so the completed-stage detail
/// can say *why* zero items arrived instead of reading as "up to date".
pub message: Option<String>,
+ /// Why the connector stopped this pass on an error (openhuman#6255). The
+ /// counts above still stand; the caller ends or retries the run on this
+ /// instead of asking again as if the connector had only paused.
+ pub failure: Option<String>,
}
/// Read one connection through the module and ingest what it returns.
@@ -488,6 +526,10 @@ pub(crate) struct SyncPassOutcome {
/// stands, and re-deciding that here would give the run two opinions about
/// what has been read.
///
+/// A pass the connector reports as failed still ingests the pages it read and
+/// comes back as `Ok`, with [`SyncPassOutcome::failure`] set and nothing
+/// pending: whether to ask again is the caller's decision (openhuman#6255).
+///
/// `pub(crate)` — also driven by `pass_budget::run_sync_within_budget` for
/// the entry points that sync once per invocation (periodic tick, manual
/// provider sync, `connection_created`, the Slack ingest RPC), which repeat
@@ -527,14 +569,22 @@ pub(crate) async fn run_sync_pass(
)
.await?;
+ // A failed pass keeps what it read but is not "more pending": read as
+ // incomplete, a failing connector was asked again fifty times a click with
+ // its reason logged nowhere (openhuman#6255). Its message is the failure.
+ let failure = pass_failure(&response, toolkit, connection_id);
+ let more_pending = failure.is_none() && !response.batch.complete;
+ let message = response.message.filter(|_| failure.is_none());
+
let count = response.batch.records.len();
if count == 0 {
return Ok(SyncPassOutcome {
records_read: 0,
written: 0,
already_ingested: false,
- more_pending: !response.batch.complete,
- message: response.message,
+ more_pending,
+ message,
+ failure,
});
}
@@ -626,7 +676,7 @@ pub(crate) async fn run_sync_pass(
}
}
- if !response.batch.complete {
+ if more_pending {
// The module keeps its own cursor, so the next call resumes where this
// one stopped. Saying so is worth a line: a partial run that looked
// complete is how a user concludes half their mail is missing.
@@ -649,8 +699,9 @@ pub(crate) async fn run_sync_pass(
records_read: count,
written: outcome.written,
already_ingested: outcome.already_ingested,
- more_pending: !response.batch.complete,
- message: response.message,
+ more_pending,
+ message,
+ failure,
})
}