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
feat(web_chat): track client id on in-flight turns
Steven Enamakel868a518e860c
diff --git a/crates/openhuman-core/src/web_chat/ops/parallel_turn.rs b/crates/openhuman-core/src/web_chat/ops/parallel_turn.rsindex 4e206f7f6e..2a4a78292c 100644--- a/crates/openhuman-core/src/web_chat/ops/parallel_turn.rs+++ b/crates/openhuman-core/src/web_chat/ops/parallel_turn.rs@@ -208,6 +208,7 @@ pub(crate) async fn spawn_parallel_turn(map_key,ParallelEntry {thread_id: key_for(thread_id),+ client_id: client_id.to_string(),handle,cancel_token,},@@ -217,7 +218,7 @@ pub(crate) async fn spawn_parallel_turn(/// Cooperatively cancel every parallel turn on a thread. Returns the cancelled/// `(request_id, client_id)` pairs. Used by the thread-level cancel paths so a cancel/stop also/// tears down any concurrent forked turns, not just the primary turn.-pub(crate) async fn cancel_parallel_turns_for_thread(thread_id: &str) -> Vec<String> {+pub(crate) async fn cancel_parallel_turns_for_thread(thread_id: &str) -> Vec<(String, String)> {let mut cancelled = Vec::new();let scoped_thread = key_for(thread_id);let mut parallel = parallel_in_flight().lock_owned().await;@@ -238,7 +239,7 @@ pub(crate) async fn cancel_parallel_turns_for_thread(thread_id: &str) -> Vec<Str}}});- cancelled.push(unscope(&request_id));+ cancelled.push((unscope(&request_id), entry.client_id));}}cancelled@@ -251,7 +252,7 @@ pub(crate) async fn cancel_parallel_turns_for_thread(thread_id: &str) -> Vec<Strpub(crate) async fn cancel_parallel_turn_by_request_id(thread_id: &str,request_id: &str,-) -> Vec<String> {+) -> Vec<(String, String)> {let map_key = key_for(request_id);let scoped_thread = key_for(thread_id);let mut parallel = parallel_in_flight().lock_owned().await;@@ -264,6 +265,7 @@ pub(crate) async fn cancel_parallel_turn_by_request_id(}if let Some(entry) = parallel.remove(&map_key) {entry.cancel_token.cancel();+ let client_id = entry.client_id.clone();let mut handle = entry.handle;tokio::spawn(async move {tokio::select! {@@ -273,7 +275,7 @@ pub(crate) async fn cancel_parallel_turn_by_request_id(}}});- return vec![request_id.to_string()];+ return vec![(request_id.to_string(), client_id)];}Vec::new()}diff --git a/crates/openhuman-core/src/web_chat/ops/start_chat.rs b/crates/openhuman-core/src/web_chat/ops/start_chat.rsindex a59bde4cca..9d6d8c37e1 100644--- a/crates/openhuman-core/src/web_chat/ops/start_chat.rs+++ b/crates/openhuman-core/src/web_chat/ops/start_chat.rs@@ -691,6 +691,7 @@ async fn start_chat_inner(map_key,InFlightEntry {request_id: request_id.clone(),+ client_id: client_id.clone(),handle,run_queue: turn_run_queue,cancel_token,diff --git a/crates/openhuman-core/src/web_chat/ops/state.rs b/crates/openhuman-core/src/web_chat/ops/state.rsindex 7cc6a72bec..b8f8f09994 100644--- a/crates/openhuman-core/src/web_chat/ops/state.rs+++ b/crates/openhuman-core/src/web_chat/ops/state.rs@@ -191,6 +191,7 @@ pub(crate) async fn track_parallel_turn_for_test(key_for(request_id),ParallelEntry {thread_id: key_for(thread_id),+ client_id: "test-client".to_string(),handle,cancel_token: cancel,},diff --git a/crates/openhuman-core/src/web_chat/types.rs b/crates/openhuman-core/src/web_chat/types.rsindex 3bc4810852..4cf866af3f 100644--- a/crates/openhuman-core/src/web_chat/types.rs+++ b/crates/openhuman-core/src/web_chat/types.rs@@ -88,6 +88,9 @@ pub(super) struct SessionEntry {#[derive(Debug)]pub(super) struct InFlightEntry {pub(super) request_id: String,+ /// The client that started the turn, so a teardown that no client asked+ /// for (a lost profile lease) still resolves that client's stream.+ pub(super) client_id: String,pub(super) handle: tokio::task::JoinHandle<()>,pub(super) run_queue: std::sync::Arc<tinyagents_harness::run_queue::RunQueue<crate::agent::queued_turn::QueuedTurn>,@@ -108,6 +111,8 @@ pub(super) struct InFlightEntry {#[derive(Debug)]pub(super) struct ParallelEntry {pub(super) thread_id: String,+ /// The client that started the turn (see [`InFlightEntry::client_id`]).+ pub(super) client_id: String,pub(super) handle: tokio::task::JoinHandle<()>,pub(super) cancel_token: tokio_util::sync::CancellationToken,}