Skip to content

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

fix: bound library cleanup and managed preflight

Steven Enamakel1c09de1d6844
diff --git a/src/embed/harness/mod.rs b/src/embed/harness/mod.rs
index f153e9e904..a7c52e897b 100644
--- a/src/embed/harness/mod.rs
+++ b/src/embed/harness/mod.rs
@@ -195,11 +195,22 @@ impl Drop for Harness {
// `keep()` hands back the path without removing the directory so
// we can do the retried removal ourselves.
let root = temp.keep();
- // Keep clearing through the whole bounded settling window. A
- // successful first removal is not sufficient: a detached session
- // writer can recreate the directory immediately afterward.
+ // Require a short quiet period rather than trusting one successful
+ // removal: a detached session writer can recreate the directory
+ // immediately afterward. Most drops finish in ~200 ms; repeated
+ // writes retain the one-second hard cap.
+ let mut quiet_passes = 0;
for _ in 0..20 {
- let _ = std::fs::remove_dir_all(&root);
+ match std::fs::remove_dir_all(&root) {
+ Ok(()) => quiet_passes += 1,
+ Err(error) if error.kind() == std::io::ErrorKind::NotFound => {
+ quiet_passes += 1;
+ }
+ Err(_) => quiet_passes = 0,
+ }
+ if quiet_passes >= 5 {
+ break;
+ }
std::thread::sleep(std::time::Duration::from_millis(50));
}
let _ = std::fs::remove_dir_all(&root);
diff --git a/src/openhuman/flows/ops_part_03.rs b/src/openhuman/flows/ops_part_03.rs
index 634a50acaa..ff4512b7f2 100644
--- a/src/openhuman/flows/ops_part_03.rs
+++ b/src/openhuman/flows/ops_part_03.rs
@@ -189,12 +189,19 @@ async fn evaluate_inference_readiness(
.collect();
let first_node = *agent_nodes.first()?;
+ let needs_backend_session = agent_nodes.iter().any(|node| {
+ crate::openhuman::inference::provider::factory::resolves_to_managed_backend(
+ agent_node_role(config, node),
+ config,
+ )
+ });
+ let needs_session =
+ crate::openhuman::inference::provider::factory::current_host_requires_session()
+ || needs_backend_session;
// Layer 1: signed-out is the cheapest, most decisive check. Session-wide
// — checked once for the whole graph, not per node/role.
- if crate::openhuman::inference::provider::factory::current_host_requires_session()
- && crate::openhuman::cron::scheduler_gate::is_signed_out()
- {
+ if needs_session && crate::openhuman::cron::scheduler_gate::is_signed_out() {
tracing::debug!(
target: "flows",
node = %first_node.id,
@@ -221,7 +228,13 @@ async fn evaluate_inference_readiness(
// behavior for a real signed-out desktop user is unchanged — only the
// (redundant, in that case) early rejection here is test-only skipped.
#[cfg(not(test))]
- if let Err(e) = crate::openhuman::inference::provider::factory::verify_session_active(config) {
+ let session_result = if needs_backend_session {
+ crate::openhuman::inference::provider::factory::verify_backend_session_active(config)
+ } else {
+ crate::openhuman::inference::provider::factory::verify_session_active(config)
+ };
+ #[cfg(not(test))]
+ if let Err(e) = session_result {
tracing::debug!(
target: "flows",
node = %first_node.id,
diff --git a/src/openhuman/inference/provider/factory_part_02.rs b/src/openhuman/inference/provider/factory_part_02.rs
index e3756781b1..365859f325 100644
--- a/src/openhuman/inference/provider/factory_part_02.rs
+++ b/src/openhuman/inference/provider/factory_part_02.rs
@@ -58,7 +58,7 @@ fn create_chat_model_with_model_id_inner(
/// Whether `role` resolves to the managed OpenHuman backend (vs BYOK / local /
/// claude-code). Uses the same empty/`cloud`/`openhuman` normalization as
/// [`create_chat_model_from_string`] so every managed role shares one path.
-fn resolves_to_managed_backend(role: &str, config: &Config) -> bool {
+pub(crate) fn resolves_to_managed_backend(role: &str, config: &Config) -> bool {
let mut resolved = provider_for_role(role, config);
let trimmed = resolved.trim();
if trimmed.is_empty() || trimmed == "cloud" {
diff --git a/src/openhuman/memory/conversations/store/store_ops.rs b/src/openhuman/memory/conversations/store/store_ops.rs
index b6e77e3907..aca8537e86 100644
--- a/src/openhuman/memory/conversations/store/store_ops.rs
+++ b/src/openhuman/memory/conversations/store/store_ops.rs
@@ -309,16 +309,19 @@ impl ConversationStore {
)?;
}
let messages_path = self.thread_messages_path(thread_id);
- match fs::remove_file(&messages_path) {
- Ok(()) => {}
- Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}
- Err(error) => {
- return Err(format!(
- "delete conversation messages {}: {error}",
- messages_path.display()
- ));
- }
- }
+ let remove_result = match fs::remove_file(&messages_path) {
+ Ok(()) => Ok(()),
+ Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(()),
+ Err(error) => Err(format!(
+ "delete conversation messages {}: {error}",
+ messages_path.display()
+ )),
+ };
+ // Evict on every path after the tombstone is durable, including a
+ // filesystem deletion error. The lifecycle write guard prevents a new
+ // operation from observing a replacement lock before this one drops.
+ self.locks.remove_thread(thread_id);
+ remove_result?;
// Drop every indexed message for this thread so future searches
// don't surface stale content.
{
@@ -327,7 +330,6 @@ impl ConversationStore {
idx.remove_thread(thread_id);
}
}
- self.locks.remove_thread(thread_id);
Ok(true)
}