Skip to content

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

fix(composio): key the connected-integrations cache by effective credential

oxoxDev7aed716ad4d4
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 2c3dfa0b30..e9ee76704f 100644
--- a/crates/openhuman-core/src/integrations/composio/connected_integrations/cache.rs
+++ b/crates/openhuman-core/src/integrations/composio/connected_integrations/cache.rs
@@ -46,8 +46,18 @@ pub(crate) fn composio_cache_test_lock() -> std::sync::MutexGuard<'static, ()> {
}
/// The Composio credential identity a [`Config`] resolves to: its credential
-/// store (`config_path`), mode, entity, and any inline or host-pinned key.
-/// Hashed so the key material never appears in the cache key or its logs.
+/// store (`config_path`), mode, entity, any inline or host-pinned key, and —
+/// in unpinned direct mode — the stored key [`create_composio_client`] would
+/// actually dispatch with. Hashed so the key material never appears in the
+/// cache key or its logs.
+///
+/// The stored key must be included even though `config_path` already is:
+/// the generic credential RPCs can rotate it in place without publishing
+/// `ComposioConfigChanged`, and two agents that share a `config_path` (the
+/// normal multi-agent-per-runtime shape) would otherwise collide on the same
+/// key and read each other's cached connections across that rotation.
+///
+/// [`create_composio_client`]: super::super::client::create_composio_client
pub(crate) fn cache_key(config: &Config) -> String {
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
@@ -74,6 +84,13 @@ pub(crate) fn cache_key(config: &Config) -> String {
)
})
.hash(&mut hasher);
+ if composio.host_credential.is_none()
+ && composio.mode.trim() == crate::config::schema::COMPOSIO_MODE_DIRECT
+ {
+ if let Ok(Some(stored)) = crate::security::credentials::get_composio_api_key(config) {
+ stored.hash(&mut hasher);
+ }
+ }
format!("composio:{:016x}", hasher.finish())
}
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 37d782bfcc..a16f6e232a 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
@@ -258,3 +258,50 @@ fn redaction_covers_every_result_channel() {
let debug = format!("{:?}", agent.composio);
assert!(!debug.contains(KEY_A), "{debug}");
}
+
+/// Regression for CodeRabbit finding bdd9216d on PR #6689: two agents that
+/// share a `config_path` (the normal multi-agent-per-runtime shape) and are
+/// both unpinned direct mode resolve to the SAME cache key regardless of
+/// which stored credential is actually active, because `cache_key` never
+/// hashed the effective `COMPOSIO_DIRECT_PROVIDER` key. The generic
+/// credential RPCs can rotate that stored key in place without publishing
+/// `ComposioConfigChanged`, so — before this fix — an agent reading the
+/// cache right after a rotation would transparently receive the previous
+/// credential's cached connection list. Two DIFFERENT credentials must
+/// never collide on one cache identity.
+#[test]
+fn cache_key_changes_when_the_shared_stored_key_rotates_in_unpinned_direct_mode() {
+ let tmp = tempfile::tempdir().unwrap();
+ let mut base = shared_runtime_config(&tmp);
+ base.composio.mode = crate::config::schema::COMPOSIO_MODE_DIRECT.into();
+
+ let key_before = cache_key(&base);
+
+ crate::security::credentials::AuthService::from_config(&base)
+ .store_provider_token(
+ crate::security::credentials::COMPOSIO_DIRECT_PROVIDER,
+ crate::security::credentials::DEFAULT_AUTH_PROFILE_NAME,
+ "ck_tenant_rotated_0004",
+ std::collections::HashMap::new(),
+ true,
+ )
+ .unwrap();
+
+ let key_after = cache_key(&base);
+ assert_ne!(
+ key_before, key_after,
+ "cache identity must change when the effective stored Composio credential rotates"
+ );
+ assert!(!key_after.contains("ck_tenant_rotated_0004"), "{key_after}");
+}
+
+/// Sanity counterpart: an unchanged stored key must keep producing the same
+/// cache identity (no key material, no unrelated flapping).
+#[test]
+fn cache_key_is_stable_for_unpinned_direct_mode_when_nothing_rotates() {
+ let tmp = tempfile::tempdir().unwrap();
+ let mut base = shared_runtime_config(&tmp);
+ base.composio.mode = crate::config::schema::COMPOSIO_MODE_DIRECT.into();
+
+ assert_eq!(cache_key(&base), cache_key(&base));
+}