Skip to content

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

Finish the import when its last batch is slow to be listed

M3gA-Mind32272f3da98a
diff --git a/crates/openhuman-core/src/memory/import.rs b/crates/openhuman-core/src/memory/import.rs
index 8425c2d0e7..bffcd4848e 100644
--- a/crates/openhuman-core/src/memory/import.rs
+++ b/crates/openhuman-core/src/memory/import.rs
@@ -654,13 +654,18 @@ async fn run(
let _ = reader.await;
// Every batch was stored accepted. Before the import says it is done
// (and organizing reads it back), wait once for the last batch to be
- // listed: storing it again visible is a replay that returns when it is.
+ // listed: storing it again visible is a replay that returns when it is,
+ // retried like any batch. The wait is best-effort: every item is already
+ // accepted, and organizing checks each one it copies, so a listing still
+ // behind (or rate limited) finishes the import rather than leaving it to
+ // resume into the same wait again.
if failure.is_none() && !pausing && !last.is_empty() {
let settled = store_batch(bound, last, WaitFor::Visible).await;
if let Some(error) = settled.fatal {
- failure = Some(error);
- transient = settled.transient;
- credits = settled.credits;
+ tracing::warn!(
+ %error,
+ "[memory:import] the last batch is not listed yet; finishing the import anyway"
+ );
}
}
if pausing {
diff --git a/crates/openhuman-core/src/memory/import_tests.rs b/crates/openhuman-core/src/memory/import_tests.rs
index ccced67bae..b5a5d120de 100644
--- a/crates/openhuman-core/src/memory/import_tests.rs
+++ b/crates/openhuman-core/src/memory/import_tests.rs
@@ -713,6 +713,8 @@ async fn an_automatic_resume_that_cannot_start_is_stopped_not_retried() {
struct WaitRecordingEngine {
inner: tinymemory_api::conformance::ReferenceEngine,
waits: std::sync::Mutex<Vec<tinymemory_api::WaitFor>>,
+ /// A visible bulk store times out, as on a listing that lags.
+ never_listed: bool,
}
#[async_trait::async_trait]
@@ -747,6 +749,11 @@ impl tinymemory_api::MemoryEngine for WaitRecordingEngine {
options: tinymemory_api::WriteOptions,
) -> tinymemory_api::Result<Vec<tinymemory_api::StoreReceipt>> {
self.waits.lock().unwrap().push(options.wait);
+ if self.never_listed && options.wait == tinymemory_api::WaitFor::Visible {
+ return Err(tinymemory_api::Error::Unavailable(
+ "accepted but did not become readable within 30s".into(),
+ ));
+ }
self.inner.store_many(items).await
}
async fn forget(
@@ -789,3 +796,33 @@ async fn batches_are_stored_accepted_and_the_last_waited_for_once() {
"one accepted batch, then the visible wait for it"
);
}
+
+/// The end-of-import wait is best-effort: a listing that never catches up
+/// (every visible store times out) still ends the import `Done`, instead of
+/// leaving it to resume into the same wait for ever.
+#[tokio::test]
+async fn a_last_batch_never_listed_still_finishes_the_import() {
+ let tmp = tempfile::tempdir().unwrap();
+ let config = config_in(&tmp);
+ legacy_workspace(&config.workspace_dir);
+ let engine = Arc::new(WaitRecordingEngine {
+ never_listed: true,
+ ..WaitRecordingEngine::default()
+ });
+ crate::memory::engine::install_test_engine(&config.workspace_dir, engine.clone());
+
+ start(&config, true).await.unwrap();
+ let done = wait_until_settled(&config).await;
+ assert_eq!(done.phase, ImportPhase::Done, "{done:?}");
+ assert_eq!(done.imported, 5);
+ assert!(done.error.is_none(), "{done:?}");
+ let waits = engine.waits.lock().unwrap().clone();
+ assert_eq!(waits[0], tinymemory_api::WaitFor::Accepted, "{waits:?}");
+ assert!(
+ waits[1..]
+ .iter()
+ .all(|wait| *wait == tinymemory_api::WaitFor::Visible)
+ && waits.len() > 2,
+ "the final wait was retried, then given up: {waits:?}"
+ );
+}
diff --git a/docs/TEST-COVERAGE-MATRIX.md b/docs/TEST-COVERAGE-MATRIX.md
index b1e23a8b86..789d969e3a 100644
--- a/docs/TEST-COVERAGE-MATRIX.md
+++ b/docs/TEST-COVERAGE-MATRIX.md
@@ -368,7 +368,7 @@ Spec: `docs/specs/memory-v2.md` (host) and `vendor/tinymemory/docs/specs/memory-
| 8.2.5 | Document sources: add, sync, list, remove | RU+RI+WD | `crates/openhuman-core/src/memory/sources/sync_tests.rs`, `crates/openhuman-core/src/memory/sources/composio_tests.rs`, `crates/openhuman-core/src/memory/sources/mod_tests.rs`, `tests/memory_v2_e2e.rs` (`sources_add_sync_list_and_remove`), `app/test/playwright/specs/memory-v2.spec.ts` | ✅ | folder, file, link, github, rss, composio |
| 8.2.6 | Folder-source path picker | RU+VU | `crates/openhuman-app/src/directory_picker.rs`, `app/src/utils/tauriCommands/directoryPicker.test.ts` | ✅ | |
| 8.2.7 | Pack preview (Ask tab) and brain views | RU+RI+WD | `crates/openhuman-core/src/memory/lifecycle/views_tests.rs`, `crates/openhuman-core/src/memory/brain_tests.rs`, `tests/memory_v2_e2e.rs`, `app/test/playwright/specs/memory-v2.spec.ts` | ✅ | No `context.md`; pack never persisted in the transcript |
-| 8.2.8 | One-time import of previous (v1) memory | RU+RI+WD | `crates/openhuman-core/src/memory/import_tests.rs`, `tests/memory_v2_e2e.rs`, `app/test/playwright/specs/memory-v2.spec.ts` (`importing previous memory needs explicit consent`, `a stopped import resumes only after consent`), `app/src/components/memory/MemoryImportBanner.test.tsx` | ✅ | Refused without consent; stops (not skips) on exhausted credits (`exhausted_credits_stop_the_import_instead_of_skipping_everything`) and resumes on its own only while memory work is free, per `billing::free_period_active` (`an_import_out_of_credits_resumes_only_once_automatic_runs_are_allowed`); batches are stored accepted and the last waited for once before Done (`batches_are_stored_accepted_and_the_last_waited_for_once`); an unavailable engine is retried in-run (`a_transient_failure_is_retried_within_the_run`) and then resumed by the background job (`an_engine_that_stays_unavailable_is_resumed_by_the_background_job`); refused items are kept and retried (`a_refused_item_is_kept_and_a_retry_stores_it`); state written atomically and a resume keeps its total (`the_import_state_is_written_whole_and_leaves_no_staging_file`, `a_resumed_import_keeps_its_total_instead_of_rescanning`); the background job resumes an import the app quit during (`the_background_job_resumes_an_interrupted_import`), never while paused, including a pause mid-run (`nothing_resumes_while_background_work_is_paused`, `a_pause_that_lands_after_the_check_stops_the_run_at_the_next_batch`); a resume that cannot start is stopped, not retried (`an_automatic_resume_that_cannot_start_is_stopped_not_retried`); Resume button after an error, behind consent (`a stopped import resumes only after consent`) |
+| 8.2.8 | One-time import of previous (v1) memory | RU+RI+WD | `crates/openhuman-core/src/memory/import_tests.rs`, `tests/memory_v2_e2e.rs`, `app/test/playwright/specs/memory-v2.spec.ts` (`importing previous memory needs explicit consent`, `a stopped import resumes only after consent`), `app/src/components/memory/MemoryImportBanner.test.tsx` | ✅ | Refused without consent; stops (not skips) on exhausted credits (`exhausted_credits_stop_the_import_instead_of_skipping_everything`) and resumes on its own only while memory work is free, per `billing::free_period_active` (`an_import_out_of_credits_resumes_only_once_automatic_runs_are_allowed`); batches are stored accepted and the last waited for once before Done (`batches_are_stored_accepted_and_the_last_waited_for_once`), a wait that never sees the listing still finishes Done (`a_last_batch_never_listed_still_finishes_the_import`); an unavailable engine is retried in-run (`a_transient_failure_is_retried_within_the_run`) and then resumed by the background job (`an_engine_that_stays_unavailable_is_resumed_by_the_background_job`); refused items are kept and retried (`a_refused_item_is_kept_and_a_retry_stores_it`); state written atomically and a resume keeps its total (`the_import_state_is_written_whole_and_leaves_no_staging_file`, `a_resumed_import_keeps_its_total_instead_of_rescanning`); the background job resumes an import the app quit during (`the_background_job_resumes_an_interrupted_import`), never while paused, including a pause mid-run (`nothing_resumes_while_background_work_is_paused`, `a_pause_that_lands_after_the_check_stops_the_run_at_the_next_batch`); a resume that cannot start is stopped, not retried (`an_automatic_resume_that_cannot_start_is_stopped_not_retried`); Resume button after an error, behind consent (`a stopped import resumes only after consent`) |
| 8.2.9 | MCP memory tools | RU | `crates/openhuman-core/src/mcp/server/tools/` | ✅ | `memory.recall`, `memory.fetch`, `memory.list`, `memory.learn`, `memory.forget` |
| 8.2.10 | Memory UI chips and legacy redirects | VU+WD | `app/src/components/memory/*.test.tsx`, `app/test/playwright/specs/memory-v2.spec.ts` | ✅ | Engine, Ask, Explorer, Learnings, Conversations, Brain, Background, Settings; `/brain` and `/settings/memory-engine` redirect |
| 8.2.11 | Move into the per-user layout (v3) | RU+VU+WD | `crates/openhuman-core/src/memory/layout_migration/*_tests.rs`, `app/src/components/memory/MemoryImportBanner.test.tsx`, `app/test/playwright/specs/memory-v2.spec.ts` (`migrate now moves the legacy memory and the banner goes away`, `a tree other accounts may share is taken only after consent`) | ✅ | Items are stored again and verified, never copied as events; no switch before a full copy, then a catch-up copy; a source is removed only after its twin is verified (`an_item_without_its_twin_is_never_removed`), by kind-scope erasure or by id where the engine cannot erase; resumable after a pause or crash; runs on its own only while moving is free; a shared self-hosted tree moves only with consent and only one account may claim it (`a_tree_another_account_took_is_left_alone`, `the_first_account_takes_the_tree_and_keeps_it`); items are placed in the v3 layout before the setting switches (`places_into_the_v3_layout_before_the_switch`); signed out there is nothing to move; never starts while an import of old local memory is unfinished, counting a reserved import before its first state write (`nothing_starts_while_an_import_is_unfinished`, `an_import_counts_as_in_progress_from_its_reservation`), and starts on its own once the import is done, free period or not (`a_finished_import_starts_organizing_into_the_per_user_tree`); one banner shows import then organize (`does not organize while the import is still running`) |