Skip to content

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

chore: files changed crates/openhuman-core/src/agent/host_agents_tests.rs,crates/openhuman-core/src/

Steven Enamakel1aa5b8bbbf29
diff --git a/crates/openhuman-core/src/agent/host_agents_tests.rs b/crates/openhuman-core/src/agent/host_agents_tests.rs
index 52ba853738..489951c3f6 100644
--- a/crates/openhuman-core/src/agent/host_agents_tests.rs
+++ b/crates/openhuman-core/src/agent/host_agents_tests.rs
@@ -7,14 +7,16 @@ use crate::core::runtime::DomainSet;
static SLOT: std::sync::Mutex<()> = std::sync::Mutex::new(());
pub(crate) fn lock() -> std::sync::MutexGuard<'static, ()> {
- SLOT.lock().unwrap_or_else(std::sync::PoisonError::into_inner)
+ SLOT.lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
}
fn definition(id: &str) -> AgentDefinition {
- let mut definition = crate::agent::harness::definition::AgentDefinitionRegistry::builtins_only()
- .get("orchestrator")
- .cloned()
- .expect("the orchestrator is built in");
+ let mut definition =
+ crate::agent::harness::definition::AgentDefinitionRegistry::builtins_only()
+ .get("orchestrator")
+ .cloned()
+ .expect("the orchestrator is built in");
definition.id = id.to_string();
definition
}
@@ -72,7 +74,10 @@ fn clear_if_leaves_a_replacement_installed_by_someone_else() {
install(Arc::clone(&first));
let previous = install(Arc::clone(&second));
assert!(previous.is_some_and(|previous| Arc::ptr_eq(&previous, &first)));
- assert!(!clear_if(&first), "the first owner no longer holds the slot");
+ assert!(
+ !clear_if(&first),
+ "the first owner no longer holds the slot"
+ );
assert!(resolve("host-agents-second").is_some());
assert!(clear_if(&second));
assert!(resolve("host-agents-second").is_none());
diff --git a/crates/openhuman-core/src/core/runtime/services.rs b/crates/openhuman-core/src/core/runtime/services.rs
index 56404bc1b3..e8947c5d08 100644
--- a/crates/openhuman-core/src/core/runtime/services.rs
+++ b/crates/openhuman-core/src/core/runtime/services.rs
@@ -42,9 +42,7 @@ impl ServiceTasks {
/// Claim the start; `false` when the services already started and have
/// not been stopped since.
pub fn begin(&self) -> bool {
- !self
- .started
- .swap(true, std::sync::atomic::Ordering::AcqRel)
+ !self.started.swap(true, std::sync::atomic::Ordering::AcqRel)
}
/// Track a service task so [`stop`](Self::stop) can abort it.
diff --git a/crates/openhuman-core/src/cron/ops.rs b/crates/openhuman-core/src/cron/ops.rs
index b979131b7d..a8208edccb 100644
--- a/crates/openhuman-core/src/cron/ops.rs
+++ b/crates/openhuman-core/src/cron/ops.rs
@@ -290,7 +290,10 @@ fn refuse_if_single_flight_running(config: &Config, job_id: &str) -> Result<(),
if crate::cron::scheduler::in_flight::is_running(job_id)
&& crate::cron::policy::policy_or_default(config, job_id).single_flight
{
- tracing::debug!(job_id, "[cron_run] single-flight job already running; refused");
+ tracing::debug!(
+ job_id,
+ "[cron_run] single-flight job already running; refused"
+ );
return Err(format!("cron job '{job_id}' is already running"));
}
Ok(())
diff --git a/crates/openhuman-core/src/cron/ops_tests.rs b/crates/openhuman-core/src/cron/ops_tests.rs
index 6a051b24cf..5cfb32419f 100644
--- a/crates/openhuman-core/src/cron/ops_tests.rs
+++ b/crates/openhuman-core/src/cron/ops_tests.rs
@@ -552,7 +552,9 @@ fn single_flight_system_job(config: &Config, name: &str) -> CronJob {
let job = crate::cron::system_jobs::ensure_system_job(
config,
name,
- Schedule::Every { every_ms: 3_600_000 },
+ Schedule::Every {
+ every_ms: 3_600_000,
+ },
)
.unwrap();
crate::cron::policy::set_policy(
@@ -583,7 +585,10 @@ async fn run_job_now_runs_and_records_the_handler_result() {
assert_eq!(runs.len(), 1);
assert_eq!(runs[0].status, "error");
assert_eq!(
- cron::get_job(&config, &job.id).unwrap().last_status.as_deref(),
+ cron::get_job(&config, &job.id)
+ .unwrap()
+ .last_status
+ .as_deref(),
Some("error")
);
}
diff --git a/crates/openhuman-core/src/cron/policy_tests.rs b/crates/openhuman-core/src/cron/policy_tests.rs
index b9934c1d1e..ef7a576c8f 100644
--- a/crates/openhuman-core/src/cron/policy_tests.rs
+++ b/crates/openhuman-core/src/cron/policy_tests.rs
@@ -28,7 +28,10 @@ fn shell_job(config: &Config, name: &str) -> String {
fn a_job_without_a_policy_row_gets_the_default() {
let tmp = TempDir::new().unwrap();
let config = config(&tmp);
- assert_eq!(get_policy(&config, "no-such-job").unwrap(), JobPolicy::default());
+ assert_eq!(
+ get_policy(&config, "no-such-job").unwrap(),
+ JobPolicy::default()
+ );
}
#[test]
diff --git a/crates/openhuman-core/src/cron/scheduler.rs b/crates/openhuman-core/src/cron/scheduler.rs
index 21989581de..e84192cda3 100644
--- a/crates/openhuman-core/src/cron/scheduler.rs
+++ b/crates/openhuman-core/src/cron/scheduler.rs
@@ -31,11 +31,11 @@ use run_record::*;
#[allow(unused_imports)]
use shell_job::*;
-pub(crate) use dispatch::JobDispatcher;
pub use delivery::deliver_job;
+pub(crate) use dispatch::JobDispatcher;
+pub use retry::execute_job_now;
pub use slot::is_running;
pub(crate) use slot::SchedulerSlot;
-pub use retry::execute_job_now;
use crate::config::Config;
use crate::core::bus::BUS;
@@ -52,7 +52,9 @@ const MIN_POLL_SECONDS: u64 = 5;
pub async fn run(config: Config) -> Result<()> {
// One poll loop per process: two would each see the same due rows.
let Some(_slot) = SchedulerSlot::acquire() else {
- tracing::warn!("[cron:scheduler] a scheduler loop is already running; not starting another");
+ tracing::warn!(
+ "[cron:scheduler] a scheduler loop is already running; not starting another"
+ );
return Ok(());
};
// Ensure the global event bus is initialized so cron delivery events
@@ -84,7 +86,13 @@ pub async fn run(config: Config) -> Result<()> {
loop {
interval.tick().await;
- tick_once(&config, &security, &mut last_emitted_health, &mut dispatcher).await;
+ tick_once(
+ &config,
+ &security,
+ &mut last_emitted_health,
+ &mut dispatcher,
+ )
+ .await;
}
}
@@ -210,4 +218,3 @@ pub(super) async fn execute_and_persist_job(
(job.id.clone(), success, failure_message)
}
-
diff --git a/crates/openhuman-core/src/cron/scheduler/agent_run.rs b/crates/openhuman-core/src/cron/scheduler/agent_run.rs
index 3e6b31d532..3cd30b80ad 100644
--- a/crates/openhuman-core/src/cron/scheduler/agent_run.rs
+++ b/crates/openhuman-core/src/cron/scheduler/agent_run.rs
@@ -353,7 +353,10 @@ fn build_cron_agent(
agent_id = %agent_id,
"[cron] built scheduled job agent from definition"
);
- Ok(BuiltCronAgent { agent, context: None })
+ Ok(BuiltCronAgent {
+ agent,
+ context: None,
+ })
}
Err(e) => {
tracing::warn!(
@@ -362,11 +365,12 @@ fn build_cron_agent(
error = %e,
"[cron] failed to build agent from definition; falling back to canonical orchestrator"
);
- OpenHumanSessionHost::from_config_for_agent(config, "orchestrator")
- .map(|agent| BuiltCronAgent {
+ OpenHumanSessionHost::from_config_for_agent(config, "orchestrator").map(|agent| {
+ BuiltCronAgent {
agent,
context: None,
- })
+ }
+ })
}
}
}
diff --git a/crates/openhuman-core/src/cron/scheduler/dispatch.rs b/crates/openhuman-core/src/cron/scheduler/dispatch.rs
index 240a2a573b..ba0bb44020 100644
--- a/crates/openhuman-core/src/cron/scheduler/dispatch.rs
+++ b/crates/openhuman-core/src/cron/scheduler/dispatch.rs
@@ -84,9 +84,8 @@ impl JobDispatcher {
BUS.publish(DomainEvent::HealthChanged {
component: "scheduler".to_string(),
healthy: success,
- message: (!success).then(|| {
- failure_message.unwrap_or_else(|| format!("job {job_id} failed"))
- }),
+ message: (!success)
+ .then(|| failure_message.unwrap_or_else(|| format!("job {job_id} failed"))),
});
}));
}
@@ -152,7 +151,15 @@ fn skip_in_flight(config: &Config, job: &CronJob) {
}
tracing::info!(job_id = %job.id, "[cron:dispatch] single-flight job still running; slot skipped");
let now = Utc::now();
- if let Err(error) = record_run(config, &job.id, now, now, "skipped", Some(SKIPPED_OUTPUT), 0) {
+ if let Err(error) = record_run(
+ config,
+ &job.id,
+ now,
+ now,
+ "skipped",
+ Some(SKIPPED_OUTPUT),
+ 0,
+ ) {
tracing::warn!(job_id = %job.id, %error, "[cron:dispatch] recording the skipped run failed");
}
if next_run_for_schedule(&job.schedule, now).is_ok() {
diff --git a/crates/openhuman-core/src/cron/scheduler_classifier_and_delivery_tests.rs b/crates/openhuman-core/src/cron/scheduler_classifier_and_delivery_tests.rs
index c501d5204e..356194df30 100644
--- a/crates/openhuman-core/src/cron/scheduler_classifier_and_delivery_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler_classifier_and_delivery_tests.rs
@@ -459,7 +459,13 @@ async fn scheduler_tick_once_publishes_health_recovery_signal_on_empty_queue() {
// transition and fires the recovery event — same shape as `run()`
// immediately after boot.
let mut last_emitted_health: Option<bool> = None;
- tick_once(&config, &security, &mut last_emitted_health, &mut JobDispatcher::new(1)).await;
+ tick_once(
+ &config,
+ &security,
+ &mut last_emitted_health,
+ &mut JobDispatcher::new(1),
+ )
+ .await;
// Bus delivery is async — wait briefly for the subscriber to drain.
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(2);
@@ -517,7 +523,13 @@ async fn scheduler_tick_once_does_not_re_emit_recovery_signal_on_steady_state()
let mut last_emitted_health: Option<bool> = None;
// First tick: transition from None → Some(true), publishes once.
- tick_once(&config, &security, &mut last_emitted_health, &mut JobDispatcher::new(1)).await;
+ tick_once(
+ &config,
+ &security,
+ &mut last_emitted_health,
+ &mut JobDispatcher::new(1),
+ )
+ .await;
assert_eq!(
last_emitted_health,
Some(true),
@@ -530,7 +542,13 @@ async fn scheduler_tick_once_does_not_re_emit_recovery_signal_on_steady_state()
// Some(true)` guard inside `tick_once` short-circuited and no
// `publish_global` call ran on those ticks.
for tick in 2..=5 {
- tick_once(&config, &security, &mut last_emitted_health, &mut JobDispatcher::new(1)).await;
+ tick_once(
+ &config,
+ &security,
+ &mut last_emitted_health,
+ &mut JobDispatcher::new(1),
+ )
+ .await;
assert_eq!(
last_emitted_health,
Some(true),
diff --git a/crates/openhuman-core/src/cron/scheduler_dispatch_tests.rs b/crates/openhuman-core/src/cron/scheduler_dispatch_tests.rs
index b16287a0f0..c4fdcd7a31 100644
--- a/crates/openhuman-core/src/cron/scheduler_dispatch_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler_dispatch_tests.rs
@@ -21,14 +21,22 @@ fn security(config: &Config) -> Arc<SecurityPolicy> {
/// A system job row named `name`, already due.
fn due_system_job(config: &Config, name: &str) -> CronJob {
- let mut job =
- ensure_system_job(config, name, Schedule::Every { every_ms: 3_600_000 }).unwrap();
+ let mut job = ensure_system_job(
+ config,
+ name,
+ Schedule::Every {
+ every_ms: 3_600_000,
+ },
+ )
+ .unwrap();
// Due now, both in the row the next poll reads and in the value we pass.
crate::cron::update_job(
config,
&job.id,
crate::cron::CronJobPatch {
- schedule: Some(Schedule::Every { every_ms: 3_600_000 }),
+ schedule: Some(Schedule::Every {
+ every_ms: 3_600_000,
+ }),
..Default::default()
},
)
@@ -50,7 +58,10 @@ fn force_due(config: &Config, job_id: &str) {
.unwrap();
}
-fn counting(calls: Arc<AtomicUsize>, result: Result<(), String>) -> crate::cron::system_job_handlers::SystemJobHandler {
+fn counting(
+ calls: Arc<AtomicUsize>,
+ result: Result<(), String>,
+) -> crate::cron::system_job_handlers::SystemJobHandler {
Arc::new(move |_ctx: SystemJobContext| {
calls.fetch_add(1, Ordering::SeqCst);
let result = result.clone();
@@ -104,7 +115,12 @@ async fn a_long_job_does_not_hold_up_the_next_poll() {
.await
.expect("a poll returns while an earlier job is still running");
assert!(
- wait_for(|| cron::get_job(&config, &fast.id).unwrap().last_status.as_deref() == Some("ok")).await,
+ wait_for(|| cron::get_job(&config, &fast.id)
+ .unwrap()
+ .last_status
+ .as_deref()
+ == Some("ok"))
+ .await,
"the fast job completed while the slow one was still running"
);
assert!(in_flight::is_running(&slow.id));
@@ -114,7 +130,10 @@ async fn a_long_job_does_not_hold_up_the_next_poll() {
dispatcher.drain().await;
assert!(!in_flight::is_running(&slow.id));
assert_eq!(
- cron::get_job(&config, &slow.id).unwrap().last_status.as_deref(),
+ cron::get_job(&config, &slow.id)
+ .unwrap()
+ .last_status
+ .as_deref(),
Some("ok")
);
}
@@ -137,10 +156,15 @@ async fn dispatch_claims_the_slot_so_a_running_job_is_not_due_again() {
);
let job = due_system_job(&config, "dispatch-claim");
let mut dispatcher = JobDispatcher::new(4);
- dispatcher.dispatch(&config, &security(&config), vec![job.clone()]).await;
+ dispatcher
+ .dispatch(&config, &security(&config), vec![job.clone()])
+ .await;
let stored = cron::get_job(&config, &job.id).unwrap();
assert!(stored.next_run > Utc::now(), "the running slot is claimed");
- assert!(cron::due_jobs(&config, Utc::now()).unwrap().iter().all(|due| due.id != job.id));
+ assert!(cron::due_jobs(&config, Utc::now())
+ .unwrap()
+ .iter()
+ .all(|due| due.id != job.id));
release.notify_one();
dispatcher.drain().await;
}
@@ -154,11 +178,16 @@ async fn a_job_already_in_flight_is_not_dispatched_again() {
let job = due_system_job(&config, "dispatch-dedupe");
let running = in_flight::enter(&job.id);
let mut dispatcher = JobDispatcher::new(4);
- dispatcher.dispatch(&config, &security(&config), vec![job.clone()]).await;
+ dispatcher
+ .dispatch(&config, &security(&config), vec![job.clone()])
+ .await;
dispatcher.drain().await;
drop(running);
assert_eq!(calls.load(Ordering::SeqCst), 0);
- assert!(cron::list_runs(&config, &job.id, 10).unwrap().is_empty(), "a default job's overlap is silent");
+ assert!(
+ cron::list_runs(&config, &job.id, 10).unwrap().is_empty(),
+ "a default job's overlap is silent"
+ );
}
#[tokio::test]
@@ -179,11 +208,17 @@ async fn a_single_flight_job_records_the_missed_slot_as_skipped() {
.unwrap();
let running = in_flight::enter(&job.id);
let mut dispatcher = JobDispatcher::new(4);
- dispatcher.dispatch(&config, &security(&config), vec![job.clone()]).await;
+ dispatcher
+ .dispatch(&config, &security(&config), vec![job.clone()])
+ .await;
dispatcher.drain().await;
drop(running);
- assert_eq!(calls.load(Ordering::SeqCst), 0, "the overlapping run is skipped");
+ assert_eq!(
+ calls.load(Ordering::SeqCst),
+ 0,
+ "the overlapping run is skipped"
+ );
let runs = cron::list_runs(&config, &job.id, 10).unwrap();
assert_eq!(runs.len(), 1);
assert_eq!(runs[0].status, "skipped");
@@ -214,7 +249,8 @@ async fn zero_retries_means_exactly_one_attempt() {
},
)
.unwrap();
- let security = SecurityPolicy::from_config(&config.autonomy, &config.workspace_dir, &config.action_dir);
+ let security =
+ SecurityPolicy::from_config(&config.autonomy, &config.workspace_dir, &config.action_dir);
let (success, output) = execute_job_with_retry(&config, &security, &job).await;
assert!(!success);
assert!(output.contains("boom"), "{output}");
@@ -233,7 +269,8 @@ async fn without_a_policy_the_configured_retry_budget_applies() {
counting(Arc::clone(&calls), Err("again".to_string())),
);
let job = due_system_job(&config, "dispatch-default-retries");
- let security = SecurityPolicy::from_config(&config.autonomy, &config.workspace_dir, &config.action_dir);
+ let security =
+ SecurityPolicy::from_config(&config.autonomy, &config.workspace_dir, &config.action_dir);
let (success, _) = execute_job_with_retry(&config, &security, &job).await;
assert!(!success);
assert_eq!(calls.load(Ordering::SeqCst), 2);
@@ -245,7 +282,10 @@ async fn a_system_job_handler_error_is_recorded_as_the_run_result() {
let config = test_config(&tmp).await;
let _handler = register(
"dispatch-recorded",
- counting(Arc::new(AtomicUsize::new(0)), Err("handler failed".to_string())),
+ counting(
+ Arc::new(AtomicUsize::new(0)),
+ Err("handler failed".to_string()),
+ ),
);
let job = due_system_job(&config, "dispatch-recorded");
set_policy(
@@ -258,11 +298,16 @@ async fn a_system_job_handler_error_is_recorded_as_the_run_result() {
)
.unwrap();
let mut dispatcher = JobDispatcher::new(4);
- dispatcher.dispatch(&config, &security(&config), vec![job.clone()]).await;
+ dispatcher
+ .dispatch(&config, &security(&config), vec![job.clone()])
+ .await;
dispatcher.drain().await;
let stored = cron::get_job(&config, &job.id).unwrap();
assert_eq!(stored.last_status.as_deref(), Some("error"));
- assert!(stored.last_output.unwrap_or_default().contains("handler failed"));
+ assert!(stored
+ .last_output
+ .unwrap_or_default()
+ .contains("handler failed"));
}
#[tokio::test]
@@ -270,7 +315,8 @@ async fn a_system_job_without_a_handler_is_still_ok_on_dispatch() {
let tmp = TempDir::new().unwrap();
let config = test_config(&tmp).await;
let job = due_system_job(&config, "dispatch-unclaimed");
- let security = SecurityPolicy::from_config(&config.autonomy, &config.workspace_dir, &config.action_dir);
+ let security =
+ SecurityPolicy::from_config(&config.autonomy, &config.workspace_dir, &config.action_dir);
let (success, output) = execute_job_with_retry(&config, &security, &job).await;
assert!(success);
assert!(output.contains("dispatched"), "{output}");
@@ -280,7 +326,10 @@ async fn a_system_job_without_a_handler_is_still_ok_on_dispatch() {
fn only_one_scheduler_loop_holds_the_slot() {
let first = SchedulerSlot::acquire().expect("the slot is free");
assert!(is_running());
- assert!(SchedulerSlot::acquire().is_none(), "a second loop is refused");
+ assert!(
+ SchedulerSlot::acquire().is_none(),
+ "a second loop is refused"
+ );
drop(first);
assert!(!is_running());
let again = SchedulerSlot::acquire();
diff --git a/crates/openhuman-core/src/cron/scheduler_halt_and_persist_tests.rs b/crates/openhuman-core/src/cron/scheduler_halt_and_persist_tests.rs
index 926c24a47b..2e1044c0de 100644
--- a/crates/openhuman-core/src/cron/scheduler_halt_and_persist_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler_halt_and_persist_tests.rs
@@ -397,7 +397,9 @@ async fn scheduler_flow_runs_active_hours_job_and_reschedules_inside_window() {
&config.workspace_dir,
));
let mut dispatcher = JobDispatcher::new(1);
- dispatcher.dispatch(&config, &security, vec![job.clone()]).await;
+ dispatcher
+ .dispatch(&config, &security, vec![job.clone()])
+ .await;
dispatcher.drain().await;
let stored = cron::get_job(&config, &job.id).unwrap();
diff --git a/crates/openhuman-core/src/cron/scheduler_host_agent_tests.rs b/crates/openhuman-core/src/cron/scheduler_host_agent_tests.rs
index b3a4dfd644..5a847ffb79 100644
--- a/crates/openhuman-core/src/cron/scheduler_host_agent_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler_host_agent_tests.rs
@@ -36,10 +36,11 @@ impl HostAgentResolver for Host {
if agent_id != "cron-host-agent" {
return None;
}
- let mut definition = crate::agent::harness::definition::AgentDefinitionRegistry::builtins_only()
- .get("orchestrator")
- .cloned()
- .unwrap();
+ let mut definition =
+ crate::agent::harness::definition::AgentDefinitionRegistry::builtins_only()
+ .get("orchestrator")
+ .cloned()
+ .unwrap();
definition.id = agent_id.to_string();
let builds = Arc::clone(&self.belt_builds);
Some(HostAgent {
@@ -50,7 +51,10 @@ impl HostAgentResolver for Host {
builds.fetch_add(1, Ordering::SeqCst);
crate::agent::HostTurnTools::advertised(vec![Box::new(Marker)])
})),
- context: CoreContext::for_test(DomainSet::full(), Some(self.config.workspace_dir.clone())),
+ context: CoreContext::for_test(
+ DomainSet::full(),
+ Some(self.config.workspace_dir.clone()),
+ ),
})
}
}
@@ -79,8 +83,14 @@ async fn a_cron_job_for_a_host_agent_builds_with_its_host_tools_and_context() {
host_agents::clear_if(&installed);
let built = built.expect("the host agent builds");
- assert!(built.context.is_some(), "the turn runs in the host agent's context");
- assert!(belt_builds.load(Ordering::SeqCst) > 0, "the host belt was built");
+ assert!(
+ built.context.is_some(),
+ "the turn runs in the host agent's context"
+ );
+ assert!(
+ belt_builds.load(Ordering::SeqCst) > 0,
+ "the host belt was built"
+ );
assert!(built
.agent
.visible_tool_specs_arc()
diff --git a/crates/openhuman-core/src/cron/scheduler_tests.rs b/crates/openhuman-core/src/cron/scheduler_tests.rs
index 4ab7f42257..61398f97ad 100644
--- a/crates/openhuman-core/src/cron/scheduler_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler_tests.rs
@@ -102,12 +102,12 @@ fn next_user_error(
mod classifier_and_delivery_tests;
#[path = "scheduler_dispatch_tests.rs"]
mod dispatch_tests;
-#[path = "scheduler_host_agent_tests.rs"]
-mod host_agent_tests;
#[path = "scheduler_frequency_tests.rs"]
mod frequency_tests;
#[path = "scheduler_halt_and_persist_tests.rs"]
mod halt_and_persist_tests;
+#[path = "scheduler_host_agent_tests.rs"]
+mod host_agent_tests;
#[path = "scheduler_transcript_isolation_tests.rs"]
mod transcript_isolation_tests;
diff --git a/crates/openhuman-core/src/cron/system_job_handlers_tests.rs b/crates/openhuman-core/src/cron/system_job_handlers_tests.rs
index 007d9a039f..3dc1da77da 100644
--- a/crates/openhuman-core/src/cron/system_job_handlers_tests.rs
+++ b/crates/openhuman-core/src/cron/system_job_handlers_tests.rs
@@ -53,7 +53,10 @@ async fn dropping_the_registration_unregisters_the_handler() {
async fn a_replaced_registration_does_not_remove_its_replacement() {
let first_calls = Arc::new(AtomicUsize::new(0));
let second_calls = Arc::new(AtomicUsize::new(0));
- let first = register("handlers-replaced", answering(Ok(()), Arc::clone(&first_calls)));
+ let first = register(
+ "handlers-replaced",
+ answering(Ok(()), Arc::clone(&first_calls)),
+ );
let second = register(
"handlers-replaced",
answering(Err("second".into()), Arc::clone(&second_calls)),
diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs b/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs
index 28ea759b3e..2a9f1b54b7 100644
--- a/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs
@@ -212,7 +212,8 @@ impl AgentRunner for OpenHumanAgentRunner {
// A shipped/TOML harness definition has no `entry.model` — the
// definition's own `ModelSpec` (already applied by the session
// builder) is the only model pin in play here.
- self.run_via_harness(agent_ref, request, conn, None, None).await
+ self.run_via_harness(agent_ref, request, conn, None, None)
+ .await
}
AgentRoute::RegistryFallback => {
// `route_for_agent_ref` only consults the harness
@@ -357,7 +358,9 @@ impl OpenHumanAgentRunner {
// `hint:<role>` form the session builder routes on.
// A host-registered agent starts from its own config (its provider
// model and route), not the flow runner's.
- let base: &Config = host.as_ref().map_or(self.config.as_ref(), |host| &host.config);
+ let base: &Config = host
+ .as_ref()
+ .map_or(self.config.as_ref(), |host| &host.config);
let effective: Cow<'_, Config> = match node_model.as_deref() {
Some(model) => {
let mut config = base.clone();
@@ -455,7 +458,10 @@ impl OpenHumanAgentRunner {
// groups, session store); the origin task-local is untouched.
let run: std::pin::Pin<
Box<dyn std::future::Future<Output = anyhow::Result<String>> + Send>,
- > = match host.as_ref().map(|host| std::sync::Arc::clone(&host.context)) {
+ > = match host
+ .as_ref()
+ .map(|host| std::sync::Arc::clone(&host.context))
+ {
Some(context) => Box::pin(crate::core::runtime::CoreContext::scope(context, run)),
None => run,
};
diff --git a/crates/openhuman-embed/src/cron.rs b/crates/openhuman-embed/src/cron.rs
index d8aa316014..bd040bf22f 100644
--- a/crates/openhuman-embed/src/cron.rs
+++ b/crates/openhuman-embed/src/cron.rs
@@ -146,11 +146,11 @@ impl JobTarget {
.unwrap_or_else(|| "orchestrator".to_string()),
prompt: job.prompt.clone().unwrap_or_default(),
}),
- JobType::Flow => openhuman_core::cron::system_jobs::system_job_name(job).map(|name| {
- Self::System {
+ JobType::Flow => {
+ openhuman_core::cron::system_jobs::system_job_name(job).map(|name| Self::System {
name: name.to_string(),
- }
- }),
+ })
+ }
JobType::Shell => None,
}
}
@@ -539,7 +539,8 @@ fn create(
JobTarget::System { name: system } => {
// One row per system job: the store keys it by its command.
let command = format!("{SYSTEM_COMMAND_PREFIX}{system}");
- let job = openhuman_core::cron::add_flow_schedule_job(config, &command, schedule.clone())?;
+ let job =
+ openhuman_core::cron::add_flow_schedule_job(config, &command, schedule.clone())?;
Ok(openhuman_core::cron::update_job(
config,
&job.id,
diff --git a/crates/openhuman-embed/src/cron_tests.rs b/crates/openhuman-embed/src/cron_tests.rs
index 3f4ef0c50f..6c9f98ad38 100644
--- a/crates/openhuman-embed/src/cron_tests.rs
+++ b/crates/openhuman-embed/src/cron_tests.rs
@@ -74,13 +74,21 @@ fn targets_are_read_back_from_agent_and_system_rows_only() {
name: "digest".into()
})
);
- assert_eq!(JobTarget::from_job(&core_job(JobType::Flow, "flow-123")), None);
+ assert_eq!(
+ JobTarget::from_job(&core_job(JobType::Flow, "flow-123")),
+ None
+ );
assert_eq!(JobTarget::from_job(&core_job(JobType::Shell, "echo")), None);
}
#[test]
fn specs_carry_their_defaults_and_overrides() {
- let spec = JobSpec::agent("hourly", "teeny", "check in", JobSchedule::Every { ms: 3_600_000 });
+ let spec = JobSpec::agent(
+ "hourly",
+ "teeny",
+ "check in",
+ JobSchedule::Every { ms: 3_600_000 },
+ );
assert!(spec.enabled);
assert!(!spec.single_flight);
assert_eq!(spec.retries, None);
@@ -89,7 +97,12 @@ fn specs_carry_their_defaults_and_overrides() {
assert!(spec.single_flight);
assert!(!spec.enabled);
let system = JobSpec::system("digest", "digest", JobSchedule::Every { ms: 60_000 });
- assert_eq!(system.target, JobTarget::System { name: "digest".into() });
+ assert_eq!(
+ system.target,
+ JobTarget::System {
+ name: "digest".into()
+ }
+ );
}
#[test]
@@ -102,7 +115,10 @@ fn blank_names_and_targets_are_refused() {
JobSpec::system("n", "", every.clone()),
JobSpec::system("n", "has:colon", every.clone()),
] {
- assert!(matches!(spec.validate(), Err(CronError::Invalid(_))), "{spec:?}");
+ assert!(
+ matches!(spec.validate(), Err(CronError::Invalid(_))),
+ "{spec:?}"
+ );
}
assert!(JobSpec::agent("n", "teeny", "p", every).validate().is_ok());
}
diff --git a/crates/openhuman-embed/src/runtime/mod.rs b/crates/openhuman-embed/src/runtime/mod.rs
index 9806667615..7a436c22b0 100644
--- a/crates/openhuman-embed/src/runtime/mod.rs
+++ b/crates/openhuman-embed/src/runtime/mod.rs
@@ -163,9 +163,8 @@ pub(crate) struct CoreGuard {
/// this runtime's agents; removed with the runtime.
host_agents: Arc<dyn openhuman_core::agent::host_agents::HostAgentResolver>,
/// Handlers registered with [`Runtime::on_system_job`], by job name.
- system_jobs: Mutex<
- HashMap<String, openhuman_core::cron::system_job_handlers::SystemJobRegistration>,
- >,
+ system_jobs:
+ Mutex<HashMap<String, openhuman_core::cron::system_job_handlers::SystemJobRegistration>>,
}
impl Drop for CoreGuard {
diff --git a/crates/openhuman-embed/tests/cron_agents.rs b/crates/openhuman-embed/tests/cron_agents.rs
index c598d247c6..358614ec33 100644
--- a/crates/openhuman-embed/tests/cron_agents.rs
+++ b/crates/openhuman-embed/tests/cron_agents.rs
@@ -233,7 +233,11 @@ fn background_services_drive_the_scheduler_and_stop_with_the_runtime() {
.build()
.await
.expect("runtime builds");
- wait_for("the scheduler to start", openhuman_core::cron::scheduler::is_running).await;
+ wait_for(
+ "the scheduler to start",
+ openhuman_core::cron::scheduler::is_running,
+ )
+ .await;
let fired = Arc::new(Mutex::new(0usize));
let sink = Arc::clone(&fired);
@@ -251,7 +255,10 @@ fn background_services_drive_the_scheduler_and_stop_with_the_runtime() {
JobSchedule::Every { ms: 1_000 },
))
.unwrap();
- wait_for("the scheduler to fire the job", || *fired.lock().unwrap() > 0).await;
+ wait_for("the scheduler to fire the job", || {
+ *fired.lock().unwrap() > 0
+ })
+ .await;
assert!(matches!(
Runtime::builder().build().await,
@@ -265,7 +272,11 @@ fn background_services_drive_the_scheduler_and_stop_with_the_runtime() {
})
.await;
runtime.start_services().await;
- wait_for("the scheduler to restart", openhuman_core::cron::scheduler::is_running).await;
+ wait_for(
+ "the scheduler to restart",
+ openhuman_core::cron::scheduler::is_running,
+ )
+ .await;
drop(runtime);
wait_for("the scheduler to stop with the runtime", || {
diff --git a/crates/openhuman-embed/tests/public_api.rs b/crates/openhuman-embed/tests/public_api.rs
index de78933097..c62730628d 100644
--- a/crates/openhuman-embed/tests/public_api.rs
+++ b/crates/openhuman-embed/tests/public_api.rs
@@ -2,9 +2,10 @@ use std::sync::Arc;
use openhuman_embed::{
Access, Agent, AgentDefinitionSpec, AgentSpec, AgentTurnOrigin, ApiKey, Core, CoreBuilder,
- CoreRuntime, DomainSet, GroupMode, Harness, HostKind, Provider, Runtime, RuntimeBuilder,
- RuntimeConfig, SandboxModeSpec, ServiceSet, ToolGroups, ToolScopeSpec, TrustedAccess,
- TrustedAutomationSource, Workspace,
+ CoreRuntime, Cron, CronError, DomainSet, GroupMode, Harness, HostKind, JobRun, JobRunRecord,
+ JobSchedule, JobSpec, JobTarget, Provider, Runtime, RuntimeBuilder, RuntimeConfig,
+ SandboxModeSpec, ScheduledJob, ServiceSet, SystemJobContext, ToolGroups, ToolScopeSpec,
+ TrustedAccess, TrustedAutomationSource, Workspace,
};
#[test]
@@ -70,3 +71,62 @@ fn exposes_the_host_facing_embedding_contract() {
.trust("/tmp/embed-public-api", TrustedAccess::ReadWrite)
.origin(automation);
}
+
+#[test]
+fn exposes_the_scheduling_contract() {
+ fn cron_of(runtime: &Runtime) -> Cron<'_> {
+ runtime.cron()
+ }
+ fn upserts(cron: &Cron<'_>, spec: JobSpec) -> Result<ScheduledJob, CronError> {
+ cron.upsert(spec)
+ }
+ fn lists(cron: &Cron<'_>) -> Result<Vec<ScheduledJob>, CronError> {
+ cron.list()
+ }
+ fn removes(cron: &Cron<'_>) -> Result<bool, CronError> {
+ cron.remove("job")
+ }
+ fn history(cron: &Cron<'_>) -> Result<Vec<JobRunRecord>, CronError> {
+ cron.runs("job", 10)
+ }
+ async fn runs_now(cron: &Cron<'_>) -> Result<JobRun, CronError> {
+ cron.run_now("job").await
+ }
+ fn handles(runtime: &Runtime) -> Result<(), CronError> {
+ runtime.on_system_job("digest", |ctx: SystemJobContext| async move {
+ let _ = (ctx.job_id, ctx.name);
+ Ok(())
+ })
+ }
+ async fn controls_services(runtime: &Runtime) {
+ runtime.start_services().await;
+ runtime.stop_services();
+ }
+ let _ = (cron_of, upserts, lists, removes, history, handles);
+ let _ = runs_now;
+ let _ = controls_services;
+
+ let spec = JobSpec::agent(
+ "morning",
+ "teeny",
+ "Plan the day.",
+ JobSchedule::Cron {
+ expr: "0 8 * * *".into(),
+ tz: None,
+ },
+ )
+ .retries(0)
+ .single_flight(true)
+ .enabled(true);
+ assert_eq!(spec.retries, Some(0));
+ let system = JobSpec::system("digest", "digest", JobSchedule::Every { ms: 60_000 });
+ assert_eq!(
+ system.target,
+ JobTarget::System {
+ name: "digest".into()
+ }
+ );
+ let _ = JobSchedule::At {
+ at: std::time::SystemTime::now(),
+ };
+}