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/subagent_host/lifecycle.rs,crates/openhuman-cor

Steven Enamakele59e865255d6
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
index 720d9f1378..07dec4e70e 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle.rs
@@ -391,9 +391,10 @@ async fn invoke_driver_tool_with_request(
.unwrap_or_else(|| PathBuf::from(".openhuman/subagent_checkpoints"))
}),
);
- let bundle = OpenHumanDriverBundle::with_in_flight(
+ let bundle = OpenHumanDriverBundle::with_in_flight_for(
checkpoint_dir.clone(),
shared_subagent_flight(&parent.data.dispatch_ctx(), &checkpoint_dir),
+ parent.data.dispatch_ctx(),
)?;
let request_host = host_request.clone();
let request_task_id = task_id.clone();
@@ -554,9 +555,7 @@ pub(crate) fn load_subagent_checkpoint(
task_id: &str,
) -> Result<super::SubagentCheckpointData, SubagentRunError> {
let persistence = OpenHumanPersistence::new(checkpoint_dir.to_path_buf());
- // This reads under the full-key lifecycle lock and filters terminal state,
- // so an index left behind by terminal cleanup can never reopen a closed
- // subagent as an old pause.
+ // The owner filters terminal records, so stale indexes cannot reopen a pause.
persistence.checkpoint_for_task(task_id)
}
@@ -675,9 +674,10 @@ impl OpenHumanSubagentHost {
invocation: HostInvocation::Agent(self.definition),
options: self.options,
};
- let driver = OpenHumanDriverBundle::with_in_flight(
+ let driver = OpenHumanDriverBundle::with_in_flight_for(
checkpoint_dir.clone(),
shared_subagent_flight(&parent.data.dispatch_ctx(), &checkpoint_dir),
+ parent.data.dispatch_ctx(),
)?;
let request = if continuation {
SubagentRequest::continue_with_key(task_key.clone(), child, request, input, None, None)
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs
index 21bf218356..111b695598 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs
@@ -20,6 +20,18 @@ impl OpenHumanDriverBundle {
pub(crate) fn with_in_flight(
checkpoint_dir: PathBuf,
in_flight: tinyagents_orchestration::subagent::SubagentInFlight,
+ ) -> Result<Self, SubagentRunError> {
+ Self::with_in_flight_for(
+ checkpoint_dir,
+ in_flight,
+ crate::core::runtime::DispatchCtx::ambient(),
+ )
+ }
+
+ pub(crate) fn with_in_flight_for(
+ checkpoint_dir: PathBuf,
+ in_flight: tinyagents_orchestration::subagent::SubagentInFlight,
+ dispatch: crate::core::runtime::DispatchCtx,
) -> Result<Self, SubagentRunError> {
let failures = Arc::new(Mutex::new(HashMap::new()));
let host_outcome = Arc::new(Mutex::new(HashMap::new()));
@@ -35,7 +47,9 @@ impl OpenHumanDriverBundle {
configured_tool_result: Arc::clone(&configured_tool_result),
});
let persistence = Arc::new(
- OpenHumanPersistence::new(checkpoint_dir).with_host_outcome(Arc::clone(&host_outcome)),
+ OpenHumanPersistence::new(checkpoint_dir)
+ .with_dispatch(dispatch)
+ .with_host_outcome(Arc::clone(&host_outcome)),
);
let lifecycle_persistence: Arc<
dyn tinyagents_orchestration::subagent::SubagentPersistence,
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle/persistence.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle/persistence.rs
index e9b45d4364..d1ce9eae14 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle/persistence.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle/persistence.rs
@@ -3,6 +3,7 @@ use crate::agent::subagent_host::types::SubagentCheckpointData;
pub(in crate::agent::subagent_host) struct OpenHumanPersistence {
checkpoint_dir: std::path::PathBuf,
+ dispatch: crate::core::runtime::DispatchCtx,
host_outcome: Arc<Mutex<HashMap<SubagentTaskKey, SubagentRunOutcome>>>,
}
@@ -26,10 +27,19 @@ impl OpenHumanPersistence {
pub(in crate::agent::subagent_host) fn new(checkpoint_dir: std::path::PathBuf) -> Self {
Self {
checkpoint_dir,
+ dispatch: crate::core::runtime::DispatchCtx::ambient(),
host_outcome: Arc::new(Mutex::new(HashMap::new())),
}
}
+ pub(in crate::agent::subagent_host) fn with_dispatch(
+ mut self,
+ dispatch: crate::core::runtime::DispatchCtx,
+ ) -> Self {
+ self.dispatch = dispatch;
+ self
+ }
+
pub(in crate::agent::subagent_host) fn with_host_outcome(
mut self,
host_outcome: Arc<Mutex<HashMap<SubagentTaskKey, SubagentRunOutcome>>>,
@@ -85,7 +95,34 @@ impl OpenHumanPersistence {
&self,
) -> Result<tinyagents_orchestration::subagent::DocumentSubagentPersistence, SubagentError>
{
- super::store::LifecycleStore::open(&self.checkpoint_dir)?.neutral_store()
+ self.open_store(false)
+ }
+
+ fn open_store(
+ &self,
+ terminal: bool,
+ ) -> Result<tinyagents_orchestration::subagent::DocumentSubagentPersistence, SubagentError>
+ {
+ let open = || {
+ let legacy = if terminal {
+ super::store::LifecycleStore::before_terminal(&self.checkpoint_dir)?
+ } else {
+ super::store::LifecycleStore::open(&self.checkpoint_dir)?
+ };
+ legacy.neutral_store()
+ };
+ // The generic driver may run in a detached Tokio task. Storage reads
+ // before execution and commits after execution must use the actor the
+ // authenticated parent carried, even outside the executor's scope.
+ if let Some(core) = self.dispatch.resolved() {
+ crate::core::runtime::CoreContext::sync_scope(core, open)
+ } else if crate::core::runtime::is_saas() {
+ Err(SubagentError::Persistence(
+ "subagent lifecycle requires a resolved actor context".into(),
+ ))
+ } else {
+ open()
+ }
}
pub(super) fn pause_path(&self, key: &SubagentTaskKey) -> std::path::PathBuf {