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
fix(composio): fail closed when the scope preference cannot be read
M3gA-Mind22f931425995
diff --git a/crates/openhuman-core/src/integrations/composio/flow_gate.rs b/crates/openhuman-core/src/integrations/composio/flow_gate.rsindex 0e1d0424f1..4ab25f008f 100644--- a/crates/openhuman-core/src/integrations/composio/flow_gate.rs+++ b/crates/openhuman-core/src/integrations/composio/flow_gate.rs@@ -72,9 +72,10 @@ pub(crate) async fn flow_tool_allowed(tracing::debug!(target: "flows", %slug, %toolkit, "[flows] tool_call curation: reject — slug is not a curated action of this toolkit");return false;};+ // A pref that cannot be read admits nothing (fail closed).let allowed = load_user_scope_pref(ctx, config, &toolkit).await- .allows(curated.scope);+ .is_ok_and(|pref| pref.allows(curated.scope));tracing::debug!(target: "flows", %slug, %toolkit, allowed, "[flows] tool_call curation: static curated catalog decision");return allowed;}@@ -102,7 +103,7 @@ pub(crate) async fn flow_tool_allowed(}let allowed = load_user_scope_pref(ctx, config, &toolkit).await- .allows(classify_unknown(slug));+ .is_ok_and(|pref| pref.allows(classify_unknown(slug)));tracing::debug!(target: "flows", %slug, %toolkit, allowed, "[flows] tool_call curation: live catalog + scope decision");allowed}diff --git a/crates/openhuman-core/src/integrations/composio/ops/mod.rs b/crates/openhuman-core/src/integrations/composio/ops/mod.rsindex 7239b78165..1807563223 100644--- a/crates/openhuman-core/src/integrations/composio/ops/mod.rs+++ b/crates/openhuman-core/src/integrations/composio/ops/mod.rs@@ -59,7 +59,7 @@ pub use triggers::{};// The `composio.{get,set}_user_scopes` handlers' storage half.pub(crate) use scope_prefs::{- ensure_migrated as ensure_user_scopes_migrated, load_or_default as load_user_scope_pref,+ ensure_migrated as ensure_user_scopes_migrated, load as load_user_scope_pref,save as save_user_scope_pref,};diff --git a/crates/openhuman-core/src/integrations/composio/ops/scope_prefs.rs b/crates/openhuman-core/src/integrations/composio/ops/scope_prefs.rsindex 6d01c18461..1d1d765aa0 100644--- a/crates/openhuman-core/src/integrations/composio/ops/scope_prefs.rs+++ b/crates/openhuman-core/src/integrations/composio/ops/scope_prefs.rs@@ -120,21 +120,24 @@ pub(crate) async fn ensure_migrated(ctx: &crate::core::runtime::DispatchCtx, conmigrate_legacy(ctx, config).await;}-/// The scope pref stored for `toolkit`, or the default when none is.+/// The scope pref stored for `toolkit` (the module's default when none is).///-/// **This read fails open**: a module that cannot be reached lands on the-/// same default (`read+write`, no `admin`) a user who never opened the toggle-/// gets. A failed read is not evidence the user revoked anything, and refusing-/// every integration on a transient error would break a working app. The-/// failure is logged. The **write** below does not fail open.-pub(crate) async fn load_or_default(+/// **This read fails closed**: an unreachable module or a stored row that+/// cannot be read is an `Err`, never the default. The default is `read+write`,+/// so answering it for a user who turned `write` off would widen what the agent+/// may run. Callers that gate on the pref treat an `Err` as "not allowed".+///+/// # Errors+///+/// An empty toolkit, or the module could not answer.+pub(crate) async fn load(ctx: &crate::core::runtime::DispatchCtx,config: &Config,toolkit: &str,-) -> UserScopePref {+) -> Result<UserScopePref, String> {let key = UserScopePref::key(toolkit);if key.is_empty() {- return UserScopePref::default();+ return Err("user_scopes: toolkit must not be empty".to_string());}migrate_legacy(ctx, config).await;let request = ComposioGetUserScopesRequest {@@ -156,11 +159,11 @@ pub(crate) async fn load_or_default(admin = pref.admin,"{LOG} pref loaded");- pref+ Ok(pref)}Err(error) => {- tracing::warn!(toolkit = %key, %error, "{LOG} pref unavailable, using default");- UserScopePref::default()+ tracing::warn!(toolkit = %key, %error, "{LOG} pref unavailable, failing closed");+ Err(error)}}}diff --git a/crates/openhuman-core/src/integrations/composio/ops/scope_prefs_tests.rs b/crates/openhuman-core/src/integrations/composio/ops/scope_prefs_tests.rsindex 4e0a5b31d6..027e791056 100644--- a/crates/openhuman-core/src/integrations/composio/ops/scope_prefs_tests.rs+++ b/crates/openhuman-core/src/integrations/composio/ops/scope_prefs_tests.rs@@ -45,8 +45,8 @@ async fn save_rejects_an_empty_toolkit() {/// A stored preference is never lost: either the module took it (the read/// returns it and the stored value is emptied) or the module was unreachable-/// (the read fails open to the default and the value is left exactly as it was-/// so the migration retries).+/// (the read fails closed and the value is left exactly as it was so the+/// migration retries).#[tokio::test]async fn a_legacy_pref_either_reaches_the_module_or_stays_stored() {let dir = tempfile::tempdir().unwrap();@@ -66,7 +66,7 @@ async fn a_legacy_pref_either_reaches_the_module_or_stays_stored() {admin: true,};- let pref = load_or_default(+ let pref = load(&crate::core::runtime::DispatchCtx::ambient(),&config,"github",@@ -81,18 +81,23 @@ async fn a_legacy_pref_either_reaches_the_module_or_stays_stored() {.await.unwrap();if done {- assert_eq!(pref, stored, "the migrated row must decide visibility");+ assert_eq!(pref, Ok(stored), "the migrated row must decide visibility");assert!(left.is_empty(), "the stored value is emptied once moved");} else {- assert_eq!(- pref,- UserScopePref::default(),- "unreachable module fails open"- );+ assert!(pref.is_err(), "an unreachable module fails closed: {pref:?}");assert_eq!(left.get("github"), Some(&stored));}}+#[tokio::test]+async fn load_rejects_an_empty_toolkit_instead_of_answering_the_default() {+ let dir = tempfile::tempdir().unwrap();+ let config = config_in(&dir);+ assert!(load(&crate::core::runtime::DispatchCtx::ambient(), &config, " ")+ .await+ .is_err());+}+#[tokio::test]async fn a_workspace_with_no_legacy_file_is_marked_migrated() {let dir = tempfile::tempdir().unwrap();diff --git a/crates/openhuman-core/src/integrations/composio/schemas/definitions.rs b/crates/openhuman-core/src/integrations/composio/schemas/definitions.rsindex 43627be455..ba66f33f77 100644--- a/crates/openhuman-core/src/integrations/composio/schemas/definitions.rs+++ b/crates/openhuman-core/src/integrations/composio/schemas/definitions.rs@@ -291,7 +291,8 @@ pub fn schemas(function: &str) -> ControllerSchema {description:"Read the per-toolkit user scope preference (read/write/admin) used to gate \composio_execute. Defaults to {read:true, write:true, admin:false} when no \- pref is stored.",+ pref is stored; errors (rather than answering the default) when the stored \+ pref cannot be read.",inputs: vec![FieldSchema {name: "toolkit",ty: TypeSchema::String,diff --git a/crates/openhuman-core/src/integrations/composio/schemas/handlers_identity.rs b/crates/openhuman-core/src/integrations/composio/schemas/handlers_identity.rsindex b384ebefda..73818ee955 100644--- a/crates/openhuman-core/src/integrations/composio/schemas/handlers_identity.rs+++ b/crates/openhuman-core/src/integrations/composio/schemas/handlers_identity.rs@@ -52,26 +52,21 @@ pub(super) fn handle_get_user_scopes(toolkit = %toolkit,"[composio:scopes] handler entry");- // Reads through the bound memory driver's `Graph` family, not through- // the engine's `load_or_default` (which resolved the in-process client- // itself — openhuman#5560 deleted that client). The read still fails- // OPEN onto the default pref for every failure mode, deliberately; see- // `ops::user_scopes`.- //- // The config load is `?`-free for the same reason: this handler has- // never had a failing path, and turning "settings file momentarily- // unreadable" into an RPC error would make the scopes panel fail where- // it used to render the defaults.- let pref = match ctx.load_config().await {- Ok(config) => ops::load_user_scope_pref(&ctx, &config, &toolkit).await,+ // Fails closed: a pref the module cannot read is an error, not the+ // default. The default is `read+write`, so showing it for a user who+ // turned `write` off would misstate what the agent may run; the+ // Connections panel renders the error instead.+ let config = ctx.load_config().await?;+ let pref = match ops::load_user_scope_pref(&ctx, &config, &toolkit).await {+ Ok(pref) => pref,Err(error) => {tracing::warn!(method = "composio.get_user_scopes",toolkit = %toolkit,%error,- "[composio:scopes] config load failed, using default pref (read+write)"+ "[composio:scopes] pref unavailable");- contract::UserScopePref::default()+ return Err(format!("scope preference for `{toolkit}` is unavailable: {error}"));}};tracing::debug!(diff --git a/crates/openhuman-core/src/integrations/composio/tools/execute.rs b/crates/openhuman-core/src/integrations/composio/tools/execute.rsindex 63ee5fb0e6..d59db95cd9 100644--- a/crates/openhuman-core/src/integrations/composio/tools/execute.rs+++ b/crates/openhuman-core/src/integrations/composio/tools/execute.rs@@ -227,7 +227,9 @@ impl ComposioExecuteTool {ToolDecision::Allow | ToolDecision::PassthroughCheckScope { .. } => {}ToolDecision::BlockedByScope { scope } => {let toolkit = toolkit_from_slug(&tool).unwrap_or_default();- let pref = load_user_scope_pref(ctx, self.config.as_ref(), &toolkit).await;+ let pref = load_user_scope_pref(ctx, self.config.as_ref(), &toolkit)+ .await+ .ok();let msg = scope_error_message(&tool, scope, pref);tracing::info!(tool = %tool,diff --git a/crates/openhuman-core/src/integrations/composio/tools/scope_gate.rs b/crates/openhuman-core/src/integrations/composio/tools/scope_gate.rsindex ff0001a0f6..a640cc172a 100644--- a/crates/openhuman-core/src/integrations/composio/tools/scope_gate.rs+++ b/crates/openhuman-core/src/integrations/composio/tools/scope_gate.rs@@ -72,11 +72,19 @@ pub(crate) fn action_mutates_external_state(slug: &str) -> bool {/// Decide whether a Composio action slug should be visible / executable/// for the current user.///+/// The preference applied when the stored one cannot be read: no scope on.+pub(super) const NOTHING_ALLOWED: UserScopePref = UserScopePref {+ read: false,+ write: false,+ admin: false,+};+/// Asks the connector module which curated actions the user's stored scope/// preference exposes for the slug's toolkit (`ListVisibleTools`), so the/// preference and the catalog are read from the module that enforces them.-/// A module that cannot be reached answers as the default preference would,-/// which is what the host did before the preference moved.+/// A module that cannot be reached fails closed: every scope is treated as+/// off, so nothing is allowed. The default preference (`read+write`) would+/// widen a user's `write=false`.pub(super) async fn evaluate_tool_visibility(ctx: &crate::core::runtime::DispatchCtx,config: &Config,@@ -98,11 +106,11 @@ pub(super) async fn evaluate_tool_visibility({Ok(visible) => decide_from_visible(slug, &visible),Err(error) => {- tracing::debug!(+ tracing::warn!(toolkit = %toolkit,- "[composio][scopes] list_visible_tools failed, using the default preference: {error}"+ "[composio][scopes] list_visible_tools failed, failing closed: {error}");- decide_visibility(&toolkit, slug, UserScopePref::default())+ decide_visibility(&toolkit, slug, NOTHING_ALLOWED)}}}@@ -169,17 +177,30 @@ fn decide_visibility(toolkit: &str, slug: &str, pref: UserScopePref) -> ToolDeci/// toggles the scope in the Connections UI. The agent has no tool to/// flip scopes (see the note above the removed `ComposioEnableScopeTool`/// for why) — it can only describe the gate and point at the UI.-pub(super) fn scope_error_message(slug: &str, scope: ToolScope, pref: UserScopePref) -> String {+///+/// `pref` is `None` when the stored preference could not be read; the message+/// then says so instead of printing flags nobody chose.+pub(super) fn scope_error_message(+ slug: &str,+ scope: ToolScope,+ pref: Option<UserScopePref>,+) -> String {let toolkit = toolkit_from_slug(slug).unwrap_or_default();let scope_str = scope.as_str();+ let current = match pref {+ Some(pref) => format!(+ "read={}, write={}, admin={}",+ pref.read, pref.write, pref.admin+ ),+ None => "the stored preferences could not be read".to_string(),+ };format!("composio_execute: action `{slug}` is classified `{scope_str}` and is \disabled in the user's current scope preferences for `{toolkit}` \- (read={}, write={}, admin={}). Tell the user this action requires the \+ ({current}). Tell the user this action requires the \`{scope_str}` scope and they can enable it themselves in \**Connections → {toolkit} → {scope_str}**. Do not claim you can flip \it — you cannot.",- pref.read, pref.write, pref.admin,)}diff --git a/crates/openhuman-core/src/integrations/composio/tools/scope_gate_tests.rs b/crates/openhuman-core/src/integrations/composio/tools/scope_gate_tests.rsindex bfe33304de..4f3c18b71a 100644--- a/crates/openhuman-core/src/integrations/composio/tools/scope_gate_tests.rs+++ b/crates/openhuman-core/src/integrations/composio/tools/scope_gate_tests.rs@@ -17,6 +17,29 @@ fn a_curated_write_action_follows_the_write_flag() {));}+/// What `evaluate_tool_visibility` applies when the module cannot answer: an+/// unreadable preference must not widen a user's `write=false` to the default+/// `read+write`. Nothing is allowed, curated or not, read or write.+#[test]+fn an_unreadable_preference_allows_nothing() {+ assert!(matches!(+ decide_visibility("gmail", "GMAIL_SEND_EMAIL", NOTHING_ALLOWED),+ ToolDecision::BlockedByScope {+ scope: ToolScope::Write+ }+ ));+ assert!(matches!(+ decide_visibility("flowstestkit", "FLOWSTESTKIT_SEND_THING", NOTHING_ALLOWED),+ ToolDecision::BlockedByScope {+ scope: ToolScope::Write+ }+ ));+ assert!(matches!(+ decide_visibility("flowstestkit", "FLOWSTESTKIT_GET_THING", NOTHING_ALLOWED),+ ToolDecision::BlockedByScope { .. }+ ));+}+#[test]fn an_action_outside_a_curated_catalog_is_not_curated() {let decision = decide_visibility("gmail", "GMAIL_NOT_A_REAL_ACTION", UserScopePref::default());@@ -55,10 +78,14 @@ fn the_scope_error_names_the_toolkit_and_the_unlock_path() {let message = scope_error_message("GMAIL_SEND_EMAIL",ToolScope::Write,- only(true, false, false),+ Some(only(true, false, false)),);assert!(message.contains("Connections → gmail → write"), "{message}");assert!(message.contains("write=false"), "{message}");++ let unread = scope_error_message("GMAIL_SEND_EMAIL", ToolScope::Write, None);+ assert!(unread.contains("could not be read"), "{unread}");+ assert!(!unread.contains("write="), "{unread}");}fn visible(