Skip to content

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

fix(storage): guard tinyflows import with a claim to prevent concurrent runs

Steven Enamakel7164451315ef
diff --git a/crates/openhuman-core/src/storage/import/tinyflows.rs b/crates/openhuman-core/src/storage/import/tinyflows.rs
index f3d269d1cf..653f167d68 100644
--- a/crates/openhuman-core/src/storage/import/tinyflows.rs
+++ b/crates/openhuman-core/src/storage/import/tinyflows.rs
@@ -67,6 +67,14 @@ pub(super) fn marked(
if done {
return Ok(Outcome::AlreadyDone);
}
+ let claimed = super::super::import_claim::with_claim(&markers, MARKER_COLLECTION, &marker.clone(), || {
+ let again = marker.clone();
+ let done = markers
+ .run(move |docs| async move { docs.get(MARKER_COLLECTION, &again).await })?
+ .is_some();
+ if done {
+ return Ok(Outcome::AlreadyDone);
+ }
let Some((found, written, skipped)) = body()? else {
return Ok(Outcome::NoSource);
};
@@ -98,6 +106,8 @@ pub(super) fn marked(
}
})?;
Ok(Outcome::Imported { found, written })
+ })?;
+ Ok(claimed.unwrap_or(Outcome::InProgress))
}
/// `(found, written, skipped)` of a `tinyflows-import` report; problems are logged by
@@ -278,6 +288,11 @@ pub(super) fn finish(domain: &'static str, outcome: Result<Outcome>) -> Report {
domain,
"[storage::import] already imported"
),
+ Ok(Outcome::InProgress) => tracing::debug!(
+ target: "openhuman::storage_import",
+ domain,
+ "[storage::import] another process is importing; skipped"
+ ),
Ok(Outcome::NoSource) => tracing::debug!(
target: "openhuman::storage_import",
domain,