Skip to content

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

fix(subagent-host): key in-flight reservations by normalized checkpoint dir

Steven Enamakel0e5ebc61e244
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
index 07dec4e70e..17f8ccabb9 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
@@ -581,8 +581,10 @@ pub(super) fn shared_subagent_flight(
let mut flights = flights
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner());
+ // Key by the normalized root so every caller of one task, whether or not the
+ // directory exists yet, reaches the same reservation.
flights
- .entry(checkpoint_dir.to_path_buf())
+ .entry(checkpoint::absolute_checkpoint_dir(checkpoint_dir.to_path_buf()))
.or_default()
.clone()
}
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle_checkpoint.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle_checkpoint.rs
index ac9d068be3..7a1af8b687 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle_checkpoint.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle_checkpoint.rs
@@ -2,14 +2,37 @@
use std::path::PathBuf;
+/// The in-flight reservation map is keyed by this path, so it must name a
+/// directory identically before and after the lifecycle store creates it.
+/// Canonicalizing the whole path only once it exists would resolve symlinked
+/// parents (macOS `/var` -> `/private/var`) for a late caller but not an early
+/// one, putting two callers of one task in different flights. Resolve the
+/// deepest existing ancestor and re-append the not-yet-created tail instead.
pub(super) fn absolute_checkpoint_dir(path: PathBuf) -> PathBuf {
- std::fs::canonicalize(&path).unwrap_or_else(|_| {
- if path.is_absolute() {
- path
- } else {
- std::env::current_dir()
- .map(|cwd| cwd.join(&path))
- .unwrap_or(path)
+ let absolute = if path.is_absolute() {
+ path
+ } else {
+ match std::env::current_dir() {
+ Ok(cwd) => cwd.join(&path),
+ Err(_) => path,
}
- })
+ };
+ let mut tail = Vec::new();
+ let mut ancestor = absolute.as_path();
+ loop {
+ if let Ok(resolved) = std::fs::canonicalize(ancestor) {
+ return tail.iter().rev().fold(resolved, |dir, name| dir.join(name));
+ }
+ match (ancestor.file_name(), ancestor.parent()) {
+ (Some(name), Some(parent)) => {
+ tail.push(name.to_owned());
+ ancestor = parent;
+ }
+ _ => return absolute,
+ }
+ }
}
+
+#[cfg(test)]
+#[path = "lifecycle_checkpoint_tests.rs"]
+mod tests;