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(plan_review): resolve socket tenant from connection context
Steven Enamakel1e89493c38d7
diff --git a/crates/openhuman-core/src/plan_review/gate.rs b/crates/openhuman-core/src/plan_review/gate.rsindex e7f5133733..59aedd2078 100644--- a/crates/openhuman-core/src/plan_review/gate.rs+++ b/crates/openhuman-core/src/plan_review/gate.rs@@ -195,21 +195,15 @@ impl PlanReviewGate {self.parked.lock().get(&(scope, request_id)).cloned()}- /// The parked review a socket subscribed under its own profile should- /// replay. SaaS sockets carry that profile in their authenticated client- /// state; a missing id fails closed. Single-host sockets retain the host's- /// ambient tenant and ignore the optional profile hint.+ /// The parked review a socket connected under its server-bound tenant+ /// should replay. The caller must capture this tenant from trusted server+ /// context when the socket connects; client event payloads are not identity.pub fn parked_review_for_socket(&self,- socket_profile_id: Option<&str>,+ socket_tenant: &Tenant,thread_id: &str,) -> Option<ParkedReview> {- let tenant = socket_tenant(- socket_profile_id,- crate::core::runtime::DispatchCtx::ambient().tenant(),- crate::core::runtime::is_saas(),- )?;- self.parked_review_for_thread(&tenant, thread_id)+ self.parked_review_for_thread(socket_tenant, thread_id)}/// Resolve a parked review by `request_id`. Returns `true` when a waiter was@@ -257,22 +251,6 @@ impl PlanReviewGate {}}-fn socket_tenant(- profile_id: Option<&str>,- ambient: Result<Tenant, crate::core::runtime::tenant::NoTenant>,- saas: bool,-) -> Option<Tenant> {- if saas {- let profile = profile_id.filter(|profile| !profile.trim().is_empty())?;- Some(Tenant {- profile: Some(profile.to_owned()),- agent: None,- })- } else {- ambient.ok()- }-}-/// Removes a parked review's registry entries on drop — covers both the normal/// return and cancellation of the parked future.struct ParkGuard<'a> {diff --git a/crates/openhuman-rpc/src/server/socketio.rs b/crates/openhuman-rpc/src/server/socketio.rsindex 1c7767ac30..e2b3e499c0 100644--- a/crates/openhuman-rpc/src/server/socketio.rs+++ b/crates/openhuman-rpc/src/server/socketio.rs@@ -65,6 +65,12 @@ fn subscribe_companion_state_changed() -> tokio::sync::broadcast::Receiver<Value#[derive(Clone, Copy, Debug)]struct AuthedConnection;+/// Tenant captured from the server-side context when the socket connects.+/// The per-process bearer authenticates the connection but does not encode a+/// SaaS profile, so never accept tenant selection from a later event payload.+#[derive(Clone, Debug)]+struct SocketTenant(crate::core_host::core::runtime::tenant::Tenant);+/// Connection-time payload the client passes via Socket.IO's `auth` field.////// Browsers do not let `EventSource` / `WebSocket` clients attach custom@@ -218,8 +224,6 @@ 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.@@ -281,6 +285,15 @@ pub fn attach_socketio() -> (socketioxide::layer::SocketIoLayer, SocketIo) {return;}socket.extensions.insert(AuthedConnection);+ let Some(tenant) = tenant_for_socket_connection(+ crate::core_host::core::runtime::DispatchCtx::ambient().tenant(),+ crate::core_host::core::runtime::is_saas(),+ ) else {+ log::warn!("[socketio] rejecting socket without a tenant scope in SaaS mode");+ let _ = socket.clone().disconnect();+ return;+ };+ socket.extensions.insert(SocketTenant(tenant));log::info!("[socketio] client connected id={client_id} (authenticated)");// Join a room named after the client ID for targeted event delivery.@@ -540,11 +553,7 @@ 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,- payload.profile_id.as_deref(),- );+ replay_parked_plan_review(&socket, thread_id);}ack.send(&ThreadSubscribeAck { joined }).ok();},@@ -1190,9 +1199,12 @@ 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, profile_id: Option<&str>) {+fn replay_parked_plan_review(socket: &SocketRef, thread_id: &str) {+ let Some(tenant) = socket.extensions.get::<SocketTenant>() else {+ return;+ };let Some(row) = crate::core_host::agent::plan_review::gate::global()- .parked_review_for_socket(profile_id, thread_id)+ .parked_review_for_socket(&tenant.0, thread_id)else {return;};@@ -1217,6 +1229,20 @@ fn replay_parked_plan_review(socket: &SocketRef, thread_id: &str, profile_id: Opemit_with_aliases(socket, "plan_review_request", &payload);}+fn tenant_for_socket_connection(+ tenant: Result<+ crate::core_host::core::runtime::tenant::Tenant,+ crate::core_host::core::runtime::tenant::NoTenant,+ >,+ saas: bool,+) -> Option<crate::core_host::core::runtime::tenant::Tenant> {+ match tenant {+ Ok(tenant) => Some(tenant),+ Err(_) if saas => None,+ Err(_) => Some(Default::default()),+ }+}+fn emit_with_aliases(socket: &SocketRef, name: &str, payload: &serde_json::Value) {let _ = socket.emit(name, payload);if let Some(alias) = event_alias(name) {