Skip to content

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

fix(profiles): release lease when profile disappears during provisioning

Steven Enamakelcf39b776d960
diff --git a/crates/openhuman-core/src/cron/limits.rs b/crates/openhuman-core/src/cron/limits.rs
index 0722a861ed..e8e481bd65 100644
--- a/crates/openhuman-core/src/cron/limits.rs
+++ b/crates/openhuman-core/src/cron/limits.rs
@@ -79,7 +79,7 @@ fn clear_capacity_limit_if_supported(config: &Config) -> Result<()> {
})
}
-/// Refuse a new job that breaks the limits. No-op unless [`enforced`].
+/// Enforce the limits for a new job, or clear a stored cap while they are off.
pub(crate) fn check_new(
config: &Config,
job_type: &JobType,
@@ -98,7 +98,7 @@ pub(crate) fn check_new(
install_capacity_limit(config)
}
-/// Refuse an update that breaks the limits. No-op unless [`enforced`].
+/// Enforce update limits, or clear a stored cap while they are off.
pub(crate) fn check_patch(config: &Config, patch: &CronJobPatch) -> Result<()> {
if !enforced(config) {
clear_capacity_limit_if_supported(config)?;
diff --git a/crates/openhuman-core/src/profiles/lifecycle.rs b/crates/openhuman-core/src/profiles/lifecycle.rs
index fc0311dec0..986c72b07f 100644
--- a/crates/openhuman-core/src/profiles/lifecycle.rs
+++ b/crates/openhuman-core/src/profiles/lifecycle.rs
@@ -123,6 +123,17 @@ impl ProfileHost {
let _profile = self.lifecycle.lock(id).await;
if self.registry.get(id).await?.is_some() {
let grant = self.acquire_for_lifecycle(id, "provision").await?;
+ match self.registry.get(id).await {
+ Ok(Some(_)) => {}
+ Ok(None) => {
+ profile_lease::release_all(self, vec![(id.clone(), grant)]).await;
+ return Ok(false);
+ }
+ Err(error) => {
+ profile_lease::release_all(self, vec![(id.clone(), grant)]).await;
+ return Err(error);
+ }
+ }
let config = self.forced_config(&self.layout_of(id), id);
let reconciled = reconcile_cron_admission(&config, id).await;
profile_lease::release_all(self, vec![(id.clone(), grant)]).await;