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): honor the scheduler pause and stop a resume that cannot start
Ghost Scriptera9b47c2b8fee
diff --git a/app/test/playwright/specs/memory-v2.spec.ts b/app/test/playwright/specs/memory-v2.spec.tsindex 7cac9c8ed8..ebb1024679 100644--- a/app/test/playwright/specs/memory-v2.spec.ts+++ b/app/test/playwright/specs/memory-v2.spec.ts@@ -58,6 +58,8 @@ interface FakeOptions {engineOn: boolean;/** `memory_import_scan` finds v1 data to import. */importFound?: boolean;+ /** An earlier import stopped with this error (e.g. credits ran out) after 7 of 20 items. */+ importStoppedWith?: string;}interface RpcCall {@@ -95,7 +97,9 @@ async function installMemoryFake(page: Page, opts: FakeOptions): Promise<MemoryF];const sources: Array<Record<string, unknown>> = [];let nextId = 1;- let importState = { phase: 'idle', imported: 0, total: 0, error: null as string | null };+ let importState = opts.importStoppedWith+ ? { phase: 'error', imported: 7, total: 20, error: opts.importStoppedWith as string | null }+ : { phase: 'idle', imported: 0, total: 0, error: null as string | null };const policy = {log_conversations: true,@@ -263,7 +267,8 @@ async function installMemoryFake(page: Page, opts: FakeOptions): Promise<MemoryF? { found: true, counts: { documents: 12, conversations: 3, learnings: 5 } }: { found: false, counts: null };case 'memory_import_start':- importState = { phase: 'running', imported: 0, total: 20, error: null };+ // A restart resumes from the persisted progress.+ importState = { phase: 'running', imported: importState.imported, total: 20, error: null };return { state: importState };case 'memory_import_status': {const current = importState;@@ -433,6 +438,41 @@ test.describe('Memory v2 — engine active', () => {await expect(page.getByTestId('memory-import-done')).toBeVisible({ timeout: 15_000 });});+ test('a stopped import resumes only after consent', async ({ page }) => {+ const stopped =+ 'not enough credits to import your memory; top up, then resume the import to continue where it stopped';+ const fake = await installMemoryFake(page, {+ engineOn: true,+ importFound: true,+ importStoppedWith: stopped,+ });+ await bootAuthenticatedPage(page, 'pw-memory-v2-import-resume');+ await openMemory(page, '&brain=ask');++ // The stopped import shows its reason and a Resume control, not the fresh offer.+ const failed = page.getByTestId('memory-import-error');+ await expect(failed).toBeVisible({ timeout: 20_000 });+ await expect(failed).toContainText('not enough credits');+ await expect(page.getByTestId('memory-import-open')).toHaveCount(0);++ // Resume asks again; nothing restarts until the user confirms.+ await page.getByTestId('memory-import-resume').click();+ const consent = page.getByTestId('memory-import-consent');+ await expect(consent).toBeVisible();+ expect(fake.paramsOf('memory_import_start')).toEqual([]);++ await page.getByTestId('memory-import-confirm').click();+ await expect(consent).toBeHidden();+ expect(fake.paramsOf('memory_import_start')).toEqual([{ consent: true }]);++ // It picks up from the stored progress and finishes.+ await expect(+ page.getByTestId('memory-import-running').or(page.getByTestId('memory-import-done'))+ ).toBeVisible();+ await expect(page.getByTestId('memory-import-done')).toBeVisible({ timeout: 15_000 });+ await expect(page.getByTestId('memory-import-resume')).toHaveCount(0);+ });+test('legacy Brain and settings links land on their v2 chips', async ({ page }) => {await installMemoryFake(page, { engineOn: true });await bootAuthenticatedPage(page, 'pw-memory-v2-legacy');diff --git a/crates/openhuman-core/src/memory/import.rs b/crates/openhuman-core/src/memory/import.rsindex 28dc66f649..76a72d172b 100644--- a/crates/openhuman-core/src/memory/import.rs+++ b/crates/openhuman-core/src/memory/import.rs@@ -224,15 +224,30 @@ pub fn status(config: &Config) -> ImportState {state}-/// Resumes an import the app quit in the middle of, if there is one.+/// Resumes an import the app quit in the middle of, if there is one, under+/// the scheduler's current policy ([`resume_interrupted_with`]). Called from+/// memory's background job.+pub async fn resume_interrupted(config: &Config) -> bool {+ resume_interrupted_with(config, crate::cron::scheduler_gate::current_policy()).await+}++/// Resumes an interrupted import under `policy`.////// Only a `Running` state with no live run counts: the user consented when-/// it started, and quitting the app is not a decision to stop. An import that-/// stopped on an error (credits exhausted, signed out) stays stopped until the-/// user starts it again, so a failure that would recur does not loop. Returns-/// whether a run was started. Called from memory's background job.-pub async fn resume_interrupted(config: &Config) -> bool {- if read_file(&config.workspace_dir).state.phase != ImportPhase::Running {+/// it started, and quitting the app is not a decision to stop. Nothing+/// resumes while background work is paused (which includes being signed+/// out); the state stays `Running`, so a later tick resumes it. An import+/// that stopped on an error (credits exhausted, engine unreachable) stays+/// stopped until the user starts it again, and so does one whose automatic+/// resume could not start: that failure is persisted as `Error`, so a+/// failure that would recur does not loop. Returns whether a run was+/// started.+pub(crate) async fn resume_interrupted_with(+ config: &Config,+ policy: crate::cron::scheduler_gate::Policy,+) -> bool {+ let mut file = read_file(&config.workspace_dir);+ if file.state.phase != ImportPhase::Running {return false;}let live = RUNNING@@ -242,6 +257,13 @@ pub async fn resume_interrupted(config: &Config) -> bool {if live {return false;}+ if let crate::cron::scheduler_gate::Policy::Paused { reason } = policy {+ tracing::debug!(+ ?reason,+ "[memory:import] background paused; interrupted import left for later"+ );+ return false;+ }match start(config, true).await {Ok(state) => {tracing::info!(@@ -252,10 +274,13 @@ pub async fn resume_interrupted(config: &Config) -> bool {true}Err(error) => {- tracing::debug!(+ tracing::warn!(code = error.code(),- "[memory:import] interrupted import not resumed"+ "[memory:import] interrupted import could not resume; stopped");+ file.state.phase = ImportPhase::Error;+ file.state.error = Some(format!("the import could not resume: {error}"));+ write_file(&config.workspace_dir, &file);false}}diff --git a/crates/openhuman-core/src/memory/import_tests.rs b/crates/openhuman-core/src/memory/import_tests.rsindex c5d4022bf4..b730dad7ba 100644--- a/crates/openhuman-core/src/memory/import_tests.rs+++ b/crates/openhuman-core/src/memory/import_tests.rs@@ -451,3 +451,90 @@ async fn a_stopped_or_finished_import_is_not_resumed_on_its_own() {}assert!(stored(&engine, MetaFilter::default()).await.is_empty());}++/// A persisted `Running` import with no live run: what the app leaves behind+/// when it quits mid-import after storing d1.+fn quit_mid_import(config: &Config) {+ write_file(+ &config.workspace_dir,+ &ImportFile {+ state: ImportState {+ phase: ImportPhase::Running,+ imported: 1,+ total: 5,+ error: None,+ },+ checkpoint: Checkpoint {+ documents: Some("d1".into()),+ ..Checkpoint::default()+ },+ },+ );+}++#[tokio::test]+async fn the_background_job_resumes_an_interrupted_import() {+ let tmp = tempfile::tempdir().unwrap();+ let config = config_in(&tmp);+ legacy_workspace(&config.workspace_dir);+ let engine = bind_reference(&config);+ quit_mid_import(&config);++ crate::memory::bus::run_system_job(&config, crate::memory::lifecycle::jobs::BACKGROUND_JOB)+ .await;+ let done = wait_until_settled(&config).await;+ assert_eq!(done.phase, ImportPhase::Done, "{done:?}");+ assert_eq!(stored(&engine, MetaFilter::default()).await.len(), 4);+}++#[tokio::test]+async fn nothing_resumes_while_background_work_is_paused() {+ use crate::cron::scheduler_gate::{PauseReason, Policy};+ let tmp = tempfile::tempdir().unwrap();+ let config = config_in(&tmp);+ legacy_workspace(&config.workspace_dir);+ let engine = bind_reference(&config);+ quit_mid_import(&config);++ let paused = Policy::Paused {+ reason: PauseReason::UserDisabled,+ };+ assert!(!resume_interrupted_with(&config, paused).await);+ assert!(stored(&engine, MetaFilter::default()).await.is_empty());+ assert_eq!(+ read_file(&config.workspace_dir).state.phase,+ ImportPhase::Running,+ "left resumable for a later, unpaused tick"+ );++ assert!(resume_interrupted_with(&config, Policy::Normal).await);+ assert_eq!(wait_until_settled(&config).await.phase, ImportPhase::Done);+}++#[tokio::test]+async fn an_automatic_resume_that_cannot_start_is_stopped_not_retried() {+ let tmp = tempfile::tempdir().unwrap();+ let config = config_in(&tmp);+ legacy_workspace(&config.workspace_dir);+ // No engine bound: memory is off, so `start` fails before any run.+ quit_mid_import(&config);++ let policy = crate::cron::scheduler_gate::Policy::Normal;+ assert!(!resume_interrupted_with(&config, policy).await);+ let state = read_file(&config.workspace_dir).state;+ assert_eq!(state.phase, ImportPhase::Error);+ assert_eq!(state.imported, 1, "progress is kept");+ assert!(+ state.error.as_deref().unwrap().contains("could not resume"),+ "{state:?}"+ );+ // The next tick does not try again; the user resumes it.+ assert!(!resume_interrupted_with(&config, policy).await);+ assert_eq!(+ read_file(&config.workspace_dir)+ .checkpoint+ .documents+ .as_deref(),+ Some("d1")+ );+}diff --git a/docs/TEST-COVERAGE-MATRIX.md b/docs/TEST-COVERAGE-MATRIX.mdindex 051299c143..f9caed7e87 100644--- a/docs/TEST-COVERAGE-MATRIX.md+++ b/docs/TEST-COVERAGE-MATRIX.md@@ -365,7 +365,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`), `app/src/components/memory/MemoryImportBanner.test.tsx` | ✅ | Refused without consent; stops (not skips) on exhausted credits or an unreachable engine; resumes on its own after the app quits; Resume button after an error |+| 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 or an unreachable engine; resumes on its own after the app quits (unless background work is paused; a resume that cannot start is stopped, not retried); Resume button after an error || 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 |