Skip to content

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

fix(running_subagents): fall back to live registry when no workspace context

Steven Enamakel994d8f81a2fe
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/resolve.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/resolve.rs
index c40c878333..0bcfb6eb2d 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/resolve.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/resolve.rs
@@ -6,7 +6,8 @@
use std::path::Path;
use tinyagents_orchestration::subagent::{
- resolve_detached_or_durable, SubagentResumeRef, WaitError,
+ resolve_detached_or_durable, resume_ref_for_task as live_resume_ref_for_task,
+ task_id_for_session as live_task_id_for_session, SubagentResumeRef, WaitError,
};
use super::registry::{admit_workspace, owner_key, registry};
@@ -19,10 +20,13 @@ pub(crate) fn task_id_for_session(
subagent_session_id: &str,
parent_session: &str,
) -> Result<String, WaitError> {
- let workspace = ctx
- .resolved()
- .and_then(|context| context.workspace_dir().ok())
- .ok_or(WaitError::NotOwned)?;
+ let owner = owner_key(ctx, parent_session)?;
+ let Some(context) = ctx.resolved() else {
+ return live_task_id_for_session(registry(), subagent_session_id, &owner);
+ };
+ let Ok(workspace) = context.workspace_dir() else {
+ return live_task_id_for_session(registry(), subagent_session_id, &owner);
+ };
task_id_for_session_in_workspace(ctx, subagent_session_id, parent_session, &workspace)
}
@@ -33,11 +37,13 @@ pub(crate) fn task_id_for_session_in_workspace(
workspace_dir: &Path,
) -> Result<String, WaitError> {
admit_workspace(ctx, workspace_dir)?;
+ let owner = owner_key(ctx, parent_session)?;
+ let store = scoped_task_store(ctx, workspace_dir)?;
let resolved = resolve_detached_or_durable(
registry(),
- task_store_for_workspace(workspace_dir).as_ref(),
+ store.as_ref(),
subagent_session_id,
- &owner_key(ctx, parent_session)?,
+ &owner,
)?;
let task_id = resolved.task_id;
log::debug!(
@@ -54,10 +60,13 @@ pub(crate) fn resume_ref_for_task(
task_id: &str,
parent_session: &str,
) -> Result<SubagentResumeRef, WaitError> {
- let workspace = ctx
- .resolved()
- .and_then(|context| context.workspace_dir().ok())
- .ok_or(WaitError::NotOwned)?;
+ let owner = owner_key(ctx, parent_session)?;
+ let Some(context) = ctx.resolved() else {
+ return live_resume_ref_for_task(registry(), task_id, &owner);
+ };
+ let Ok(workspace) = context.workspace_dir() else {
+ return live_resume_ref_for_task(registry(), task_id, &owner);
+ };
resume_ref_for_task_in_workspace(ctx, task_id, parent_session, &workspace)
}
@@ -68,11 +77,13 @@ pub(crate) fn resume_ref_for_task_in_workspace(
workspace_dir: &Path,
) -> Result<SubagentResumeRef, WaitError> {
admit_workspace(ctx, workspace_dir)?;
+ let owner = owner_key(ctx, parent_session)?;
+ let store = scoped_task_store(ctx, workspace_dir)?;
let reference = resolve_detached_or_durable(
registry(),
- task_store_for_workspace(workspace_dir).as_ref(),
+ store.as_ref(),
task_id,
- &owner_key(ctx, parent_session)?,
+ &owner,
)?;
log::debug!(
"[running_subagents] resolved resume ref from task store task_id={} workspace_dir={}",
@@ -81,3 +92,13 @@ pub(crate) fn resume_ref_for_task_in_workspace(
);
Ok(reference)
}
+
+fn scoped_task_store(
+ ctx: &crate::core::runtime::DispatchCtx,
+ workspace_dir: &Path,
+) -> Result<std::sync::Arc<dyn tinyagents_tasks::TaskStore>, WaitError> {
+ let context = ctx.resolved().ok_or(WaitError::NotOwned)?;
+ Ok(crate::core::runtime::CoreContext::sync_scope(context, || {
+ task_store_for_workspace(workspace_dir)
+ }))
+}
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/wait.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/wait.rs
index 0fe1505fbc..81fd1c6012 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/wait.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/wait.rs
@@ -5,7 +5,9 @@
use std::path::Path;
use std::time::Duration;
-use tinyagents_orchestration::subagent::{wait_detached_or_durable, WaitError, WaitOutcome};
+use tinyagents_orchestration::subagent::{
+ wait_detached, wait_detached_or_durable, WaitError, WaitOutcome,
+};
use super::registry::{admit_workspace, owner_key, registry};
@@ -16,14 +18,20 @@ pub(crate) async fn wait(
parent_session: &str,
timeout: Duration,
) -> Result<WaitOutcome, WaitError> {
- let workspace_dir = ctx
- .resolved()
- .and_then(|context| context.workspace_dir().ok())
- .ok_or(WaitError::NotOwned)?;
let owner = owner_key(ctx, parent_session)?;
+ let Some(context) = ctx.resolved() else {
+ return wait_detached(registry(), task_id, &owner, timeout).await;
+ };
+ let Ok(workspace_dir) = context.workspace_dir() else {
+ return wait_detached(registry(), task_id, &owner, timeout).await;
+ };
+ admit_workspace(ctx, &workspace_dir)?;
+ let store = crate::core::runtime::CoreContext::sync_scope(context, || {
+ super::task_ledger::task_store_for_workspace(&workspace_dir)
+ });
wait_detached_or_durable(
registry(),
- super::task_ledger::task_store_for_workspace(&workspace_dir).as_ref(),
+ store.as_ref(),
&super::super::background_completions::router_for_workspace_ctx(ctx, &workspace_dir),
task_id,
&owner,
@@ -41,9 +49,13 @@ pub(crate) async fn wait_in_workspace(
) -> Result<WaitOutcome, WaitError> {
admit_workspace(ctx, workspace_dir)?;
let owner = owner_key(ctx, parent_session)?;
+ let context = ctx.resolved().ok_or(WaitError::NotOwned)?;
+ let store = crate::core::runtime::CoreContext::sync_scope(context, || {
+ super::task_ledger::task_store_for_workspace(workspace_dir)
+ });
wait_detached_or_durable(
registry(),
- super::task_ledger::task_store_for_workspace(workspace_dir).as_ref(),
+ store.as_ref(),
&super::super::background_completions::router_for_workspace_ctx(ctx, workspace_dir),
task_id,
&owner,
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs
index 1b86cf184d..35cfc8a762 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs
@@ -2,6 +2,9 @@ use super::*;
use crate::core::runtime::DispatchCtx;
use crate::core::runtime::{ContextOverlay, CoreContext, DomainSet, Mode};
use crate::tools::toolpacks::ToolGroups;
+use crate::agent::orchestration::running_subagents::resolve::{
+ resume_ref_for_task_in_workspace, task_id_for_session_in_workspace,
+};
use tinyagents_orchestration::subagent::SteerError;
const CHILD: &str = "OPENHUMAN_DETACHED_TENANT_TEST_CHILD";