Skip to content

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

refactor(composio): extract cache lookup to accept an explicit map

Steven Enamakel12756017e064
diff --git a/crates/openhuman-core/src/integrations/composio/connected_integrations.rs b/crates/openhuman-core/src/integrations/composio/connected_integrations.rs
index 8617290e13..cf0e74cf42 100644
--- a/crates/openhuman-core/src/integrations/composio/connected_integrations.rs
+++ b/crates/openhuman-core/src/integrations/composio/connected_integrations.rs
@@ -34,6 +34,8 @@ pub use fetch::{
// these via a plain `use super::<name>;`, exactly as when this was one
// un-split file. See each item's `pub(super)` in its owning submodule.
#[cfg(test)]
-pub(crate) use cache::{cache_key, CachedIntegrations, INTEGRATIONS_CACHE};
+pub(crate) use cache::{
+ cache_key, read_cached_integrations_from, CachedIntegrations, INTEGRATIONS_CACHE,
+};
#[cfg(test)]
pub(crate) use fetch::{connectable_toolkit_slugs, resolve_toolkit_description};
diff --git a/crates/openhuman-core/src/integrations/composio/connected_integrations/cache.rs b/crates/openhuman-core/src/integrations/composio/connected_integrations/cache.rs
index 36010fab25..fbea19b828 100644
--- a/crates/openhuman-core/src/integrations/composio/connected_integrations/cache.rs
+++ b/crates/openhuman-core/src/integrations/composio/connected_integrations/cache.rs
@@ -162,8 +162,19 @@ pub fn cached_active_integrations_including_expired(
}
fn read_cached_integrations(config: &Config) -> Option<Vec<ConnectedIntegration>> {
+ read_cached_integrations_from(&INTEGRATIONS_CACHE, config)
+}
+
+/// [`read_cached_integrations`] over an explicit map, so the credential-keyed
+/// lookup can be exercised against a private map instead of the process-wide
+/// [`INTEGRATIONS_CACHE`], which unrelated code paths clear at any time (see
+/// [`invalidate_connected_integrations_cache`]).
+pub(crate) fn read_cached_integrations_from(
+ cache: &RwLock<HashMap<String, CachedIntegrations>>,
+ config: &Config,
+) -> Option<Vec<ConnectedIntegration>> {
let key = cache_key(config);
- let guard = match INTEGRATIONS_CACHE.try_read() {
+ let guard = match cache.try_read() {
Ok(g) => g,
Err(_) => {
tracing::trace!(
diff --git a/crates/openhuman-core/src/integrations/composio/tools_host_credential_tests.rs b/crates/openhuman-core/src/integrations/composio/tools_host_credential_tests.rs
index 6691174c5e..38f32dd2e5 100644
--- a/crates/openhuman-core/src/integrations/composio/tools_host_credential_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/tools_host_credential_tests.rs
@@ -1,4 +1,5 @@
-use std::sync::{Arc, Mutex};
+use std::collections::HashMap;
+use std::sync::{Arc, Mutex, RwLock};
use axum::extract::State;
use axum::http::{HeaderMap, StatusCode};
@@ -10,7 +11,7 @@ use tinytools::Tool;
use crate::config::{ComposioHostCredential, Config};
use crate::integrations::composio::client::{resolve_composio_route, ComposioRoute};
use crate::integrations::composio::connected_integrations::{
- cache_key, composio_cache_test_lock, CachedIntegrations, INTEGRATIONS_CACHE,
+ cache_key, read_cached_integrations_from, CachedIntegrations,
};
use crate::integrations::composio::tools::{live_composio_config, ComposioListConnectionsTool};
@@ -175,7 +176,6 @@ async fn two_agents_on_one_runtime_each_call_composio_with_their_own_key() {
#[test]
fn connected_integrations_cache_is_keyed_per_credential() {
- let _guard = composio_cache_test_lock();
let tmp = tempfile::tempdir().unwrap();
let base = shared_runtime_config(&tmp);
let agent_a = pinned(&base, KEY_A, "tenant-a", None);
@@ -188,7 +188,11 @@ fn connected_integrations_cache_is_keyed_per_credential() {
assert_eq!(cache_key(&agent_a), cache_key(&agent_a.clone()));
assert!(!cache_key(&agent_a).contains(KEY_A));
- INTEGRATIONS_CACHE.write().unwrap().insert(
+ // A private map, not the process-wide `INTEGRATIONS_CACHE`: any test that
+ // stores a credential invalidates the global map without taking the cache
+ // test lock, which would empty it between the insert and the reads below.
+ let cache = RwLock::new(HashMap::new());
+ cache.write().unwrap().insert(
cache_key(&agent_a),
CachedIntegrations {
entries: vec![crate::agent::prompts::ConnectedIntegration {
@@ -204,12 +208,8 @@ fn connected_integrations_cache_is_keyed_per_credential() {
},
);
- let seen_by_a = crate::integrations::composio::cached_active_integrations(&agent_a);
- let seen_by_b = crate::integrations::composio::cached_active_integrations(&agent_b);
- INTEGRATIONS_CACHE
- .write()
- .unwrap()
- .remove(&cache_key(&agent_a));
+ let seen_by_a = read_cached_integrations_from(&cache, &agent_a);
+ let seen_by_b = read_cached_integrations_from(&cache, &agent_b);
assert_eq!(seen_by_a.map(|v| v.len()), Some(1));
assert!(seen_by_b.is_none());