From d31623985a1365adbae0123a5000be24d4267d6a Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 6 Nov 2026 11:37:34 +0530 Subject: [PATCH 1/2] test(cron): a policy-refused shell job must not spend its retries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit security_policy_block_halts_without_spending_the_retry_budget returned early whenever the output lacked "blocked by security policy:", which is exactly what TinySecurity's refusals look like ("[policy-blocked] …"), so it never asserted. It now returns early only for an unavailable module and otherwise requires the final prefix (TS-E2E-031). --- crates/openhuman-core/src/cron/scheduler_tests.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/openhuman-core/src/cron/scheduler_tests.rs b/crates/openhuman-core/src/cron/scheduler_tests.rs index 2b165111e1d..ffacce596bc 100644 --- a/crates/openhuman-core/src/cron/scheduler_tests.rs +++ b/crates/openhuman-core/src/cron/scheduler_tests.rs @@ -321,11 +321,17 @@ async fn security_policy_block_halts_without_spending_the_retry_budget() { "a read-only policy must refuse before the command is spawned; the command ran {} times", attempt_count(&counter) ); - if !output.starts_with("blocked by security policy:") { + if output == crate::security::policy::Refusal::Unavailable.to_string() { // A test runner without the TinySecurity module exercises its - // fail-closed path. Module startup latency is outside this retry test. + // fail-closed path, which stays retryable (the module may come back). return; } + // Any other refusal is the policy's answer: final, whichever text it has + // (a read-only refusal used to read "[policy-blocked] …" and be retried). + assert!( + output.starts_with("blocked by security policy:"), + "a policy refusal must be marked final for the retry loop; got {output}" + ); assert!( elapsed < std::time::Duration::from_millis(config.reliability.provider_backoff_ms) * 2, "the loop slept for {elapsed:?} on a deterministic policy refusal. A security block is \ From 7b25571c555b2712e59fd9e412f42cd2afdfd045 Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 6 Nov 2026 11:37:34 +0530 Subject: [PATCH 2/2] fix(cron): treat TinySecurity's policy refusals of a shell job as final MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit authorize_shell_command passed a TinySecurity refusal through as its display text ("[policy-blocked] …"), while the retry loop stops only on "blocked by security policy:". So a scheduled shell job the policy refused was retried across the whole backoff curve, each attempt refused again. A refusal the policy decided now carries the final prefix (POLICY_REFUSAL_PREFIX, shared with the retry loop). An unavailable module or an exhausted action budget may recover and stays retryable. The cron README no longer describes TinyBox AnalyzeCommand/StartExec. Fixes TS-E2E-031. --- crates/openhuman-core/src/cron/README.md | 19 +++++----- .../src/cron/scheduler/executor.rs | 2 +- .../src/cron/scheduler/shell_job.rs | 25 +++++++++++-- .../src/cron/scheduler/shell_job_tests.rs | 35 +++++++++++++++++++ 4 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 crates/openhuman-core/src/cron/scheduler/shell_job_tests.rs diff --git a/crates/openhuman-core/src/cron/README.md b/crates/openhuman-core/src/cron/README.md index aa945af5bcc..05182307fd6 100644 --- a/crates/openhuman-core/src/cron/README.md +++ b/crates/openhuman-core/src/cron/README.md @@ -113,15 +113,16 @@ permanent-failure classification stay in the executor and are not pluggable. `shell` jobs run through `run_job_command_with_timeout` ([`scheduler/shell_job.rs`](./scheduler/shell_job.rs)). Before spawning anything, -it checks `can_act`, `is_rate_limited`, the host security policy against command -facts returned by TinyBox `AnalyzeCommand`, and `record_action` against the -action budget. Missing module analysis fails closed; no local parser replaces -it. Any refusal returns a string starting `blocked by security policy:`, which -the retry loop treats as final. Execution uses TinyBox `StartExec` on a -module-owned passthrough resource, preserving the action directory and the -shell's default pipeline exit status. The command has a hard 120 second timeout -(`SHELL_JOB_TIMEOUT_SECS`); timeout cancellation and output cleanup are -acknowledged by TinyBox before the resource is closed. With the autonomy policy +`authorize_shell_command` checks the command with TinySecurity +(`check_command`, `CommandFlow::Scheduled`), which also reserves it against the +action budget. A refusal the policy decided (protected path, read-only, +allowlist, hidden execution, high risk, category, local-only, or a `Block` +gate) returns a string starting `blocked by security policy:` +(`POLICY_REFUSAL_PREFIX`), which the retry loop treats as final. An unavailable +module (fail closed) or an exhausted action budget may recover, so those stay +retryable. Execution runs on the host (`sandbox::shell_exec::run_host`), in the +action directory and with the shell's default pipeline exit status, under a +hard 120 second timeout (`SHELL_JOB_TIMEOUT_SECS`). With the autonomy policy disabled (the default), most policy checks are inert; see the project `CLAUDE.md`. diff --git a/crates/openhuman-core/src/cron/scheduler/executor.rs b/crates/openhuman-core/src/cron/scheduler/executor.rs index 2be23701979..914d049ba94 100644 --- a/crates/openhuman-core/src/cron/scheduler/executor.rs +++ b/crates/openhuman-core/src/cron/scheduler/executor.rs @@ -102,7 +102,7 @@ impl HostExecutor { retryable: false, raw_detail: agent_error.map(str::to_string), }; - if output.starts_with("blocked by security policy:") { + if output.starts_with(super::shell_job::POLICY_REFUSAL_PREFIX) { // Deterministic policy violations are not retryable. return permanent(output); } diff --git a/crates/openhuman-core/src/cron/scheduler/shell_job.rs b/crates/openhuman-core/src/cron/scheduler/shell_job.rs index d9fca3a33da..78fe9a2bc98 100644 --- a/crates/openhuman-core/src/cron/scheduler/shell_job.rs +++ b/crates/openhuman-core/src/cron/scheduler/shell_job.rs @@ -8,7 +8,15 @@ use tokio::time::Duration; pub(super) const SHELL_JOB_TIMEOUT_SECS: u64 = 120; +/// Prefix the retry loop (`executor.rs#classify_failure`) reads as final. +pub(super) const POLICY_REFUSAL_PREFIX: &str = "blocked by security policy:"; + /// Check and reserve a scheduled shell command through TinySecurity. +/// +/// A refusal that waiting cannot change (the policy said no) carries +/// [`POLICY_REFUSAL_PREFIX`], so the job fails without spending its retries. +/// An unavailable module or an exhausted action budget may recover, so those +/// stay retryable. pub(crate) async fn authorize_shell_command( _config: &Config, security: &SecurityPolicy, @@ -22,9 +30,9 @@ pub(crate) async fn authorize_shell_command( stage: crate::security::policy::CommandStage::Execute, }) .await - .map_err(|reason| reason.to_string())?; + .map_err(refusal_output)?; if verdict.gate == crate::security::policy::GateDecision::Block { - return Err("blocked by security policy: command rejected".to_owned()); + return Err(format!("{POLICY_REFUSAL_PREFIX} command rejected")); } Ok(()) } @@ -45,6 +53,15 @@ pub(super) async fn run_job_command( .await } +/// The job output for a refused command: final unless it may recover. +fn refusal_output(reason: crate::security::policy::Refusal) -> String { + use crate::security::policy::Refusal; + match reason { + Refusal::Unavailable | Refusal::RateLimit => reason.to_string(), + _ => format!("{POLICY_REFUSAL_PREFIX} {reason}"), + } +} + pub(super) async fn run_job_command_with_timeout( ctx: &crate::core::runtime::DispatchCtx, config: &Config, @@ -95,3 +112,7 @@ pub(super) async fn run_job_command_with_timeout( ); (output.success(), combined) } + +#[cfg(test)] +#[path = "shell_job_tests.rs"] +mod tests; diff --git a/crates/openhuman-core/src/cron/scheduler/shell_job_tests.rs b/crates/openhuman-core/src/cron/scheduler/shell_job_tests.rs new file mode 100644 index 00000000000..342d8e7f40e --- /dev/null +++ b/crates/openhuman-core/src/cron/scheduler/shell_job_tests.rs @@ -0,0 +1,35 @@ +use super::*; +use crate::security::policy::Refusal; + +#[test] +fn a_policy_refusal_is_final_for_the_retry_loop() { + // TS-E2E-031: these used to reach the retry loop as "[policy-blocked] …", + // which it retried as if waiting could change the policy's answer. + for refusal in [ + Refusal::Protected, + Refusal::ReadOnly, + Refusal::Hidden, + Refusal::NotAllowed, + Refusal::HighRisk, + Refusal::Category, + Refusal::LocalOnly, + ] { + let output = refusal_output(refusal); + assert!( + output.starts_with(POLICY_REFUSAL_PREFIX), + "{refusal:?} must be final: {output}" + ); + assert!(output.ends_with(&refusal.to_string()), "{output}"); + } +} + +#[test] +fn an_unavailable_module_or_spent_budget_stays_retryable() { + for refusal in [Refusal::Unavailable, Refusal::RateLimit] { + let output = refusal_output(refusal); + assert!( + !output.starts_with(POLICY_REFUSAL_PREFIX), + "{refusal:?} may recover and must stay retryable: {output}" + ); + } +}