Skip to content

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

feat(profiles): add lease tracking for profile access

Steven Enamakel48dcb8ef95f8
diff --git a/crates/openhuman-core/src/profiles/lease.rs b/crates/openhuman-core/src/profiles/lease.rs
index a45ccbe0b2..00b0f07bcd 100644
--- a/crates/openhuman-core/src/profiles/lease.rs
+++ b/crates/openhuman-core/src/profiles/lease.rs
@@ -147,11 +147,25 @@ pub struct HeartbeatReport {
/// is gone (see the module docs).
pub async fn renew_once(host: &ProfileHost) -> HeartbeatReport {
let mut report = HeartbeatReport::default();
- for (id, grant) in host.grants() {
+ for (id, _) in host.grants() {
+ // Renew and store the new grant under the host gate, which every
+ // close-and-release holds: a renewal supersedes the slot's grant in
+ // the lease store, so a release that took the slot's grant between
+ // the two would carry the superseded one and fail as lost. Read the
+ // grant again under the gate, since the slot may have moved on.
+ let gate = host.gate.lock().await;
+ let Some(grant) = host.grant_of(&id) else {
+ log::debug!("[profiles][lease] profile={id} closed before its renewal");
+ continue;
+ };
let now = now_ms();
- match host.leases().renew(&grant, now).await {
- Ok(renewed) => {
- host.store_grant(&id, &grant, renewed);
+ let outcome = host.leases().renew(&grant, now).await;
+ if let Ok(renewed) = &outcome {
+ host.store_grant(&id, &grant, renewed.clone());
+ }
+ drop(gate);
+ match outcome {
+ Ok(_) => {
report.renewed += 1;
}
Err(LeaseError::Lost) => {