Skip to content

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

refactor(agent): delegate artifact offload materialization to harness

Steven Enamakel88d116c9f0e9
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 c5782581a3..b7cfcec1f9 100644
--- a/crates/openhuman-core/src/agent/harness/artifact_offload/mod.rs
+++ b/crates/openhuman-core/src/agent/harness/artifact_offload/mod.rs
@@ -51,7 +51,7 @@ pub mod policy;
use std::path::Path;
use std::sync::Arc;
-use tinyagents_harness::artifacts::{ArtifactKind, ArtifactOffload};
+use tinyagents_harness::artifacts::ArtifactOffload;
use tinystoragedrivers::BlobStore;
use crate::security::SecurityPolicy;
@@ -118,43 +118,20 @@ pub async fn offload_oversized_result(
materialize_root: &Path,
policy: Option<&SecurityPolicy>,
) -> (String, Option<OffloadedArtifact>) {
- // The blob key is relative, so the crate's path policy cannot see where the
- // reader's copy will land. Refuse here, before anything is stored, a target
- // that would reach the core's internal state.
- if let Some(policy) = policy {
- if let Ok(key) = offload.resolve(ArtifactKind::Output, &offload.default_result_name()) {
- let target = materialize_root.join(&key);
- if policy.is_workspace_internal_path(&target)
- || target.starts_with(&policy.workspace_dir)
- {
- tracing::warn!(
- path = %key,
- "[artifact] materialized target reaches workspace state; keeping the inline result"
- );
- return (output, None);
- }
- }
- }
- let (pointer, artifact) = tinyagents_harness::artifacts::offload_oversized_result(
+ // The owner's filesystem-aware offload validates the eventual target
+ // before storing bytes, then writes and materializes through its policy.
+ let (pointer, artifact) = tinyagents_harness::artifacts::offload_oversized_result_to_fs(
output.clone(),
offload,
threshold_bytes,
READ_TOOL,
+ materialize_root,
)
.await;
- let Some(artifact) = artifact else {
- return (output, None);
- };
- match materialize(offload, &artifact, materialize_root).await {
- Ok(()) => (pointer, Some(artifact)),
- Err(error) => {
- tracing::warn!(
- path = %artifact.relative_path,
- error = %error,
- "[artifact] could not materialize the stored artifact; keeping the inline result"
- );
- (output, None)
- }
+ if artifact.is_some() {
+ (pointer, artifact)
+ } else {
+ (output, None)
}
}
@@ -200,32 +177,6 @@ pub async fn offload_run_result(
.await
}
-/// Write the stored (redacted) body of `artifact` to `root/<key>`.
-async fn materialize(
- offload: &ArtifactOffload,
- artifact: &OffloadedArtifact,
- root: &Path,
-) -> Result<(), String> {
- let body = offload
- .read(&artifact.relative_path)
- .await
- .map_err(|error| error.to_string())?
- .ok_or_else(|| "the artifact vanished from the blob store".to_string())?;
- // `read` re-ran the fail-closed key checks (no absolute names, `..`, or
- // control characters), so the join cannot leave `root`.
- let target = root.join(&artifact.relative_path);
- if let Some(parent) = target.parent() {
- tokio::fs::create_dir_all(parent)
- .await
- .map_err(|error| error.to_string())?;
- }
- tokio::fs::write(&target, body)
- .await
- .map_err(|error| error.to_string())?;
- tracing::debug!(path = %artifact.relative_path, "[artifact] materialized for file_read");
- Ok(())
-}
-
#[cfg(test)]
#[path = "artifact_offload_tests.rs"]
mod tests;