Skip to content

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

fix(memory): start organizing from the core when the import finishes

M3gA-Mindebcd88559a26
diff --git a/app/src/components/memory/MemoryImportBanner.test.tsx b/app/src/components/memory/MemoryImportBanner.test.tsx
index bd39b6badc..edf686fd22 100644
--- a/app/src/components/memory/MemoryImportBanner.test.tsx
+++ b/app/src/components/memory/MemoryImportBanner.test.tsx
@@ -192,16 +192,6 @@ describe('MemoryImportBanner', () => {
expect(await screen.findByTestId('memory-import-error')).toHaveTextContent('sign in again');
});
- it('organizes on its own once the import is done, in the same banner', async () => {
- hoisted.status.mockResolvedValue({ state: { phase: 'done', imported: 9, total: 9 } });
- hoisted.mScan.mockResolvedValue({ needed: true, shared: false });
- renderWithProviders(<MemoryImportBanner engineLabel="TinyHumans" />);
- await waitFor(() => expect(hoisted.mStart).toHaveBeenCalledWith(false));
- expect(await screen.findByTestId('memory-migration-running')).toHaveTextContent('4');
- expect(screen.queryByTestId('memory-import-done')).not.toBeInTheDocument();
- expect(screen.queryByTestId('memory-migration-start')).not.toBeInTheDocument();
- });
-
it('does not organize while the import is still running', async () => {
hoisted.status.mockResolvedValue({ state: { phase: 'running', imported: 1, total: 9 } });
hoisted.mScan.mockResolvedValue({ needed: true, shared: false });
diff --git a/app/src/components/memory/MemoryImportBanner.tsx b/app/src/components/memory/MemoryImportBanner.tsx
index 89c72d4f38..b82c636a63 100644
--- a/app/src/components/memory/MemoryImportBanner.tsx
+++ b/app/src/components/memory/MemoryImportBanner.tsx
@@ -5,8 +5,8 @@
* Step 1: when `memory_import_scan` finds old local memory, offer to upload
* it. Nothing leaves the device without the consent dialog's confirmation,
* the only caller of `memory_import_start({consent: true})`.
- * Step 2: once the import is done, the move starts on its own (the core
- * refuses it while an import is unfinished). With no import, it is offered
+ * Step 2: the core starts the move itself once the import is done (and
+ * refuses it while an import is unfinished); this banner shows its progress. With no import, it is offered
* ("Migrate now") or runs in the background while free. A legacy tree other
* accounts may share (self-hosted) is only taken after the takeover dialog.
*
@@ -209,16 +209,7 @@ export default function MemoryImportBanner({ engineLabel }: MemoryImportBannerPr
}
};
- // The import finished: organize next, without asking again. Once per mount,
- // so a start the core declines does not loop. A shared tree still asks.
const importDone = state?.phase === 'done';
- const autoStarted = useRef(false);
- useEffect(() => {
- if (!importDone || !moveOffered || moving || mScan?.shared || autoStarted.current) return;
- autoStarted.current = true;
- mlog('import done; organizing next');
- void startMove(false);
- }, [importDone, moveOffered, moving, mScan?.shared, startMove]);
const mState = mStatus?.state;
const left = (mState?.failures?.length ?? 0) + (mState?.incomplete?.length ?? 0);
diff --git a/crates/openhuman-core/src/memory/import.rs b/crates/openhuman-core/src/memory/import.rs
index 6cc8318961..60721f3a77 100644
--- a/crates/openhuman-core/src/memory/import.rs
+++ b/crates/openhuman-core/src/memory/import.rs
@@ -510,12 +510,24 @@ async fn start_with(
write_file(&workspace_dir, &file);
let state = file.state.clone();
tracing::info!(total = state.total, "[memory:import] import started");
+ let config = config.clone();
tokio::spawn(async move {
run(&workspace_dir, &bound, file, paused).await;
RUNNING
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.remove(&workspace_dir);
+ // Import first, then organize: the move starts here, on whatever
+ // screen the user is, once the import is done.
+ if read_file(&workspace_dir).state.phase == ImportPhase::Done {
+ let started = super::layout_migration::start(
+ config,
+ Arc::new(super::layout_migration::AppHost),
+ super::layout_migration::Trigger::Manual { takeover: false },
+ Arc::new(scheduler_paused),
+ );
+ tracing::info!(started, "[memory:import] import done; organizing next");
+ }
});
Ok(state)
}
diff --git a/crates/openhuman-core/src/memory/layout_migration/service_tests.rs b/crates/openhuman-core/src/memory/layout_migration/service_tests.rs
index 653dc55053..fa4bfaafec 100644
--- a/crates/openhuman-core/src/memory/layout_migration/service_tests.rs
+++ b/crates/openhuman-core/src/memory/layout_migration/service_tests.rs
@@ -82,15 +82,26 @@ async fn nothing_starts_while_an_import_is_unfinished() {
let tmp = tempfile::tempdir().unwrap();
let config = crate::memory::test_fixtures::config_in(&tmp);
let host = Arc::new(FakeHost::with(3).await);
- let path = config.workspace_dir.join("memory").join("import_state.json");
+ let path = config
+ .workspace_dir
+ .join("memory")
+ .join("import_state.json");
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
- std::fs::write(&path, r#"{"state":{"phase":"running","total":3,"imported":1}}"#).unwrap();
+ std::fs::write(
+ &path,
+ r#"{"state":{"phase":"running","total":3,"imported":1}}"#,
+ )
+ .unwrap();
assert!(crate::memory::import::in_progress(&config));
assert!(!start(config.clone(), host.clone(), Trigger::Auto, never()));
assert!(!tick(&config, host.clone(), never()));
assert_eq!(count(host.tree.as_ref()).await, 0);
- std::fs::write(&path, r#"{"state":{"phase":"done","total":3,"imported":3}}"#).unwrap();
+ std::fs::write(
+ &path,
+ r#"{"state":{"phase":"done","total":3,"imported":3}}"#,
+ )
+ .unwrap();
assert!(start(config.clone(), host.clone(), Trigger::Auto, never()));
settle(&config).await;
assert_eq!(count(host.tree.as_ref()).await, 3);