The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(session): filter rehydrated actions by current integration policy
Steven Enamakeldcc4582972b7
diff --git a/crates/openhuman-core/src/agent/session_host/recorded_tools.rs b/crates/openhuman-core/src/agent/session_host/recorded_tools.rsindex 011c460f0f..d3fef179c4 100644--- a/crates/openhuman-core/src/agent/session_host/recorded_tools.rs+++ b/crates/openhuman-core/src/agent/session_host/recorded_tools.rs@@ -61,11 +61,28 @@ pub(super) fn recorded_integration_actions(recorded: &[ToolSpec]) -> Vec<ToolSpepub(super) fn rehydrate_integration_actions(recorded: &[ToolSpec],live: &[Box<dyn Tool>],+ integrations: &[crate::agent::prompts::ConnectedIntegration],+ integrations_are_authoritative: bool,) -> Vec<Box<dyn Tool>> {let live_names: HashSet<&str> = live.iter().map(|tool| tool.name()).collect();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.+ .filter(|spec| {+ !integrations_are_authoritative+ || integrations.iter().any(|integration| {+ integration.connected+ && integration.toolkit.eq_ignore_ascii_case(&toolkit_of(&spec.name))+ && !integration+ .gated_tools+ .iter()+ .any(|gated| gated.name == spec.name)+ })+ }).filter(|spec| !live_names.contains(spec.name.as_str())).filter(|spec| seen.insert(spec.name.clone())).map(|spec| {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.rsindex e8f09bf8c0..bb38ca07d2 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@@ -11,6 +11,22 @@ fn spec(name: &str) -> ToolSpec {}}+fn integration(+ toolkit: &str,+ connected: bool,+ gated_tools: Vec<crate::agent::prompts::GatedIntegrationTool>,+) -> crate::agent::prompts::ConnectedIntegration {+ crate::agent::prompts::ConnectedIntegration {+ toolkit: toolkit.into(),+ description: String::new(),+ tools: Vec::new(),+ gated_tools,+ connected,+ connections: Vec::new(),+ non_active_status: None,+ }+}+#[test]fn only_composio_slugs_count_as_integration_actions() {assert!(is_integration_action_name("GMAIL_SEND_EMAIL"));@@ -36,7 +52,7 @@ fn recorded_actions_are_filtered_from_a_mixed_declaration_set() {#[test]fn a_restart_with_no_integrations_rebuilds_the_recorded_actions_as_deferred() {let recorded = vec![spec("GMAIL_SEND_EMAIL"), spec("GMAIL_FETCH_EMAILS")];- let rebuilt = rehydrate_integration_actions(&recorded, &[]);+ 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"]);@@ -54,19 +70,41 @@ fn a_restart_with_no_integrations_rebuilds_the_recorded_actions_as_deferred() {#[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")], &[]);- let rebuilt = rehydrate_integration_actions(&recorded, &live);+ let live: Vec<Box<dyn Tool>> =+ rehydrate_integration_actions(&[spec("GMAIL_SEND_EMAIL")], &[], &[], false);+ let rebuilt = rehydrate_integration_actions(&recorded, &live, &[], false);let names: Vec<&str> = rebuilt.iter().map(|tool| tool.name()).collect();assert_eq!(names, vec!["SLACK_SEND_MESSAGE"]);}#[test]fn a_rebuilt_declaration_is_byte_identical_to_the_recorded_one() {- let first = rehydrate_integration_actions(&[spec("GMAIL_SEND_EMAIL")], &[]);- let recorded = vec![first[0].spec()];- let second = rehydrate_integration_actions(&recorded, &[]);+ let recorded = vec![spec("GMAIL_SEND_EMAIL")];+ let first = rehydrate_integration_actions(&recorded, &[], &[], false);+ let second = rehydrate_integration_actions(&recorded, &[], &[], false);assert_eq!(serde_json::to_string(&first[0].spec()).unwrap(),serde_json::to_string(&second[0].spec()).unwrap());}++#[test]+fn authoritative_integrations_do_not_restore_revoked_or_gated_actions() {+ let recorded = vec![spec("GMAIL_SEND_EMAIL"), spec("SLACK_SEND_MESSAGE")];+ let integrations = vec![+ integration(+ "gmail",+ true,+ vec![crate::agent::prompts::GatedIntegrationTool {+ name: "GMAIL_SEND_EMAIL".into(),+ description: String::new(),+ required_scope: "write".into(),+ unlock_paths: Vec::new(),+ }],+ ),+ integration("slack", false, Vec::new()),+ ];++ let rebuilt = rehydrate_integration_actions(&recorded, &[], &integrations, true);+ assert!(rebuilt.is_empty());+}diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rsindex 50eba93603..0340f18b36 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs@@ -421,12 +421,16 @@ impl OpenHumanTurnPrelude {if definition.subagents.is_empty() {return;}- let integrations = self- .mutable- .lock()- .unwrap_or_else(std::sync::PoisonError::into_inner)- .connected_integrations- .clone();+ let (integrations, integrations_are_authoritative) = {+ let mutable = self+ .mutable+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner);+ (+ mutable.connected_integrations.clone(),+ mutable.connected_integrations_initialized,+ )+ };let mut surface = self.tool_surface.lock()@@ -448,8 +452,12 @@ impl OpenHumanTurnPrelude {.unwrap_or_else(std::sync::PoisonError::into_inner).recorded_integration_actions.clone();- let rebuilt =- super::recorded_tools::rehydrate_integration_actions(&recorded, &collected);+ let rebuilt = super::recorded_tools::rehydrate_integration_actions(+ &recorded,+ &collected,+ &integrations,+ integrations_are_authoritative,+ );if !rebuilt.is_empty() {log::info!("[session] rebuilt {} recorded integration action(s) the live integrations did not supply agent={}",