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
fix(memory): heartbeat between sync passes; prune the in-flight map
Shanu2d35b2f52677
diff --git a/src/openhuman/integrations/composio/ops/providers_ops.rs b/src/openhuman/integrations/composio/ops/providers_ops.rsindex fa38c0d5fe..54379ccf0f 100644--- a/src/openhuman/integrations/composio/ops/providers_ops.rs+++ b/src/openhuman/integrations/composio/ops/providers_ops.rs@@ -393,6 +393,20 @@ pub async fn composio_sync_budgeted(// settles with the honest count and the remainder named.break Ok(());}+ // A heartbeat between passes. The module reports only a+ // run's first stage and its last, and a run of many passes+ // can outlive the host's memory of it: `memory::sync_activity`+ // forgets a run after a bounded silence, because the bus can+ // lose a terminal stage (openhuman#6019). One pass is bounded+ // by the slow call's deadline, so a stage per pass keeps the+ // run alive for exactly as long as it runs — and tells the+ // row where it is.+ publish_stage(+ "running",+ Some(format!(+ "pass {passes} done, {total_written} item(s) so far"+ )),+ );}Err(error) => break Err(error),}diff --git a/src/openhuman/memory/sources/status.rs b/src/openhuman/memory/sources/status.rsindex 63dd5f3091..2b0e5a294b 100644--- a/src/openhuman/memory/sources/status.rs+++ b/src/openhuman/memory/sources/status.rs@@ -203,6 +203,9 @@ pub(crate) fn source_id_prefix(source: &MemorySourceEntry) -> String {pub async fn status_list(config: &Config) -> Result<Vec<SourceStatus>, String> {let sources = super::registry::list_sources().await?;if sources.is_empty() {+ // Nothing to ask about, so nothing would touch the in-flight map;+ // sweep it here so a source removed mid-run leaves it eventually.+ crate::openhuman::memory::sync_activity::prune_stale();return Ok(Vec::new());}diff --git a/src/openhuman/memory/sync_activity.rs b/src/openhuman/memory/sync_activity.rsindex 881c9554de..31df5b7352 100644--- a/src/openhuman/memory/sync_activity.rs+++ b/src/openhuman/memory/sync_activity.rs@@ -36,12 +36,16 @@ pub struct LiveSync {pub updated_at_ms: i64,}-/// An entry older than this without a terminal stage is no run at all.+/// An entry silent for longer than this without a terminal stage is no run+/// at all.////// The bus delivers locally over a broadcast channel that drops under lag, so-/// a `completed` can go missing; a connector run is bounded well inside this-/// by its pass cap and per-call deadline. Without a ceiling a lost terminal-/// stage would pin a "running" bar to the row for the life of the process.+/// a `completed` can go missing, and without a ceiling that lost stage would+/// pin a "running" bar to the row for the life of the process. A live run is+/// never silent this long: the connector loop publishes a stage after every+/// pass, and one pass is bounded by the slow call's fifteen-minute deadline+/// (`modules::connectors::call_slow`), so the ceiling measures silence, not+/// the run.const STALE_AFTER_MS: i64 = 30 * 60 * 1_000;static LIVE: OnceLock<Mutex<HashMap<String, LiveSync>>> = OnceLock::new();@@ -65,8 +69,26 @@ pub(crate) fn note_stage(source_id: &str, stage: &str, detail: Option<&str>) {note_stage_at(source_id, stage, detail, now_ms());}+/// Drop every entry that has gone silent past the ceiling.+///+/// `live_sync_at` already answers `None` for a stale entry; this is what keeps+/// the map from holding it — and its strings — for the rest of the process. A+/// source removed mid-run is never asked about again, so its entry would+/// otherwise never leave.+fn prune_stale_at(map: &mut HashMap<String, LiveSync>, now_ms: i64) {+ map.retain(|_, entry| now_ms.saturating_sub(entry.updated_at_ms) <= STALE_AFTER_MS);+}++/// Sweep stale entries now. The status list calls it on a batch with no+/// sources, the one shape that would otherwise never touch the map.+pub fn prune_stale() {+ let mut map = live().lock().unwrap_or_else(PoisonError::into_inner);+ prune_stale_at(&mut map, now_ms());+}+fn note_stage_at(source_id: &str, stage: &str, detail: Option<&str>, at_ms: i64) {let mut map = live().lock().unwrap_or_else(PoisonError::into_inner);+ prune_stale_at(&mut map, at_ms);if is_terminal(stage) {map.remove(source_id);} else {@@ -87,10 +109,9 @@ pub fn live_sync(source_id: &str) -> Option<LiveSync> {}fn live_sync_at(source_id: &str, now_ms: i64) -> Option<LiveSync> {- let map = live().lock().unwrap_or_else(PoisonError::into_inner);- map.get(source_id)- .filter(|entry| now_ms.saturating_sub(entry.updated_at_ms) <= STALE_AFTER_MS)- .cloned()+ let mut map = live().lock().unwrap_or_else(PoisonError::into_inner);+ prune_stale_at(&mut map, now_ms);+ map.get(source_id).cloned()}/// Subscribe the tracker to the bus, once. Registered beside the sync-stagediff --git a/src/openhuman/memory/sync_activity_tests.rs b/src/openhuman/memory/sync_activity_tests.rsindex 3430b30c41..4e587ce3ca 100644--- a/src/openhuman/memory/sync_activity_tests.rs+++ b/src/openhuman/memory/sync_activity_tests.rs@@ -73,6 +73,28 @@ fn a_run_with_no_terminal_stage_goes_stale_after_the_ceiling() {);}+/// A stale entry leaves the map on the next touch of any kind — a read for+/// another source, a stage for another source, or the explicit sweep — so a+/// source removed mid-run does not keep its entry for the life of the process.+#[test]+fn stale_entries_are_pruned_on_the_next_touch() {+ let has = |id: &str| live().lock().unwrap().contains_key(id);++ note_stage_at("src-prune-a", "running", None, 1_000);+ assert!(has("src-prune-a"));+ let _ = live_sync_at("src-prune-other", 1_000 + STALE_AFTER_MS + 1);+ assert!(!has("src-prune-a"), "a read for another source sweeps it");++ note_stage_at("src-prune-b", "running", None, 5_000);+ note_stage_at("src-prune-c", "running", None, 5_000 + STALE_AFTER_MS + 1);+ assert!(!has("src-prune-b"), "a stage for another source sweeps it");+ assert!(has("src-prune-c"));++ note_stage_at("src-prune-d", "running", None, 0);+ prune_stale();+ assert!(!has("src-prune-d"), "the explicit sweep drops an old entry");+}+#[test]fn the_latest_stage_wins() {note_stage_at("src-latest", "requested", None, 10);