Skip to content

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

test(cron): add accepted_followups tracking to scheduler tests

Steven Enamakel90c881d1ae0b
diff --git a/crates/openhuman-core/src/cron/scheduler_headless_descendants_tests.rs b/crates/openhuman-core/src/cron/scheduler_headless_descendants_tests.rs
index 785de80aaf..a562e27815 100644
--- a/crates/openhuman-core/src/cron/scheduler_headless_descendants_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler_headless_descendants_tests.rs
@@ -7,6 +7,7 @@ const CHILD_PROMPT: &str = "headless-cron-child-result-marker";
struct CronChildModel {
spawn_calls: std::sync::atomic::AtomicUsize,
child_calls: std::sync::atomic::AtomicUsize,
+ accepted_followups: std::sync::atomic::AtomicUsize,
child_started: std::sync::Mutex<Option<tokio::sync::oneshot::Sender<()>>>,
child_release: tokio::sync::Notify,
}
@@ -41,6 +42,16 @@ impl ChatModel<()> for CronChildModel {
return Ok(ModelResponse::assistant("headless-cron-child-result"));
}
+ if request.messages.iter().any(|message| {
+ message
+ .text()
+ .contains("Accepted async sub-agent `task_manager_agent`")
+ }) {
+ self.accepted_followups
+ .fetch_add(1, std::sync::atomic::Ordering::SeqCst);
+ return Ok(ModelResponse::assistant("headless-cron-root-result"));
+ }
+
if self
.spawn_calls
.fetch_add(1, std::sync::atomic::Ordering::SeqCst)
@@ -71,6 +82,7 @@ async fn scheduled_agent_history_includes_its_spawned_child_result() {
let model = std::sync::Arc::new(CronChildModel {
spawn_calls: std::sync::atomic::AtomicUsize::new(0),
child_calls: std::sync::atomic::AtomicUsize::new(0),
+ accepted_followups: std::sync::atomic::AtomicUsize::new(0),
child_started: std::sync::Mutex::new(None),
child_release: tokio::sync::Notify::new(),
});
@@ -99,23 +111,47 @@ async fn scheduled_agent_history_includes_its_spawned_child_result() {
.definitions(definitions),
);
let dispatch = crate::core::runtime::DispatchCtx::new(std::sync::Arc::clone(&core));
- let mut job = test_job("");
- job.job_type = JobType::Agent;
- job.agent_id = Some("orchestrator".into());
- job.prompt = Some("Delegate this scheduled task to its worker.".into());
- job.name = Some("headless child test".into());
+ config.reliability.scheduler_retries = 0;
+ let job = crate::cron::add_agent_job(
+ &config,
+ Some("headless child test".into()),
+ tinyflows_bus::schedule::types::Schedule::Every {
+ every_ms: 3_600_000,
+ },
+ "Delegate this scheduled task to its worker.",
+ SessionTarget::Isolated,
+ Some("test-model".into()),
+ None,
+ false,
+ )
+ .expect("persist scheduled agent job");
+ crate::cron::store::force_next_run_for_test(
+ &config,
+ &job.id,
+ chrono::Utc::now() - chrono::Duration::seconds(1),
+ )
+ .expect("make the job due");
let (child_started_tx, child_started_rx) = tokio::sync::oneshot::channel();
*model.child_started.lock().unwrap() = Some(child_started_tx);
+ let security = Arc::new(SecurityPolicy::from_config(
+ &config.autonomy,
+ &config.workspace_dir,
+ &config.action_dir,
+ ));
+ let mut dispatcher = JobDispatcher::new(&dispatch, &config, &security);
+ let scheduler_config = config.clone();
let run = tokio::spawn(async move {
crate::core::runtime::CoreContext::scope(
core,
- Box::pin(super::super::agent_run::run_agent_job_for_run(
- &dispatch,
- &config,
- &job,
- "cron-run-test",
- )),
+ Box::pin(async move {
+ let dispatched = dispatcher
+ .tick(&scheduler_config)
+ .await
+ .expect("scheduler tick");
+ assert_eq!(dispatched, 1, "the persisted due job is dispatched");
+ dispatcher.drain().await;
+ }),
)
.await
});
@@ -126,18 +162,22 @@ async fn scheduled_agent_history_includes_its_spawned_child_result() {
model.child_release.notify_one();
let result = tokio::time::timeout(std::time::Duration::from_secs(5), run).await;
panic!(
- "scheduled child never reached its model (spawn calls: {}); run result: {result:?}",
- model.spawn_calls.load(std::sync::atomic::Ordering::SeqCst)
+ "scheduled child never reached its model (spawn calls: {}, followups: {}); run result: {result:?}",
+ model.spawn_calls.load(std::sync::atomic::Ordering::SeqCst),
+ model.accepted_followups.load(std::sync::atomic::Ordering::SeqCst),
);
}
}
model.child_release.notify_one();
- let (success, output, error) = run.await.expect("cron runner task");
- assert!(success, "cron run should succeed: {error:?}");
+ run.await.expect("cron scheduler task");
+ let runs = crate::cron::list_runs(&config, &job.id, 10).expect("read persisted run history");
+ assert_eq!(runs.len(), 1, "scheduler persisted one completed run");
+ assert_eq!(runs[0].status, "ok", "agent job completed successfully");
assert!(
- output.contains("headless-cron-child-result"),
- "the recorded cron result must include its spawned child output: {output}"
+ runs[0].output.contains("headless-cron-child-result"),
+ "the persisted cron result must include its spawned child output: {}",
+ runs[0].output
);
assert_eq!(
model.spawn_calls.load(std::sync::atomic::Ordering::SeqCst),
@@ -147,4 +187,9 @@ async fn scheduled_agent_history_includes_its_spawned_child_result() {
model.child_calls.load(std::sync::atomic::Ordering::SeqCst),
1
);
+ assert_eq!(
+ model.accepted_followups.load(std::sync::atomic::Ordering::SeqCst),
+ 1,
+ "the parent accepted the real spawn result before the child completed"
+ );
}