The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(cron): keep a job's pipeline exit status as the shell's own
sanil-234b75b0d02283
diff --git a/crates/openhuman-core/src/agent/platform_shell.rs b/crates/openhuman-core/src/agent/platform_shell.rsindex 1f5ef03358..ffc36df4e9 100644--- a/crates/openhuman-core/src/agent/platform_shell.rs+++ b/crates/openhuman-core/src/agent/platform_shell.rs@@ -29,14 +29,48 @@use std::path::Path;+/// Whether the Unix arm prefixes `set -o pipefail`.+#[derive(Clone, Copy, PartialEq, Eq)]+enum PipeFail {+ /// Surface a masked pipe-stage failure, so `curl … | sh` failing in the+ /// first stage is not reported as a success.+ Surface,+ /// Leave a pipeline's exit status as the shell's own default.+ ///+ /// For a caller whose exit status is a contract with something outside this+ /// process. `pipefail` makes `false | true` fail where a plain `sh -lc`+ /// succeeded, so switching an existing surface onto the `Surface` arm+ /// silently re-statuses every command with a pipeline in it.+ AsShellDefault,+}+/// Build a [`tokio::process::Command`] that runs `command` under the/// platform's default shell. Callers are responsible for setting/// `current_dir`, environment, and stdio.pub fn build_tokio_command(command: &str) -> tokio::process::Command {+ build_tokio_command_with(command, PipeFail::Surface)+}++/// [`build_tokio_command`] without the `set -o pipefail` prefix.+///+/// For a caller that records its command's exit status and acts on it —+/// [`crate::cron`]'s shell jobs report `success`/`failure` per run and spend a+/// retry budget on it. Turning `pipefail` on for those would flip an existing+/// job whose command ends in a tolerated pipe stage from success to failure,+/// which is a behaviour change to somebody's schedule rather than a lint.+///+/// Everything else about the platform matrix is shared with+/// [`build_tokio_command`], so a caller here still gets `cmd /C` on Windows+/// rather than a shell that does not exist there.+pub fn build_tokio_command_preserving_pipe_status(command: &str) -> tokio::process::Command {+ build_tokio_command_with(command, PipeFail::AsShellDefault)+}++fn build_tokio_command_with(command: &str, pipefail: PipeFail) -> tokio::process::Command {let mut cmd = tokio::process::Command::new(shell_program());// `as_std_mut()` so the Windows arm can reach `raw_arg` (only defined on// `std::process::Command`); the tokio wrapper forwards the raw arg.- configure_shell_args(cmd.as_std_mut(), command);+ configure_shell_args(cmd.as_std_mut(), command, pipefail);cmd}@@ -45,7 +79,7 @@ pub fn build_tokio_command(command: &str) -> tokio::process::Command {/// `std::process::Command` (not the tokio variant).pub fn build_std_command(command: &str) -> std::process::Command {let mut cmd = std::process::Command::new(shell_program());- configure_shell_args(&mut cmd, command);+ configure_shell_args(&mut cmd, command, PipeFail::Surface);cmd}@@ -73,16 +107,18 @@ fn shell_program() -> &'static str {/// string to cmd verbatim, which is exactly the byte-transparent contract this/// module promises. `/C` itself has no special characters.#[cfg(windows)]-fn configure_shell_args(cmd: &mut std::process::Command, command: &str) {+fn configure_shell_args(cmd: &mut std::process::Command, command: &str, _pipefail: PipeFail) {use std::os::windows::process::CommandExt;+ // `cmd.exe` has no `pipefail` equivalent, so the flag cannot be honoured+ // here: a Windows pipeline's exit status is its last stage either way.cmd.arg("/C").raw_arg(command);}-/// Unix arm: `bash -lc "set -o pipefail\n<command>"` when bash is present-/// (so a masked pipe-stage failure still surfaces), else plain `sh -lc`.+/// Unix arm: `bash -lc "set -o pipefail\n<command>"` when bash is present **and**+/// the caller asked to surface pipe-stage failures, else a plain `-lc`.#[cfg(not(windows))]-fn configure_shell_args(cmd: &mut std::process::Command, command: &str) {- if bash_path().is_some() {+fn configure_shell_args(cmd: &mut std::process::Command, command: &str, pipefail: PipeFail) {+ if bash_path().is_some() && pipefail == PipeFail::Surface {cmd.arg("-lc").arg(format!("set -o pipefail\n{command}"));} else {cmd.arg("-lc").arg(command);diff --git a/crates/openhuman-core/src/cron/scheduler/shell_job.rs b/crates/openhuman-core/src/cron/scheduler/shell_job.rsindex 3597527236..66d4aa35ff 100644--- a/crates/openhuman-core/src/cron/scheduler/shell_job.rs+++ b/crates/openhuman-core/src/cron/scheduler/shell_job.rs@@ -128,15 +128,23 @@ pub(super) async fn run_job_command_with_timeout(// 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())- .stderr(Stdio::piped())- .kill_on_drop(true)- .spawn()+ // named the program itself.+ //+ // The `preserving_pipe_status` variant, not the ordinary one: a job's exit+ // status is recorded per run and spends a retry budget, so `set -o pipefail`+ // would flip an existing job ending in a tolerated pipe stage (`false |+ // true`, a `… | grep -q` that finds nothing) from success to failure. That+ // is a change to somebody's schedule, not a lint. The `-lc` flag and the+ // per-platform shell are shared with every other caller.+ let child = match crate::agent::platform_shell::build_tokio_command_preserving_pipe_status(+ &job.command,+ )+ .current_dir(&config.action_dir)+ .stdin(Stdio::null())+ .stdout(Stdio::piped())+ .stderr(Stdio::piped())+ .kill_on_drop(true)+ .spawn(){Ok(child) => child,Err(e) => return (false, format!("spawn error: {e}")),diff --git a/crates/openhuman-core/src/cron/scheduler_tests.rs b/crates/openhuman-core/src/cron/scheduler_tests.rsindex 6ab99eadce..5c3ff60d26 100644--- a/crates/openhuman-core/src/cron/scheduler_tests.rs+++ b/crates/openhuman-core/src/cron/scheduler_tests.rs@@ -278,3 +278,39 @@ async fn a_shell_job_runs_on_this_platform() {"the job's stdout was not captured: {output}");}++/// A pipeline keeps the shell's own exit status, not `pipefail`'s.+///+/// Regression guard for a behaviour change review caught on this branch. Routing+/// this call site through `platform_shell::build_tokio_command` would have added+/// `set -o pipefail`, and `false | true` — which a plain `-lc` reports as+/// success, because only the last stage counts — would have started reporting+/// failure. Any existing job ending in a tolerated pipe stage (a `… | grep -q`+/// that finds nothing, say) would have flipped from success to failure with+/// nothing about the job having changed, and cron would have begun spending a+/// retry budget on it.+///+/// `#[cfg(unix)]` because the command is POSIX pipeline syntax. `cmd.exe` has no+/// `pipefail` to preserve — a Windows pipeline already reports its last stage —+/// so there is nothing for this to assert there.+#[cfg(unix)]+#[tokio::test]+async fn a_pipeline_reports_its_last_stage_rather_than_pipefail() {+ 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 report failure for a+ // reason that has nothing to do with the pipeline.+ assert!(security.can_act(), "the fixture policy must permit acting");++ let job = test_job("false | true");++ let (success, output) = run_job_command(&config, &security, &job).await;++ assert!(+ success,+ "`false | true` is a success under a plain `-lc`; pipefail would make it \+ a failure and re-status every existing job with a pipeline in it: {output}"+ );+}