Skip to content

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

fix: prune revoked media references

Steven Enamakeld5ff398a5f09
diff --git a/crates/openhuman-core/src/media/generation/artifact_tool.rs b/crates/openhuman-core/src/media/generation/artifact_tool.rs
index 51faef7985..6755bf295a 100644
--- a/crates/openhuman-core/src/media/generation/artifact_tool.rs
+++ b/crates/openhuman-core/src/media/generation/artifact_tool.rs
@@ -329,6 +329,10 @@ impl<T: Tool> MediaArtifactTool<T> {
};
let mut recovered = std::collections::HashSet::new();
+ let previously_allowed = allowed
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .clone();
let mut offset = 0usize;
loop {
let (artifacts, total) = match crate::agent::artifacts::store::list_artifacts(
@@ -375,12 +379,13 @@ impl<T: Tool> MediaArtifactTool<T> {
}
}
- // Merge rather than replace so an artifact finalized concurrently with
- // this scan cannot be lost from the current session's allowlist.
- allowed
+ // Prune paths that were allowed before this scan but are no longer
+ // Ready. Paths added concurrently after the snapshot are preserved.
+ let mut allowed = allowed
.lock()
- .unwrap_or_else(std::sync::PoisonError::into_inner)
- .extend(recovered);
+ .unwrap_or_else(std::sync::PoisonError::into_inner);
+ allowed.retain(|path| !previously_allowed.contains(path) || recovered.contains(path));
+ allowed.extend(recovered);
}
async fn file_blob(&self, key: &Path, dest: &Path) -> Result<u64, String> {
diff --git a/crates/openhuman-core/src/media/generation/artifact_tool_tests.rs b/crates/openhuman-core/src/media/generation/artifact_tool_tests.rs
index 9a16f89de9..e85cc17401 100644
--- a/crates/openhuman-core/src/media/generation/artifact_tool_tests.rs
+++ b/crates/openhuman-core/src/media/generation/artifact_tool_tests.rs
@@ -210,9 +210,33 @@ async fn files_a_blob_backed_generated_artifact() {
.with_blobs(blobs)
.with_reference_allowlist(Arc::new(std::sync::Mutex::new(Default::default())));
fresh.refresh_allowed_references().await;
- let allowed = fresh.allowed_references.as_ref().unwrap().lock().unwrap();
- assert!(allowed.contains(&std::path::PathBuf::from(file).canonicalize().unwrap()));
- assert!(!allowed.contains(&failed_file.canonicalize().unwrap()));
+ {
+ let allowed = fresh.allowed_references.as_ref().unwrap().lock().unwrap();
+ assert!(allowed.contains(&canonical_file));
+ assert!(!allowed.contains(&failed_file.canonicalize().unwrap()));
+ }
+
+ crate::agent::artifacts::fail_artifact(
+ &workspace,
+ fresh.files_dir.clone(),
+ artifact_id,
+ "revoked for the refresh test",
+ None,
+ )
+ .await
+ .unwrap();
+ assert!(
+ canonical_file.exists(),
+ "failed regeneration retains the previous non-empty file"
+ );
+ fresh.refresh_allowed_references().await;
+ assert!(!fresh
+ .allowed_references
+ .as_ref()
+ .unwrap()
+ .lock()
+ .unwrap()
+ .contains(&canonical_file));
}
#[tokio::test]