Skip to content

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

refactor(composio): drop DispatchCtx params from store helpers

Steven Enamakel91d31218ff38
diff --git a/crates/openhuman-core/src/integrations/composio/file_store.rs b/crates/openhuman-core/src/integrations/composio/file_store.rs
index f24cd80b59..d44a688daa 100644
--- a/crates/openhuman-core/src/integrations/composio/file_store.rs
+++ b/crates/openhuman-core/src/integrations/composio/file_store.rs
@@ -25,14 +25,13 @@ pub(crate) const USER_SCOPES_FILE: &str = "composio_user_scopes.json";
/// ever read, never renamed or rewritten, so the old data stays byte-identical.
/// A missing file is the common case and a no-op.
async fn import_legacy(
- ctx: &crate::core::runtime::DispatchCtx,
config: &Config,
docs: &super::file_store_documents::Docs,
name: &'static str,
) -> Result<(), String> {
let marker_docs = docs.clone();
let done =
- ctx.spawn_blocking(move || marker_docs.legacy_imported(name))
+ crate::core::runtime::DispatchCtx::ambient().spawn_blocking(move || marker_docs.legacy_imported(name))
.await
.map_err(|error| format!("[composio:store] checking legacy {name} failed: {error}"))?
.map_err(|error| {
@@ -55,7 +54,7 @@ async fn import_legacy(
.map_err(|error| format!("[composio:store] parsing legacy {name} failed: {error}"))?;
let docs = docs.clone();
let wrote =
- ctx.spawn_blocking(move || docs.import_if_absent(name, value))
+ crate::core::runtime::DispatchCtx::ambient().spawn_blocking(move || docs.import_if_absent(name, value))
.await
.map_err(|error| format!("[composio:store] importing legacy {name} failed: {error}"))?
.map_err(|error| {
@@ -70,19 +69,16 @@ async fn import_legacy(
/// # Errors
///
/// The value cannot be read or does not parse as `T`.
-pub(crate) async fn load<T>(
- ctx: &crate::core::runtime::DispatchCtx,
- config: &Config, name: &'static str,
-) -> Result<T, String>
+pub(crate) async fn load<T>(config: &Config, name: &'static str) -> Result<T, String>
where
T: DeserializeOwned + Default + Send + 'static,
{
let docs = super::file_store_documents::current(&config.workspace_dir)
.map_err(|e| format!("[composio:store] {e:#}"))?;
- import_legacy(ctx, config, &docs, name).await?;
+ import_legacy(config, &docs, name).await?;
// The document port is reached through a blocking bridge; keep it off the
// async worker, under the caller's context.
- ctx.spawn_blocking(move || docs.load(name))
+ crate::core::runtime::DispatchCtx::ambient().spawn_blocking(move || docs.load(name))
.await
.map_err(|error| format!("[composio:store] reading {name} failed: {error}"))?
.map_err(|error| format!("[composio:store] reading {name} failed: {error:#}"))
@@ -96,7 +92,6 @@ where
///
/// The value cannot be read or written.
pub(crate) async fn update<T, R>(
- ctx: &crate::core::runtime::DispatchCtx,
config: &Config,
name: &'static str,
change: impl Fn(&mut T) -> (R, bool) + Send + 'static,
@@ -107,8 +102,8 @@ where
{
let docs = super::file_store_documents::current(&config.workspace_dir)
.map_err(|e| format!("[composio:store] {e:#}"))?;
- import_legacy(ctx, config, &docs, name).await?;
- ctx.spawn_blocking(move || docs.update(name, change))
+ import_legacy(config, &docs, name).await?;
+ crate::core::runtime::DispatchCtx::ambient().spawn_blocking(move || docs.update(name, change))
.await
.map_err(|error| format!("[composio:store] updating {name} failed: {error}"))?
.map_err(|error| format!("[composio:store] updating {name} failed: {error:#}"))
@@ -120,12 +115,7 @@ where
///
/// The value cannot be serialized or written.
#[cfg(test)]
-pub(crate) async fn save<T>(
- ctx: &crate::core::runtime::DispatchCtx,
- config: &Config,
- name: &'static str,
- value: &T,
-) -> Result<(), String>
+pub(crate) async fn save<T>(config: &Config, name: &'static str, value: &T) -> Result<(), String>
where
T: Serialize,
{
@@ -133,7 +123,7 @@ where
.map_err(|e| format!("[composio:store] {e:#}"))?;
let value = serde_json::to_value(value)
.map_err(|error| format!("[composio:store] serializing failed: {error}"))?;
- ctx.spawn_blocking(move || docs.save(name, &value))
+ crate::core::runtime::DispatchCtx::ambient().spawn_blocking(move || docs.save(name, &value))
.await
.map_err(|error| format!("[composio:store] writing {name} failed: {error}"))?
.map_err(|error| format!("[composio:store] writing {name} failed: {error:#}"))
diff --git a/crates/openhuman-core/src/integrations/composio/identity_store.rs b/crates/openhuman-core/src/integrations/composio/identity_store.rs
index ffeadef8f9..d372660c9c 100644
--- a/crates/openhuman-core/src/integrations/composio/identity_store.rs
+++ b/crates/openhuman-core/src/integrations/composio/identity_store.rs
@@ -26,7 +26,6 @@ use super::file_store::{self, IDENTITIES_FILE};
///
/// The identities file cannot be read or written.
pub async fn persist_provider_profile(
- ctx: &crate::core::runtime::DispatchCtx,
config: &Config,
profile: &ProviderUserProfile,
) -> Result<usize, String> {
@@ -49,7 +48,6 @@ pub async fn persist_provider_profile(
let written = rows.len();
let (key_source, key_identifier) = (toolkit.clone(), identifier.clone());
file_store::update(
- ctx,
config,
IDENTITIES_FILE,
move |identities: &mut Vec<ConnectedIdentity>| {
@@ -155,11 +153,8 @@ fn json_str<'a>(v: &'a serde_json::Value, key: &str) -> Option<&'a str> {
/// # Errors
///
/// The identities file exists but cannot be read or parsed.
-pub async fn load_connected_identities(
- ctx: &crate::core::runtime::DispatchCtx,
- config: &Config,
-) -> Result<Vec<ConnectedIdentity>, String> {
- file_store::load(ctx, config, IDENTITIES_FILE).await
+pub async fn load_connected_identities(config: &Config) -> Result<Vec<ConnectedIdentity>, String> {
+ file_store::load(config, IDENTITIES_FILE).await
}
/// Delete the stored identity for a `(source, connection_id)` pair — used on
@@ -169,7 +164,6 @@ pub async fn load_connected_identities(
///
/// The identities file cannot be read or written.
pub async fn delete_connected_identity_facets(
- ctx: &crate::core::runtime::DispatchCtx,
config: &Config,
source: &str,
identifier: &str,
@@ -182,7 +176,6 @@ pub async fn delete_connected_identity_facets(
let identifier = keys.next().unwrap_or_default();
file_store::update(
- ctx,
config,
IDENTITIES_FILE,
move |identities: &mut Vec<ConnectedIdentity>| {
diff --git a/crates/openhuman-core/src/integrations/composio/ops/scope_prefs.rs b/crates/openhuman-core/src/integrations/composio/ops/scope_prefs.rs
index 16edaf1d0b..0e366e078b 100644
--- a/crates/openhuman-core/src/integrations/composio/ops/scope_prefs.rs
+++ b/crates/openhuman-core/src/integrations/composio/ops/scope_prefs.rs
@@ -56,7 +56,7 @@ fn migrated() -> &'static Mutex<HashSet<PathBuf>> {
/// Move rows still in the legacy workspace file into the module, then empty
/// the file. A failure leaves the file untouched and is retried on the next
/// call, so no stored preference is lost to a transient module error.
-async fn migrate_legacy(ctx: &crate::core::runtime::DispatchCtx, config: &Config) {
+async fn migrate_legacy(config: &Config) {
let workspace = config.workspace_dir.clone();
if migrated()
.lock()
@@ -65,7 +65,7 @@ async fn migrate_legacy(ctx: &crate::core::runtime::DispatchCtx, config: &Config
{
return;
}
- let rows = match file_store::load::<LegacyScopeFile>(ctx, config, USER_SCOPES_FILE).await {
+ let rows = match file_store::load::<LegacyScopeFile>(config, USER_SCOPES_FILE).await {
Ok(rows) => rows,
Err(error) => {
// Unreadable is not "no rows": keep the file and try again later.
@@ -91,7 +91,7 @@ async fn migrate_legacy(ctx: &crate::core::runtime::DispatchCtx, config: &Config
}
if !rows.is_empty() {
let cleared =
- file_store::update(ctx, config, USER_SCOPES_FILE, |prefs: &mut LegacyScopeFile| {
+ file_store::update(config, USER_SCOPES_FILE, |prefs: &mut LegacyScopeFile| {
prefs.clear();
((), true)
})
@@ -112,8 +112,8 @@ async fn migrate_legacy(ctx: &crate::core::runtime::DispatchCtx, config: &Config
/// preference (a visibility query, a filtered listing) sees rows a user stored
/// before the preference moved into the module. Idempotent per workspace; the
/// pref reads and writes below call it themselves.
-pub(crate) async fn ensure_migrated(ctx: &crate::core::runtime::DispatchCtx, config: &Config) {
- migrate_legacy(ctx, config).await;
+pub(crate) async fn ensure_migrated(config: &Config) {
+ migrate_legacy(config).await;
}
/// The scope pref stored for `toolkit`, or the default when none is.
@@ -123,16 +123,12 @@ pub(crate) async fn ensure_migrated(ctx: &crate::core::runtime::DispatchCtx, con
/// gets. A failed read is not evidence the user revoked anything, and refusing
/// every integration on a transient error would break a working app. The
/// failure is logged. The **write** below does not fail open.
-pub(crate) async fn load_or_default(
- ctx: &crate::core::runtime::DispatchCtx,
- config: &Config,
- toolkit: &str,
-) -> UserScopePref {
+pub(crate) async fn load_or_default(config: &Config, toolkit: &str) -> UserScopePref {
let key = UserScopePref::key(toolkit);
if key.is_empty() {
return UserScopePref::default();
}
- migrate_legacy(ctx, config).await;
+ migrate_legacy(config).await;
let request = ComposioGetUserScopesRequest {
toolkit: key.clone(),
};
@@ -171,7 +167,6 @@ pub(crate) async fn load_or_default(
///
/// An empty toolkit, or the module could not store the row.
pub(crate) async fn save(
- ctx: &crate::core::runtime::DispatchCtx,
config: &Config,
toolkit: &str,
pref: UserScopePref,
@@ -180,7 +175,7 @@ pub(crate) async fn save(
if key.is_empty() {
return Err("user_scopes: toolkit must not be empty".to_string());
}
- migrate_legacy(ctx, config).await;
+ migrate_legacy(config).await;
let request = ComposioSetUserScopesRequest {
toolkit: key.clone(),
scopes: to_wire(pref),