Skip to content

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

refactor(artifacts): extract document-mode delete into store_documents

Steven Enamakel463d2b80ff6d
diff --git a/crates/openhuman-core/src/agent/artifacts/store.rs b/crates/openhuman-core/src/agent/artifacts/store.rs
index a68ae57965..8527d84144 100644
--- a/crates/openhuman-core/src/agent/artifacts/store.rs
+++ b/crates/openhuman-core/src/agent/artifacts/store.rs
@@ -390,26 +390,7 @@ pub(crate) async fn delete_artifact(
}
}
if let Some(docs) = documents(workspace_dir).await? {
- let id = artifact_id.to_string();
- let existed = on_docs(docs, move |docs| docs.delete(&id)).await?;
- // The legacy directory goes too, so a later import does not bring
- // the artifact back.
- match tokio::fs::remove_dir_all(&artifact_dir).await {
- Ok(()) => {}
- Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
- Err(e) => {
- return Err(format!(
- "[artifacts] failed to delete legacy record for id={artifact_id}: {e}"
- ))
- }
- }
- if !existed {
- return Err(format!(
- "[artifacts] failed to delete artifact id={artifact_id}: not found"
- ));
- }
- log::debug!("[artifacts] delete_artifact: deleted record id={artifact_id}");
- return Ok(());
+ return store_documents::delete_record(docs, &artifact_dir, artifact_id).await;
}
tokio::fs::remove_dir_all(&artifact_dir)
.await
diff --git a/crates/openhuman-core/src/agent/artifacts/store_documents.rs b/crates/openhuman-core/src/agent/artifacts/store_documents.rs
index 393efc770b..fe7a80fbb5 100644
--- a/crates/openhuman-core/src/agent/artifacts/store_documents.rs
+++ b/crates/openhuman-core/src/agent/artifacts/store_documents.rs
@@ -278,6 +278,30 @@ pub(super) async fn documents(workspace_dir: &Path) -> Result<Option<Docs>, Stri
Ok(Some(docs))
}
+/// Deletes artifact `id` in document mode: the record and its arguments,
+/// then its legacy directory (`artifact_dir`) so a later import does not bring
+/// it back. Not found when there was no record, as the file store reports.
+pub(super) async fn delete_record(docs: Docs, artifact_dir: &Path, id: &str) -> Result<(), String> {
+ let owned = id.to_string();
+ let existed = on_docs(docs, move |docs| docs.delete(&owned)).await?;
+ match tokio::fs::remove_dir_all(artifact_dir).await {
+ Ok(()) => {}
+ Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
+ Err(e) => {
+ return Err(format!(
+ "[artifacts] failed to delete legacy record for id={id}: {e}"
+ ))
+ }
+ }
+ if !existed {
+ return Err(format!(
+ "[artifacts] failed to delete artifact id={id}: not found"
+ ));
+ }
+ log::debug!("[artifacts] delete_artifact: deleted record id={id}");
+ Ok(())
+}
+
/// Sorts newest first, applies the thread filter and then the page.
pub(super) fn page_of(
mut all: Vec<ArtifactMeta>,
diff --git a/crates/openhuman-core/src/storage/documents_tests.rs b/crates/openhuman-core/src/storage/documents_tests.rs
index 8ef02d784d..c6ae455419 100644
--- a/crates/openhuman-core/src/storage/documents_tests.rs
+++ b/crates/openhuman-core/src/storage/documents_tests.rs
@@ -193,8 +193,12 @@ fn one_time_work_runs_once_per_backend_and_scope_and_retries_failures() {
repo.once_per_backend("k", count).unwrap();
assert_eq!(runs.get(), 1, "a failure is retried, a success is recorded");
repo.once_per_backend("other", count).unwrap();
- repo_on(&first, "once-b").once_per_backend("k", count).unwrap();
- repo_on(&backend(), "once").once_per_backend("k", count).unwrap();
+ repo_on(&first, "once-b")
+ .once_per_backend("k", count)
+ .unwrap();
+ repo_on(&backend(), "once")
+ .once_per_backend("k", count)
+ .unwrap();
assert_eq!(runs.get(), 4, "another key, scope or backend runs afresh");
// Without an origin there is no identity to key on: it always runs.