Skip to content

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

fix(session): prune stale integration and MCP announcements on refresh

Steven Enamakel8f4963d7ab81
diff --git a/crates/openhuman-core/src/agent/session_host/prelude_integrations.rs b/crates/openhuman-core/src/agent/session_host/prelude_integrations.rs
index b80a0e5dfa..4997425184 100644
--- a/crates/openhuman-core/src/agent/session_host/prelude_integrations.rs
+++ b/crates/openhuman-core/src/agent/session_host/prelude_integrations.rs
@@ -18,9 +18,6 @@ impl OpenHumanTurnPrelude {
return;
};
let actions = super::super::recorded_tools::recorded_integration_actions(recorded.specs());
- if actions.is_empty() {
- return;
- }
log::debug!(
"[session] adopting {} recorded integration action declaration(s) agent={}",
actions.len(),
@@ -105,7 +102,11 @@ impl OpenHumanTurnPrelude {
pub(super) async fn refresh_dynamic_announcements(&self) {
let skills_changed = self.drain_host_events();
- if let Some(config) = self.runtime_config.as_deref() {
+ let config = match self.runtime_config.clone() {
+ Some(config) => Some(config),
+ None => crate::config::Config::load_or_init().await.ok().map(Arc::new),
+ };
+ if let Some(config) = config.as_deref() {
// An expired cache is refetched rather than skipped, so a
// long-lived session keeps tracking connects/revokes.
let current = match crate::integrations::composio::cached_active_integrations(config) {
@@ -119,6 +120,10 @@ impl OpenHumanTurnPrelude {
.unwrap_or_else(std::sync::PoisonError::into_inner);
let current_slugs: std::collections::HashSet<_> =
current.iter().map(|item| item.toolkit.clone()).collect();
+ mutable.announced_integrations.retain(|slug| current_slugs.contains(slug));
+ mutable
+ .pending_integration_announcement
+ .retain(|slug| current_slugs.contains(slug));
for slug in &current_slugs {
if mutable.announced_integrations.insert(slug.clone())
&& !mutable.pending_integration_announcement.contains(slug)
@@ -139,6 +144,13 @@ impl OpenHumanTurnPrelude {
.mutable
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner);
+ let connected_mcp: std::collections::HashSet<_> = connected_mcp.into_iter().collect();
+ mutable
+ .announced_mcp_servers
+ .retain(|server| connected_mcp.contains(server));
+ mutable
+ .pending_mcp_announcement
+ .retain(|server| connected_mcp.contains(server));
for server in connected_mcp {
if mutable.announced_mcp_servers.insert(server.clone())
&& !mutable.pending_mcp_announcement.contains(&server)
diff --git a/crates/openhuman-core/src/agent/session_host/recorded_tools.rs b/crates/openhuman-core/src/agent/session_host/recorded_tools.rs
index e422d66623..37b0c4b43a 100644
--- a/crates/openhuman-core/src/agent/session_host/recorded_tools.rs
+++ b/crates/openhuman-core/src/agent/session_host/recorded_tools.rs
@@ -68,13 +68,12 @@ pub(super) fn rehydrate_integration_actions(
let mut seen = HashSet::new();
recorded
.iter()
- // A missing snapshot is not evidence that a connection was revoked,
- // so preserve the resume fallback until integrations can be fetched.
- // Once the snapshot is authoritative, however, never reintroduce an
- // action which its current connection or scope policy removed.
+ // Transcript declarations are historical state, never authorization.
+ // Do not make a deferred executor available until a current
+ // authoritative integration snapshot permits its toolkit and action.
.filter(|spec| {
- !integrations_are_authoritative
- || integrations.iter().any(|integration| {
+ integrations_are_authoritative
+ && integrations.iter().any(|integration| {
integration.connected
&& integration
.toolkit
diff --git a/crates/openhuman-core/src/agent/session_host/recorded_tools_tests.rs b/crates/openhuman-core/src/agent/session_host/recorded_tools_tests.rs
index 308d9e3ed0..c5e2bba382 100644
--- a/crates/openhuman-core/src/agent/session_host/recorded_tools_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/recorded_tools_tests.rs
@@ -50,29 +50,26 @@ fn recorded_actions_are_filtered_from_a_mixed_declaration_set() {
}
#[test]
-fn a_restart_with_no_integrations_rebuilds_the_recorded_actions_as_deferred() {
+fn unavailable_authorization_does_not_rebuild_recorded_actions() {
let recorded = vec![spec("GMAIL_SEND_EMAIL"), spec("GMAIL_FETCH_EMAILS")];
let rebuilt = rehydrate_integration_actions(&recorded, &[], &[], false);
-
- let names: Vec<&str> = rebuilt.iter().map(|tool| tool.name()).collect();
- assert_eq!(names, vec!["GMAIL_SEND_EMAIL", "GMAIL_FETCH_EMAILS"]);
- for tool in &rebuilt {
- assert_eq!(tool.exposure(), tinytools::ToolExposure::Deferred);
- assert_eq!(tool.family(), Some("gmail"));
- }
- // The declaration round-trips: same description, and the schema keeps the
- // recorded properties (the tool only adds `connection_id` when absent).
- let schema = rebuilt[0].parameters_schema();
- assert_eq!(rebuilt[0].description(), "GMAIL_SEND_EMAIL description");
- assert!(schema["properties"]["to"].is_object());
+ assert!(rebuilt.is_empty());
}
#[test]
fn a_live_action_is_not_rebuilt_from_the_record() {
let recorded = vec![spec("GMAIL_SEND_EMAIL"), spec("SLACK_SEND_MESSAGE")];
- let live: Vec<Box<dyn Tool>> =
- rehydrate_integration_actions(&[spec("GMAIL_SEND_EMAIL")], &[], &[], false);
- let rebuilt = rehydrate_integration_actions(&recorded, &live, &[], false);
+ let integrations = vec![
+ integration("gmail", true, Vec::new()),
+ integration("slack", true, Vec::new()),
+ ];
+ let live: Vec<Box<dyn Tool>> = rehydrate_integration_actions(
+ &[spec("GMAIL_SEND_EMAIL")],
+ &[],
+ &integrations,
+ true,
+ );
+ let rebuilt = rehydrate_integration_actions(&recorded, &live, &integrations, true);
let names: Vec<&str> = rebuilt.iter().map(|tool| tool.name()).collect();
assert_eq!(names, vec!["SLACK_SEND_MESSAGE"]);
}
@@ -80,8 +77,9 @@ fn a_live_action_is_not_rebuilt_from_the_record() {
#[test]
fn a_rebuilt_declaration_is_byte_identical_to_the_recorded_one() {
let recorded = vec![spec("GMAIL_SEND_EMAIL")];
- let first = rehydrate_integration_actions(&recorded, &[], &[], false);
- let second = rehydrate_integration_actions(&recorded, &[], &[], false);
+ let integrations = vec![integration("gmail", true, Vec::new())];
+ let first = rehydrate_integration_actions(&recorded, &[], &integrations, true);
+ let second = rehydrate_integration_actions(&recorded, &[], &integrations, true);
let mut rebuilt = first[0].spec();
rebuilt
.parameters
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
index 0199e3bb29..20c19dc8d8 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -1492,7 +1492,9 @@ impl OpenHumanSessionHost {
pending_skill_retraction: self.pending_skill_retraction.clone(),
connected_integrations: self.connected_integrations.clone(),
connected_integrations_initialized: self.connected_integrations_initialized,
- connected_integrations_authoritative: self.connected_integrations_initialized,
+ // Builder-provided integrations have not been verified by
+ // this session's current authorization refresh.
+ connected_integrations_authoritative: false,
recorded_integration_actions: Vec::new(),
workflows: self.workflows.clone(),
composio_events: None,