Skip to content

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

fix(storage): propagate session rebind failures instead of returning a count

Steven Enamakela9d673978697
diff --git a/crates/openhuman-core/src/storage/rebind.rs b/crates/openhuman-core/src/storage/rebind.rs
index c162053d4b..42954e69d1 100644
--- a/crates/openhuman-core/src/storage/rebind.rs
+++ b/crates/openhuman-core/src/storage/rebind.rs
@@ -51,9 +51,9 @@ pub fn rebind(config: &Config) -> Result<Option<Rebound>> {
rebind_with(config, super::installed_url(), |url, backend| {
// Sessions first: no store may read one workspace's sessions beside
// another's documents, so both move together.
- let rebound = crate::storage::sessions::rebind_all(&backend);
+ let rebound = crate::storage::sessions::rebind_all(&backend)?;
super::install_for_url(url, backend);
- rebound
+ Ok(rebound)
})
}
@@ -64,7 +64,7 @@ pub fn rebind(config: &Config) -> Result<Option<Rebound>> {
pub(crate) fn rebind_with(
config: &Config,
current: Option<String>,
- install: impl FnOnce(&str, Arc<dyn StorageBackend>) -> usize,
+ install: impl FnOnce(&str, Arc<dyn StorageBackend>) -> Result<usize>,
) -> Result<Option<Rebound>> {
let Some(current) = current else {
return Ok(None);
diff --git a/crates/openhuman-core/src/storage/rebind_tests.rs b/crates/openhuman-core/src/storage/rebind_tests.rs
index a0c267ee96..9b4820796a 100644
--- a/crates/openhuman-core/src/storage/rebind_tests.rs
+++ b/crates/openhuman-core/src/storage/rebind_tests.rs
@@ -16,13 +16,17 @@ fn config_in(dir: &TempDir) -> Config {
struct Installed(Mutex<Vec<(String, Arc<dyn StorageBackend>)>>);
impl Installed {
- fn install(&self) -> impl FnOnce(&str, Arc<dyn StorageBackend>) -> usize + '_ {
+ fn install(&self) -> impl FnOnce(&str, Arc<dyn StorageBackend>) -> Result<usize> + '_ {
|url, backend| {
self.0.lock().unwrap().push((url.to_string(), backend));
- 0
+ Ok(0)
}
}
+ fn reject_install(&self) -> impl FnOnce(&str, Arc<dyn StorageBackend>) -> Result<usize> + '_ {
+ |_url, _backend| Err(anyhow::anyhow!("session stores refused the backend"))
+ }
+
fn urls(&self) -> Vec<String> {
self.0
.lock()
@@ -191,6 +195,23 @@ fn a_backend_that_cannot_be_opened_keeps_the_previous_one() {
assert!(installed.urls().is_empty(), "nothing was installed");
}
+#[test]
+fn a_session_store_rebind_failure_keeps_the_previous_backend_installed() {
+ let first = TempDir::new().unwrap();
+ let second = TempDir::new().unwrap();
+ let installed = Installed::default();
+ let current = super::super::config::default_url(first.path());
+
+ let error = rebind_with(
+ &config_in(&second),
+ Some(current),
+ installed.reject_install(),
+ );
+
+ assert!(error.is_err());
+ assert!(installed.urls().is_empty(), "the new backend was not installed");
+}
+
#[test]
fn rebinding_to_a_fresh_v2_profile_opens_its_storage_db_and_leaves_a_v1_one_alone() {
let root = TempDir::new().unwrap();
diff --git a/crates/openhuman-core/src/storage/sessions/tenant_router.rs b/crates/openhuman-core/src/storage/sessions/tenant_router.rs
index 0300512588..dc7681084a 100644
--- a/crates/openhuman-core/src/storage/sessions/tenant_router.rs
+++ b/crates/openhuman-core/src/storage/sessions/tenant_router.rs
@@ -33,7 +33,7 @@ struct TenantStoreRegistryState {
}
impl TenantStoreRegistry {
- fn rebind(&self, backend: &Arc<dyn StorageBackend>) -> usize {
+ fn rebind(&self, backend: &Arc<dyn StorageBackend>) -> Result<usize, StorageError> {
let mut state = self.state.lock().unwrap_or_else(PoisonError::into_inner);
let backends = state
.backends
@@ -85,13 +85,14 @@ impl TenantStoreRegistry {
}
if rollback_failures.is_empty() {
tracing::error!(target: "openhuman::storage", %error, "[session_store] tenant provider rebind failed; prior providers were restored");
- return 0;
+ return Err(error);
}
tracing::error!(target: "openhuman::storage", %error, rollback_errors = ?rollback_failures, restored = moved.len() - rollback_failures.len(), "[session_store] tenant provider rebind and rollback failed; providers may remain split across backends");
- // The return count is intentionally non-zero when rollback
- // could not restore every provider, so callers cannot mistake
- // this for a clean no-op.
- return rollback_failures.len();
+ return Err(StorageError::invalid_input(format!(
+ "tenant session-store rebind failed ({error}); rollback failed for {} provider(s): {}",
+ rollback_failures.len(),
+ rollback_failures.join("; ")
+ )));
}
moved.push((Arc::clone(provider), Arc::clone(old_backend)));
}
@@ -102,7 +103,7 @@ impl TenantStoreRegistry {
state.backends.retain(|weak| weak.strong_count() > 0);
state.tenants.retain(|weak| weak.strong_count() > 0);
state.current_backend = Some(Arc::clone(backend));
- moved.len()
+ Ok(moved.len())
}
fn register_backend(
@@ -125,7 +126,7 @@ static PROCESS_SESSION_STORES: LazyLock<Arc<TenantStoreRegistry>> =
LazyLock::new(|| Arc::new(TenantStoreRegistry::default()));
/// Rebinds the host's live tenant routers to `backend`.
-pub fn rebind_all(backend: &Arc<dyn StorageBackend>) -> usize {
+pub fn rebind_all(backend: &Arc<dyn StorageBackend>) -> Result<usize, StorageError> {
PROCESS_SESSION_STORES.rebind(backend)
}