Skip to content

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

fix(artifacts): read version files through the file store

Steven Enamakel784370f1aa8b
diff --git a/crates/openhuman-core/src/artifacts/tiny_store.rs b/crates/openhuman-core/src/artifacts/tiny_store.rs
index a74720d8d8..085953a620 100644
--- a/crates/openhuman-core/src/artifacts/tiny_store.rs
+++ b/crates/openhuman-core/src/artifacts/tiny_store.rs
@@ -101,6 +101,7 @@ pub struct LegacyUiBridge {
workspace_dir: PathBuf,
files: FileRoots,
chat: Option<ApprovalChatContext>,
+ file_store: Option<Arc<dyn tiny_artifacts::FileStore>>,
}
impl LegacyUiBridge {
@@ -110,11 +111,20 @@ impl LegacyUiBridge {
workspace_dir: impl Into<PathBuf>,
files: FileRoots,
chat: Option<&ApprovalChatContext>,
+ file_store: Option<Arc<dyn tiny_artifacts::FileStore>>,
) -> Self {
Self {
workspace_dir: workspace_dir.into(),
files,
chat: chat.cloned(),
+ file_store,
+ }
+ }
+
+ async fn read_version_file(&self, file: &tiny_artifacts::FileRef) -> anyhow::Result<Vec<u8>> {
+ match &self.file_store {
+ Some(file_store) => Ok(file_store.read(&file.key).await?),
+ None => Ok(tokio::fs::read(stored_file_path(&self.workspace_dir, file)).await?),
}
}
@@ -139,12 +149,13 @@ impl LegacyUiBridge {
== Some(ext.clone())
});
if let Some(owned) = owned {
- let source_buf = stored_file_path(&self.workspace_dir, file);
- let source = source_buf.as_path();
- let size = if same_file(owned, source) {
- tokio::fs::metadata(source).await?.len()
+ let source_path = stored_file_path(&self.workspace_dir, file);
+ let size = if self.file_store.is_none() && same_file(owned, &source_path) {
+ tokio::fs::metadata(&source_path).await?.len()
} else {
- tokio::fs::copy(source, owned).await?
+ let bytes = self.read_version_file(file).await?;
+ tokio::fs::write(owned, &bytes).await?;
+ bytes.len() as u64
};
super::store::finalize_artifact(
&self.workspace_dir,
@@ -171,14 +182,17 @@ impl LegacyUiBridge {
.await
.map_err(anyhow::Error::msg)?;
let size = if record.holds_file() {
- let source = latest.file.as_ref().map_or_else(
- || PathBuf::from(&latest.body),
- |f| stored_file_path(&self.workspace_dir, f),
- );
- if same_file(&source, &dest) {
- tokio::fs::metadata(&dest).await?.len()
+ if let Some(file) = latest.file.as_ref() {
+ let bytes = self.read_version_file(file).await?;
+ tokio::fs::write(&dest, &bytes).await?;
+ bytes.len() as u64
} else {
- tokio::fs::copy(&source, &dest).await?
+ let source = PathBuf::from(&latest.body);
+ if same_file(&source, &dest) {
+ tokio::fs::metadata(&dest).await?.len()
+ } else {
+ tokio::fs::copy(&source, &dest).await?
+ }
}
} else {
tokio::fs::write(&dest, latest.body.as_bytes()).await?;
@@ -302,20 +316,28 @@ pub fn artifacts_service(
chat: Option<&ApprovalChatContext>,
) -> Artifacts {
let roots = file_roots(workspace_dir, &files, action_dir);
- let service = Artifacts::new(Arc::new(versioned_store(workspace_dir)))
- .with_observer(Arc::new(LegacyUiBridge::new(workspace_dir, files, chat)))
- .with_file_roots(guarded_roots(roots));
- match crate::storage::local::open("artifacts::files", workspace_dir)
+ let file_store = match crate::storage::local::open("artifacts::files", workspace_dir)
.and_then(|opened| opened.scoped())
{
- Ok(scoped) => {
- service.with_file_store(Arc::new(tiny_artifacts::BlobFileStore::new(&scoped)))
- }
+ Ok(scoped) => Some(Arc::new(tiny_artifacts::BlobFileStore::new(&scoped))
+ as Arc<dyn tiny_artifacts::FileStore>),
Err(error) => {
log::warn!("[artifacts] file storage unavailable: {error:#}");
- service
+ None
}
+ };
+ let mut service = Artifacts::new(Arc::new(versioned_store(workspace_dir)))
+ .with_observer(Arc::new(LegacyUiBridge::new(
+ workspace_dir,
+ files,
+ chat,
+ file_store.clone(),
+ )))
+ .with_file_roots(guarded_roots(roots));
+ if let Some(file_store) = file_store {
+ service = service.with_file_store(file_store);
}
+ service
}
/// Where each file version keeps its own copy: