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
Recheck in the same run, not on a later tick
M3gA-Mindacc7876a5562
diff --git a/crates/openhuman-core/src/memory/layout_migration/job.rs b/crates/openhuman-core/src/memory/layout_migration/job.rsindex 1e61e57008..a5e5b2e648 100644--- a/crates/openhuman-core/src/memory/layout_migration/job.rs+++ b/crates/openhuman-core/src/memory/layout_migration/job.rs@@ -115,6 +115,12 @@ pub trait LayoutHost: Send + Sync {/// batch not confirmed listed.const MAX_RECHECKS: u32 = 3;+/// How long a recheck lets the listing catch up before copying again.+#[cfg(not(test))]+const RECHECK_DELAY: std::time::Duration = std::time::Duration::from_secs(45);+#[cfg(test)]+const RECHECK_DELAY: std::time::Duration = std::time::Duration::from_millis(300);+/// Runs (or resumes) the migration of `config`'s account. `paused` is the/// scheduler's own pause (background work held), asked before every page.///@@ -197,25 +203,45 @@ where).await?;// An import that ended with its last batch not confirmed listed may hold- // items no copy saw yet: copy again on a later tick (at least once, then- // while a pass still moves something new, at most MAX_RECHECKS times)- // before finishing. A late item is never erased meanwhile (`cleanup`).- if state.phase == Phase::Cleaned && crate::memory::import::listed_unconfirmed(dir) {+ // items no copy saw yet: in this same run, wait for the listing to catch+ // up, then copy, verify and clean up again; at least once, then while a+ // pass still moves something new, at most MAX_RECHECKS times. A late item+ // is never erased meanwhile (`cleanup`). Each recheck is saved before its+ // wait, so a stop or a restart resumes it.+ while state.phase == Phase::Cleaned && crate::memory::import::listed_unconfirmed(dir) {let new = state.copied > state.replayed;- if (state.rechecks == 0 || new) && state.rechecks < MAX_RECHECKS {- state.rechecks += 1;- state.caught_up = false;- state.cleaning = false;- state.cursor = None;- state.phase = Phase::Copied;- state::save(dir, &state)?;- tracing::info!(- rechecks = state.rechecks,- "[memory:layout_migration] import not confirmed listed; copying again"- );+ if !((state.rechecks == 0 || new) && state.rechecks < MAX_RECHECKS) {+ crate::memory::import::clear_listed_unconfirmed(dir);+ break;+ }+ state.rechecks += 1;+ state.caught_up = false;+ state.cleaning = false;+ state.cursor = None;+ // Parked as paused, not copied: a scan must not offer a fresh move.+ state.phase = Phase::Paused;+ state.error = Some("copying again for items the import may list late".to_string());+ state::save(dir, &state)?;+ tracing::info!(+ rechecks = state.rechecks,+ "[memory:layout_migration] import not confirmed listed; copying again"+ );+ tokio::time::sleep(RECHECK_DELAY).await;+ copy(dir, &engines, &placement, &mut state, stop).await?;+ if state.phase != Phase::Copied {return Ok(Outcome::Paused);}- crate::memory::import::clear_listed_unconfirmed(dir);+ state.caught_up = true;+ state::save(dir, &state)?;+ cleanup(+ dir,+ &engines,+ &placement,+ shared.is_some(),+ &mut state,+ stop,+ )+ .await?;}Ok(if state.phase == Phase::Cleaned {Outcome::Donediff --git a/crates/openhuman-core/src/memory/layout_migration/job_tests.rs b/crates/openhuman-core/src/memory/layout_migration/job_tests.rsindex adfea62095..879e32d995 100644--- a/crates/openhuman-core/src/memory/layout_migration/job_tests.rs+++ b/crates/openhuman-core/src/memory/layout_migration/job_tests.rs@@ -153,9 +153,9 @@ async fn a_tree_another_account_took_is_left_alone() {}/// After an import that ended with its last batch not confirmed listed, an-/// item the listing shows only after the first pass is still moved: the run-/// copies again on later ticks instead of finishing, and finishes (clearing-/// the flag) once a pass moves nothing new.+/// item the listing shows only after the first pass is still moved, in the+/// same run: it copies again after a short wait instead of finishing, and+/// finishes (clearing the flag) once a pass moves nothing new.#[tokio::test]async fn after_an_unconfirmed_import_an_item_listed_late_is_still_moved() {let tmp = tempfile::tempdir().unwrap();@@ -171,24 +171,26 @@ async fn after_an_unconfirmed_import_an_item_listed_late_is_still_moved() {&config.workspace_dir));let host = FakeHost::with(3).await;- let manual = Trigger::Manual { takeover: false };- assert_eq!(- go(&config, &host, manual).await,- Outcome::Paused,- "an unconfirmed import is copied again, not finished"+ // The item is accepted by the import but listed only once the first+ // pass is over: stored while the run waits before its first recheck.+ let late = async {+ let deadline = std::time::Instant::now() + std::time::Duration::from_secs(10);+ while state::load(&config.workspace_dir).unwrap().rechecks == 0 {+ if std::time::Instant::now() > deadline {+ return false;+ }+ tokio::time::sleep(std::time::Duration::from_millis(2)).await;+ }+ host.legacy.store(fact("listed late")).await.unwrap();+ true+ };+ let (outcome, stored_late) = tokio::join!(+ go(&config, &host, Trigger::Manual { takeover: false }),+ late);- assert_eq!(count(host.tree.as_ref()).await, 3);- // Accepted by the import, listed only now.- host.legacy.store(fact("listed late")).await.unwrap();- let mut outcome = Outcome::Paused;- for _ in 0..5 {- outcome = go(&config, &host, manual).await;- if outcome == Outcome::Done {- break;- }- }+ assert!(stored_late, "the run waited to copy again");assert_eq!(outcome, Outcome::Done);assert_eq!(count(host.tree.as_ref()).await,@@ -199,4 +201,9 @@ async fn after_an_unconfirmed_import_an_item_listed_late_is_still_moved() {assert!(!crate::memory::import::listed_unconfirmed(&config.workspace_dir));+ assert_eq!(+ state::load(&config.workspace_dir).unwrap().rechecks,+ 2,+ "one forced recheck that moved the late item, one that moved nothing"+ );}