The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix: abort media reuse when artifact refresh fails
Steven Enamakeldbbd78aa56b5
diff --git a/crates/openhuman-core/src/media/generation/artifact_tool.rs b/crates/openhuman-core/src/media/generation/artifact_tool.rsindex c9a85a60fb..f69527ca03 100644--- a/crates/openhuman-core/src/media/generation/artifact_tool.rs+++ b/crates/openhuman-core/src/media/generation/artifact_tool.rs@@ -358,18 +358,16 @@ impl<T: Tool> MediaArtifactTool<T> {/// Rehydrates finalized media paths after a session rebuild. Only Ready/// image/video artifacts whose files still resolve through the configured/// trusted roots enter the exact-path allowlist.- async fn refresh_allowed_references(&self) {+ async fn refresh_allowed_references(&self) -> Result<(), String> {let Some(allowed) = &self.allowed_references else {- return;+ return Ok(());};let mut recovered = std::collections::HashSet::new();- let previously_allowed = {- let mut allowed = allowed- .lock()- .unwrap_or_else(std::sync::PoisonError::into_inner);- std::mem::take(&mut *allowed)- };+ let previously_allowed = allowed+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner)+ .clone();let artifacts = match crate::agent::artifacts::store::list_artifacts(&self.workspace_dir,0,@@ -385,7 +383,10 @@ impl<T: Tool> MediaArtifactTool<T> {%error,"[media_generation] could not refresh reusable artifact paths");- return;+ return Err(+ "could not validate previously generated media references; retry the media call"+ .to_string(),+ );}};@@ -414,6 +415,7 @@ impl<T: Tool> MediaArtifactTool<T> {.unwrap_or_else(std::sync::PoisonError::into_inner);allowed.retain(|path| !previously_allowed.contains(path) || recovered.contains(path));allowed.extend(recovered);+ Ok(())}async fn file_blob(&self, key: &Path, dest: &Path) -> Result<u64, String> {@@ -564,7 +566,9 @@ impl<T: Tool> Tool for MediaArtifactTool<T> {context: Option<&dyn ToolRunContext>,) -> anyhow::Result<ToolResult> {if has_reusable_files_reference(&args, &self.files_dir) {- self.refresh_allowed_references().await;+ self.refresh_allowed_references()+ .await+ .map_err(anyhow::Error::msg)?;}// Generation blocks for minutes; report a heartbeat (with the videodiff --git a/crates/openhuman-core/src/media/generation/artifact_tool_tests.rs b/crates/openhuman-core/src/media/generation/artifact_tool_tests.rsindex c65bd31022..11ccb59a0d 100644--- a/crates/openhuman-core/src/media/generation/artifact_tool_tests.rs+++ b/crates/openhuman-core/src/media/generation/artifact_tool_tests.rs@@ -8,7 +8,6 @@ use tinytools::{PermissionLevel, Tool, ToolCategory, ToolContent, ToolResult};use super::{copy_blob_to_file, has_reusable_files_reference, MediaArtifactTool};use crate::agent::artifacts::{ArtifactKind, ArtifactStatus, FileRoots};-use crate::media::generation::tools::reference_policy;#[test]fn artifact_history_is_refreshed_only_for_absolute_paths_in_files_roots() {@@ -38,7 +37,7 @@ fn artifact_history_is_refreshed_only_for_absolute_paths_in_files_roots() {}#[tokio::test]-async fn artifact_history_refresh_failure_clears_previous_reference_grants() {+async fn artifact_history_refresh_failure_fails_closed_for_cached_files() {let root = tempfile::tempdir().unwrap();let workspace = root.path().join("not-a-workspace-directory");std::fs::write(&workspace, b"force artifact listing failure").unwrap();@@ -62,11 +61,11 @@ async fn artifact_history_refresh_failure_clears_previous_reference_grants() {).with_reference_allowlist(Arc::clone(&allowed));- tool.refresh_allowed_references().await;-- assert!(allowed.lock().unwrap().is_empty());- let policy = reference_policy(&action, &workspace, allowed);- assert!(policy(&replacement).is_err());+ assert!(allowed.lock().unwrap().contains(&replacement));+ assert!(tool+ .execute(json!({ "references": [replacement.to_string_lossy()] }))+ .await+ .is_err());}struct PartialThenFail(bool);@@ -269,7 +268,7 @@ 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;+ fresh.refresh_allowed_references().await.unwrap();{let allowed = fresh.allowed_references.as_ref().unwrap().lock().unwrap();assert!(allowed.contains(&canonical_file));@@ -289,7 +288,7 @@ async fn files_a_blob_backed_generated_artifact() {canonical_file.exists(),"failed regeneration retains the previous non-empty file");- fresh.refresh_allowed_references().await;+ fresh.refresh_allowed_references().await.unwrap();assert!(!fresh.allowed_references.as_ref()