Skip to content

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

style(storage): reformat lease record fallback

Steven Enamakelf5ff2bc2ab95
diff --git a/crates/openhuman-core/src/storage/lease_local.rs b/crates/openhuman-core/src/storage/lease_local.rs
index 8569254e73..48eba80fba 100644
--- a/crates/openhuman-core/src/storage/lease_local.rs
+++ b/crates/openhuman-core/src/storage/lease_local.rs
@@ -165,13 +165,17 @@ impl LeaseStore for LocalLeases {
return Err(io_error("lock", &path, &error).into());
}
// Locked elsewhere: an unreadable record reads as an unknown owner.
- let record = self.read_record(key).ok().flatten().unwrap_or_else(|| LeaseRecord {
- owner: "unknown".to_string(),
- endpoint: None,
- epoch: 0,
- expires_at_ms: u64::MAX,
- released: false,
- });
+ let record = self
+ .read_record(key)
+ .ok()
+ .flatten()
+ .unwrap_or_else(|| LeaseRecord {
+ owner: "unknown".to_string(),
+ endpoint: None,
+ epoch: 0,
+ expires_at_ms: u64::MAX,
+ released: false,
+ });
tracing::debug!(
target: "openhuman::storage::lease",
key,
diff --git a/crates/openhuman-core/src/storage/lease_local_tests.rs b/crates/openhuman-core/src/storage/lease_local_tests.rs
index 061e0b7a3d..0e8f2cf3ae 100644
--- a/crates/openhuman-core/src/storage/lease_local_tests.rs
+++ b/crates/openhuman-core/src/storage/lease_local_tests.rs
@@ -67,3 +67,17 @@ async fn keys_are_validated_and_nothing_is_held_by_default() {
assert!(a.holder("free").await.unwrap().is_none());
assert!(!dir.path().join("..").join("x").join(".lease").exists());
}
+
+#[tokio::test]
+async fn a_malformed_record_is_an_error_not_a_fresh_start() {
+ let dir = tempfile::tempdir().unwrap();
+ let a = LocalLeases::new(dir.path(), "a");
+ let key_dir = local_dir(dir.path(), "k");
+ fs::create_dir_all(&key_dir).unwrap();
+ fs::write(key_dir.join(RECORD_FILE), b"{not json").unwrap();
+ assert!(matches!(
+ a.acquire("k", 0).await,
+ Err(LeaseError::Storage(_))
+ ));
+ assert!(matches!(a.holder("k").await, Err(LeaseError::Storage(_))));
+}