Skip to content

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

chore(composio): remove unused connector run history and periodic sync modules

Steven Enamakel3b770a3a1804
diff --git a/crates/openhuman-core/src/integrations/composio/ops/connector_runs.rs b/crates/openhuman-core/src/integrations/composio/ops/connector_runs.rs
deleted file mode 100644
index 1a30d6cce0..0000000000
--- a/crates/openhuman-core/src/integrations/composio/ops/connector_runs.rs
+++ /dev/null
@@ -1,102 +0,0 @@
-//! Sync History rows for Composio runs (openhuman#6257).
-//!
-//! Every Composio run is read by the connector module and ingested by this
-//! host, so the memory driver's audit log never sees one — the engine loop that
-//! used to write those rows left with tinymemory v1.13.4. They are recorded in
-//! the host's run log instead, at the two places a run ends: the Sources row's
-//! budgeted loop in `providers_ops`, and the single-call drain in `pass_budget`
-//! that every other entry point shares.
-
-use std::time::Instant;
-
-use chrono::{DateTime, Utc};
-
-use crate::config::Config;
-use crate::memory::api::provider::sync::SyncAuditEntry;
-use crate::memory::sources::run_history::{self, HostRun};
-
-use super::providers_ops::SOURCE_KIND;
-use super::source_rows::source_id_for_connection;
-
-/// The reason the periodic loop syncs under.
-const PERIODIC: &str = "periodic";
-
-/// Whether a finished run earns a Sync History row.
-///
-/// A run someone started always does — the Sync button, Apply all, the first
-/// sync after connecting, a provider sync, Slack's own RPC — because "did my
-/// sync happen" is the question the history answers. The periodic loop polls
-/// every connection on a short interval, and a poll that found nothing new is
-/// not a sync anyone asked about; recorded, it would bury the runs that were.
-/// So a periodic run earns a row only when it wrote something or failed.
-pub(crate) fn should_record(reason: &str, written: u64, failed: bool) -> bool {
- reason != PERIODIC || failed || written > 0
-}
-
-/// The scope a connector run files under: `{toolkit}:{connection_id}`, toolkit
-/// lowercased, both trimmed — the ingest funnel's `path_scope`, so the history
-/// row and the sealed tree name the same thing.
-pub(crate) fn connector_scope(toolkit: &str, connection_id: &str) -> String {
- format!(
- "{}:{}",
- toolkit.trim().to_ascii_lowercase(),
- connection_id.trim()
- )
-}
-
-/// One finished connector run.
-pub(crate) struct ConnectorRun<'a> {
- pub toolkit: &'a str,
- pub connection_id: &'a str,
- /// The Sources row that started the run, when one did; otherwise the row is
- /// looked up by connection.
- pub source_id: Option<&'a str>,
- pub reason: &'a str,
- pub started: Instant,
- /// Items the run wrote before it ended.
- pub written: u64,
- /// Why the run failed; `None` for a run that completed.
- pub error: Option<&'a str>,
-}
-
-/// The history row for `run`, naming `source_id` when the registry has one and
-/// the connection's scope otherwise.
-pub(crate) fn connector_run_entry(
- run: &ConnectorRun<'_>,
- source_id: Option<String>,
- finished_at: DateTime<Utc>,
-) -> SyncAuditEntry {
- let scope = connector_scope(run.toolkit, run.connection_id);
- HostRun {
- source_id: source_id.unwrap_or_else(|| scope.clone()),
- source_kind: SOURCE_KIND.to_string(),
- scope,
- items: run.written,
- duration_ms: run_history::elapsed_ms(run.started),
- error: run.error.map(str::to_string),
- ..HostRun::default()
- }
- .into_entry(finished_at)
-}
-
-/// Record `run` in the host's run log, when [`should_record`] says it earns a
-/// row.
-pub(crate) fn record(config: &Config, run: &ConnectorRun<'_>) {
- if !should_record(run.reason, run.written, run.error.is_some()) {
- tracing::debug!(
- toolkit = %run.toolkit,
- connection_id = %run.connection_id,
- "[composio] periodic run found nothing new; no history row"
- );
- return;
- }
- let source_id = run
- .source_id
- .map(str::to_string)
- .or_else(|| source_id_for_connection(config, run.toolkit, run.connection_id));
- run_history::record_run(config, connector_run_entry(run, source_id, Utc::now()));
-}
-
-#[cfg(test)]
-#[path = "connector_runs_tests.rs"]
-mod tests;
diff --git a/crates/openhuman-core/src/integrations/composio/ops/connector_runs_tests.rs b/crates/openhuman-core/src/integrations/composio/ops/connector_runs_tests.rs
deleted file mode 100644
index e5349c0ef8..0000000000
--- a/crates/openhuman-core/src/integrations/composio/ops/connector_runs_tests.rs
+++ /dev/null
@@ -1,122 +0,0 @@
-//! Which connector runs earn a history row, and the row they write
-//! (openhuman#6257).
-
-use chrono::TimeZone;
-
-use super::*;
-use crate::memory::sources::run_history::{read_runs, KEEP_ROWS};
-
-fn finished_at() -> DateTime<Utc> {
- Utc.timestamp_opt(1_789_000_000, 0)
- .single()
- .expect("a valid instant")
-}
-
-fn gmail_run(
- reason: &'static str,
- written: u64,
- error: Option<&'static str>,
-) -> ConnectorRun<'static> {
- ConnectorRun {
- toolkit: "gmail",
- connection_id: "ca_1",
- source_id: None,
- reason,
- started: Instant::now(),
- written,
- error,
- }
-}
-
-#[test]
-fn a_run_someone_started_always_earns_a_row() {
- for reason in ["manual", "connection_created"] {
- assert!(
- should_record(reason, 0, false),
- "{reason} with nothing written"
- );
- assert!(should_record(reason, 3, false), "{reason} with items");
- assert!(should_record(reason, 0, true), "{reason} that failed");
- }
-}
-
-#[test]
-fn a_periodic_run_earns_a_row_only_when_it_wrote_or_failed() {
- assert!(
- !should_record("periodic", 0, false),
- "a quiet poll adds no row"
- );
- assert!(should_record("periodic", 1, false));
- assert!(should_record("periodic", 0, true));
-}
-
-#[test]
-fn the_scope_is_the_ingest_funnels_path_scope() {
- assert_eq!(connector_scope(" GMAIL ", " ca_1 "), "gmail:ca_1");
-}
-
-#[test]
-fn the_row_names_the_source_when_one_is_known_and_the_scope_otherwise() {
- let run = gmail_run("manual", 12, None);
-
- let known = connector_run_entry(&run, Some("src_gmail".to_string()), finished_at());
- assert_eq!(known.source_id, "src_gmail");
- assert_eq!(known.source_kind, "composio");
- assert_eq!(known.scope, "gmail:ca_1");
- assert!(known.success);
- assert_eq!(known.items_fetched, 12);
- assert_eq!(known.timestamp, finished_at());
-
- let unknown = connector_run_entry(&run, None, finished_at());
- assert_eq!(unknown.source_id, "gmail:ca_1");
-}
-
-#[test]
-fn a_failed_run_row_carries_the_error_and_what_it_wrote() {
- let row = connector_run_entry(
- &gmail_run("manual", 4, Some("module unavailable")),
- None,
- finished_at(),
- );
- assert!(!row.success);
- assert_eq!(row.error.as_deref(), Some("module unavailable"));
- assert_eq!(
- row.items_fetched, 4,
- "items written before the failure are committed"
- );
-}
-
-#[test]
-fn record_skips_a_quiet_periodic_poll_and_writes_the_rest() {
- let dir = tempfile::tempdir().expect("tempdir");
- let config = Config {
- workspace_dir: dir.path().join("workspace"),
- config_path: dir.path().join("config.toml"),
- ..Config::default()
- };
-
- record(&config, &gmail_run("periodic", 0, None));
- assert!(
- read_runs(&config.workspace_dir, KEEP_ROWS)
- .expect("read the run log")
- .is_empty(),
- "a periodic poll that wrote nothing is not recorded"
- );
-
- let mut started_by_a_row = gmail_run("manual", 2, None);
- started_by_a_row.source_id = Some("src_gmail");
- record(&config, &started_by_a_row);
- record(
- &config,
- &gmail_run("periodic", 0, Some("module unavailable")),
- );
-
- let rows = read_runs(&config.workspace_dir, KEEP_ROWS).expect("read the run log");
- assert_eq!(rows.len(), 2);
- assert_eq!(rows[0].error.as_deref(), Some("module unavailable"));
- assert_eq!(
- rows[0].source_id, "gmail:ca_1",
- "no registry row for the connection, so the row names its scope"
- );
- assert_eq!(rows[1].source_id, "src_gmail");
-}
diff --git a/crates/openhuman-core/src/integrations/composio/ops/pass_budget.rs b/crates/openhuman-core/src/integrations/composio/ops/pass_budget.rs
deleted file mode 100644
index a1330ee7f8..0000000000
--- a/crates/openhuman-core/src/integrations/composio/ops/pass_budget.rs
+++ /dev/null
@@ -1,157 +0,0 @@
-//! Drain a connection within one invocation's item budget, one bounded pass
-//! at a time (openhuman#6025).
-//!
-//! `SYNC_PASS_MAX_ITEMS` dropped from 500 to 200 so that a single
-//! `AcceptSourceItems` call fits the host's 15-minute deadline. The entry
-//! points that make one sync call per invocation — the periodic tick, the
-//! manual provider sync, the `connection_created` initial sync and the Slack
-//! ingest RPC — used to hand the whole 500 to that one pass. Handing them 200
-//! would stop an account with 201–500 records short and still report the run
-//! complete (Codex review finding on #6026). So they keep the per-invocation
-//! budget they had, and spend it in passes the deadline can hold: each pass
-//! is sized by [`next_pass_budget`], and the loop ends when the connector
-//! reports the end or the budget is spent.
-
-use std::future::Future;
-
-use super::providers_ops::{next_pass_budget, run_sync_pass, SyncPassOutcome};
-use crate::config::Config;
-
-/// Records one single-call entry point may read per invocation — the ceiling
-/// those callers had when a pass was 500 items. Read, not written: the old
-/// call's budget was what the module fetched, and a record the driver already
-/// held still spent it. The Sources-row button is not bound by this: it loops
-/// `composio_sync_budgeted` under its own cap.
-pub(crate) const SINGLE_CALL_ITEM_BUDGET: u32 = 500;
-
-/// Passes one call may make before it stops regardless — the same bound the
-/// Sources-row loop uses. Unreachable with full pages (three passes spend the
-/// budget); it exists so a module that keeps answering "more pending" with a
-/// trickle cannot pin the caller.
-const SINGLE_CALL_MAX_PASSES: usize = 50;
-
-/// A drain a pass error ended, with what the passes before it wrote.
-///
-/// Those writes are committed by the driver whatever the later pass did, so the
-/// run's history row reports them rather than zero (Codex review on #6264).
-#[derive(Debug, PartialEq)]
-pub(crate) struct DrainFailure {
- /// The failing pass's error.
- pub error: String,
- /// 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,
-}
-
-/// Run passes until the connector reports the end, `budget` records have been
-/// read, a pass reads nothing, or [`SINGLE_CALL_MAX_PASSES`] is reached; each
-/// pass is capped at `SYNC_PASS_MAX_ITEMS` through [`next_pass_budget`].
-///
-/// 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, 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,
-) -> Result<SyncPassOutcome, DrainFailure>
-where
- F: FnMut(usize) -> Fut,
- Fut: Future<Output = Result<SyncPassOutcome, String>>,
-{
- let mut total = SyncPassOutcome {
- already_ingested: true,
- ..SyncPassOutcome::default()
- };
- let mut read: u64 = 0;
- let mut passes = 0usize;
- while let Some(pass_budget) = next_pass_budget(Some(budget), read) {
- if passes >= SINGLE_CALL_MAX_PASSES {
- break;
- }
- let pass = match run_pass(pass_budget).await {
- Ok(pass) => pass,
- Err(error) => {
- return Err(DrainFailure {
- error,
- written: total.written,
- });
- }
- };
- passes += 1;
- read = read.saturating_add(u64::try_from(pass.records_read).unwrap_or(u64::MAX));
- total.records_read = total.records_read.saturating_add(pass.records_read);
- total.written = total.written.saturating_add(pass.written);
- 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 {
- break;
- }
- }
- if passes > 1 {
- tracing::debug!(
- passes,
- written = total.written,
- more_pending = total.more_pending,
- "[composio] single-call sync spent its budget across passes"
- );
- }
- Ok(total)
-}
-
-/// [`run_sync_pass`] for the single-call entry points: the same
-/// tinyconnectors-mediated pass, repeated within [`SINGLE_CALL_ITEM_BUDGET`].
-///
-/// Also where each of those runs gets its Sync History row (openhuman#6257):
-/// the periodic tick, the first sync after connecting, a provider sync and the
-/// Slack RPC all end here, so recording at the callers would be four copies of
-/// one rule. A drain a later pass fails still records what its earlier passes
-/// wrote: the driver has committed those.
-pub(crate) async fn run_sync_within_budget(
- config: &Config,
- toolkit: &str,
- connection_id: &str,
- reason: &str,
-) -> Result<SyncPassOutcome, String> {
- let started = std::time::Instant::now();
- let result = run_passes_within_budget(SINGLE_CALL_ITEM_BUDGET, |pass_budget| {
- run_sync_pass(config, toolkit, connection_id, reason, pass_budget)
- })
- .await;
- let (written, error) = match &result {
- Ok(pass) => (pass.written, None),
- Err(failure) => (failure.written, Some(failure.error.as_str())),
- };
- super::connector_runs::record(
- config,
- &super::connector_runs::ConnectorRun {
- toolkit,
- connection_id,
- source_id: None,
- reason,
- started,
- written: u64::from(written),
- error,
- },
- );
- result.map_err(|failure| failure.error)
-}
-
-#[cfg(test)]
-#[path = "pass_budget_tests.rs"]
-mod tests;
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
deleted file mode 100644
index 00b9b4e67a..0000000000
--- a/crates/openhuman-core/src/integrations/composio/ops/pass_budget_tests.rs
+++ /dev/null
@@ -1,286 +0,0 @@
-//! The budgeted drain the single-call sync entry points run (openhuman#6025).
-//!
-//! Scripted passes stand in for the connector: each test says what the
-//! module would return per call and asserts which pass budgets were asked for
-//! and what the aggregate reports.
-
-use std::cell::RefCell;
-use std::collections::VecDeque;
-
-use super::super::providers_ops::{SyncPassOutcome, SYNC_PASS_MAX_ITEMS};
-use super::{run_passes_within_budget, DrainFailure, SINGLE_CALL_ITEM_BUDGET};
-
-fn pass(written: u32, more_pending: bool) -> SyncPassOutcome {
- SyncPassOutcome {
- records_read: written as usize,
- written,
- already_ingested: false,
- more_pending,
- message: None,
- failure: None,
- }
-}
-
-/// Drive the loop with a scripted connector; returns the outcome and the
-/// per-pass budgets it asked for, in order.
-async fn drive(
- budget: u32,
- script: Vec<Result<SyncPassOutcome, String>>,
-) -> (Result<SyncPassOutcome, DrainFailure>, Vec<usize>) {
- let script = RefCell::new(VecDeque::from(script));
- let asked = RefCell::new(Vec::new());
- let out = run_passes_within_budget(budget, |pass_budget| {
- asked.borrow_mut().push(pass_budget);
- let next = script
- .borrow_mut()
- .pop_front()
- .expect("the loop asked for more passes than the script holds");
- async move { next }
- })
- .await;
- (out, asked.into_inner())
-}
-
-#[tokio::test]
-async fn stops_when_the_connector_reports_the_end() {
- // 320 records: one full pass, then a short one that says "done".
- let (out, asked) = drive(
- SINGLE_CALL_ITEM_BUDGET,
- vec![Ok(pass(200, true)), Ok(pass(120, false))],
- )
- .await;
- let out = out.expect("both passes succeed");
- assert_eq!(asked, vec![SYNC_PASS_MAX_ITEMS, SYNC_PASS_MAX_ITEMS]);
- assert_eq!(out.written, 320);
- assert_eq!(out.records_read, 320);
- assert!(!out.more_pending, "the last pass's word wins");
-}
-
-#[tokio::test]
-async fn stops_when_the_budget_is_spent_and_says_more_is_pending() {
- // An account bigger than the budget: 200 + 200 + the 100 remainder, then
- // stop even though the connector still has more — that is the ceiling the
- // single-call entry points always had, now in deadline-sized calls.
- let (out, asked) = drive(
- SINGLE_CALL_ITEM_BUDGET,
- vec![
- Ok(pass(200, true)),
- Ok(pass(200, true)),
- Ok(pass(100, true)),
- ],
- )
- .await;
- let out = out.expect("all passes succeed");
- assert_eq!(asked, vec![SYNC_PASS_MAX_ITEMS, SYNC_PASS_MAX_ITEMS, 100]);
- assert_eq!(out.written, u32::try_from(SINGLE_CALL_ITEM_BUDGET).unwrap());
- assert!(
- out.more_pending,
- "the caller must learn the account is not drained"
- );
-}
-
-#[tokio::test]
-async fn a_small_account_is_still_one_pass() {
- let (out, asked) = drive(SINGLE_CALL_ITEM_BUDGET, vec![Ok(pass(37, false))]).await;
- let out = out.expect("one pass succeeds");
- assert_eq!(asked, vec![SYNC_PASS_MAX_ITEMS]);
- assert_eq!(out.written, 37);
- assert!(!out.more_pending);
-}
-
-#[tokio::test]
-async fn a_pass_error_ends_the_run_with_that_error_and_the_earlier_writes() {
- let (out, asked) = drive(
- SINGLE_CALL_ITEM_BUDGET,
- vec![Ok(pass(200, true)), Err("module went away".to_string())],
- )
- .await;
- // The first pass's 200 records are committed whatever the second did, so
- // the run's history row reports them (openhuman#6257).
- assert_eq!(
- out.unwrap_err(),
- DrainFailure {
- error: "module went away".to_string(),
- written: 200,
- }
- );
- assert_eq!(asked.len(), 2, "no pass is attempted after the failure");
-}
-
-#[tokio::test]
-async fn a_first_pass_error_reports_nothing_written() {
- let (out, asked) = drive(
- SINGLE_CALL_ITEM_BUDGET,
- vec![Err("connector refused the call".to_string())],
- )
- .await;
- assert_eq!(
- out.unwrap_err(),
- DrainFailure {
- error: "connector refused the call".to_string(),
- written: 0,
- }
- );
- assert_eq!(asked.len(), 1);
-}
-
-#[tokio::test]
-async fn already_ingested_holds_only_when_every_pass_was_a_no_op() {
- let noop = SyncPassOutcome {
- records_read: 200,
- written: 0,
- already_ingested: true,
- more_pending: true,
- message: None,
- failure: None,
- };
- let last = SyncPassOutcome {
- more_pending: false,
- ..noop.clone()
- };
- let (out, _) = drive(SINGLE_CALL_ITEM_BUDGET, vec![Ok(noop.clone()), Ok(last)]).await;
- let out = out.expect("passes succeed");
- assert!(out.already_ingested, "two no-op passes are a no-op run");
- assert_eq!(out.records_read, 400);
- assert_eq!(out.written, 0);
-
- let (out, _) = drive(SINGLE_CALL_ITEM_BUDGET, vec![Ok(noop), Ok(pass(5, false))]).await;
- assert!(
- !out.expect("passes succeed").already_ingested,
- "one write makes it a run that wrote"
- );
-}
-
-#[tokio::test]
-async fn the_last_pass_note_wins_present_or_absent() {
- let noted = SyncPassOutcome {
- message: Some(" daily request budget spent ".to_string()),
- ..pass(200, true)
- };
- let noted = SyncPassOutcome {
- more_pending: false,
- ..noted
- };
- let (out, _) = drive(
- SINGLE_CALL_ITEM_BUDGET,
- vec![Ok(pass(200, true)), Ok(noted)],
- )
- .await;
- assert_eq!(
- out.expect("passes succeed").message.as_deref(),
- Some(" daily request budget spent "),
- "the note rides through untouched; the stage detail trims it"
- );
-
- let noted = SyncPassOutcome {
- message: Some("stopped short".to_string()),
- ..pass(200, true)
- };
- let (out, _) = drive(
- SINGLE_CALL_ITEM_BUDGET,
- vec![Ok(noted), Ok(pass(10, false))],
- )
- .await;
- assert_eq!(
- out.expect("passes succeed").message,
- None,
- "a pass that completes cleanly must not inherit an earlier pass's note"
- );
-}
-
-#[tokio::test]
-async fn the_budget_counts_records_read_not_records_written() {
- // Everything the module returns is already ingested, and it keeps saying
- // more is pending. The old single call fetched 500 and stopped; so does
- // this — charging the budget by writes would ask forever.
- let noop = SyncPassOutcome {
- records_read: 200,
- written: 0,
- already_ingested: true,
- more_pending: true,
- message: None,
- failure: None,
- };
- let (out, asked) = drive(
- SINGLE_CALL_ITEM_BUDGET,
- vec![
- Ok(noop.clone()),
- Ok(noop.clone()),
- Ok(SyncPassOutcome {
- records_read: 100,
- ..noop
- }),
- ],
- )
- .await;
- let out = out.expect("passes succeed");
- assert_eq!(asked, vec![SYNC_PASS_MAX_ITEMS, SYNC_PASS_MAX_ITEMS, 100]);
- assert_eq!(out.records_read, 500);
- assert_eq!(out.written, 0);
- assert!(out.more_pending);
-}
-
-#[tokio::test]
-async fn a_pass_that_reads_nothing_ends_the_run() {
- // "More pending" with an empty page cannot be acted on: asking again
- // would fetch the same nothing. One pass, then stop.
- let empty = SyncPassOutcome {
- records_read: 0,
- written: 0,
- 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");
- assert_eq!(asked.len(), 1);
- 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/source_rows.rs b/crates/openhuman-core/src/integrations/composio/ops/source_rows.rs
deleted file mode 100644
index f629d24a94..0000000000
--- a/crates/openhuman-core/src/integrations/composio/ops/source_rows.rs
+++ /dev/null
@@ -1,133 +0,0 @@
-//! Which memory-sources registry row a Composio connection belongs to.
-//!
-//! One matching rule with more than one reader: the pass's sync-depth cap and
-//! the history row's source id both find the row this way (openhuman#6257).
-//! Call sites that each open-code one row rule are how two of them came to
-//! disagree before (openhuman#6007).
-
-use crate::config::Config;
-use crate::memory::sources::SourceKind;
-
-/// Whether a registry row's toolkit and connection name this connection.
-///
-/// Matched the way the engine keys the rows: toolkit case-insensitively and
-/// trimmed, connection trimmed.
-fn names_connection(
- row_toolkit: Option<&str>,
- row_connection: Option<&str>,
- toolkit: &str,
- connection_id: &str,
-) -> bool {
- row_toolkit.is_some_and(|slug| slug.trim().eq_ignore_ascii_case(toolkit.trim()))
- && row_connection.is_some_and(|id| id.trim() == connection_id.trim())
-}
-
-/// The per-source "Sync depth (days)" cap for one connection, from the
-/// memory-sources registry the pass's own `config` names.
-///
-/// Resolved here rather than threaded through every caller because there are
-/// five of them (the row button, All In, the periodic loop, the connection
-/// bootstrap, Slack's own RPC), and `max_items` already showed what happens
-/// when each open-codes the same rule: two of the five disagreed
-/// (openhuman#6007). Read through `config`, not the process environment: a
-/// pass is bound to one workspace, and the global registry path would answer a
-/// caller bound to workspace B with workspace A's rows — the cross-workspace
-/// leak the registry's `_in` variants exist to prevent. `None` when the row is
-/// missing, carries no cap, or the registry cannot be read — each means "no
-/// lower bound", which is what every release before the field existed did, so
-/// a registry hiccup degrades to the old behaviour rather than to a failed
-/// sync.
-pub(super) fn source_sync_depth_days(
- config: &Config,
- toolkit: &str,
- connection_id: &str,
-) -> Option<u32> {
- let sources = match crate::memory::sources::registry::list_sources_in(config) {
- Ok(sources) => sources,
- Err(error) => {
- tracing::warn!(
- toolkit = %toolkit,
- connection_id = %connection_id,
- error = %error,
- "[composio] memory-sources registry unreadable for the sync depth; \
- syncing without a lower bound"
- );
- return None;
- }
- };
- pick_source_sync_depth_days(
- sources
- .iter()
- .filter(|source| source.kind == SourceKind::Composio)
- .map(|source| {
- (
- source.toolkit.as_deref(),
- source.connection_id.as_deref(),
- source.sync_depth_days,
- )
- }),
- toolkit,
- connection_id,
- )
-}
-
-/// The cap of the row matching `toolkit` and `connection_id`, if any.
-///
-/// Matched by [`names_connection`], and a cap of zero reads as none: the
-/// settings field stores "unlimited" as an empty value, and a zero typed by
-/// hand would otherwise ask Gmail for mail newer than today.
-pub(crate) fn pick_source_sync_depth_days<'a>(
- rows: impl IntoIterator<Item = (Option<&'a str>, Option<&'a str>, Option<u32>)>,
- toolkit: &str,
- connection_id: &str,
-) -> Option<u32> {
- rows.into_iter()
- .find_map(|(row_toolkit, row_connection, depth)| {
- names_connection(row_toolkit, row_connection, toolkit, connection_id)
- .then_some(depth)
- .flatten()
- .filter(|days| *days > 0)
- })
-}
-
-/// The registry id of the Composio row for this connection, if the pass's
-/// workspace has one.
-///
-/// `None` when no row matches or the registry cannot be read. A history row
-/// then names the connection's scope instead, which still identifies the run
-/// it describes, so neither case is worth failing a recording over.
-pub(super) fn source_id_for_connection(
- config: &Config,
- toolkit: &str,
- connection_id: &str,
-) -> Option<String> {
- let sources = match crate::memory::sources::registry::list_sources_in(config) {
- Ok(sources) => sources,
- Err(error) => {
- tracing::warn!(
- toolkit = %toolkit,
- connection_id = %connection_id,
- error = %error,
- "[composio] memory-sources registry unreadable; the run's history row \
- names its scope instead of a source"
- );
- return None;
- }
- };
- sources
- .into_iter()
- .find(|source| {
- source.kind == SourceKind::Composio
- && names_connection(
- source.toolkit.as_deref(),
- source.connection_id.as_deref(),
- toolkit,
- connection_id,
- )
- })
- .map(|source| source.id)
-}
-
-#[cfg(test)]
-#[path = "source_rows_tests.rs"]
-mod tests;
diff --git a/crates/openhuman-core/src/integrations/composio/ops/source_rows_tests.rs b/crates/openhuman-core/src/integrations/composio/ops/source_rows_tests.rs
deleted file mode 100644
index 33aba855ad..0000000000
--- a/crates/openhuman-core/src/integrations/composio/ops/source_rows_tests.rs
+++ /dev/null
@@ -1,112 +0,0 @@
-//! Which registry row a Composio connection belongs to (openhuman#6257).
-//!
-//! Driven through a real registry file: `list_sources_in` reads the config the
-//! pass names, so each test writes one and points its `Config` at it.
-
-use super::*;
-use crate::memory::sources::MemorySourceEntry;
-
-fn composio(
- id: &str,
- toolkit: &str,
- connection_id: &str,
- depth_days: Option<u32>,
-) -> MemorySourceEntry {
- let mut entry: MemorySourceEntry = serde_json::from_value(serde_json::json!({
- "id": id,
- "kind": "composio",
- "label": format!("{toolkit} source"),
- "enabled": true,
- "toolkit": toolkit,
- "connection_id": connection_id,
- }))
- .expect("a valid composio source entry");
- entry.sync_depth_days = depth_days;
- entry
-}
-
-fn folder(id: &str) -> MemorySourceEntry {
- serde_json::from_value(serde_json::json!({
- "id": id,
- "kind": "folder",
- "label": "Notes",
- "enabled": true,
- "path": ".",
- }))
- .expect("a valid folder source entry")
-}
-
-/// A config whose registry holds `entries`. The tempdir is returned so it
-/// outlives the test body.
-fn config_with(entries: &[MemorySourceEntry]) -> (tempfile::TempDir, Config) {
- let dir = tempfile::tempdir().expect("tempdir");
- let config = Config {
- workspace_dir: dir.path().join("workspace"),
- config_path: dir.path().join("config.toml"),
- ..Config::default()
- };
- crate::memory::sources::registry::replace_sources_in(&config, entries)
- .expect("write the registry");
- (dir, config)
-}
-
-#[test]
-fn a_connection_resolves_to_its_own_registry_row() {
- let (_dir, config) = config_with(&[
- folder("src_notes"),
- composio("src_gmail_work", "gmail", "ca_work", Some(30)),
- composio("src_gmail_home", "gmail", "ca_home", None),
- composio("src_notion", "notion", "ca_work", Some(14)),
- ]);
-
- assert_eq!(
- source_id_for_connection(&config, "gmail", "ca_home").as_deref(),
- Some("src_gmail_home"),
- "two connections of one toolkit are told apart by connection"
- );
- assert_eq!(
- source_id_for_connection(&config, " GMAIL ", "ca_work ").as_deref(),
- Some("src_gmail_work"),
- "matched the way the engine keys the rows: trimmed, toolkit case-insensitive"
- );
- assert_eq!(
- source_id_for_connection(&config, "notion", "ca_work").as_deref(),
- Some("src_notion"),
- "one connection id under two toolkits is told apart by toolkit"
- );
- assert_eq!(
- source_id_for_connection(&config, "gmail", "ca_unknown"),
- None
- );
-}
-
-#[test]
-fn the_depth_cap_comes_from_the_same_row() {
- let (_dir, config) = config_with(&[
- composio("src_gmail_work", "gmail", "ca_work", Some(30)),
- composio("src_gmail_home", "gmail", "ca_home", None),
- ]);
-
- assert_eq!(
- source_sync_depth_days(&config, "gmail", "ca_work"),
- Some(30)
- );
- assert_eq!(source_sync_depth_days(&config, "gmail", "ca_home"), None);
- assert_eq!(source_sync_depth_days(&config, "slack", "ca_work"), None);
-}
-
-#[test]
-fn an_unreadable_registry_degrades_to_no_row() {
- let dir = tempfile::tempdir().expect("tempdir");
- // A directory where the config file should be cannot be read as one.
- let config_path = dir.path().join("config.toml");
- std::fs::create_dir_all(&config_path).expect("occupy the config path");
- let config = Config {
- workspace_dir: dir.path().join("workspace"),
- config_path,
- ..Config::default()
- };
-
- assert_eq!(source_id_for_connection(&config, "gmail", "ca_work"), None);
- assert_eq!(source_sync_depth_days(&config, "gmail", "ca_work"), None);
-}
diff --git a/crates/openhuman-core/src/integrations/composio/periodic.rs b/crates/openhuman-core/src/integrations/composio/periodic.rs
deleted file mode 100644
index fd86477923..0000000000
--- a/crates/openhuman-core/src/integrations/composio/periodic.rs
+++ /dev/null
@@ -1,148 +0,0 @@
-//! Periodic Composio connection sync, driven by this host.
-//!
-//! # Why this is host code now, and not a shim
-//!
-//! This used to be `pub use memory_sync::composio::periodic::*` — engine code
-//! (`tinymemory_core::sync::composio::periodic`) running in this process
-//! against the in-process engine. tinymemory v1.13.4 deleted that module
-//! along with the rest of the in-process Composio pipeline (reaching a
-//! connected account needs a credential the engine must not hold), and the
-//! `tinymemory-module` this host loads never grew a replacement — its own
-//! `crate::composio` bridge, referenced in its own docs, does not exist in
-//! the pinned release either. So nothing anywhere in this build runs a
-//! periodic Composio sync unless this file does it.
-//!
-//! The mechanics are unchanged in spirit: on a tick, list every active
-//! connection, skip toolkits/connections that synced recently enough, and
-//! read+ingest the rest through [`super::ops::run_sync_pass`] — the same
-//! `tinyconnectors` → `MemorySourceSink::accept_source_items` path every other
-//! sync entry point in this domain uses.
-//!
-//! # What did not carry over
-//!
-//! The deleted engine tracked cost (`actions_called`, `provider_cost_usd`)
-//! and a persisted per-connection cursor across restarts. Neither survives
-//! here: `ConnectorSyncResponse` carries no cost field, and "due to sync" is
-//! tracked in an in-process map rather than on disk, so a process restart
-//! forgets when a connection last ran and syncs it on the next tick rather
-//! than waiting out the remainder of its interval. Both are worth knowing if
-//! Composio spend or sync cadence ever needs auditing across a restart.
-
-use std::collections::HashMap;
-use std::sync::{Mutex, OnceLock};
-use std::time::{Duration, Instant};
-
-use super::providers::native_provider_sync_interval_secs;
-
-/// How often the loop wakes up to check whether anything is due. Independent
-/// of any one toolkit's own interval — this is just the polling granularity.
-const TICK_INTERVAL: Duration = Duration::from_secs(60);
-
-/// Guards [`start_periodic_sync`] so a second call (e.g. a second embedder
-/// boot path) does not spawn a second loop.
-static STARTED: OnceLock<()> = OnceLock::new();
-
-/// When each `(toolkit, connection_id)` last completed a sync — either the
-/// periodic loop's own run or a trigger-driven one recorded through
-/// [`record_sync_success`].
-fn last_synced() -> &'static Mutex<HashMap<(String, String), Instant>> {
- static LAST_SYNCED: OnceLock<Mutex<HashMap<(String, String), Instant>>> = OnceLock::new();
- LAST_SYNCED.get_or_init(|| Mutex::new(HashMap::new()))
-}
-
-/// Record that `(toolkit, connection_id)` just synced successfully outside
-/// the periodic loop (a trigger-driven sync), so the next tick does not
-/// immediately re-run it.
-pub fn record_sync_success(toolkit: &str, connection_id: &str) {
- let key = (toolkit.to_ascii_lowercase(), connection_id.to_string());
- if let Ok(mut map) = last_synced().lock() {
- map.insert(key, Instant::now());
- }
-}
-
-/// Start the periodic Composio sync loop. Idempotent — a second call is a
-/// no-op.
-pub fn start_periodic_sync() {
- if STARTED.set(()).is_err() {
- log::debug!("[composio:periodic] start_periodic_sync called again; loop already running");
- return;
- }
- log::info!("[composio:periodic] starting periodic Composio sync loop (tick={TICK_INTERVAL:?})");
- tokio::spawn(async move {
- loop {
- tokio::time::sleep(TICK_INTERVAL).await;
- if let Err(error) = run_one_tick().await {
- log::warn!("[composio:periodic] tick failed: {error}");
- }
- }
- });
-}
-
-/// One pass over every active connection: sync whichever toolkits are due.
-async fn run_one_tick() -> Result<(), String> {
- let config = crate::config::rpc::load_config_with_timeout().await?;
-
- let connections = crate::integrations::composio::ops::composio_list_connections(&config)
- .await
- .map_err(|error| format!("list_connections: {error}"))?
- .value
- .connections;
-
- for conn in connections {
- if !conn.is_active() {
- continue;
- }
- let toolkit = conn.normalized_toolkit();
-
- // A toolkit with no periodic interval opted out entirely — matches
- // `ComposioProvider::sync_interval_secs() -> None` in the deleted
- // engine, now answered by the catalog instead of a provider instance.
- let Some(interval_secs) = native_provider_sync_interval_secs(&toolkit) else {
- continue;
- };
-
- let key = (toolkit.clone(), conn.id.clone());
- let due = {
- let map = last_synced()
- .lock()
- .map_err(|_| "sync bookkeeping lock poisoned".to_string())?;
- match map.get(&key) {
- Some(last) => last.elapsed() >= Duration::from_secs(interval_secs),
- None => true,
- }
- };
- if !due {
- continue;
- }
-
- match crate::integrations::composio::ops::run_sync_within_budget(
- &config, &toolkit, &conn.id, "periodic",
- )
- .await
- {
- Ok(pass) => {
- log::debug!(
- "[composio:periodic] toolkit={toolkit} connection={} synced \
- records_read={} written={} more_pending={}",
- conn.id,
- pass.records_read,
- pass.written,
- pass.more_pending
- );
- record_sync_success(&toolkit, &conn.id);
- }
- Err(error) => {
- log::warn!(
- "[composio:periodic] toolkit={toolkit} connection={} sync failed: {error}",
- conn.id
- );
- // Record the attempt regardless of outcome: a connection that
- // keeps failing must not be retried every tick, which would
- // turn one broken account into a hot loop against the module.
- record_sync_success(&toolkit, &conn.id);
- }
- }
- }
-
- Ok(())
-}