Skip to content

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

chore: files changed crates/openhuman-core/src/flows/tinyflows/caps/ops_tier_live_config_tests.rs,cr

Steven Enamakel89d48e15d395
diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/ops_tier_live_config_tests.rs b/crates/openhuman-core/src/flows/tinyflows/caps/ops_tier_live_config_tests.rs
index b0e5a4012a..01af4220c7 100644
--- a/crates/openhuman-core/src/flows/tinyflows/caps/ops_tier_live_config_tests.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/caps/ops_tier_live_config_tests.rs
@@ -72,12 +72,18 @@ async fn one_live_capability_observes_full_readonly_full_updates() {
path: dir.path().join("trusted").display().to_string(),
access: crate::security::TrustedAccess::ReadWrite,
});
+ baseline.max_actions_per_hour = 2;
baseline.tracker.record();
let fresh = current_tier_policy(&ctx, &config, &baseline).await.unwrap();
assert_eq!(fresh.workspace_dir, baseline.workspace_dir);
assert_eq!(fresh.action_dir, baseline.action_dir);
assert_eq!(fresh.trusted_roots, baseline.trusted_roots);
assert_eq!(fresh.tracker.count(), baseline.tracker.count());
+ assert!(fresh.record_action());
+ assert_eq!(baseline.tracker.count(), 2);
+ let next_refresh = current_tier_policy(&ctx, &config, &baseline).await.unwrap();
+ assert!(next_refresh.is_rate_limited());
+ assert_eq!(next_refresh.tracker.count(), 2);
assert_eq!(
enforce_current_node_tier_gate(&ctx, &config, &baseline, CommandClass::Write, "code")
diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/tier.rs b/crates/openhuman-core/src/flows/tinyflows/caps/tier.rs
index fc34ce006c..e694a359e9 100644
--- a/crates/openhuman-core/src/flows/tinyflows/caps/tier.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/caps/tier.rs
@@ -104,6 +104,7 @@ pub(crate) fn tier_policy_from_config(
baseline: &SecurityPolicy,
) -> Result<SecurityPolicy> {
let mut policy = baseline.clone();
+ policy.tracker = baseline.tracker.shared_clone();
let ceiling = ctx.autonomy_tier_ceiling();
if ctx.autonomy_tier_source() == crate::core::runtime::AutonomyTierSource::Captured {
if let Some(ceiling) = ceiling {
diff --git a/crates/openhuman-core/src/security/policy/types.rs b/crates/openhuman-core/src/security/policy/types.rs
index c2f36c2ec0..c4ce288486 100644
--- a/crates/openhuman-core/src/security/policy/types.rs
+++ b/crates/openhuman-core/src/security/policy/types.rs
@@ -80,7 +80,7 @@ pub enum ToolOperation {
#[derive(Debug)]
pub struct ActionTracker {
/// Timestamps of recent actions (kept within the last hour).
- actions: Mutex<Vec<Instant>>,
+ actions: Arc<Mutex<Vec<Instant>>>,
}
impl Default for ActionTracker {
@@ -92,7 +92,7 @@ impl Default for ActionTracker {
impl ActionTracker {
pub fn new() -> Self {
Self {
- actions: Mutex::new(Vec::new()),
+ actions: Arc::new(Mutex::new(Vec::new())),
}
}
@@ -116,13 +116,23 @@ impl ActionTracker {
actions.retain(|t| *t > cutoff);
actions.len()
}
+
+ /// Shares the action history with a short-lived policy derived from this
+ /// tracker. Ordinary `Clone` intentionally snapshots history for separate
+ /// policies; live flow gates use this handle so rebuilding the tier view
+ /// does not reset one run's action budget.
+ pub(crate) fn shared_clone(&self) -> Self {
+ Self {
+ actions: Arc::clone(&self.actions),
+ }
+ }
}
impl Clone for ActionTracker {
fn clone(&self) -> Self {
let actions = self.actions.lock();
Self {
- actions: Mutex::new(actions.clone()),
+ actions: Arc::new(Mutex::new(actions.clone())),
}
}
}