The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
docs(storage): document the v2 lease cutover and driver fence fields
Steven Enamakel03f94c1bc0b1
diff --git a/crates/openhuman-core/src/storage/README.md b/crates/openhuman-core/src/storage/README.mdindex 0edd14c1bd..a2e79fe858 100644--- a/crates/openhuman-core/src/storage/README.md+++ b/crates/openhuman-core/src/storage/README.md@@ -186,6 +186,10 @@ unique among live processes.| `DocumentLeases` | a thin adapter over tinystoragedrivers' `Leases` (`tsd.leases`, owner `profiles`, scope `cluster`); the record, CAS loop, epoch rules and fence are tsd's | clustered nodes on a driver with cross-process CAS || `LocalLeases` | an exclusive `fs2` flock on `<root>/<sha256(key) hex>/.lease`, record in `.lease.json` beside it; no expiry, the OS drops the lock when the process dies | hosts without a backend |+The move from the v1 `leases` collection runs once per cluster scope+(`profiles::storage_schema::migrate_legacy_leases`) and is a stop-the-world+cutover like the rest of schema v2: every node must run this version.+Keys are 1 to 200 bytes of ASCII letters, digits and `- _ . @`, not startingwith `.`, so they are safe as directory names and document ids. The scope`cluster` is shared by every node; an agent whose id is literally `cluster`@@ -217,8 +221,8 @@ change. A scope with one runs `LeaseFence::check` first:A write the host check admits then goes to the driver through`StorageBackend::for_scope_fenced` with `LeaseFence::driver_fence`: the lease-record (`cluster` scope, `leases` collection, id = the profile) must still-match `epoch`, `owner` = this node and `released = false`. The driver checks+record (`cluster` scope, `tsd.leases` collection, id = `Key::of(["profiles", <profile>])`)+must still match `epoch`, `holder` = this node and no `released` field. The driver checksit in the same statement or transaction as the write (tinystoragedriversv0.5.0, `Capability::Fencing`), so a holder paused between its check andits write cannot land the write after a takeover. The driver answersdiff --git a/crates/openhuman-core/src/storage/lease_documents_tests.rs b/crates/openhuman-core/src/storage/lease_documents_tests.rsindex d62a8a99a5..5b77bc1c28 100644--- a/crates/openhuman-core/src/storage/lease_documents_tests.rs+++ b/crates/openhuman-core/src/storage/lease_documents_tests.rs@@ -217,3 +217,18 @@ async fn sub_millisecond_ttl_does_not_expire_at_acquisition() {assert!(grant.expires_at_ms > 5);assert!(matches!(b.acquire("k", 5).await, Err(LeaseError::Held(_))));}++#[tokio::test]+async fn concurrent_renewals_of_one_grant_have_one_winner() {+ let storage = MemoryStorage::new();+ let a = std::sync::Arc::new(node(&storage, "a"));+ let grant = a.acquire("k", 0).await.unwrap();+ let go = || {+ let (a, grant) = (std::sync::Arc::clone(&a), grant.clone());+ tokio::spawn(async move { a.renew(&grant, 100).await.is_ok() })+ };+ let (x, y) = tokio::join!(go(), go());+ assert!(x.unwrap() ^ y.unwrap(), "exactly one renewal may succeed");+ // The heartbeat's next renewal, from the grant the winner returned, holds.+ assert!(a.holder("k").await.unwrap().unwrap().is_live(150));+}