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(threads): scope run mode and plan review replay to the caller's profile
Steven Enamakelb62b415a0738
diff --git a/app/src/services/socketService.ts b/app/src/services/socketService.tsindex e361842f3d..e90d9dae12 100644--- a/app/src/services/socketService.ts+++ b/app/src/services/socketService.ts@@ -240,7 +240,10 @@ class SocketService {roomThreadIds.add(threadState.selectedThreadId);}for (const threadId of roomThreadIds) {- this.socket?.emit('thread:subscribe', { thread_id: threadId });+ this.socket?.emit('thread:subscribe', {+ thread_id: threadId,+ profile_id: getCoreStateSnapshot().snapshot.auth.profileId ?? undefined,+ });}});@@ -471,7 +474,13 @@ class SocketService {socketWarn('Thread room subscription not acknowledged', { threadId });finish(false);}, timeoutMs);- socket.emit('thread:subscribe', { thread_id: threadId }, () => {+ socket.emit(+ 'thread:subscribe',+ {+ thread_id: threadId,+ profile_id: getCoreStateSnapshot().snapshot.auth.profileId ?? undefined,+ },+ () => {clearTimeout(timer);finish(true);});diff --git a/crates/openhuman-core/src/agent/tools/plan_exit_tests.rs b/crates/openhuman-core/src/agent/tools/plan_exit_tests.rsindex a277e2f606..cb6dcb10bb 100644--- a/crates/openhuman-core/src/agent/tools/plan_exit_tests.rs+++ b/crates/openhuman-core/src/agent/tools/plan_exit_tests.rs@@ -148,7 +148,7 @@ async fn plan_exit_publishes_build_run_mode_change() {loop {match events.recv().await {Some((event_thread_id, mode)) if event_thread_id == thread_id && mode == "build" => {- break event;+ break (event_thread_id, mode);}Some(_) => continue,None => panic!("run mode event stream ended"),diff --git a/crates/openhuman-core/src/threads/run_mode.rs b/crates/openhuman-core/src/threads/run_mode.rsindex 467c38c614..ddc5460fc1 100644--- a/crates/openhuman-core/src/threads/run_mode.rs+++ b/crates/openhuman-core/src/threads/run_mode.rs@@ -199,6 +199,7 @@ struct ThreadIdParams {fn handle_set_run_mode(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {let p = parse::<ThreadModeParams>(params)?;+ require_owned_thread(&ctx, &p.thread_id).await?;let Some(mode) = parse_mode_label(&p.mode) else {return Err(format!("invalid mode '{}' (expected plan|build)", p.mode));};@@ -215,11 +216,29 @@ fn handle_set_run_mode(ctx: DispatchCtx, params: Map<String, Value>) -> Controllfn handle_get_run_mode(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {let p = parse::<ThreadIdParams>(params)?;+ require_owned_thread(&ctx, &p.thread_id).await?;let mode = get_mode(&ctx, &p.thread_id);Ok(serde_json::json!({ "mode": mode_label(mode) }))})}+async fn require_owned_thread(ctx: &DispatchCtx, thread_id: &str) -> Result<(), String> {+ if thread_id.trim().is_empty() {+ return Err("thread_id is required".to_string());+ }+ let config = ctx.load_config().await?;+ let threads = crate::threads::store::blocking::list_threads(+ ctx.clone(),+ config.workspace_dir,+ )+ .await?;+ if threads.iter().any(|thread| thread.id == thread_id) {+ Ok(())+ } else {+ Err(format!("thread '{thread_id}' not found or not owned by caller"))+ }+}+fn parse<T: DeserializeOwned>(params: Map<String, Value>) -> Result<T, String> {serde_json::from_value(Value::Object(params)).map_err(|e| format!("invalid params: {e}"))}diff --git a/crates/openhuman-rpc/src/server/socketio.rs b/crates/openhuman-rpc/src/server/socketio.rsindex cc9332e34c..647d1934df 100644--- a/crates/openhuman-rpc/src/server/socketio.rs+++ b/crates/openhuman-rpc/src/server/socketio.rs@@ -218,6 +218,8 @@ struct ChatCancelPayload {#[derive(Debug, Deserialize)]struct ThreadSubscribePayload {thread_id: String,+ #[serde(default)]+ profile_id: Option<String>,}/// Reply to `thread:subscribe`, so a client can order a read after the join.@@ -538,7 +540,11 @@ pub fn attach_socketio() -> (socketioxide::layer::SocketIoLayer, SocketIo) {// already holds the card.if joined {replay_parked_approval(&socket, thread_id);- replay_parked_plan_review(&socket, thread_id);+ replay_parked_plan_review(+ &socket,+ thread_id,+ payload.profile_id.as_deref(),+ );}ack.send(&ThreadSubscribeAck { joined }).ok();},@@ -1184,8 +1190,24 @@ fn replay_parked_approval(socket: &SocketRef, thread_id: &str) {/// just joined that thread's room. Mirrors [`replay_parked_approval`] — a/// plan review is a live, in-memory park (no SQLite row), but it reaches the/// UI the same fire-and-forget way, so the same reconciliation applies.-fn replay_parked_plan_review(socket: &SocketRef, thread_id: &str) {- let Ok(tenant) = crate::core_host::core::runtime::DispatchCtx::ambient().tenant() else {+fn socket_replay_tenant(+ profile_id: Option<&str>,+ ambient: Result<crate::core_host::core::runtime::Tenant, crate::core_host::core::runtime::NoTenant>,+) -> Result<crate::core_host::core::runtime::Tenant, crate::core_host::core::runtime::NoTenant> {+ match profile_id {+ Some(profile) if !profile.trim().is_empty() => {+ Ok(crate::core_host::core::runtime::Tenant {+ profile: Some(profile.to_owned()),+ agent: None,+ })+ }+ _ => ambient,+ }+}++fn replay_parked_plan_review(socket: &SocketRef, thread_id: &str, profile_id: Option<&str>) {+ let ambient = crate::core_host::core::runtime::DispatchCtx::ambient().tenant();+ let Ok(tenant) = socket_replay_tenant(profile_id, ambient) else {return;};let Some(row) = crate::core_host::agent::plan_review::gate::global()