Skip to content

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

fix(embed): deny a removed agent's approvals before ending its turns (#7032)

oxoxDev15151e023a1e
diff --git a/crates/openhuman-embed/src/agent/mod.rs b/crates/openhuman-embed/src/agent/mod.rs
index 0ca9f7ead3..e1329521b2 100644
--- a/crates/openhuman-embed/src/agent/mod.rs
+++ b/crates/openhuman-embed/src/agent/mod.rs
@@ -128,18 +128,7 @@ impl AgentInner {
if !self.lifecycle.begin_teardown() {
return;
}
- if let Some(gate) = openhuman_core::security::approval::ApprovalGate::try_global() {
- match gate.deny_all_for_agent(&self.id, resolution) {
- Ok(denied) => log::debug!(
- "[embed][agent] teardown id={} denied_approvals={denied}",
- self.id
- ),
- Err(error) => log::warn!(
- "[embed][agent] teardown id={} could not deny approvals: {error}",
- self.id
- ),
- }
- }
+ self.deny_approvals(resolution);
self.ctx.agent_state().clear();
if openhuman_core::mcp::host::take_agent_host(&self.config.workspace_dir, &self.id)
.is_some()
@@ -152,6 +141,23 @@ impl AgentInner {
openhuman_core::core::runtime::AgentContextRegistry::deregister(&self.id, &self.ctx);
log::debug!("[embed][agent] teardown complete id={}", self.id);
}
+
+ /// Denies every approval this agent has parked, with `resolution`.
+ pub(crate) fn deny_approvals(&self, resolution: &str) {
+ let Some(gate) = openhuman_core::security::approval::ApprovalGate::try_global() else {
+ return;
+ };
+ match gate.deny_all_for_agent(&self.id, resolution) {
+ Ok(denied) => log::debug!(
+ "[embed][agent] id={} denied_approvals={denied} resolution={resolution}",
+ self.id
+ ),
+ Err(error) => log::warn!(
+ "[embed][agent] id={} could not deny approvals: {error}",
+ self.id
+ ),
+ }
+ }
}
impl Drop for AgentInner {
diff --git a/crates/openhuman-embed/src/runtime/lifecycle.rs b/crates/openhuman-embed/src/runtime/lifecycle.rs
index ed49c4b8a2..5a9cf8c41d 100644
--- a/crates/openhuman-embed/src/runtime/lifecycle.rs
+++ b/crates/openhuman-embed/src/runtime/lifecycle.rs
@@ -40,12 +40,12 @@ impl<'a> IntoFuture for RemoveAgent<'a> {
impl Runtime {
/// Remove agent `id` from this runtime.
///
- /// In order: new turns on any handle to it are refused with
+ /// In order: its parked approvals are denied with resolution
+ /// `agent_removed`; new turns on any handle to it are refused with
/// [`CoreError::AgentRemoved`](crate::CoreError::AgentRemoved); turns in
/// flight end with the same error, waited on for up to ten seconds; its
- /// parked approvals are denied with resolution `agent_removed`; its state
- /// slots and MCP host are dropped and its context deregistered, so its
- /// cron jobs stay dormant. The id is free for reuse once this returns.
+ /// state slots and MCP host are dropped and its context deregistered, so
+ /// its cron jobs stay dormant. The id is free for reuse once this returns.
///
/// Cancellation is cooperative: a tool already executing when the agent
/// is removed, or a sub-agent it detached, may finish after this returns.
@@ -67,6 +67,7 @@ impl Runtime {
.ok_or_else(|| AgentError::UnknownId(id.to_string()))?
};
log::debug!("[embed][runtime] removing agent id={id} purge={purge}");
+ inner.deny_approvals("agent_removed");
inner.lifecycle.mark_removed();
if !inner.lifecycle.wait_idle(REMOVE_IDLE_WAIT).await {
log::warn!(