Skip to content

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

fix: delegate Piper install serialization

Steven Enamakel13c2deb6222a
diff --git a/crates/openhuman-core/src/inference/local/schemas.rs b/crates/openhuman-core/src/inference/local/schemas.rs
index 11af7c1fea..37b7dfe257 100644
--- a/crates/openhuman-core/src/inference/local/schemas.rs
+++ b/crates/openhuman-core/src/inference/local/schemas.rs
@@ -419,26 +419,6 @@ fn handle_local_ai_install_piper(params: Map<String, Value>) -> ControllerFuture
let config = config_rpc::load_config_with_timeout().await?;
let force = p.force.unwrap_or(false);
- // Atomic install-start guard: a duplicate click while an install is
- // already in flight must be a no-op, not a second concurrent download
- // racing on the same `.part` file. `try_acquire_install_slot` does the
- // check-and-claim under a single mutex acquisition.
- let slot = match tinyinference::local::download::try_acquire_install_slot(
- tinyinference::local::download::ENGINE_PIPER,
- ) {
- Some(slot) => slot,
- None => {
- tracing::debug!(
- "[voice-install:piper] slot already held — returning current status"
- );
- let current = tinyinference::local::download::read_status(
- tinyinference::local::download::ENGINE_PIPER,
- );
- return serde_json::to_value(current)
- .map_err(|e| format!("serialize piper status: {e}"));
- }
- };
-
tinyinference::local::download::write_status(
tinyinference::local::download::VoiceInstallStatus {
engine: tinyinference::local::download::ENGINE_PIPER.to_string(),
@@ -457,12 +437,7 @@ fn handle_local_ai_install_piper(params: Map<String, Value>) -> ControllerFuture
"[voice-install:piper] spawning background install"
);
let voice_id = p.voice_id.clone();
- // Move the slot into the spawned task so it lives for the actual
- // install duration (download + extract + validate), not just the RPC
- // handler's lifetime. The slot's Drop releases the single-writer guard
- // on task exit, including via panic.
tokio::spawn(async move {
- let _slot = slot;
let install = tinyinference::local::piper::PiperInstall::new(
crate::inference::paths::workspace_piper_dir(&config),
);
diff --git a/crates/openhuman-core/src/inference/local/schemas_tests.rs b/crates/openhuman-core/src/inference/local/schemas_tests.rs
index 5349d24bbb..02b3f65799 100644
--- a/crates/openhuman-core/src/inference/local/schemas_tests.rs
+++ b/crates/openhuman-core/src/inference/local/schemas_tests.rs
@@ -97,68 +97,6 @@ fn deserialize_params_errors_on_invalid_shape() {
assert!(err.contains("invalid params"));
}
-// ── Handler-level tests that don't need Ollama ────────────────
-
-use crate::config::TEST_ENV_LOCK as ENV_LOCK;
-use tempfile::TempDir;
-
-/// Regression test for the CodeRabbit #7 race on PR #1755: when two concurrent
-/// RPC calls (a double-click, or an auto-install firing alongside a manual
-/// click) hit `handle_local_ai_install_piper` at the same time, only one must
-/// spawn a real install task. The other must short-circuit and return the
-/// in-flight status without starting a second download that would race on the
-/// same `.part` file.
-///
-/// Exercises the actual handler — not just the slot primitive — so the wiring
-/// at the call site is covered too.
-#[tokio::test]
-async fn install_piper_handler_serializes_concurrent_calls() {
- let _g = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
- let tmp = TempDir::new().unwrap();
- unsafe {
- std::env::set_var("OPENHUMAN_WORKSPACE", tmp.path());
- }
-
- let slot = tinyinference::local::download::try_acquire_install_slot(
- tinyinference::local::download::ENGINE_PIPER,
- )
- .expect("test should be able to claim the slot first");
-
- tinyinference::local::download::write_status(
- tinyinference::local::download::VoiceInstallStatus {
- engine: tinyinference::local::download::ENGINE_PIPER.to_string(),
- state: tinyinference::local::download::VoiceInstallState::Installing,
- progress: Some(0),
- downloaded_bytes: None,
- total_bytes: None,
- stage: Some("queued".to_string()),
- error_detail: None,
- },
- );
-
- let (r1, r2) = tokio::join!(
- handle_local_ai_install_piper(Map::new()),
- handle_local_ai_install_piper(Map::new())
- );
-
- unsafe {
- std::env::remove_var("OPENHUMAN_WORKSPACE");
- }
- drop(slot);
- tinyinference::local::download::reset_status(tinyinference::local::download::ENGINE_PIPER);
-
- let v1 = r1.expect("first call ok");
- let v2 = r2.expect("second call ok");
- for (label, v) in [("first", &v1), ("second", &v2)] {
- let state = v.get("state").and_then(|s| s.as_str());
- assert_eq!(
- state,
- Some("installing"),
- "{label} concurrent call should see Installing, got {v:?}"
- );
- }
-}
-
/// `agent_id` is a declared, optional input of `inference.agent_chat` — the
/// embed crate pins its `TurnRequest` field names against this schema, so a
/// param the controller accepts but never declares would be unreachable.
diff --git a/vendor/tinyagents b/vendor/tinyagents
index f5eeb77c3b..004b44b0a3 160000
--- a/vendor/tinyagents
+++ b/vendor/tinyagents
@@ -1 +1 @@
-Subproject commit f5eeb77c3b6fa539437184f9acb6c186945d3940
+Subproject commit 004b44b0a3b08e9e8e78c95640f680ecd5a98a71