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(mcp): fail closed when the active workspace is unknown
Shanu0b63258ce34b
diff --git a/src/openhuman/desktop/notifications/bus.rs b/src/openhuman/desktop/notifications/bus.rsindex 736e065d95..2ee662ede3 100644--- a/src/openhuman/desktop/notifications/bus.rs+++ b/src/openhuman/desktop/notifications/bus.rs@@ -125,33 +125,60 @@ impl NotificationBridgeSubscriber {/// marker read, paid only for the handful of events a supervisor tick/// produces: everything else returns on the first line.///- /// **Fails open.** If the workspace cannot be resolved the notification is- /// announced anyway. A banner from the wrong workspace is a visible- /// annoyance the user can dismiss; a silently swallowed "your MCP tools- /// are down" is the exact failure #5931 exists to end.+ /// **Fails closed.** If the workspace cannot be resolved, nothing is+ /// announced. That costs a *banner*, not the alert: the notification is+ /// already persisted under its own workspace by the time this runs, so it+ /// still reaches the notification centre — which is exactly the durability+ /// split #3805 built, with the store as the reliable channel and the+ /// broadcast as best effort. Announcing on an unknown workspace would+ /// instead put another account's server name and transport error in front+ /// of whoever is connected, and there is no undoing that.async fn should_announce(&self, event: &DomainEvent) -> bool {let Some(event_workspace) = workspace_of(event) else {return true;};- match crate::openhuman::config::active_workspace_dir().await {- Ok(active) if active == event_workspace => true,- Ok(active) => {- log::debug!(- "{LOG_PREFIX} not announcing {} from an inactive workspace event_ws={} active_ws={}",- event.variant_name(),- event_workspace.display(),- active.display()- );- false- }+ let active = match crate::openhuman::config::active_workspace_dir().await {+ Ok(active) => Some(active),Err(error) => {log::warn!(- "{LOG_PREFIX} could not resolve the active workspace ({error}); announcing {} anyway",+ "{LOG_PREFIX} could not resolve the active workspace ({error}); not announcing {} — it is persisted and will show in the notification centre",event.variant_name());- true+ None}+ };+ let announces = announces_to(Some(event_workspace), active.as_deref());+ if !announces && active.is_some() {+ log::debug!(+ "{LOG_PREFIX} not announcing {} from an inactive workspace event_ws={} active_ws={}",+ event.variant_name(),+ event_workspace.display(),+ active.as_deref().unwrap_or(std::path::Path::new("?")).display()+ );}+ announces+ }+}++/// The announcement rule, as a function of its two inputs.+///+/// Separated from the I/O so the decision can be asserted directly — in+/// particular the fail-closed arm, which is otherwise reachable only by making+/// the on-disk config unreadable.+///+/// - `event_workspace` `None`: the event is not workspace-bound, so it is not+/// this rule's business and is announced.+/// - `active` `None`: the active workspace could not be resolved. **Fail+/// closed** — see [`NotificationBridgeSubscriber::should_announce`].+/// - Otherwise the event is announced only in the workspace it belongs to.+fn announces_to(+ event_workspace: Option<&std::path::Path>,+ active: Option<&std::path::Path>,+) -> bool {+ match (event_workspace, active) {+ (None, _) => true,+ (Some(_), None) => false,+ (Some(event), Some(active)) => event == active,}}diff --git a/src/openhuman/desktop/notifications/bus_tests_2_tests.rs b/src/openhuman/desktop/notifications/bus_tests_2_tests.rsindex 3d9c1f281b..d19fa21981 100644--- a/src/openhuman/desktop/notifications/bus_tests_2_tests.rs+++ b/src/openhuman/desktop/notifications/bus_tests_2_tests.rs@@ -485,7 +485,11 @@ impl Drop for ActiveWorkspaceEnvGuard {#[tokio::test]async fn the_active_workspace_s_outage_is_announced() {- let lock = crate::openhuman::config::TEST_ENV_LOCK+ // Held for the whole test. NOT dropped explicitly: `_guard` is declared+ // after it, so scope exit destroys the guard first and the env var is+ // cleared while this lock is still held. Releasing the lock early would+ // let the next test set its own override and have this guard erase it.+ let _lock = crate::openhuman::config::TEST_ENV_LOCK.lock().unwrap_or_else(|poisoned| poisoned.into_inner());let active = tempfile::TempDir::new().unwrap();@@ -502,12 +506,15 @@ async fn the_active_workspace_s_outage_is_announced() {bridge.should_announce(&parked_in(&resolved)).await,"the workspace the user is in must still hear about its own outage");- drop(lock);}#[tokio::test]async fn a_switched_away_workspace_s_outage_is_not_announced() {- let lock = crate::openhuman::config::TEST_ENV_LOCK+ // Held for the whole test. NOT dropped explicitly: `_guard` is declared+ // after it, so scope exit destroys the guard first and the env var is+ // cleared while this lock is still held. Releasing the lock early would+ // let the next test set its own override and have this guard erase it.+ let _lock = crate::openhuman::config::TEST_ENV_LOCK.lock().unwrap_or_else(|poisoned| poisoned.into_inner());let active = tempfile::TempDir::new().unwrap();@@ -529,7 +536,6 @@ async fn a_switched_away_workspace_s_outage_is_not_announced() {.await,"another workspace's server name and error must not reach this one");- drop(lock);}#[tokio::test]@@ -548,3 +554,25 @@ async fn a_process_wide_event_is_announced_without_consulting_the_workspace() {.await);}++/// The announcement rule, including the arm that is otherwise reachable only+/// by making the on-disk config unreadable.+#[test]+fn the_announcement_rule_fails_closed_on_an_unknown_workspace() {+ let a = std::path::Path::new("/tmp/openhuman-ws-a");+ let b = std::path::Path::new("/tmp/openhuman-ws-b");++ // Not workspace-bound: never this rule's business.+ assert!(announces_to(None, Some(a)));+ assert!(announces_to(None, None));++ // Bound and live: announced only where it belongs.+ assert!(announces_to(Some(a), Some(a)));+ assert!(!announces_to(Some(a), Some(b)));++ // Bound, but the active workspace is unknown. Fail closed: the+ // notification is already persisted, so suppressing costs a banner, while+ // announcing could put another account's server name and error in front of+ // whoever is connected.+ assert!(!announces_to(Some(a), None));+}