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(agent): don't retain the turn commit receipt (leaked the progress bridge per turn)
Steven Enamakel83c761216b64
diff --git a/crates/openhuman-core/src/agent/agent_tests.rs b/crates/openhuman-core/src/agent/agent_tests.rsindex c764f4e787..3584d9ded6 100644--- a/crates/openhuman-core/src/agent/agent_tests.rs+++ b/crates/openhuman-core/src/agent/agent_tests.rs@@ -294,3 +294,5 @@ mod agent_turn_loop_nudge_tests;mod agent_turn_loop_packed_tool_tests;#[path = "agent_turn_loop_tests.rs"]mod agent_turn_loop_tests;+#[path = "agent_turn_progress_release_tests.rs"]+mod agent_turn_progress_release_tests;diff --git a/crates/openhuman-core/src/agent/agent_turn_progress_release_tests.rs b/crates/openhuman-core/src/agent/agent_turn_progress_release_tests.rsnew file mode 100644index 0000000000..82404f48cb--- /dev/null+++ b/crates/openhuman-core/src/agent/agent_turn_progress_release_tests.rs@@ -0,0 +1,43 @@+//! A finished turn must release every clone of its progress sender once the+//! caller clears the sink. The web channel's progress bridge only exits when+//! its receiver closes, so a clone retained by the cached session (the+//! committed receipt's run context carries `progress` and the attached+//! parent's `on_progress`) kept one bridge task — and in SaaS mode its+//! profile's turn context — alive per turn.++use super::*;++#[tokio::test]+async fn clearing_progress_after_a_turn_closes_the_receiver() {+ let provider = Arc::new(ScriptedProvider::new(vec![+ text_response("first"),+ text_response("second"),+ ]));+ let (mut agent, _tmp) =+ build_agent_with(provider, vec![Box::new(EchoTool)], Box::new(NativeDialect));++ // Two turns on the same (cached) session host, each with its own sink, as+ // the web channel does.+ for message in ["hi", "again"] {+ let (tx, mut rx) = tokio::sync::mpsc::channel(256);+ let weak = tx.downgrade();+ agent.set_on_progress(Some(tx));+ agent.turn(message).await.expect("turn");+ agent.set_on_progress(None);++ assert_eq!(+ weak.strong_count(),+ 0,+ "the session kept progress sender clone(s) alive after the turn"+ );+ // The turn's own events are still delivered, then the channel closes.+ let mut saw_completed = false;+ while let Some(event) = rx.recv().await {+ saw_completed |= matches!(+ event,+ crate::agent::progress::AgentProgress::TurnCompleted { .. }+ );+ }+ assert!(saw_completed, "turn must still report TurnCompleted");+ }+}diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rsindex 5df931b859..752643119f 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs@@ -48,7 +48,6 @@ mod progress;/// resume cache, or persistence handle. Those are exclusively `Session` state.#[derive(Default)]pub(super) struct OpenHumanSessionState {- last_commit: Option<CommitReceipt<OpenHumanRunContext>>,terminals: Vec<SessionTerminal>,pub(super) last_turn_hit_cap: bool,pub(super) last_turn_usage: Option<crate::agent::tinyagents::host::LastTurnUsage>,@@ -1286,10 +1285,10 @@ impl OpenHumanSessionHost {let _ =progress::send_receipt_progress(&receipt, &input, &output, iterations).await;- state- .lock()- .unwrap_or_else(|poisoned| poisoned.into_inner())- .last_commit = Some(receipt);+ // Never retain the receipt: its run context holds the+ // turn's progress sender, which would keep the caller's+ // bridge alive after `set_on_progress(None)`.+ drop(receipt);{let mut state = state.lock()diff --git a/crates/openhuman-core/src/web_chat/run_task.rs b/crates/openhuman-core/src/web_chat/run_task.rsindex 915acf7b8c..a7fbc4aae2 100644--- a/crates/openhuman-core/src/web_chat/run_task.rs+++ b/crates/openhuman-core/src/web_chat/run_task.rs@@ -340,14 +340,13 @@ pub(crate) async fn run_chat_task(// Settle the turn's own snapshot now the turn is over.//// The bridge marks the snapshot terminal on its way out, but it only exits- // once its progress sender drops — and for a cached per-thread session that- // does not happen until the *next* turn replaces the sink, so a bridge- // routinely outlives its turn by minutes (the `did not drain` warning above- // is the visible edge of it). The last turn of a thread has no next turn to- // release it, leaving `Streaming` on disk indefinitely: re-entering the- // thread then hydrates that snapshot and paints a live "Thinking..."- // indicator under a reply that was already delivered. The turn has ended- // here by construction, so record that. A bridge that later observes+ // once every clone of its progress sender drops. The cached session no+ // longer keeps the turn's commit receipt (which held two), yet a detached+ // sub-agent may still hold one past the turn, and an exit the bridge never+ // reaches would leave `Streaming` on disk: re-entering the thread then+ // hydrates that snapshot and paints a live "Thinking..." indicator under a+ // reply that was already delivered. The turn has ended here by+ // construction, so record that. A bridge that later observes// `TurnCompleted` overwrites this with `Completed`, terminal either way.{let lifecycle = if result.is_ok() {diff --git a/scripts/ci/check-openhuman-rust-layout.mjs b/scripts/ci/check-openhuman-rust-layout.mjsindex 024de87f74..ec5c75e0c3 100644--- a/scripts/ci/check-openhuman-rust-layout.mjs+++ b/scripts/ci/check-openhuman-rust-layout.mjs@@ -38,7 +38,7 @@ const LEGACY_LIMIT_ENTRIES = [// under the general 750 limit, so it needs no exception at all.// The session-todo integration added transcript metadata construction to// this already-exempt composition seam. Keep its allowance exact.- ["crates/openhuman-core/src/agent/session_host/runtime_session.rs", 1465],+ ["crates/openhuman-core/src/agent/session_host/runtime_session.rs", 1464],// Session-host factory still assembles the product's deliberately coupled// provider, security, memory, tool and prompt policy. Generic session// state moved to tinyagents-runtime; this remaining composition is split in