Skip to content

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

fix(running_subagents): resolve task store from dispatch context

Steven Enamakel3f4cd31fb2fa
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs
index e8c53231ed..ee23afea25 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs
@@ -73,7 +73,7 @@ pub(crate) fn cancel_by_task_with_workspace_reason(
let already_finished = cancelled.status.finished_outcome();
let metadata = cancelled.metadata;
if already_finished.is_none() {
- record_cancelled(&metadata.workspace_dir, task_id);
+ record_cancelled(ctx, &metadata.workspace_dir, task_id);
}
log::debug!(
"[running_subagents] cancel_by_task task_id={} agent_id={} parent_thread_id={:?} live_entries={}",
@@ -157,7 +157,7 @@ pub(crate) fn cancel_for_thread(ctx: &crate::core::runtime::DispatchCtx, thread_
})
.expect("detached task registry lock poisoned");
for entry in &cancelled {
- record_cancelled(&entry.metadata.workspace_dir, entry.task_id.as_str());
+ record_cancelled(ctx, &entry.metadata.workspace_dir, entry.task_id.as_str());
}
let count = cancelled.len();
log::debug!(
@@ -193,7 +193,7 @@ pub(crate) fn stop_for_thread(
let mut task_ids = Vec::with_capacity(cancelled.len());
for entry in cancelled {
let task_id = entry.task_id.as_str().to_string();
- record_cancelled(&entry.metadata.workspace_dir, &task_id);
+ record_cancelled(ctx, &entry.metadata.workspace_dir, &task_id);
if let Some(subagent_session_id) = entry.metadata.subagent_session_id.as_deref() {
let store = crate::agent::orchestration::subagent_sessions::SubagentSessionStore::new(
entry.metadata.workspace_dir.clone(),
@@ -262,7 +262,7 @@ pub(crate) fn cancel_all(ctx: &crate::core::runtime::DispatchCtx) -> Vec<String>
let mut thread_ids: Vec<String> = Vec::new();
let mut seen: HashSet<String> = HashSet::new();
for entry in cancelled {
- record_cancelled(&entry.metadata.workspace_dir, entry.task_id.as_str());
+ record_cancelled(ctx, &entry.metadata.workspace_dir, entry.task_id.as_str());
if let Some(thread_id) = entry.metadata.parent_thread_id {
if seen.insert(thread_id.clone()) {
thread_ids.push(thread_id);
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/registry.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/registry.rs
index edbb8e5326..75a9caa959 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/registry.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/registry.rs
@@ -33,7 +33,8 @@ use tinyagents_harness::run_queue::RunQueue;
use tinyagents_harness::CancellationToken;
use tinyagents_tasks::DetachedTaskRegistry;
-use super::task_ledger::{record_spawned, task_store_for_workspace};
+use super::resolve::scoped_task_store;
+use super::task_ledger::record_spawned_in_store;
use tinyagents_orchestration::subagent::{
spawn_status_watcher, DetachedSubagentStatus, SubagentIdentity, WaitError,
};
@@ -190,6 +191,10 @@ pub(crate) fn register(
return Err(error);
}
};
+ let task_store = scoped_task_store(ctx, &workspace_dir).map_err(|_| {
+ abort.abort();
+ RegistrationError::Scope
+ })?;
let owner = crate::core::runtime::tenant::tenant_key(
&crate::core::runtime::tenant::Tenant {
profile: profile.clone(),
@@ -245,7 +250,8 @@ pub(crate) fn register(
RegistrationError::Registry(error)
})?;
// Failed admission must not leave a Running lifecycle record or watcher.
- record_spawned(
+ record_spawned_in_store(
+ task_store.as_ref(),
&task_id,
&agent_id,
&parent_session,
@@ -254,11 +260,7 @@ pub(crate) fn register(
&workspace_dir,
parent_thread_id.as_deref(),
);
- spawn_status_watcher(
- task_store_for_workspace(&workspace_dir),
- task_id.clone(),
- status,
- );
+ spawn_status_watcher(task_store, task_id.clone(), status);
log::debug!(
"[running_subagents] registered task_id={} live_entries={}",
task_id,
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/task_ledger.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/task_ledger.rs
index ffec82d723..494424987b 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/task_ledger.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/task_ledger.rs
@@ -114,10 +114,32 @@ pub(crate) fn record_spawned(
subagent_session_id: Option<&str>,
workspace_dir: &Path,
parent_thread_id: Option<&str>,
+) {
+ record_spawned_in_store(
+ task_store_for_workspace(workspace_dir).as_ref(),
+ task_id,
+ agent_id,
+ parent_session,
+ session_parent_prefix,
+ subagent_session_id,
+ workspace_dir,
+ parent_thread_id,
+ );
+}
+
+pub(crate) fn record_spawned_in_store(
+ store: &dyn TaskStore,
+ task_id: &str,
+ agent_id: &str,
+ parent_session: &str,
+ session_parent_prefix: Option<&str>,
+ subagent_session_id: Option<&str>,
+ workspace_dir: &Path,
+ parent_thread_id: Option<&str>,
) {
let workspace = workspace_dir.display().to_string();
if let Err(err) = ledger_spawned(
- task_store_for_workspace(workspace_dir).as_ref(),
+ store,
&SpawnedSubagent {
task_id,
agent_id,
@@ -135,19 +157,36 @@ pub(crate) fn record_spawned(
}
/// Record a cancellation (`CancelRequested` → `Cancelled`) for `task_id`.
-pub(crate) fn record_cancelled(workspace_dir: &Path, task_id: &str) {
+pub(crate) fn record_cancelled_in_store(
+ store: &dyn TaskStore,
+ workspace_dir: &Path,
+ task_id: &str,
+) {
log::debug!(
"[running_subagents] recording task cancellation task_id={} workspace_dir={}",
task_id,
workspace_dir.display()
);
- if let Err(err) = ledger_cancelled(task_store_for_workspace(workspace_dir).as_ref(), task_id) {
+ if let Err(err) = ledger_cancelled(store, task_id) {
log::debug!(
"[running_subagents] cancel ledger update ignored task_id={task_id} error={err}"
);
}
}
+pub(crate) fn record_cancelled(
+ ctx: &crate::core::runtime::DispatchCtx,
+ workspace_dir: &Path,
+ task_id: &str,
+) {
+ match super::resolve::scoped_task_store(ctx, workspace_dir) {
+ Ok(store) => record_cancelled_in_store(store.as_ref(), workspace_dir, task_id),
+ Err(error) => log::debug!(
+ "[running_subagents] cancel ledger store unavailable task_id={task_id} error={error}"
+ ),
+ }
+}
+
pub(crate) fn list_task_records(workspace_dir: &Path) -> Vec<OrchestrationTaskRecord> {
list_subagent_records(task_store_for_workspace(workspace_dir).as_ref())
}