Skip to content

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

refactor(security): refine cron turn security gate logic

Steven Enamakelde94a8d9ada1
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs b/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs
index 687f2e4dc7..d44b7e78a2 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs
@@ -537,9 +537,11 @@ impl OpenHumanSecurityGate {
};
// A scheduled prompt is data, not an open-ended approval for later
- // actions. Keep cron agent turns within a read-only tool capability.
- // This check precedes the shell shortcut and all approval settings,
- // including installations where the approval gate is disabled.
+ // actions. Keep Cron turns read-only, except that a headless root which
+ // owns descendant settlement may use the canonical spawn tool as
+ // internal orchestration control. This does not permit effectful spawn
+ // implementations, shell, or any other acting tool. The check precedes
+ // shell and approval shortcuts, including when approvals are disabled.
let is_cron_turn = matches!(
self.turn_origin(),
Some(
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/security_gate_tests.rs b/crates/openhuman-core/src/agent/tinyagents/host/security_gate_tests.rs
index dc8e74775e..43590a8e51 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/security_gate_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/security_gate_tests.rs
@@ -213,6 +213,17 @@ async fn cron_headless_settlement_allows_only_spawn_control() {
.await;
assert_eq!(opted_in, GateDecision::Allow);
+ let read_only = cron_decision(
+ OpenHumanSecurityGate::new(policy(AutonomyLevel::ReadOnly), registry())
+ .with_headless_descendant_settlement(true),
+ "spawn_subagent",
+ )
+ .await;
+ assert!(
+ !read_only.is_allowed(),
+ "headless settlement must not override the agent's autonomy tier"
+ );
+
let write = cron_decision(
gate(AutonomyLevel::Full).with_headless_descendant_settlement(true),
"write_file",
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 2cec9b701f..985d953f26 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,
+ child_effect_denials: 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,
@@ -33,10 +34,30 @@ impl ChatModel<()> for CronChildModel {
.iter()
.any(|message| message.text().contains(CHILD_PROMPT))
{
- self.child_calls
+ let call = self
+ .child_calls
.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
- if let Some(started) = self.child_started.lock().unwrap().take() {
- let _ = started.send(());
+ if call == 0 {
+ if let Some(started) = self.child_started.lock().unwrap().take() {
+ let _ = started.send(());
+ }
+ let mut response = ModelResponse::assistant("");
+ response.message.tool_calls = vec![tinyinference_llm::tool::ToolCall::new(
+ "headless-cron-forbidden-effect",
+ "task_source_remove",
+ serde_json::json!({"id": "headless-cron-forbidden-source"}),
+ )];
+ response.finish_reason = Some("tool_calls".into());
+ return Ok(response);
+ }
+
+ if request.messages.iter().any(|message| {
+ message
+ .text()
+ .contains("Scheduled agent turns may use read-only tools only")
+ }) {
+ self.child_effect_denials
+ .fetch_add(1, std::sync::atomic::Ordering::SeqCst);
}
self.child_release.notified().await;
return Ok(ModelResponse::assistant("headless-cron-child-result"));
@@ -82,6 +103,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),
+ child_effect_denials: 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(),
@@ -189,7 +211,15 @@ async fn scheduled_agent_history_includes_its_spawned_child_result() {
);
assert_eq!(
model.child_calls.load(std::sync::atomic::Ordering::SeqCst),
- 1
+ 2,
+ "the real child was called again after its denied effectful tool"
+ );
+ assert_eq!(
+ model
+ .child_effect_denials
+ .load(std::sync::atomic::Ordering::SeqCst),
+ 1,
+ "the Cron child policy denied the effectful tool in its own run"
);
assert_eq!(
model.accepted_followups.load(std::sync::atomic::Ordering::SeqCst),