Skip to content

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

chore: files changed crates/openhuman-core/src/agent/orchestration/background_delivery.rs,crates/ope

Steven Enamakel9d28c2594a3d
diff --git a/crates/openhuman-core/src/agent/orchestration/background_delivery.rs b/crates/openhuman-core/src/agent/orchestration/background_delivery.rs
index e0cc82262b..424ecdcc04 100644
--- a/crates/openhuman-core/src/agent/orchestration/background_delivery.rs
+++ b/crates/openhuman-core/src/agent/orchestration/background_delivery.rs
@@ -28,9 +28,9 @@
//! `chat_done`, so a reconnect cannot lose a completed delegated result.
use std::collections::{HashMap, HashSet};
-use std::sync::atomic::{AtomicU64, Ordering};
use std::future::Future;
use std::path::{Path, PathBuf};
+use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Arc, Mutex, OnceLock};
use std::time::Duration;
diff --git a/crates/openhuman-core/src/agent/orchestration/background_delivery_slots_tests.rs b/crates/openhuman-core/src/agent/orchestration/background_delivery_slots_tests.rs
index 1353699534..79dc1f50af 100644
--- a/crates/openhuman-core/src/agent/orchestration/background_delivery_slots_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/background_delivery_slots_tests.rs
@@ -184,10 +184,10 @@ async fn desktop_keys_are_the_bare_ids() {
let turn = in_scope(&desktop, || TurnBusy::start(&session));
assert_eq!(turn.key, session);
- assert!(busy().lock().unwrap().contains(&session));
+ assert!(busy().lock().unwrap().contains_key(&session));
assert!(in_scope(&desktop, || is_busy(&thread)));
drop(turn);
- assert!(!busy().lock().unwrap().contains(&session));
+ assert!(!busy().lock().unwrap().contains_key(&session));
let router = router_for_workspace(ws.path());
let slot = in_scope(&desktop, || DeliverySlot::claim(&thread, router)).expect("free");
@@ -196,3 +196,21 @@ async fn desktop_keys_are_the_bare_ids() {
drop(slot);
assert!(!delivering().lock().unwrap().contains(&thread));
}
+
+#[tokio::test]
+async fn an_older_guard_dropping_keeps_a_replacement_turn_busy() {
+ let _guard = crate::config::TEST_ENV_LOCK.lock().await;
+ let desktop = CoreContext::for_test(DomainSet::full(), None);
+ let thread = unique("t-interrupt");
+ let session = web_session(&thread);
+
+ let old = in_scope(&desktop, || TurnBusy::start(&session));
+ let new = in_scope(&desktop, || TurnBusy::start(&session));
+ drop(old);
+ assert!(
+ in_scope(&desktop, || is_busy(&thread)),
+ "replacement still running"
+ );
+ drop(new);
+ assert!(!in_scope(&desktop, || is_busy(&thread)));
+}
diff --git a/crates/openhuman-core/src/agent/orchestration/background_delivery_tests.rs b/crates/openhuman-core/src/agent/orchestration/background_delivery_tests.rs
index c9c262c762..f80107e49c 100644
--- a/crates/openhuman-core/src/agent/orchestration/background_delivery_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/background_delivery_tests.rs
@@ -37,7 +37,12 @@ fn pending_ids(ws: &Path, thread: &str) -> Vec<String> {
}
fn mark_busy(session: &str) {
- busy().lock().expect("busy").insert(session.to_string());
+ busy()
+ .lock()
+ .expect("busy")
+ .entry(session.to_string())
+ .or_default()
+ .insert(u64::MAX);
}
fn clear_busy(session: &str) {
diff --git a/crates/openhuman-core/src/agent/session_host/runtime/run_loop.rs b/crates/openhuman-core/src/agent/session_host/runtime/run_loop.rs
index 99ede836cd..80418252c8 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime/run_loop.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime/run_loop.rs
@@ -144,12 +144,12 @@ impl OpenHumanSessionHost {
],
);
}
- drop(busy);
BUS.publish(DomainEvent::AgentError {
session_id: self.event_session_id().to_string(),
message: sanitized_message,
recoverable: false,
});
+ drop(busy);
Err(err)
}
}