Skip to content

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

fix(approval): a dropped decision channel honours a persisted approval

M3gA-Mind04834406f090
diff --git a/crates/openhuman-core/src/security/approval/gate_intercept_decision.rs b/crates/openhuman-core/src/security/approval/gate_intercept_decision.rs
index 428b59462e..dbd0405011 100644
--- a/crates/openhuman-core/src/security/approval/gate_intercept_decision.rs
+++ b/crates/openhuman-core/src/security/approval/gate_intercept_decision.rs
@@ -53,30 +53,46 @@ impl ApprovalGate {
tool = tool_name,
"[approval::gate] decision channel dropped — denying"
);
- if let Ok(Some(row)) =
- store::decide(&self.config, request_id, ApprovalDecision::Deny)
- {
- let route = self.take_request_route(request_id);
- BUS.publish(DomainEvent::ApprovalDecided {
- request_id: row.request_id,
- tool_name: row.tool_name,
- decision: ApprovalDecision::Deny.as_str().to_string(),
- thread_id: route.as_ref().and_then(|r| r.thread_id.clone()),
- client_id: route.as_ref().and_then(|r| r.client_id.clone()),
- tool_call_id: route.and_then(|r| r.tool_call_id),
- resolution: Some("cancelled".to_string()),
- agent_id: row.agent_id.clone(),
- });
+ // Same race as the TTL arm below: a decision may already be
+ // persisted (the sender dropped after `decide()` committed).
+ // Deny only an undecided row, and honour a persisted approval.
+ let denied = store::decide(&self.config, request_id, ApprovalDecision::Deny);
+ let persisted_approve = matches!(&denied, Ok(None))
+ && store::get_decision(&self.config, request_id)
+ .ok()
+ .flatten()
+ .is_some_and(|decision| decision.is_approve());
+ if persisted_approve {
+ tracing::info!(
+ request_id = %request_id,
+ tool = tool_name,
+ "[approval::gate] channel dropped after an approval was persisted, honoring it"
+ );
+ (GateOutcome::Allow, Some(request_id.to_string()))
+ } else {
+ if let Ok(Some(row)) = denied {
+ let route = self.take_request_route(request_id);
+ BUS.publish(DomainEvent::ApprovalDecided {
+ request_id: row.request_id,
+ tool_name: row.tool_name,
+ decision: ApprovalDecision::Deny.as_str().to_string(),
+ thread_id: route.as_ref().and_then(|r| r.thread_id.clone()),
+ client_id: route.as_ref().and_then(|r| r.client_id.clone()),
+ tool_call_id: route.and_then(|r| r.tool_call_id),
+ resolution: Some("cancelled".to_string()),
+ agent_id: row.agent_id.clone(),
+ });
+ }
+ (
+ GateOutcome::Deny {
+ reason: format!(
+ "{POLICY_DENIED_MARKER} Approval channel for '{tool_name}' closed \
+ before a decision was made."
+ ),
+ },
+ None,
+ )
}
- (
- GateOutcome::Deny {
- reason: format!(
- "{POLICY_DENIED_MARKER} Approval channel for '{tool_name}' closed \
- before a decision was made."
- ),
- },
- None,
- )
}
Err(_elapsed) if park_bound_active => {
// Caller park bound elapsed (#4756) — NOT the gate's own TTL.
diff --git a/crates/openhuman-core/src/security/approval/gate_ttl_and_triage_tests.rs b/crates/openhuman-core/src/security/approval/gate_ttl_and_triage_tests.rs
index 87b4f7c17c..a9749d71f9 100644
--- a/crates/openhuman-core/src/security/approval/gate_ttl_and_triage_tests.rs
+++ b/crates/openhuman-core/src/security/approval/gate_ttl_and_triage_tests.rs
@@ -184,6 +184,45 @@ async fn waiter_future_dropped_mid_park_evicts_waiter_clears_routing_and_denies_
);
}
+/// The decision channel can drop after `decide()` already committed an
+/// approval. The gate must honour the persisted decision, not deny a call
+/// the durable audit row says was approved.
+#[tokio::test]
+async fn a_dropped_channel_after_a_persisted_approval_allows() {
+ let (gate, _dir) = test_gate();
+ let gate = Arc::new(gate);
+ let g = gate.clone();
+ let handle = tokio::spawn(async move {
+ let turn = ApprovalTurnContext::chat(chat_ctx());
+ turn_origin::with_origin(
+ web_origin(),
+ g.intercept(&turn, "shell", "run ls", serde_json::json!({})),
+ )
+ .await
+ });
+ let mut tries = 0;
+ let request_id = loop {
+ if let Some(id) = gate.pending_for_thread("t-test") {
+ break id;
+ }
+ tries += 1;
+ assert!(tries < 200, "thread mapping never appeared");
+ tokio::time::sleep(Duration::from_millis(10)).await;
+ };
+
+ // The approval is persisted, then the waiter's sender goes away without
+ // delivering it.
+ store::decide(&gate.config, &request_id, ApprovalDecision::ApproveOnce)
+ .expect("persist approval")
+ .expect("row was pending");
+ drop(gate.waiters.lock().remove(&request_id));
+
+ assert!(
+ matches!(handle.await.unwrap(), GateOutcome::Allow),
+ "a persisted approval was denied because the channel dropped"
+ );
+}
+
// ── caller park bound (issue #4756) ──────────────────────────────
//
// A caller (composio_connect) can cap the park via