Skip to content

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

refactor(orchestration): introduce register_with_parent_epoch

Steven Enamakel769fa64d0562
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents.rs
index bd441aaae5..1d60011c48 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents.rs
@@ -74,7 +74,9 @@ pub(crate) use cancel::{
};
pub(crate) use registry::admit_spawn;
#[cfg(test)]
-pub(crate) use registry::{register, status_channel, RegistrationError};
+pub(crate) use registry::{
+ register, register_with_parent_epoch, status_channel, RegistrationError,
+};
pub(crate) use roster::active_subagents_context_block;
#[cfg(test)]
pub(crate) use steering::steer;
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 b1f4fef198..df0935a26b 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/registry.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/registry.rs
@@ -188,6 +188,52 @@ pub(crate) fn register(
run_queue: Arc<RunQueue<crate::agent::queued_turn::QueuedTurn>>,
abort: AbortHandle,
status: watch::Receiver<DetachedSubagentStatus>,
+) -> Result<(), RegistrationError> {
+ let parent_epoch = match parent_thread_id.as_deref() {
+ Some(thread_id) => Some(
+ crate::agent::orchestration::background_completions::CompletionTarget::new(
+ ctx.clone(),
+ workspace_dir.clone(),
+ parent_session.clone(),
+ Some(thread_id.to_owned()),
+ )
+ .map_err(RegistrationError::ParentLifecycle)?
+ .parent_epoch()
+ .expect("threaded spawn captures a parent generation"),
+ ),
+ None => None,
+ };
+ register_with_parent_epoch(
+ ctx,
+ task_id,
+ agent_id,
+ parent_session,
+ session_parent_prefix,
+ subagent_session_id,
+ workspace_dir,
+ parent_thread_id,
+ parent_epoch,
+ run_queue,
+ abort,
+ status,
+ )
+}
+
+/// Test-only lower-level hook for exercising registration after a previously
+/// captured spawn generation has gone stale.
+pub(crate) fn register_with_parent_epoch(
+ ctx: &crate::core::runtime::DispatchCtx,
+ task_id: String,
+ agent_id: String,
+ parent_session: String,
+ session_parent_prefix: Option<String>,
+ subagent_session_id: Option<String>,
+ workspace_dir: PathBuf,
+ parent_thread_id: Option<String>,
+ parent_epoch: Option<u64>,
+ run_queue: Arc<RunQueue<crate::agent::queued_turn::QueuedTurn>>,
+ abort: AbortHandle,
+ status: watch::Receiver<DetachedSubagentStatus>,
) -> Result<(), RegistrationError> {
let profile = match admit_spawn(ctx, &workspace_dir) {
Ok(profile) => profile,
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents_tests.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents_tests.rs
index 5fd11e2e61..b784e66f7a 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents_tests.rs
@@ -101,29 +101,15 @@ fn register_test_with_thread(
rq: Arc<RunQueue<QueuedTurn>>,
) -> watch::Sender<DetachedSubagentStatus> {
let (tx, rx) = status_channel();
- let ctx = cx();
- let workspace = test_workspace();
- let parent_epoch = parent_thread_id.map(|thread_id| {
- crate::agent::orchestration::background_completions::CompletionTarget::new(
- ctx.clone(),
- workspace.clone(),
- parent_session.to_owned(),
- Some(thread_id.to_owned()),
- )
- .expect("capture parent generation at spawn")
- .parent_epoch()
- .expect("threaded spawn has a parent generation")
- });
register(
- &ctx,
+ &cx(),
task_id.into(),
"researcher".into(),
parent_session.into(),
None,
None,
- workspace,
+ test_workspace(),
parent_thread_id.map(Into::into),
- parent_epoch,
rq,
dummy_abort(),
rx,
@@ -161,7 +147,7 @@ async fn late_registration_rejects_a_parent_generation_reopened_after_spawn() {
let child = tokio::spawn(std::future::pending::<()>());
let (_status_tx, status_rx) = status_channel();
- let result = register(
+ let result = register_with_parent_epoch(
&ctx,
"late-register-old-task".into(),
"researcher".into(),
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_tests.rs
index 0b9f70c39a..e08c1efbc1 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_tests.rs
@@ -88,7 +88,6 @@ async fn late_registration_refusal_aborts_the_worker_and_settles_its_durable_ses
Some(session.subagent_session_id.clone()),
workspace.path().to_path_buf(),
None,
- None,
Arc::new(RunQueue::new()),
join.abort_handle(),
rx,
diff --git a/crates/openhuman-core/src/web_chat/web_tests_session_and_concurrency_tests.rs b/crates/openhuman-core/src/web_chat/web_tests_session_and_concurrency_tests.rs
index c2d16a991a..6229bc1e27 100644
--- a/crates/openhuman-core/src/web_chat/web_tests_session_and_concurrency_tests.rs
+++ b/crates/openhuman-core/src/web_chat/web_tests_session_and_concurrency_tests.rs
@@ -619,17 +619,8 @@ async fn unscoped_cancel_stops_the_threads_detached_subagents() {
let workspace = tempfile::tempdir().expect("workspace");
let child = tokio::spawn(std::future::pending::<()>());
let (_status_tx, status_rx) = running_subagents::status_channel();
- let ctx = crate::core::runtime::DispatchCtx::ambient();
- let parent_epoch = crate::agent::orchestration::background_completions::CompletionTarget::new(
- ctx.clone(),
- workspace.path().to_path_buf(),
- "session-web-stop".into(),
- Some(thread_id.into()),
- )
- .expect("capture generation at spawn")
- .parent_epoch();
running_subagents::register(
- &ctx,
+ &crate::core::runtime::DispatchCtx::ambient(),
"task-web-stop-1".into(),
"researcher".into(),
"session-web-stop".into(),
@@ -637,7 +628,6 @@ async fn unscoped_cancel_stops_the_threads_detached_subagents() {
None,
workspace.path().to_path_buf(),
Some(thread_id.into()),
- parent_epoch,
std::sync::Arc::new(tinyagents_harness::run_queue::RunQueue::new()),
child.abort_handle(),
status_rx,