Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(session_host): release progress sinks on retained commit receipt

Steven Enamakel1c200c439625
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
index 5df931b859..6c50fecf53 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -1286,6 +1286,13 @@ impl OpenHumanSessionHost {
let _ =
progress::send_receipt_progress(&receipt, &input, &output, iterations)
.await;
+ // The kept receipt must not hold the turn's progress
+ // channel open (see `detach_progress`).
+ let mut receipt = receipt;
+ receipt.options.context.detach_progress();
+ log::debug!(
+ "[session_host] last commit kept without its progress sinks session={session_id}"
+ );
state
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner())
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
index abcee0de49..6e794eb360 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
@@ -447,6 +447,22 @@ impl OpenHumanRunContext {
self.parent.insert(parent)
}
+ /// Drops this context's progress sinks: its own and its parent
+ /// snapshot's.
+ ///
+ /// For a context kept after its turn (the session's last commit receipt).
+ /// A web-chat turn's progress bridge runs until every sender of its
+ /// channel is gone, and the bridge holds the tenant's `CoreContext` while
+ /// it runs. A retained sender therefore kept the bridge alive until the
+ /// thread's next turn, and with it the context: a SaaS profile read as in
+ /// use and could never be evicted or idle-closed.
+ pub(crate) fn detach_progress(&mut self) {
+ self.progress = None;
+ if let Some(parent) = self.parent.as_mut() {
+ parent.on_progress = None;
+ }
+ }
+
/// Sets the same cancellation token on this context and its TinyAgents run.
pub fn with_cancellation(
mut self,
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs
index edb3ce09d1..7e876b402b 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs
@@ -381,3 +381,25 @@ fn attach_parent_keeps_the_snapshot_sink_when_the_run_has_none() {
CLI/cron receiver that snapshot was carrying",
);
}
+
+/// A context kept after its turn (the session's last commit receipt) must
+/// not keep the turn's progress channel open: the progress bridge runs until
+/// every sender is gone and holds the tenant's context meanwhile, so a kept
+/// sender pinned a SaaS profile open forever.
+#[test]
+fn detach_progress_releases_every_sender_of_the_turns_channel() {
+ let (tx, mut rx) = tokio::sync::mpsc::channel::<AgentProgress>(4);
+ let mut context = OpenHumanRunContext::new();
+ context.progress = Some(tx);
+ context.attach_parent(stale_parent_snapshot());
+ assert!(context.parent.as_ref().unwrap().on_progress.is_some());
+
+ context.detach_progress();
+
+ assert!(context.progress.is_none());
+ assert!(context.parent.as_ref().unwrap().on_progress.is_none());
+ assert!(
+ matches!(rx.try_recv(), Err(tokio::sync::mpsc::error::TryRecvError::Disconnected)),
+ "no sender of the turn's channel survives in the kept context"
+ );
+}