Skip to content

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

refactor(subagent_host): simplify checkpoint dir resolution

Steven Enamakel411a1d145dc2
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
index 17f8ccabb9..07dec4e70e 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
@@ -581,10 +581,8 @@ 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::absolute_checkpoint_dir(checkpoint_dir.to_path_buf()))
+ .entry(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 7a1af8b687..ac9d068be3 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle_checkpoint.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle_checkpoint.rs
@@ -2,37 +2,14 @@
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 {
- let absolute = if path.is_absolute() {
- path
- } else {
- match std::env::current_dir() {
- Ok(cwd) => cwd.join(&path),
- Err(_) => path,
+ 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 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;