Skip to content

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

fix(config): take the workspace and its revision from one snapshot

Shanu9060865f202c
diff --git a/src/core/socketio.rs b/src/core/socketio.rs
index 0249bda198..7b453d9816 100644
--- a/src/core/socketio.rs
+++ b/src/core/socketio.rs
@@ -514,18 +514,16 @@ pub fn attach_socketio() -> (socketioxide::layer::SocketIoLayer, SocketIo) {
let socket = socket.clone();
let client_id = client_id.clone();
tokio::spawn(async move {
- match crate::openhuman::config::active_workspace_dir().await {
- Ok(dir) => {
+ match crate::openhuman::config::active_workspace_snapshot().await {
+ Ok((dir, revision)) => {
let handle = crate::openhuman::config::workspace_handle(&dir);
- // Read after the resolve, so the revision belongs
- // to the workspace being sent. This task and the
- // switch bridge are separate, so a snapshot
- // resolved before a switch can arrive after its
- // broadcast; the client keeps the highest
- // revision it has seen and discards this one if
- // it lost that race.
- let revision =
- crate::openhuman::config::active_workspace_revision();
+ // One snapshot, not two reads: resolved
+ // separately, a switch between them would pair
+ // this workspace with the *next* one's revision,
+ // and the client would rank a stale seed above
+ // the switch it lost to. This task and the switch
+ // bridge are separate, so that race is real; the
+ // client keeps the highest revision it has seen.
log::debug!(
"[socketio] emit event=workspace_changed to_client={client_id} workspace={handle} revision={revision}"
);
diff --git a/src/openhuman/config/mod.rs b/src/openhuman/config/mod.rs
index 59f040b46f..6dfa5e7266 100644
--- a/src/openhuman/config/mod.rs
+++ b/src/openhuman/config/mod.rs
@@ -27,7 +27,7 @@ pub use ops::*;
pub use schema::{
action_dir_env_override, active_user_marker_path, active_workspace_dir,
- active_workspace_dir_cached, active_workspace_revision, clear_active_user, default_action_dir,
+ active_workspace_dir_cached, active_workspace_snapshot, clear_active_user, default_action_dir,
default_projects_dir, default_root_openhuman_dir, pre_login_user_dir, read_active_user_id,
resolve_action_dir, user_openhuman_dir, write_active_user_id, PRE_LOGIN_USER_ID,
};
diff --git a/src/openhuman/config/schema/load/active_workspace.rs b/src/openhuman/config/schema/load/active_workspace.rs
index c4e20b23f0..fc7004ca47 100644
--- a/src/openhuman/config/schema/load/active_workspace.rs
+++ b/src/openhuman/config/schema/load/active_workspace.rs
@@ -87,20 +87,37 @@ struct Transition {
revision: u64,
}
+/// What a resolve left behind.
+struct Published {
+ /// Revision of the resolved workspace: freshly minted if this resolve was
+ /// a transition, otherwise the one that workspace was announced under.
+ /// Taken under the same lock as the commit, so it cannot belong to a
+ /// different workspace than the one resolved — which is what a consumer
+ /// sending the pair over the wire relies on.
+ revision: u64,
+ /// The transition to announce, if this resolve was one.
+ transition: Option<Transition>,
+}
+
impl ActiveWorkspace {
- /// Record `workspace_dir` as current. Returns the transition to announce,
- /// or `None` when the bus has already been told about this workspace.
- fn publish(&mut self, workspace_dir: &Path) -> Option<Transition> {
+ /// Record `workspace_dir` as current.
+ fn publish(&mut self, workspace_dir: &Path) -> Published {
self.current = Some(workspace_dir.to_path_buf());
if self.announced.as_deref() == Some(workspace_dir) {
- return None;
+ return Published {
+ revision: self.revision,
+ transition: None,
+ };
}
self.announced = Some(workspace_dir.to_path_buf());
self.revision += 1;
- Some(Transition {
- workspace_dir: workspace_dir.to_path_buf(),
+ Published {
revision: self.revision,
- })
+ transition: Some(Transition {
+ workspace_dir: workspace_dir.to_path_buf(),
+ revision: self.revision,
+ }),
+ }
}
/// Whether `revision` is still the newest announced transition. A
@@ -120,7 +137,8 @@ impl ActiveWorkspace {
static ACTIVE_WORKSPACE: Lazy<RwLock<ActiveWorkspace>> =
Lazy::new(|| RwLock::new(ActiveWorkspace::default()));
-/// Record `workspace_dir` as the workspace this process is serving.
+/// Record `workspace_dir` as the workspace this process is serving, and
+/// return the revision it is current under.
///
/// Called after a resolution that used the real process environment.
/// Publishes [`DomainEvent::ActiveWorkspaceChanged`](crate::core::events::DomainEvent)
@@ -128,17 +146,23 @@ static ACTIVE_WORKSPACE: Lazy<RwLock<ActiveWorkspace>> =
/// about a switch without polling — and so the switch itself becomes a
/// visible row in the Event Log rather than an invisible reason its contents
/// changed.
-pub(crate) fn publish_active_workspace(workspace_dir: &Path) {
- let transition = match ACTIVE_WORKSPACE.write() {
+///
+/// The revision comes back from the same lock acquisition that committed the
+/// workspace. A caller that needs the pair must take it from here rather than
+/// reading the workspace and the revision separately: a switch between two
+/// reads pairs workspace A with B's revision, and a receiver comparing
+/// revisions then ranks a stale A above the B it should yield to.
+pub(crate) fn publish_active_workspace(workspace_dir: &Path) -> u64 {
+ let published = match ACTIVE_WORKSPACE.write() {
Ok(mut guard) => guard.publish(workspace_dir),
Err(error) => {
log::warn!("{LOG_PREFIX} active workspace slot poisoned: {error}");
- return;
+ return 0;
}
};
- let Some(transition) = transition else {
- return;
+ let Some(transition) = published.transition else {
+ return published.revision;
};
// Re-checked after the lock was dropped and before the emit: another
@@ -151,12 +175,12 @@ pub(crate) fn publish_active_workspace(workspace_dir: &Path) {
transition.workspace_dir.display(),
transition.revision
);
- return;
+ return published.revision;
}
Ok(_) => {}
Err(error) => {
log::warn!("{LOG_PREFIX} active workspace slot poisoned: {error}");
- return;
+ return published.revision;
}
}
@@ -172,19 +196,7 @@ pub(crate) fn publish_active_workspace(workspace_dir: &Path) {
workspace_dir: transition.workspace_dir,
revision: transition.revision,
});
-}
-
-/// The revision of the newest announced workspace transition.
-///
-/// Goes on the wire beside the handle so a client can tell a stale delivery
-/// from a current one: the connect-time snapshot and the switch broadcast
-/// travel on separate tasks, so a snapshot resolved before a switch can
-/// arrive after it.
-pub fn active_workspace_revision() -> u64 {
- ACTIVE_WORKSPACE
- .read()
- .map(|guard| guard.revision)
- .unwrap_or(0)
+ published.revision
}
/// Write-through hook for [`Config::load_or_init`](crate::openhuman::config::Config).
diff --git a/src/openhuman/config/schema/load/active_workspace_tests.rs b/src/openhuman/config/schema/load/active_workspace_tests.rs
index 06bc434d4c..b2d03f6695 100644
--- a/src/openhuman/config/schema/load/active_workspace_tests.rs
+++ b/src/openhuman/config/schema/load/active_workspace_tests.rs
@@ -31,7 +31,7 @@ fn starts_unknown_rather_than_guessing() {
fn a_first_publish_is_readable_and_announces() {
let mut state = ActiveWorkspace::default();
assert!(
- state.publish(&ws("a")).is_some(),
+ state.publish(&ws("a")).transition.is_some(),
"the first resolve is news"
);
assert_eq!(state.current, Some(ws("a")));
@@ -42,7 +42,7 @@ fn a_later_publish_replaces_the_previous_workspace_and_announces() {
let mut state = ActiveWorkspace::default();
state.publish(&ws("a"));
assert!(
- state.publish(&ws("b")).is_some(),
+ state.publish(&ws("b")).transition.is_some(),
"a different workspace is a switch"
);
assert_eq!(state.current, Some(ws("b")));
@@ -54,9 +54,9 @@ fn a_later_publish_replaces_the_previous_workspace_and_announces() {
#[test]
fn republishing_the_same_workspace_announces_once() {
let mut state = ActiveWorkspace::default();
- assert!(state.publish(&ws("a")).is_some());
- assert!(state.publish(&ws("a")).is_none());
- assert!(state.publish(&ws("a")).is_none());
+ assert!(state.publish(&ws("a")).transition.is_some());
+ assert!(state.publish(&ws("a")).transition.is_none());
+ assert!(state.publish(&ws("a")).transition.is_none());
assert_eq!(state.current, Some(ws("a")));
}
@@ -92,7 +92,7 @@ fn re_resolving_the_same_workspace_after_invalidation_does_not_re_announce() {
state.invalidate();
assert!(
- state.publish(&ws("a")).is_none(),
+ state.publish(&ws("a")).transition.is_none(),
"the workspace never actually changed"
);
assert_eq!(state.current, Some(ws("a")));
@@ -107,7 +107,7 @@ fn a_different_workspace_after_invalidation_is_announced() {
state.publish(&ws("a"));
state.invalidate();
- assert!(state.publish(&ws("b")).is_some());
+ assert!(state.publish(&ws("b")).transition.is_some());
assert_eq!(state.current, Some(ws("b")));
}
@@ -142,8 +142,14 @@ fn the_global_publish_survives_an_uninitialised_bus() {
fn a_superseded_transition_is_not_announced() {
let mut state = ActiveWorkspace::default();
- let first = state.publish(&ws("a")).expect("first resolve announces");
- let second = state.publish(&ws("b")).expect("a switch announces");
+ let first = state
+ .publish(&ws("a"))
+ .transition
+ .expect("first resolve announces");
+ let second = state
+ .publish(&ws("b"))
+ .transition
+ .expect("a switch announces");
// B committed after A, so only B may reach the bus.
assert!(!state.is_current(first.revision), "A's emit is superseded");
@@ -157,12 +163,12 @@ fn a_superseded_transition_is_not_announced() {
fn revisions_increase_only_for_announced_transitions() {
let mut state = ActiveWorkspace::default();
- let first = state.publish(&ws("a")).expect("announces");
+ let first = state.publish(&ws("a")).transition.expect("announces");
assert!(
- state.publish(&ws("a")).is_none(),
+ state.publish(&ws("a")).transition.is_none(),
"same workspace is silent"
);
- let second = state.publish(&ws("b")).expect("announces");
+ let second = state.publish(&ws("b")).transition.expect("announces");
assert!(
second.revision > first.revision,
@@ -180,8 +186,34 @@ fn revisions_increase_only_for_announced_transitions() {
#[test]
fn invalidation_does_not_consume_a_revision() {
let mut state = ActiveWorkspace::default();
- let announced = state.publish(&ws("a")).expect("announces");
+ let announced = state.publish(&ws("a")).transition.expect("announces");
state.invalidate();
assert_eq!(state.revision, announced.revision);
assert!(state.is_current(announced.revision));
}
+
+/// The revision a resolve reports must be the one *its* workspace is current
+/// under — including when the resolve is not a transition. A consumer sending
+/// the pair to a client takes both from this one call; if a silent republish
+/// reported a stale or zero revision, the connect-time seed would rank below
+/// every switch and be discarded.
+#[test]
+fn a_resolve_reports_the_revision_of_the_workspace_it_resolved() {
+ let mut state = ActiveWorkspace::default();
+
+ let first = state.publish(&ws("a"));
+ let again = state.publish(&ws("a"));
+ assert!(again.transition.is_none(), "not a transition");
+ assert_eq!(
+ again.revision, first.revision,
+ "a silent republish reports the revision it was announced under"
+ );
+
+ let second = state.publish(&ws("b"));
+ assert!(second.revision > first.revision);
+
+ state.invalidate();
+ let after = state.publish(&ws("b"));
+ assert!(after.transition.is_none());
+ assert_eq!(after.revision, second.revision);
+}
diff --git a/src/openhuman/config/schema/load/dirs.rs b/src/openhuman/config/schema/load/dirs.rs
index b1a6495a46..b9e0fc331d 100644
--- a/src/openhuman/config/schema/load/dirs.rs
+++ b/src/openhuman/config/schema/load/dirs.rs
@@ -246,12 +246,13 @@ pub(crate) async fn persist_active_workspace_config_dir(config_dir: &Path) -> Re
);
}
- super::sync_directory(&default_config_dir).await?;
// Again, now that the marker on disk actually says the new workspace. The
// pre-write clear alone leaves a window in which a racing resolver reads
// the *old* marker and refills the cache with the workspace being switched
- // away from.
+ // away from. Before the directory sync, not after: the rename is what
+ // changed the answer, and a sync failure must not skip this.
super::active_workspace::invalidate_active_workspace();
+ super::sync_directory(&default_config_dir).await?;
Ok(())
}
@@ -335,7 +336,15 @@ pub(crate) async fn resolve_runtime_config_dirs(
/// about a workspace either of them has seen, and the embedder arm is
/// included deliberately: an embedding host's chosen workspace is the
/// authoritative answer for its process too.
-pub async fn active_workspace_dir() -> Result<PathBuf> {
+///
+/// The revision is the one the resolved workspace is current under, taken
+/// from the same lock acquisition that committed it. Anything sending the
+/// pair to a client — the connect-time seed, the notification stamp — must
+/// take it from here rather than resolving the workspace and reading the
+/// revision separately: a switch between those two reads pairs workspace A
+/// with B's revision, and a receiver comparing revisions then ranks the stale
+/// A above the B it should yield to.
+pub async fn active_workspace_snapshot() -> Result<(PathBuf, u64)> {
// An embedding host that supplied its own `Config` is authoritative, and
// `config::ops::load_config_with_timeout` already short-circuits on it for
// exactly this reason. Resolving from disk/env here instead would answer
@@ -346,8 +355,8 @@ pub async fn active_workspace_dir() -> Result<PathBuf> {
// with only a `debug!` line to say so. See AGENTS.md, "CoreBuilder::config
// alone configures boot and nothing else".
if let Some(config) = crate::core::runtime::context::CoreContext::current_embedder_config() {
- super::active_workspace::publish_active_workspace(&config.workspace_dir);
- return Ok(config.workspace_dir);
+ let revision = super::active_workspace::publish_active_workspace(&config.workspace_dir);
+ return Ok((config.workspace_dir, revision));
}
let (default_openhuman_dir, default_workspace_dir) = default_config_and_workspace_dirs()?;
let (_, workspace_dir, source) =
@@ -356,8 +365,14 @@ pub async fn active_workspace_dir() -> Result<PathBuf> {
source = source.as_str(),
"active workspace resolved for a workspace-bound decision"
);
- super::active_workspace::publish_active_workspace(&workspace_dir);
- Ok(workspace_dir)
+ let revision = super::active_workspace::publish_active_workspace(&workspace_dir);
+ Ok((workspace_dir, revision))
+}
+
+/// [`active_workspace_snapshot`] without the revision, for callers that only
+/// need to know which workspace is active.
+pub async fn active_workspace_dir() -> Result<PathBuf> {
+ active_workspace_snapshot().await.map(|(dir, _)| dir)
}
/// Env-injectable variant of [`resolve_runtime_config_dirs`]. Accepts any
diff --git a/src/openhuman/config/schema/load/mod.rs b/src/openhuman/config/schema/load/mod.rs
index f241c43f45..818351d22f 100644
--- a/src/openhuman/config/schema/load/mod.rs
+++ b/src/openhuman/config/schema/load/mod.rs
@@ -8,13 +8,13 @@ mod impl_load;
mod migrate;
mod secrets;
+pub use active_workspace::active_workspace_dir_cached;
pub(crate) use active_workspace::invalidate_active_workspace;
-pub use active_workspace::{active_workspace_dir_cached, active_workspace_revision};
pub use dirs::{
- action_dir_env_override, active_user_marker_path, active_workspace_dir, clear_active_user,
- default_action_dir, default_projects_dir, default_root_openhuman_dir, pre_login_user_dir,
- read_active_user_id, resolve_action_dir, user_openhuman_dir, write_active_user_id,
- PRE_LOGIN_USER_ID,
+ action_dir_env_override, active_user_marker_path, active_workspace_dir,
+ active_workspace_snapshot, clear_active_user, default_action_dir, default_projects_dir,
+ default_root_openhuman_dir, pre_login_user_dir, read_active_user_id, resolve_action_dir,
+ user_openhuman_dir, write_active_user_id, PRE_LOGIN_USER_ID,
};
// redact_url_for_log is pub(super) for the schema module; tests inside load
diff --git a/src/openhuman/config/schema/load_user_state.rs b/src/openhuman/config/schema/load_user_state.rs
index 5e3bc01281..c13ec6a8af 100644
--- a/src/openhuman/config/schema/load_user_state.rs
+++ b/src/openhuman/config/schema/load_user_state.rs
@@ -199,13 +199,14 @@ pub fn write_active_user_id(default_openhuman_dir: &Path, user_id: &str) -> Resu
);
}
- sync_directory(default_openhuman_dir)?;
// Again, now that the marker actually says the new user. The pre-write
// clear is not enough on its own: a resolver racing this call can read the
// *old* marker after that clear and refill the cache with the workspace
// being switched away from, which would then read as current after a
- // successful switch.
+ // successful switch. Before the directory sync, not after: the rename is
+ // what changed the answer, and a sync failure must not skip this.
crate::openhuman::config::schema::invalidate_active_workspace();
+ sync_directory(default_openhuman_dir)?;
tracing::debug!(user_id = %user_id, path = %path.display(), "active user written");
Ok(())
}
diff --git a/src/openhuman/config/schema/mod.rs b/src/openhuman/config/schema/mod.rs
index d19fe09d50..441042b225 100644
--- a/src/openhuman/config/schema/mod.rs
+++ b/src/openhuman/config/schema/mod.rs
@@ -34,7 +34,7 @@ mod learning;
mod load;
pub use load::{
action_dir_env_override, active_user_marker_path, active_workspace_dir,
- active_workspace_dir_cached, active_workspace_revision, clear_active_user, default_action_dir,
+ active_workspace_dir_cached, active_workspace_snapshot, clear_active_user, default_action_dir,
default_projects_dir, default_root_openhuman_dir, pre_login_user_dir, read_active_user_id,
resolve_action_dir, user_openhuman_dir, write_active_user_id, PRE_LOGIN_USER_ID,
};
diff --git a/src/openhuman/desktop/notifications/bus.rs b/src/openhuman/desktop/notifications/bus.rs
index 069236014e..1efeac3233 100644
--- a/src/openhuman/desktop/notifications/bus.rs
+++ b/src/openhuman/desktop/notifications/bus.rs
@@ -133,12 +133,17 @@ impl NotificationBridgeSubscriber {
/// 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 {
+ async fn should_announce(&self, event: &DomainEvent) -> Announce {
let Some(event_workspace) = workspace_of(event) else {
- return true;
+ return Announce::Unbound;
};
- let active = match crate::openhuman::config::active_workspace_dir().await {
- Ok(active) => Some(active),
+ // One snapshot, so the revision stamped on the notification is the
+ // one the comparison below was made against. Resolved separately, a
+ // switch in between would stamp an event from workspace A with B's
+ // newer revision — and a client that had not yet seen the switch
+ // would read that as "I am behind" and accept the stale alert.
+ let snapshot = match crate::openhuman::config::active_workspace_snapshot().await {
+ Ok(snapshot) => Some(snapshot),
Err(error) => {
log::warn!(
"{LOG_PREFIX} could not resolve the active workspace ({error}); not announcing {} — it is persisted and will show in the notification centre",
@@ -147,19 +152,40 @@ impl NotificationBridgeSubscriber {
None
}
};
- let announces = announces_to(Some(event_workspace), active.as_deref());
+ let active = snapshot.as_ref().map(|(dir, _)| dir.as_path());
+ let announces = announces_to(Some(event_workspace), active);
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()
+ active.unwrap_or(std::path::Path::new("?")).display()
);
}
- announces
+ match (announces, snapshot) {
+ (true, Some((_, revision))) => Announce::Active(revision),
+ _ => Announce::Suppressed,
+ }
}
}
+/// The announcement gate's verdict.
+///
+/// Carries the revision the gate compared against so the caller can stamp
+/// exactly that on the payload — a receiver whose own revision is older then
+/// knows it is simply behind on the switch broadcast, rather than looking at
+/// a stale notification (#5966).
+enum Announce {
+ /// Not workspace-bound: announced everywhere, nothing to stamp.
+ Unbound,
+ /// Bound to the active workspace: announced, stamped with the revision
+ /// that workspace was current under when the gate checked.
+ Active(u64),
+ /// Bound to a workspace that is not active, or the active workspace could
+ /// not be resolved (fail closed — see `should_announce`).
+ Suppressed,
+}
+
/// The announcement rule, as a function of its two inputs.
///
/// Separated from the I/O so the decision can be asserted directly — in
@@ -484,18 +510,16 @@ impl EventHandler<DomainEvent> for NotificationBridgeSubscriber {
}
// Persisted above under the workspace it belongs to; announced
// only if that workspace is the one the user is in (#5931).
- if self.should_announce(event).await {
- // Stamped here, after the gate passed and before the send, so
- // the revision names the transition the gate actually checked
- // against. A receiver whose own revision is older knows it is
- // simply behind — the switch broadcast has not reached it yet
- // — rather than looking at a stale notification (#5966).
- if notification.workspace.is_some() {
- notification.workspace_revision =
- Some(crate::openhuman::config::active_workspace_revision());
+ match self.should_announce(event).await {
+ Announce::Unbound => {
+ publish_core_notification(notification);
}
- publish_core_notification(notification);
- }
+ Announce::Active(revision) => {
+ notification.workspace_revision = Some(revision);
+ publish_core_notification(notification);
+ }
+ Announce::Suppressed => {}
+ };
}
}
}
diff --git a/src/openhuman/desktop/notifications/bus_tests_2_tests.rs b/src/openhuman/desktop/notifications/bus_tests_2_tests.rs
index 7abac03bfb..8a213deeef 100644
--- a/src/openhuman/desktop/notifications/bus_tests_2_tests.rs
+++ b/src/openhuman/desktop/notifications/bus_tests_2_tests.rs
@@ -510,7 +510,10 @@ async fn the_active_workspace_s_outage_is_announced() {
.expect("the override resolves");
let bridge = bridge_for(&resolved);
assert!(
- bridge.should_announce(&parked_in(&resolved)).await,
+ matches!(
+ bridge.should_announce(&parked_in(&resolved)).await,
+ super::Announce::Active(_)
+ ),
"the workspace the user is in must still hear about its own outage"
);
}
@@ -538,9 +541,12 @@ async fn a_switched_away_workspace_s_outage_is_not_announced() {
// with, or it would reproduce the staleness it exists to avoid.
let bridge = bridge_for(switched_away.path());
assert!(
- !bridge
- .should_announce(&parked_in(switched_away.path()))
- .await,
+ matches!(
+ bridge
+ .should_announce(&parked_in(switched_away.path()))
+ .await,
+ super::Announce::Suppressed
+ ),
"another workspace's server name and error must not reach this one"
);
}
@@ -551,15 +557,16 @@ async fn a_process_wide_event_is_announced_without_consulting_the_workspace() {
// the first line, before any resolution, so it cannot be affected by
// whichever workspace happens to be active.
let bridge = bridge_for(std::path::Path::new("/tmp/openhuman-ws-a"));
- assert!(
+ assert!(matches!(
bridge
.should_announce(&DomainEvent::CronJobCompleted {
job_id: "job-1".into(),
success: true,
output: "done".into(),
})
- .await
- );
+ .await,
+ super::Announce::Unbound
+ ));
}
/// The announcement rule, including the arm that is otherwise reachable only
diff --git a/src/openhuman/security/approval/gate.rs b/src/openhuman/security/approval/gate.rs
index f5a01ceee9..bf73910bc0 100644
--- a/src/openhuman/security/approval/gate.rs
+++ b/src/openhuman/security/approval/gate.rs
@@ -282,12 +282,20 @@ fn now_ms() -> u64 {
/// per-node HITL gate's notification) but is a distinct surface: this one
/// fires from the *tool-call* `ApprovalGate`, not the graph's own
/// `require_approval` gate node.
+/// `workspace` is the handle and revision of the workspace the flow parked in.
+/// This publisher bypasses the notification bridge that stamps workspace
+/// identity, and the approval gate itself is process-wide — so without the
+/// binding, the banner stays actionable after a workspace switch and approves
+/// another workspace's pending call from inside the one the user moved to
+/// (#5966). `None` only when the workspace could not be resolved; the caller
+/// says why that fails open.
fn publish_flow_gate_notification(
request_id: &str,
flow_id: &str,
run_id: &str,
tool_name: &str,
summary: &str,
+ workspace: Option<(String, u64)>,
) {
use crate::openhuman::desktop::notifications::bus::publish_core_notification;
use crate::openhuman::desktop::notifications::types::{
@@ -331,8 +339,8 @@ fn publish_flow_gate_notification(
payload: Some(base_payload(ApprovalDecision::Deny)),
},
]),
- workspace: None,
- workspace_revision: None,
+ workspace: workspace.as_ref().map(|(handle, _)| handle.clone()),
+ workspace_revision: workspace.map(|(_, revision)| revision),
});
}
diff --git a/src/openhuman/security/approval/gate_intercept.rs b/src/openhuman/security/approval/gate_intercept.rs
index 64ffeeaf7f..acb841a63e 100644
--- a/src/openhuman/security/approval/gate_intercept.rs
+++ b/src/openhuman/security/approval/gate_intercept.rs
@@ -501,7 +501,32 @@ impl ApprovalGate {
tool_name: tool_name.to_string(),
summary: action_summary.to_string(),
});
- publish_flow_gate_notification(&request_id, flow_id, run_id, tool_name, action_summary);
+ // The workspace the flow parked in, so the approval banner is
+ // dropped by a client that has since switched away rather than
+ // approving this workspace's call from another one. Fails open on
+ // a resolve failure: an unbound notification still reaches the
+ // user, whereas not publishing recreates the silent deadlock this
+ // bridge exists to fix.
+ let workspace = match crate::openhuman::config::active_workspace_snapshot().await {
+ Ok((dir, revision)) => {
+ Some((crate::openhuman::config::workspace_handle(&dir), revision))
+ }
+ Err(error) => {
+ tracing::warn!(
+ request_id = %request_id,
+ "[approval::gate] could not resolve the active workspace for the flow approval notification ({error}); publishing it unbound"
+ );
+ None
+ }
+ };
+ publish_flow_gate_notification(
+ &request_id,
+ flow_id,
+ run_id,
+ tool_name,
+ action_summary,
+ workspace,
+ );
}
tracing::info!(
diff --git a/src/openhuman/security/approval/gate_tests_part_03_tests.rs b/src/openhuman/security/approval/gate_tests_part_03_tests.rs
index bf015dcc05..1ee6f3607b 100644
--- a/src/openhuman/security/approval/gate_tests_part_03_tests.rs
+++ b/src/openhuman/security/approval/gate_tests_part_03_tests.rs
@@ -501,6 +501,22 @@ async fn flow_origin_park_publishes_flow_approval_request_and_notification() {
.await
.expect("timed out waiting for the flow-gate-approval notification");
assert_eq!(notif.id, format!("flow-gate-approval:{request_id}"));
+ // Bound to the workspace the flow parked in (#5966): this publisher
+ // bypasses the bridge that stamps workspace identity, and the gate is
+ // process-wide, so an unbound banner would stay actionable after a
+ // workspace switch and approve this call from another workspace.
+ let workspace = notif
+ .workspace
+ .as_deref()
+ .expect("a flow approval names the workspace it parked in");
+ assert!(
+ workspace.starts_with("ws_"),
+ "the binding is an opaque handle, never a path: {workspace}"
+ );
+ assert!(
+ notif.workspace_revision.is_some(),
+ "the binding carries the revision the workspace was current under"
+ );
let actions = notif.actions.expect("notification must declare actions");
let action_ids: Vec<_> = actions.iter().map(|a| a.action_id.as_str()).collect();
assert_eq!(