Skip to content

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

fix(cron): spawn shell jobs through `platform_shell`

sanil-23de72e1d99982
diff --git a/crates/openhuman-core/src/cron/scheduler/shell_job.rs b/crates/openhuman-core/src/cron/scheduler/shell_job.rs
index 7a94f50536..3597527236 100644
--- a/crates/openhuman-core/src/cron/scheduler/shell_job.rs
+++ b/crates/openhuman-core/src/cron/scheduler/shell_job.rs
@@ -5,7 +5,6 @@ use crate::config::Config;
use crate::cron::CronJob;
use crate::security::SecurityPolicy;
use std::process::Stdio;
-use tokio::process::Command;
use tokio::time::{self, Duration};
pub(super) const SHELL_JOB_TIMEOUT_SECS: u64 = 120;
@@ -126,9 +125,12 @@ pub(super) async fn run_job_command_with_timeout(
);
}
- let child = match Command::new("sh")
- .arg("-lc")
- .arg(&job.command)
+ // Through `platform_shell`, like every other shell spawn in this crate.
+ // `Command::new("sh")` fails at `CreateProcessW` on Windows, which is the
+ // whole reason that module exists — this call site was the one that still
+ // named the program itself. The Unix behaviour is unchanged: that arm is
+ // also `-lc`, and adds `set -o pipefail` when bash is present.
+ let child = match crate::agent::platform_shell::build_tokio_command(&job.command)
.current_dir(&config.action_dir)
.stdin(Stdio::null())
.stdout(Stdio::piped())
diff --git a/crates/openhuman-core/src/cron/scheduler_tests.rs b/crates/openhuman-core/src/cron/scheduler_tests.rs
index 09be1458ae..6ab99eadce 100644
--- a/crates/openhuman-core/src/cron/scheduler_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler_tests.rs
@@ -246,3 +246,35 @@ async fn security_policy_block_halts_without_spending_the_retry_budget() {
only delays the user's error by the full retry budget (here about 4 s)."
);
}
+
+/// A shell job runs on every platform this crate supports.
+///
+/// The spawn used to name `sh` itself, and `CreateProcessW` cannot resolve that
+/// on Windows — so every scheduled shell job failed there with `spawn error:
+/// program not found` while the identical job ran on macOS and Linux. Routing it
+/// through `agent::platform_shell`, which every other shell spawn in the crate
+/// already used, is what makes this pass.
+///
+/// `echo` and the assertion on its output are deliberately shell-agnostic: the
+/// test names neither `sh` nor `cmd`, so it keeps holding if the platform matrix
+/// in `platform_shell` changes.
+#[tokio::test]
+async fn a_shell_job_runs_on_this_platform() {
+ let tmp = TempDir::new().unwrap();
+ let config = test_config(&tmp).await;
+ let security =
+ SecurityPolicy::from_config(&config.autonomy, &config.workspace_dir, &config.action_dir);
+ // Fixture guard: a policy that refused to act would make this pass by
+ // never spawning anything.
+ assert!(security.can_act(), "the fixture policy must permit acting");
+
+ let job = test_job("echo tinyhumans");
+
+ let (success, output) = run_job_command(&config, &security, &job).await;
+
+ assert!(success, "the shell job did not succeed: {output}");
+ assert!(
+ output.contains("tinyhumans"),
+ "the job's stdout was not captured: {output}"
+ );
+}