Skip to content

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

fix(security): persist agent approval decisions to the store

Steven Enamakel1c0a67194813
diff --git a/crates/openhuman-core/src/security/approval/store_agent.rs b/crates/openhuman-core/src/security/approval/store_agent.rs
index 9922f86933..22b7338987 100644
--- a/crates/openhuman-core/src/security/approval/store_agent.rs
+++ b/crates/openhuman-core/src/security/approval/store_agent.rs
@@ -15,20 +15,23 @@ pub fn exists(_config: &Config) -> bool {
/// [`PendingApproval::belongs_to`]).
///
/// An embedded agent's requests are kept in its own storage scope, so the rows
-/// of `Some(agent)` are read there whichever scope the caller runs in (under a
-/// SaaS profile every agent shares the profile's scope, which is the caller's).
+/// of `Some(agent)` are read there as well as in the caller's scope, whichever
+/// scope the caller runs in (under a SaaS profile every agent shares the
+/// profile's scope, which is the caller's).
pub fn list_pending_for_agent(
config: &Config,
agent: Option<&str>,
) -> Result<Vec<PendingApproval>> {
- let rows = match agent {
- Some(agent) if !acts_for_a_profile() => {
- let docs = super::super::store_documents::for_agent(config, agent)?;
- super::publish_expired(&docs.expire_stale(chrono::Utc::now())?);
- docs.list_pending()?
+ let mut rows = super::list_pending(config)?;
+ if let Some(agent) = agent.filter(|_| !acts_for_a_profile()) {
+ let docs = super::super::store_documents::for_agent(config, agent)?;
+ super::publish_expired(&docs.expire_stale(chrono::Utc::now())?);
+ for row in docs.list_pending()? {
+ if !rows.iter().any(|seen| seen.request_id == row.request_id) {
+ rows.push(row);
+ }
}
- _ => super::list_pending(config)?,
- };
+ }
Ok(rows
.into_iter()
.filter(|row| row.belongs_to(agent))