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(web_chat): ignore output events after a projection turn ends
Steven Enamakele8970790689d
diff --git a/crates/openhuman-core/src/web_chat/surface.rs b/crates/openhuman-core/src/web_chat/surface.rsindex dff3e73f59..ca06f97e66 100644--- a/crates/openhuman-core/src/web_chat/surface.rs+++ b/crates/openhuman-core/src/web_chat/surface.rs@@ -26,6 +26,7 @@ pub(crate) struct TurnIds {struct SurfaceState {module: tinybus::module::ModuleClient,handle: Option<WebTurnHandle>,+ closed: bool,}/// One module-owned projection turn plus its host broadcast destination.@@ -67,6 +68,7 @@ impl Surface {state: Arc::new(tokio::sync::Mutex::new(SurfaceState {module,handle: None,+ closed: false,})),ctx: ctx.clone(),scope_key,@@ -76,6 +78,9 @@ impl Surface {}async fn begin_if_needed(&self, state: &mut SurfaceState) -> Result<String, String> {+ if state.closed {+ return Err("web projection turn is already closed".to_owned());+ }if let Some(handle) = &state.handle {return Ok(handle.handle.clone());}@@ -97,6 +102,7 @@ impl Surface {}async fn end_if_needed(&self, state: &mut SurfaceState) {+ state.closed = true;let Some(handle) = state.handle.take() else {return;};@@ -131,6 +137,13 @@ impl Surface {/// the projection locally.pub(crate) async fn output(&self, event: ChannelOutputEvent) {let mut state = self.state.lock().await;+ if state.closed {+ log::debug!(+ "[web-channel] dropping output after terminal request_id={}",+ self.ids.request_id+ );+ return;+ }let handle = match self.begin_if_needed(&mut state).await {Ok(handle) => handle,Err(error) => {diff --git a/crates/openhuman-core/src/web_chat/turn_events.rs b/crates/openhuman-core/src/web_chat/turn_events.rsindex 5f401ac1c8..b046ee02ea 100644--- a/crates/openhuman-core/src/web_chat/turn_events.rs+++ b/crates/openhuman-core/src/web_chat/turn_events.rs@@ -232,11 +232,20 @@ impl WebEvents {) -> Option<Surface> {match projection {Some(projection) => Some(projection.lock().await.surface()),- None => request- .payload- .ctx- .as_ref()- .map(|ctx| Surface::new(ctx, ids_of(request))),+ None => {+ let ctx = request.payload.ctx.as_ref()?;+ let config = match ctx.load_config().await {+ Ok(config) => config,+ Err(error) => {+ log::warn!(+ "[web-channel] unable to load config for terminal event request_id={}: {error}",+ request.request_id+ );+ return None;+ }+ };+ Some(Surface::new(ctx, ids_of(request), config).await)+ }}}