Skip to content

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

fix(subagent-host): box large futures to reduce stack frame size

Steven Enamakel7dfbd2097cc3
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
index 96334ef8ff..a754f99b07 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
@@ -58,9 +58,10 @@ pub async fn run_subagent_with_parent(
input: impl Into<String>,
options: SubagentRunOptions,
) -> Result<SubagentRunOutcome, SubagentRunError> {
- OpenHumanSubagentHost::new(definition, options)
- .run(parent, input.into())
- .await
+ // Boxed at every level of the host lifecycle: an unoptimised build keeps each
+ // awaited future inline in its caller's poll frame, so an unboxed chain
+ // multiplies the ~60 KB nested state machine per level (#6379).
+ Box::pin(OpenHumanSubagentHost::new(definition, options).run(parent, input.into())).await
}
/// Root host entrypoint for callers that begin outside a retained live parent
@@ -74,7 +75,13 @@ pub async fn run_subagent(
let mut root_data = root_context_from_options(&options);
let root_config = root_data.root_run_config("subagent-host");
let root = root_data.into_tinyagents(root_config);
- run_subagent_with_parent(&root, definition.clone(), input, options).await
+ Box::pin(run_subagent_with_parent(
+ &root,
+ definition.clone(),
+ input,
+ options,
+ ))
+ .await
}
/// Resume a durable lifecycle with its recovered original task key. The fresh
@@ -260,8 +267,7 @@ impl OpenHumanSubagentHost {
child_config,
)
.map_err(|error| SubagentRunError::Provider(anyhow::anyhow!(error.to_string())))?;
- self.run_with_request(parent, task_key, child, input, false)
- .await
+ Box::pin(self.run_with_request(parent, task_key, child, input, false)).await
}
async fn continue_with_key(
@@ -277,8 +283,7 @@ impl OpenHumanSubagentHost {
child_config,
)
.map_err(|error| SubagentRunError::Provider(anyhow::anyhow!(error.to_string())))?;
- self.run_with_request(parent, task_key, child, input, true)
- .await
+ Box::pin(self.run_with_request(parent, task_key, child, input, true)).await
}
async fn run_with_request(
@@ -335,16 +340,15 @@ impl OpenHumanSubagentHost {
.await;
}
- let result = self
- .run_leader(
- parent,
- task_key.clone(),
- child,
- input,
- continuation,
- checkpoint_dir,
- )
- .await;
+ let result = Box::pin(self.run_leader(
+ parent,
+ task_key.clone(),
+ child,
+ input,
+ continuation,
+ checkpoint_dir,
+ ))
+ .await;
entry.complete(result.as_ref().ok().cloned()).await;
let mut entries = host_in_flight().lock().await;
if entries
@@ -410,7 +414,7 @@ impl OpenHumanSubagentHost {
}
.map_err(map_lifecycle_error)?;
let cancellation = parent.cancellation.clone();
- match driver.run(request, cancellation).await {
+ match Box::pin(driver.run(request, cancellation)).await {
Ok(result) => Ok(outcome_to_host(
result,
host_outcome
@@ -534,7 +538,7 @@ impl SubagentExecutor<crate::agent::tinyagents::host::OpenHumanRunContext> for O
// its explicit OpenHuman carrier.
options.run_context = execution.prepared.run_context.data.clone();
options.run_context.cancellation = execution.cancellation.clone();
- match super::ops::run_subagent_direct(
+ match Box::pin(super::ops::run_subagent_direct(
&definition,
&execution
.prepared
@@ -543,7 +547,7 @@ impl SubagentExecutor<crate::agent::tinyagents::host::OpenHumanRunContext> for O
.map(Message::text)
.unwrap_or_default(),
options.clone(),
- )
+ ))
.await
{
Ok(outcome) => {
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
index 0ca601d8a3..3b5fe14532 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
@@ -548,7 +548,9 @@ pub(crate) async fn run_subagent_direct(
// Deliberately placed *after* `tier_gate_decision`: `load_or_init` can
// initialize config on first run, and a spawn the tier gate rejects
// should not have that side effect.
- let loaded_config: LoadedConfig = crate::config::Config::load_or_init()
+ // Boxed: the load future is ~50 KB and an unoptimised build keeps every
+ // awaited future inline in this frame (#6379).
+ let loaded_config: LoadedConfig = Box::pin(crate::config::Config::load_or_init())
.await
.map(std::sync::Arc::new)
.map_err(|e| e.to_string());
@@ -561,13 +563,13 @@ pub(crate) async fn run_subagent_direct(
// to the full sub-agent when the fast path is disabled/errs/finds
// nothing (the empty/degraded case is handled by #4655).
if definition.id == AGENT_MEMORY_ID {
- if let Some(outcome) = try_deterministic_memory_retrieval(
+ if let Some(outcome) = Box::pin(try_deterministic_memory_retrieval(
task_prompt,
definition,
&task_id,
started,
&loaded_config,
- )
+ ))
.await
{
// The fast path completes a real delegation and returns here,
@@ -630,7 +632,7 @@ pub(crate) async fn run_subagent_direct(
"[subagent_host] worktree-isolated worker: descriptor will route acting-tool CWD"
);
}
- let run_result = with_spawn_depth(attempted_depth, async {
+ let run_result = Box::pin(with_spawn_depth(attempted_depth, async {
with_file_state_agent_id(task_id.clone(), async {
with_current_sandbox_mode(definition.sandbox_mode, async {
Box::pin(run_typed_mode(
@@ -646,7 +648,7 @@ pub(crate) async fn run_subagent_direct(
.await
})
.await
- })
+ }))
.await;
// Feed this delegation's wall-clock into the turn's running maximum,
@@ -685,7 +687,7 @@ pub(crate) async fn run_subagent_direct(
// an abstract and the full-fidelity body survives on disk instead of
// being cut. A refused or failed offload is soft: the inline payload
// continues on to the cap and the summarizer detour exactly as before.
- offload_outcome_artifacts(&mut outcome, definition, &options, &task_id).await;
+ Box::pin(offload_outcome_artifacts(&mut outcome, definition, &options, &task_id)).await;
// Truncate result to the definition's cap if set (shared with the
// deterministic memory fast path via `apply_max_result_chars`).