Skip to content

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

fix(storage): bound the profile listing in the blob sweep

Steven Enamakel504446f14edf
diff --git a/crates/openhuman-core/src/storage/blob_sweep.rs b/crates/openhuman-core/src/storage/blob_sweep.rs
index e053515010..6eb08cd3c7 100644
--- a/crates/openhuman-core/src/storage/blob_sweep.rs
+++ b/crates/openhuman-core/src/storage/blob_sweep.rs
@@ -135,12 +135,31 @@ async fn sweep_host_profiles(backend: &dyn StorageBackend) -> u64 {
let Some(host) = crate::profiles::host::host() else {
return 0;
};
- match host.ids().await {
- Ok(ids) => sweep_profiles(backend, &ids).await,
- Err(error) => {
+ match bounded_listing(SCOPE_SWEEP_TIMEOUT, host.ids()).await {
+ Some(Ok(ids)) => sweep_profiles(backend, &ids).await,
+ Some(Err(error)) => {
tracing::warn!(%error, "[storage::blob_sweep] could not list profiles; skipped");
0
}
+ None => 0,
+ }
+}
+
+/// Awaits a profile listing for at most `limit`; `None` (logged) when it hangs,
+/// so a stuck registry cannot stall the scheduler. Retried on the next tick.
+async fn bounded_listing<T>(
+ limit: Duration,
+ listing: impl std::future::Future<Output = T>,
+) -> Option<T> {
+ match tokio::time::timeout(limit, listing).await {
+ Ok(value) => Some(value),
+ Err(_) => {
+ tracing::warn!(
+ limit_secs = limit.as_secs_f32(),
+ "[storage::blob_sweep] profile listing timed out; retrying on the next tick"
+ );
+ None
+ }
}
}
diff --git a/crates/openhuman-core/src/storage/blob_sweep_tests.rs b/crates/openhuman-core/src/storage/blob_sweep_tests.rs
index fdb30a8ea4..2623258c39 100644
--- a/crates/openhuman-core/src/storage/blob_sweep_tests.rs
+++ b/crates/openhuman-core/src/storage/blob_sweep_tests.rs
@@ -171,3 +171,15 @@ async fn a_hung_scope_sweep_times_out_and_counts_as_zero() {
let removed = sweep_scope_within(&hung, &Scope::local(), Duration::from_secs(30)).await;
assert_eq!(removed, 0);
}
+
+#[tokio::test]
+async fn a_hung_profile_listing_times_out_instead_of_stalling() {
+ let hung = bounded_listing(
+ Duration::from_millis(20),
+ std::future::pending::<Result<Vec<String>, String>>(),
+ )
+ .await;
+ assert!(hung.is_none());
+ let ok = bounded_listing(Duration::from_secs(5), async { 7u8 }).await;
+ assert_eq!(ok, Some(7));
+}