Skip to content

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

feat(security): shorten approval park window for sub-agent runs

Steven Enamakele3eec48ba826
diff --git a/crates/openhuman-core/src/security/approval/gate.rs b/crates/openhuman-core/src/security/approval/gate.rs
index 5ce2fc4b04..cf9d7e88fb 100644
--- a/crates/openhuman-core/src/security/approval/gate.rs
+++ b/crates/openhuman-core/src/security/approval/gate.rs
@@ -94,6 +94,30 @@ const DEFAULT_APPROVAL_TTL: Duration = Duration::from_secs(60 * 10);
/// branch scopes the task-local below.
const COPILOT_APPROVAL_TTL: Duration = Duration::from_secs(180);
+/// Shorter park window for approvals raised inside a sub-agent run — a
+/// delegated worker (`image_agent`, `video_agent`, `skill_setup`, …) calling
+/// an external-effect tool. Same three-minute window and the same rationale
+/// as [`COPILOT_APPROVAL_TTL`]: the prompt is one level removed from what the
+/// user is looking at (an async sub-agent's card lands on a parent turn that
+/// may already have finished), and a ten-minute park left every failed
+/// `media_generate_image` / `media_generate_video` / `skill_registry_install`
+/// blocking for exactly 600s with the result never delivered. If nobody answers
+/// in three minutes the call is denied with an "approval wasn't answered"
+/// result so the parent agent can tell the user and they can ask again.
+const SUBAGENT_APPROVAL_TTL: Duration = Duration::from_secs(180);
+
+/// Phrase every TTL-expiry denial carries, so a caller that renders its own
+/// refusal (the hosted `OpenHumanSecurityGate`) can tell "nobody answered" from
+/// "the user said no" without parsing the rest of the reason. See
+/// [`is_unanswered_approval_reason`].
+pub const APPROVAL_UNANSWERED_PHRASE: &str = "nobody answered the approval prompt";
+
+/// Whether a [`GateOutcome::Deny`] reason is a TTL expiry (the prompt went
+/// unanswered) rather than a refusal.
+pub fn is_unanswered_approval_reason(reason: &str) -> bool {
+ reason.contains(APPROVAL_UNANSWERED_PHRASE)
+}
+
/// Per-turn chat context for routing a parked approval's yes/no reply back to
/// the originating thread. The web channel scopes this task-local around the
/// agent run (`web_chat`); because the `run_turn` handler, the
@@ -222,6 +246,10 @@ pub(crate) struct RequestRoute {
pub(crate) tool_call_id: Option<String>,
pub(crate) forced: bool,
pub(crate) agent_id: Option<String>,
+ /// The park can outlive the chat turn it is shown on — an async-delegated
+ /// sub-agent routed through the origin fallback (#5499). Carried so the
+ /// replay path re-emits the same `detached` flag the live event had.
+ pub(crate) detached: bool,
}
/// Coordinator for pending approvals.
diff --git a/crates/openhuman-core/src/security/approval/gate_setup.rs b/crates/openhuman-core/src/security/approval/gate_setup.rs
index 39e994a578..eab85b3d7a 100644
--- a/crates/openhuman-core/src/security/approval/gate_setup.rs
+++ b/crates/openhuman-core/src/security/approval/gate_setup.rs
@@ -74,16 +74,19 @@ impl ApprovalGate {
}
/// Resolve the actual park duration from the gate's own `effective_ttl`
- /// plus the `copilot_stream` clamp ([`COPILOT_APPROVAL_TTL`]) when that
- /// origin is active. A clamp only ever *shortens* the park — it can never
+ /// plus the `copilot_stream` clamp ([`COPILOT_APPROVAL_TTL`]) and the
+ /// sub-agent clamp ([`SUBAGENT_APPROVAL_TTL`]) when those apply. A clamp only ever *shortens* the park — it can never
/// extend `effective_ttl` past what the gate itself allows (e.g. a debug
/// env override). Split out (rather than inlined at the call site) so it is
/// unit testable without needing to actually park a future.
- fn resolve_park_ttl(effective_ttl: Duration, copilot_stream: bool) -> Duration {
+ fn resolve_park_ttl(effective_ttl: Duration, copilot_stream: bool, subagent: bool) -> Duration {
let mut ttl = effective_ttl;
if copilot_stream {
ttl = ttl.min(COPILOT_APPROVAL_TTL);
}
+ if subagent {
+ ttl = ttl.min(SUBAGENT_APPROVAL_TTL);
+ }
ttl
}