Skip to content

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

feat(memory): add config changed subscriber for composio bus

Steven Enamakel907b27e18d3b
diff --git a/crates/openhuman-core/src/memory/sync/composio/bus/config_changed_subscriber.rs b/crates/openhuman-core/src/memory/sync/composio/bus/config_changed_subscriber.rs
new file mode 100644
index 0000000000..3f8f294bc0
--- /dev/null
+++ b/crates/openhuman-core/src/memory/sync/composio/bus/config_changed_subscriber.rs
@@ -0,0 +1,103 @@
+//! Drops and eagerly re-warms the integrations cache when the user flips
+//! Composio between backend and direct mode.
+
+use async_trait::async_trait;
+use tinybus::EventHandler;
+
+use crate::config::rpc as config_rpc;
+use crate::core::events::DomainEvent;
+use crate::integrations::composio::ops;
+use crate::integrations::composio::FetchConnectedIntegrationsStatus;
+
+/// Drops the prompt-level integrations cache whenever the user flips
+/// `config.composio().mode` between `"backend"` and `"direct"` or
+/// stores/clears the direct-mode API key. Without this, the chat
+/// runtime keeps the old tenant's tool catalogue / connection list
+/// pinned for up to `CACHE_TTL` (60s) — that's the regression behind
+/// "I switched to Direct and my old integrations are still showing"
+/// (#1710).
+///
+/// The subscriber is intentionally tiny: it only clears the cache,
+/// then attempts a best-effort eager warm + `ComposioIntegrationsChanged`
+/// publish in a detached task so active sessions can refresh their
+/// delegation schema without waiting for the next turn boundary.
+///
+/// The warm/publish step is intentionally opportunistic: if config load
+/// or backend access fails we leave the cache cold and rely on the
+/// existing 5 s UI poll / next-turn fallback path.
+pub struct ComposioConfigChangedSubscriber;
+
+impl ComposioConfigChangedSubscriber {
+ pub fn new() -> Self {
+ Self
+ }
+}
+
+impl Default for ComposioConfigChangedSubscriber {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
+#[async_trait]
+impl EventHandler<DomainEvent> for ComposioConfigChangedSubscriber {
+ fn name(&self) -> &str {
+ "composio::config_changed"
+ }
+
+ fn domains(&self) -> Option<&[&str]> {
+ Some(&["composio"])
+ }
+
+ async fn handle(&self, event: &DomainEvent) {
+ let DomainEvent::ComposioConfigChanged { mode, api_key_set } = event else {
+ return;
+ };
+
+ tracing::info!(
+ mode = %mode,
+ api_key_set = api_key_set,
+ "[composio-cache] config changed — invalidating integrations cache"
+ );
+ ops::invalidate_connected_integrations_cache();
+
+ tokio::spawn(async move {
+ let config = match config_rpc::load_config_with_timeout().await {
+ Ok(config) => config,
+ Err(error) => {
+ tracing::debug!(
+ error = %error,
+ "[composio-cache] config changed eager warm skipped: config load failed"
+ );
+ return;
+ }
+ };
+
+ match ops::fetch_connected_integrations_status(&config).await {
+ FetchConnectedIntegrationsStatus::Authoritative(entries) => {
+ let mut toolkits: Vec<String> = entries
+ .iter()
+ .filter(|entry| entry.connected)
+ .map(|entry| entry.toolkit.clone())
+ .collect();
+ toolkits.sort();
+ toolkits.dedup();
+ tinymemory_api::events::publish(
+ tinymemory_api::events::MemoryEvent::ComposioIntegrationsChanged {
+ toolkits: toolkits.clone(),
+ },
+ );
+ tracing::debug!(
+ active_toolkits = ?toolkits,
+ "[composio-cache] config changed eager warm complete; published integrations changed"
+ );
+ }
+ FetchConnectedIntegrationsStatus::Unavailable => {
+ tracing::debug!(
+ "[composio-cache] config changed eager warm skipped: backend unavailable"
+ );
+ }
+ }
+ });
+ }
+}