Skip to content

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

refactor(orchestration): move awaiting-input record keys into completion_target

Steven Enamakel96cdc9e96767
diff --git a/Cargo.lock b/Cargo.lock
index 469d192a7f..fd35e9f74b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5441,6 +5441,7 @@ dependencies = [
"tinyagents-definition",
"tinyagents-graph",
"tinyagents-harness",
+ "tinyagents-hooks",
"tinyagents-live",
"tinyagents-orchestration",
"tinyagents-registry",
@@ -5598,6 +5599,7 @@ dependencies = [
"tinyagents-definition",
"tinyagents-graph",
"tinyagents-harness",
+ "tinyagents-hooks",
"tinyagents-session",
"tinybus",
"tinyflows-schedule",
diff --git a/crates/openhuman-core/src/agent/orchestration/background_completions.rs b/crates/openhuman-core/src/agent/orchestration/background_completions.rs
index a3c0954d08..abd814061c 100644
--- a/crates/openhuman-core/src/agent/orchestration/background_completions.rs
+++ b/crates/openhuman-core/src/agent/orchestration/background_completions.rs
@@ -40,10 +40,9 @@ use tinyagents_tasks::{
};
use super::completion_notice::BackgroundCompletionFormatter;
-pub(crate) use super::completion_notice::{
- BackgroundAgentOutcome, AWAITING_INPUT_LABEL, AWAITING_INPUT_RECORD_PREFIX,
-};
+pub(crate) use super::completion_notice::{BackgroundAgentOutcome, AWAITING_INPUT_LABEL};
pub(crate) use super::completion_target::CompletionTarget;
+use super::completion_target::{awaiting_input_record_id, awaiting_input_record_prefix};
pub(crate) use super::completion_target::{claim_recovery, forget_recovery};
#[cfg(test)]
pub(crate) use super::completion_target::{
@@ -404,32 +403,6 @@ pub(crate) async fn record_awaiting_input(
.await;
}
-/// Completion-router key for an awaiting-input notification. The real task id
-/// remains available in the notification body; this separate key leaves the
-/// task id's dedupe slot open for its eventual terminal result.
-fn encoded_task_id(task_id: &str) -> String {
- task_id
- .as_bytes()
- .iter()
- .map(|byte| format!("{byte:02x}"))
- .collect()
-}
-
-fn awaiting_input_record_prefix(task_id: &str) -> String {
- format!(
- "{AWAITING_INPUT_RECORD_PREFIX}{}:",
- encoded_task_id(task_id)
- )
-}
-
-fn awaiting_input_record_id(task_id: &str) -> String {
- format!(
- "{}{}",
- awaiting_input_record_prefix(task_id),
- uuid::Uuid::new_v4().simple()
- )
-}
-
/// Drop every workspace's router and all process-local state about them. Called
/// when the core server stops (`openhuman_rpc::server::serve`), so the completion logs'
/// file handles close before a data reset removes their directory (Windows
@@ -766,6 +739,10 @@ pub(crate) fn recover_pending_threads(ctx: &DispatchCtx, workspace_dir: &Path) -
#[path = "background_completions_tests.rs"]
mod tests;
+#[cfg(test)]
+#[path = "background_completions_pause_tests.rs"]
+mod pause_tests;
+
#[cfg(test)]
#[path = "background_completions_release_tests.rs"]
mod release_tests;
diff --git a/crates/openhuman-core/src/agent/orchestration/background_completions_pause_tests.rs b/crates/openhuman-core/src/agent/orchestration/background_completions_pause_tests.rs
new file mode 100644
index 0000000000..5fcc5d9499
--- /dev/null
+++ b/crates/openhuman-core/src/agent/orchestration/background_completions_pause_tests.rs
@@ -0,0 +1,152 @@
+use super::*;
+use crate::core::runtime::DispatchCtx;
+use tinyagents_tasks::{CompletionFormatter, CompletionStatus};
+use tokio::sync::MutexGuard;
+
+fn cx() -> DispatchCtx {
+ DispatchCtx::ambient()
+}
+
+fn test_guard() -> MutexGuard<'static, ()> {
+ crate::config::TEST_ENV_LOCK.blocking_lock()
+}
+
+fn workspace() -> TestWorkspace {
+ TestWorkspace::new()
+}
+
+fn record(ws: &Path, session: &str, task: &str, summary: &str, thread: Option<&str>) {
+ futures::executor::block_on(record_completion(
+ &cx(),
+ ws,
+ session,
+ task,
+ "researcher",
+ summary,
+ thread.map(str::to_owned),
+ ));
+}
+
+#[test]
+fn record_awaiting_input_queues_a_framed_needs_input_for_delivery() {
+ let _guard = test_guard();
+ let ws = workspace();
+ let w = ws.path();
+ futures::executor::block_on(record_awaiting_input(
+ &cx(),
+ w,
+ "sess-ask",
+ "sub-ask",
+ "researcher",
+ "which repo?",
+ true,
+ Some("thread-ask".into()),
+ ));
+ let pending = pending_for(w, "thread-ask");
+ assert_eq!(pending.len(), 1);
+ assert_eq!(
+ BackgroundAgentOutcome::of(&pending[0]),
+ BackgroundAgentOutcome::AwaitingInput
+ );
+ assert!(pending[0].result.text.contains("which repo?"));
+}
+
+#[test]
+fn awaiting_input_does_not_dedupe_the_later_completion() {
+ let _guard = test_guard();
+ let ws = workspace();
+ let w = ws.path();
+ futures::executor::block_on(record_awaiting_input(
+ &cx(),
+ w,
+ "sess-resume",
+ "sub-resume",
+ "researcher",
+ "which repo?",
+ true,
+ Some("thread-resume".into()),
+ ));
+ record(
+ w,
+ "sess-resume",
+ "sub-resume",
+ "finished after answer",
+ Some("thread-resume"),
+ );
+
+ let pending = pending_for(w, "thread-resume");
+ assert_eq!(
+ pending.len(),
+ 2,
+ "pause notice and final result both survive"
+ );
+ let pause = pending
+ .iter()
+ .find(|record| record.result.text.contains("which repo?"))
+ .expect("pause notice remains queued");
+ let completion = pending
+ .iter()
+ .find(|record| record.result.text == "finished after answer")
+ .expect("final completion remains queued");
+ assert_ne!(
+ pause.task_id, completion.task_id,
+ "pause has a separate dedupe key"
+ );
+
+ let claimed = router_for_workspace(w)
+ .claim_pending("thread-resume", usize::MAX)
+ .unwrap();
+ assert_eq!(
+ claimed.len(),
+ 2,
+ "pause and completion are both deliverable"
+ );
+ let notice = BackgroundCompletionFormatter.format_batch(&claimed);
+ assert!(notice.contains("<background_agent_needs_input id=\"sub-resume\""));
+ assert!(notice.contains("<background_agent_result id=\"sub-resume\""));
+}
+
+#[test]
+fn repeated_pauses_are_distinct_and_inline_collection_sweeps_them() {
+ let _guard = test_guard();
+ let ws = workspace();
+ let w = ws.path();
+ for question in ["which repo?", "which branch?"] {
+ futures::executor::block_on(record_awaiting_input(
+ &cx(),
+ w,
+ "sess-repeat-pause",
+ "sub-repeat-pause",
+ "researcher",
+ question,
+ true,
+ Some("thread-repeat-pause".into()),
+ ));
+ }
+ record(
+ w,
+ "sess-repeat-pause",
+ "sub-repeat-pause",
+ "finished after answers",
+ Some("thread-repeat-pause"),
+ );
+
+ let pending = pending_for(w, "thread-repeat-pause");
+ assert_eq!(
+ pending.len(),
+ 3,
+ "each pause and the final result are retained"
+ );
+ let pause_ids: HashSet<_> = pending
+ .iter()
+ .filter(|record| record.label.as_deref() == Some(AWAITING_INPUT_LABEL))
+ .map(|record| record.task_id.as_str())
+ .collect();
+ assert_eq!(pause_ids.len(), 2, "each pause gets a unique router key");
+
+ assert!(mark_collected(w, "sub-repeat-pause"));
+ assert!(
+ pending_for(w, "thread-repeat-pause").is_empty(),
+ "collecting the final result also withdraws its queued pause notices"
+ );
+}
diff --git a/crates/openhuman-core/src/agent/orchestration/background_completions_tests.rs b/crates/openhuman-core/src/agent/orchestration/background_completions_tests.rs
index bebe8b71c6..a048a20fcd 100644
--- a/crates/openhuman-core/src/agent/orchestration/background_completions_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/background_completions_tests.rs
@@ -1,6 +1,6 @@
use super::*;
use crate::core::runtime::DispatchCtx;
-use tinyagents_tasks::{CompletionFormatter, CompletionStatus};
+use tinyagents_tasks::CompletionStatus;
use tokio::sync::MutexGuard;
/// The context these tests dispatch under: the calling task's own.
@@ -281,130 +281,6 @@ fn record_failure_queues_a_framed_failure_for_delivery() {
assert!(pending[0].result.text.contains("provider exploded"));
}
-#[test]
-fn record_awaiting_input_queues_a_framed_needs_input_for_delivery() {
- let _guard = test_guard();
- let ws = workspace();
- let w = ws.path();
- futures::executor::block_on(record_awaiting_input(
- &cx(),
- w,
- "sess-ask",
- "sub-ask",
- "researcher",
- "which repo?",
- true,
- Some("thread-ask".into()),
- ));
- let pending = pending_for(w, "thread-ask");
- assert_eq!(pending.len(), 1);
- assert_eq!(
- BackgroundAgentOutcome::of(&pending[0]),
- BackgroundAgentOutcome::AwaitingInput
- );
- assert!(pending[0].result.text.contains("which repo?"));
-}
-
-#[test]
-fn awaiting_input_does_not_dedupe_the_later_completion() {
- let _guard = test_guard();
- let ws = workspace();
- let w = ws.path();
- futures::executor::block_on(record_awaiting_input(
- &cx(),
- w,
- "sess-resume",
- "sub-resume",
- "researcher",
- "which repo?",
- true,
- Some("thread-resume".into()),
- ));
- record(
- w,
- "sess-resume",
- "sub-resume",
- "finished after answer",
- Some("thread-resume"),
- );
-
- let pending = pending_for(w, "thread-resume");
- assert_eq!(
- pending.len(),
- 2,
- "pause notice and final result both survive"
- );
- let pause = pending
- .iter()
- .find(|record| record.result.text.contains("which repo?"))
- .expect("pause notice remains queued");
- let completion = pending
- .iter()
- .find(|record| record.result.text == "finished after answer")
- .expect("final completion remains queued");
- assert_ne!(
- pause.task_id, completion.task_id,
- "pause has a separate dedupe key"
- );
-
- let claimed = router_for_workspace(w)
- .claim_pending("thread-resume", usize::MAX)
- .unwrap();
- assert_eq!(
- claimed.len(),
- 2,
- "pause and completion are both deliverable"
- );
- let notice = BackgroundCompletionFormatter.format_batch(&claimed);
- assert!(notice.contains("<background_agent_needs_input id=\"sub-resume\""));
- assert!(notice.contains("<background_agent_result id=\"sub-resume\""));
-}
-
-#[test]
-fn repeated_pauses_are_distinct_and_inline_collection_sweeps_them() {
- let _guard = test_guard();
- let ws = workspace();
- let w = ws.path();
- for question in ["which repo?", "which branch?"] {
- futures::executor::block_on(record_awaiting_input(
- &cx(),
- w,
- "sess-repeat-pause",
- "sub-repeat-pause",
- "researcher",
- question,
- true,
- Some("thread-repeat-pause".into()),
- ));
- }
- record(
- w,
- "sess-repeat-pause",
- "sub-repeat-pause",
- "finished after answers",
- Some("thread-repeat-pause"),
- );
-
- let pending = pending_for(w, "thread-repeat-pause");
- assert_eq!(
- pending.len(),
- 3,
- "each pause and the final result are retained"
- );
- let pause_ids: HashSet<_> = pending
- .iter()
- .filter(|record| record.label.as_deref() == Some(AWAITING_INPUT_LABEL))
- .map(|record| record.task_id.as_str())
- .collect();
- assert_eq!(pause_ids.len(), 2, "each pause gets a unique router key");
-
- assert!(mark_collected(w, "sub-repeat-pause"));
- assert!(
- pending_for(w, "thread-repeat-pause").is_empty(),
- "collecting the final result also withdraws its queued pause notices"
- );
-}
-
#[test]
fn the_outcome_survives_a_claim() {
let _guard = test_guard();
diff --git a/crates/openhuman-core/src/agent/orchestration/completion_target.rs b/crates/openhuman-core/src/agent/orchestration/completion_target.rs
index 400c6e6ad0..1cac8f5fd7 100644
--- a/crates/openhuman-core/src/agent/orchestration/completion_target.rs
+++ b/crates/openhuman-core/src/agent/orchestration/completion_target.rs
@@ -16,6 +16,30 @@ use super::background_completions::{new_router, Entry};
use super::background_completions::{record_awaiting_input, record_completion, record_failure};
+/// Completion-router key prefix for one task's awaiting-input notices.
+pub(super) fn awaiting_input_record_prefix(task_id: &str) -> String {
+ let encoded_task_id: String = task_id
+ .as_bytes()
+ .iter()
+ .map(|byte| format!("{byte:02x}"))
+ .collect();
+ format!(
+ "{}{}:",
+ super::completion_notice::AWAITING_INPUT_RECORD_PREFIX,
+ encoded_task_id
+ )
+}
+
+/// A pause is an independently delivered record, so each pause of a resumed
+/// task needs its own key while leaving the terminal task id free.
+pub(super) fn awaiting_input_record_id(task_id: &str) -> String {
+ format!(
+ "{}{}",
+ awaiting_input_record_prefix(task_id),
+ uuid::Uuid::new_v4().simple()
+ )
+}
+
/// Where one detached child's completion lands: its workspace (which router),
/// the parent session (the idle gate) and the parent chat thread (the router's
/// parent key). Built once at spawn so every terminal path records the same way.
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/delegate_graph.rs b/crates/openhuman-core/src/agent/orchestration/tools/delegate_graph.rs
index dc85844b49..4e95969c44 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/delegate_graph.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/delegate_graph.rs
@@ -206,7 +206,7 @@ impl DelegateGraphTool {
};
let agent_id = match args.get("agent_id").and_then(|v| v.as_str()) {
Some(s) if !s.trim().is_empty() => s.trim().to_string(),
- _ => return Ok(ToolResult::error("delegate_graph: `agent_id` is required.")),
+ _ => return Ok(ToolResult::error("delegate: `agent_id` is required.")),
};
let task = match args.get("task").and_then(|v| v.as_str()) {
Some(s) if !s.trim().is_empty() => s.to_string(),
diff --git a/vendor/tinyagents b/vendor/tinyagents
index 23b9afdaae..1ec9fa136c 160000
--- a/vendor/tinyagents
+++ b/vendor/tinyagents
@@ -1 +1 @@
-Subproject commit 23b9afdaaefe4bd966a6da2633abaa03d8f3b239
+Subproject commit 1ec9fa136c11aa80740b8ddbbfb7e0c6edfc9440