Skip to content

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

refactor(agent): extract sub-agent artifact offload into shared helper

Steven Enamakele64a88b38f2d
diff --git a/crates/openhuman-core/src/agent/harness/artifact_offload/mod.rs b/crates/openhuman-core/src/agent/harness/artifact_offload/mod.rs
index fc71e8d482..7ece885abc 100644
--- a/crates/openhuman-core/src/agent/harness/artifact_offload/mod.rs
+++ b/crates/openhuman-core/src/agent/harness/artifact_offload/mod.rs
@@ -158,6 +158,48 @@ pub async fn offload_oversized_result(
}
}
+/// Offload one finished sub-agent run's `output` for the tenant in scope: the
+/// artifact goes to its blob store and is materialised under the policy's
+/// action root (`action_dir` without a policy), the parent's root.
+///
+/// With no blob store for the tenant (a SaaS task with no scope, a refused
+/// backend) nothing is offloaded and `output` comes back untouched, like every
+/// other soft failure.
+pub async fn offload_run_result(
+ output: String,
+ policy: Option<Arc<SecurityPolicy>>,
+ action_dir: std::path::PathBuf,
+ agent_id: String,
+ task_id: &str,
+ threshold_bytes: usize,
+) -> (String, Option<OffloadedArtifact>) {
+ let materialize_root = policy
+ .as_ref()
+ .map(|p| p.action_dir.clone())
+ .unwrap_or_else(|| action_dir.clone());
+ let workspace_dir = policy
+ .as_ref()
+ .map(|p| p.workspace_dir.clone())
+ .unwrap_or(action_dir);
+ let Some(blobs) = crate::agent::session_store::artifact_blobs_for(&workspace_dir) else {
+ tracing::debug!(
+ task_id = %task_id,
+ agent_id = %agent_id,
+ "[artifact] no blob store for the acting tenant — skipping offload (summarizer/truncation backstop applies)"
+ );
+ return (output, None);
+ };
+ let offload = new_artifact_offload(blobs, policy.clone(), agent_id, task_id);
+ offload_oversized_result(
+ output,
+ &offload,
+ threshold_bytes,
+ &materialize_root,
+ policy.as_deref(),
+ )
+ .await
+}
+
/// Write the stored (redacted) body of `artifact` to `root/<key>`.
async fn materialize(
offload: &ArtifactOffload,
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 97fb8ef59d..0ad6dde952 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
@@ -9,7 +9,7 @@
use std::collections::HashSet;
use std::time::Instant;
-use crate::agent::harness::artifact_offload::{new_artifact_offload, offload_oversized_result};
+use crate::agent::harness::artifact_offload::offload_run_result;
use crate::agent::harness::fork_context::ParentExecutionContext;
use crate::agent::harness::host_definition::{AgentDefinition, AgentDefinitionRegistry};
use crate::agent::prompts::{
@@ -477,37 +477,13 @@ async fn offload_outcome_artifacts(
// The parent that receives the pointer resolves relative paths against ITS
// action root, so the stored artifact is materialised there (also for a
// worktree-isolated worker) and the handed-back `outputs/…` path opens.
- let materialize_root = policy
- .as_ref()
- .map(|p| p.action_dir.clone())
- .unwrap_or_else(|| action_dir.clone());
- let workspace_dir = policy
- .as_ref()
- .map(|p| p.workspace_dir.clone())
- .unwrap_or_else(|| action_dir.clone());
- let blobs = crate::agent::session_store::artifact_blobs_for(&workspace_dir);
- let Some(blobs) = blobs else {
- tracing::debug!(
- task_id = %task_id,
- agent_id = %outcome.agent_id,
- "[artifact] no blob store for the acting tenant — skipping offload (summarizer/truncation backstop applies)"
- );
- outcome.artifact_paths = paths;
- note_artifact_handoff(
- HANDOFF_STAGE_RECORDED,
- &outcome.agent_id,
- task_id,
- &outcome.artifact_paths,
- );
- return;
- };
- let offload = new_artifact_offload(blobs, policy.clone(), outcome.agent_id.clone(), task_id);
- let (output, _artifact) = offload_oversized_result(
+ let (output, _artifact) = offload_run_result(
std::mem::take(&mut outcome.output),
- &offload,
+ policy,
+ action_dir,
+ outcome.agent_id.clone(),
+ task_id,
threshold,
- &materialize_root,
- policy.as_deref(),
)
.await;
outcome.output = output;
diff --git a/scripts/ci/check-openhuman-rust-layout.mjs b/scripts/ci/check-openhuman-rust-layout.mjs
index f6adc435ac..d635b0d599 100644
--- a/scripts/ci/check-openhuman-rust-layout.mjs
+++ b/scripts/ci/check-openhuman-rust-layout.mjs
@@ -27,7 +27,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", 1128],
+ ["crates/openhuman-core/src/agent/session_host/runtime_session.rs", 1124],
// `[components] juice` test constructor (tokenjuice gate tests).
["crates/openhuman-core/src/core/runtime/context.rs", 753],
// Session-host factory still assembles the product's deliberately coupled
@@ -36,7 +36,7 @@ const LEGACY_LIMIT_ENTRIES = [
// a follow-up without reintroducing an old harness/session exception.
["crates/openhuman-core/src/agent/session_host/builder/factory.rs", 975],
["crates/openhuman-core/src/agent/subagent_host/lifecycle.rs", 1247],
- ["crates/openhuman-core/src/agent/subagent_host/ops/runner.rs", 1046],
+ ["crates/openhuman-core/src/agent/subagent_host/ops/runner.rs", 1045],
["crates/openhuman-core/src/web_chat/progress_bridge.rs", 1261],
// These established external test modules grew with upstream coverage. Pin
// their current sizes while follow-up work separates their test concerns.