Skip to content

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

fix(agent): box the turn futures held across a cancel select

M3gA-Mind4b1237f808fb
diff --git a/crates/openhuman-core/src/agent/session_host/driver.rs b/crates/openhuman-core/src/agent/session_host/driver.rs
index d9183d2ff5..b854f69bd0 100644
--- a/crates/openhuman-core/src/agent/session_host/driver.rs
+++ b/crates/openhuman-core/src/agent/session_host/driver.rs
@@ -190,7 +190,9 @@ impl SessionDriver<OpenHumanRunContext> for OpenHumanSessionDriver {
.harness_dispatcher(),
);
let cancellation = request.run_context.cancellation.clone();
- let turn = graph::run_chat_turn_graph(ChatTurnGraph {
+ // Boxed: the graph future is very large, and holding it inline in the
+ // `select!` below overflows the worker stack in debug builds.
+ let turn = Box::pin(graph::run_chat_turn_graph(ChatTurnGraph {
turn_models,
model: self.model_name.clone(),
messages,
@@ -209,7 +211,7 @@ impl SessionDriver<OpenHumanRunContext> for OpenHumanSessionDriver {
run_context,
hosted_base: self.hosted_base.clone(),
agent_id: self.agent_id.clone(),
- });
+ }));
// A Stop hands the runtime the rounds the provider already accepted,
// so the stopped turn's prompt and work stay in the session (#7715).
let result = tokio::select! {
diff --git a/crates/openhuman-core/src/web_chat/ops/turn_guards.rs b/crates/openhuman-core/src/web_chat/ops/turn_guards.rs
index 43abcbbba4..cc309baf1d 100644
--- a/crates/openhuman-core/src/web_chat/ops/turn_guards.rs
+++ b/crates/openhuman-core/src/web_chat/ops/turn_guards.rs
@@ -154,8 +154,11 @@ async fn run_until_stopped<T>(
turn: impl std::future::Future<Output = T>,
) -> Option<T> {
let turn_cancellation = tinyagents_harness::cancel::CancellationToken::new();
- let turn = crate::agent::host_overrides::with_cancellation(turn_cancellation.clone(), turn);
- tokio::pin!(turn);
+ // Boxed rather than stack-pinned: a chat turn's future is very large.
+ let mut turn = Box::pin(crate::agent::host_overrides::with_cancellation(
+ turn_cancellation.clone(),
+ turn,
+ ));
tokio::select! {
biased;
_ = cancel_token.cancelled() => {