Skip to content

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

fix(memory): re-read import state before recording a failed resume

Ghost Scripter5ae945d2e380
diff --git a/crates/openhuman-core/src/memory/import.rs b/crates/openhuman-core/src/memory/import.rs
index 76a72d172b..c0fdbc6279 100644
--- a/crates/openhuman-core/src/memory/import.rs
+++ b/crates/openhuman-core/src/memory/import.rs
@@ -246,8 +246,7 @@ 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 {
+ if read_file(&config.workspace_dir).state.phase != ImportPhase::Running {
return false;
}
let live = RUNNING
@@ -278,6 +277,10 @@ pub(crate) async fn resume_interrupted_with(
code = error.code(),
"[memory:import] interrupted import could not resume; stopped"
);
+ // Re-read so only the phase and reason change: the progress and
+ // the checkpoint stay exactly as persisted, and the user's Resume
+ // continues from there.
+ let mut file = read_file(&config.workspace_dir);
file.state.phase = ImportPhase::Error;
file.state.error = Some(format!("the import could not resume: {error}"));
write_file(&config.workspace_dir, &file);
diff --git a/crates/openhuman-core/src/memory/import_tests.rs b/crates/openhuman-core/src/memory/import_tests.rs
index b730dad7ba..930e73f08d 100644
--- a/crates/openhuman-core/src/memory/import_tests.rs
+++ b/crates/openhuman-core/src/memory/import_tests.rs
@@ -535,6 +535,19 @@ async fn an_automatic_resume_that_cannot_start_is_stopped_not_retried() {
.checkpoint
.documents
.as_deref(),
- Some("d1")
+ Some("d1"),
+ "the checkpoint read back from disk survives the failure"
+ );
+
+ // And the user's Resume continues from that checkpoint, not the start.
+ let engine = bind_reference(&config);
+ 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_eq!(
+ stored(&engine, MetaFilter::default()).await.len(),
+ 4,
+ "d1 is not re-sent"
);
}