Skip to content

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

feat(approval): list every parked request for a thread

Steven Enamakel811974fac605
diff --git a/crates/openhuman-core/src/security/approval/gate_state.rs b/crates/openhuman-core/src/security/approval/gate_state.rs
index 7efd585369..442c05c252 100644
--- a/crates/openhuman-core/src/security/approval/gate_state.rs
+++ b/crates/openhuman-core/src/security/approval/gate_state.rs
@@ -369,6 +369,50 @@ impl ApprovalGate {
.then_some(row)
}
+ /// Every approval still parked on `thread_id` by the ambient context's
+ /// agent, oldest first.
+ ///
+ /// [`Self::parked_request_for_thread`] follows the single thread route,
+ /// which holds only the newest park. Several async-delegated sub-agents can
+ /// park on the same parent thread at once; each keeps its own waiter and
+ /// [`RequestRoute`], so replay reads those instead and a rejoining client
+ /// can rebuild every card, not only the last one raised.
+ pub fn parked_requests_for_thread(&self, thread_id: &str) -> Vec<PendingApproval> {
+ let agent = crate::core::runtime::agent_scope::current_agent_id();
+ let parked_here = |route: &RequestRoute| {
+ route.thread_id.as_deref() == Some(thread_id)
+ && route.agent_id.as_deref() == agent.as_deref()
+ };
+ let ids: std::collections::HashSet<String> = self
+ .request_routes
+ .lock()
+ .iter()
+ .filter(|(_, route)| parked_here(route))
+ .map(|(id, _)| id.clone())
+ .collect();
+ if ids.is_empty() {
+ return Vec::new();
+ }
+ let mut rows: Vec<PendingApproval> = match self.list_pending() {
+ Ok(rows) => rows
+ .into_iter()
+ .filter(|row| ids.contains(&row.request_id))
+ .collect(),
+ Err(error) => {
+ tracing::warn!(
+ error = %error,
+ "[approval::gate] parked_requests_for_thread: store read failed"
+ );
+ return Vec::new();
+ }
+ };
+ // Re-check after the unlocked store read, as `parked_request_for_thread`
+ // does: a request decided in between must not be replayed.
+ let routes = self.request_routes.lock();
+ rows.retain(|row| routes.get(&row.request_id).is_some_and(parked_here));
+ rows
+ }
+
/// Whether the parked `request_id` was routed to its chat thread from a
/// detached task (an async-delegated sub-agent), so the replayed card keeps
/// the live event's `detached` flag. `false` for an unknown request.
diff --git a/crates/openhuman-core/src/security/approval/gate_subagent_tests.rs b/crates/openhuman-core/src/security/approval/gate_subagent_tests.rs
index c3d006aafc..ce5c377ee2 100644
--- a/crates/openhuman-core/src/security/approval/gate_subagent_tests.rs
+++ b/crates/openhuman-core/src/security/approval/gate_subagent_tests.rs
@@ -230,3 +230,64 @@ async fn an_expired_park_tells_the_model_nobody_answered() {
"{reason}"
);
}
+
+/// Two async sub-agents parked on the same parent thread: the thread route
+/// holds only the newest, but each park must stay recoverable for replay so a
+/// rejoining client can rebuild both cards, and answering one must leave the
+/// other addressable.
+#[tokio::test]
+async fn every_detached_park_on_a_thread_stays_recoverable() {
+ let _env = EnvVarGuard::locked_unset_async("OPENHUMAN_APPROVAL_TTL_SECS").await;
+ let (gate, _dir) = test_gate();
+ let gate = Arc::new(gate);
+
+ let mut handles = Vec::new();
+ for tool in ["media_generate_image_multi_a", "media_generate_video_multi_b"] {
+ let g = gate.clone();
+ handles.push(tokio::spawn(async move {
+ turn_origin::with_origin(
+ async_subagent_origin("thread-multi"),
+ g.intercept(tool, "generate media", serde_json::json!({})),
+ )
+ .await
+ }));
+ // Park them one after another so the second overwrites the thread route.
+ for _ in 0..200 {
+ if gate
+ .list_pending()
+ .unwrap()
+ .iter()
+ .any(|row| row.tool_name == tool)
+ {
+ break;
+ }
+ tokio::time::sleep(Duration::from_millis(10)).await;
+ }
+ }
+
+ let parked = gate.parked_requests_for_thread("thread-multi");
+ let tools: Vec<_> = parked.iter().map(|row| row.tool_name.as_str()).collect();
+ assert_eq!(
+ tools,
+ vec!["media_generate_image_multi_a", "media_generate_video_multi_b"],
+ "both parks must be replayable, oldest first"
+ );
+ assert!(gate
+ .parked_requests_for_thread("thread-unrelated")
+ .is_empty());
+
+ // Answer the newer one; the older one is still parked and still listed.
+ decide_parked(&gate, &parked[1].request_id, ApprovalDecision::Deny);
+ let remaining = gate.parked_requests_for_thread("thread-multi");
+ assert_eq!(remaining.len(), 1);
+ assert_eq!(remaining[0].request_id, parked[0].request_id);
+
+ decide_parked(&gate, &parked[0].request_id, ApprovalDecision::ApproveOnce);
+ let first = handles.remove(0).await.unwrap();
+ assert!(matches!(first, GateOutcome::Allow));
+ assert!(matches!(
+ handles.remove(0).await.unwrap(),
+ GateOutcome::Deny { .. }
+ ));
+ assert!(gate.parked_requests_for_thread("thread-multi").is_empty());
+}