Skip to content

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

Keep retry state current and let Retry pick up an interrupted retry

M3gA-Mind78c6ab6b88eb
diff --git a/crates/openhuman-core/src/memory/import_recovery_tests.rs b/crates/openhuman-core/src/memory/import_recovery_tests.rs
index 45b018395f..12e156c996 100644
--- a/crates/openhuman-core/src/memory/import_recovery_tests.rs
+++ b/crates/openhuman-core/src/memory/import_recovery_tests.rs
@@ -5,7 +5,7 @@
use super::tests::{
after_document, always, billing, bind_failing, legacy_workspace, out_of_credits,
- wait_until_settled,
+ wait_until_no_live_run, wait_until_settled,
};
use super::*;
use crate::memory::error::INVALID_REQUEST;
@@ -409,19 +409,32 @@ async fn a_resumed_retry_stops_when_background_work_is_paused() {
let paused: PauseCheck =
std::sync::Arc::new(move || seen.fetch_add(1, std::sync::atomic::Ordering::SeqCst) > 0);
assert!(resume_interrupted_with(&config, paused, billing(false)).await);
- for _ in 0..200 {
- if !RUNNING
- .lock()
- .unwrap_or_else(std::sync::PoisonError::into_inner)
- .contains(&config.workspace_dir)
- {
- break;
- }
- tokio::time::sleep(std::time::Duration::from_millis(10)).await;
- }
+ wait_until_no_live_run(&config).await;
let file = read_file(&config.workspace_dir);
assert_eq!(file.state.phase, ImportPhase::Running);
assert!(file.retrying);
assert_eq!(file.failed.len(), 1);
assert!(stored(&engine, MetaFilter::default()).await.is_empty());
}
+
+#[tokio::test]
+async fn retry_is_accepted_for_a_retry_the_app_quit_during() {
+ let tmp = tempfile::tempdir().unwrap();
+ let config = config_in(&tmp);
+ legacy_workspace(&config.workspace_dir);
+ let engine = bind_reference(&config);
+ quit_mid_retry(&config);
+
+ // The user presses Retry before the background job got to it.
+ retry_failed(&config).await.unwrap();
+ let done = wait_until_settled(&config).await;
+ assert_eq!(
+ (done.phase, done.failed),
+ (ImportPhase::Done, 0),
+ "{done:?}"
+ );
+ assert!(stored(&engine, MetaFilter::default())
+ .await
+ .iter()
+ .any(|item| item.text.contains("oolong")));
+}
diff --git a/crates/openhuman-core/src/memory/import_retry.rs b/crates/openhuman-core/src/memory/import_retry.rs
index 287c2ff546..1cc9fba076 100644
--- a/crates/openhuman-core/src/memory/import_retry.rs
+++ b/crates/openhuman-core/src/memory/import_retry.rs
@@ -23,7 +23,10 @@ use crate::memory::types::{ImportPhase, ImportState};
/// list; ones refused again stay, with the new reason.
pub async fn retry_failed(config: &Config) -> MemoryResult<ImportState> {
let file = read_file(&config.workspace_dir);
- if file.state.phase != ImportPhase::Done || file.failed.is_empty() {
+ // A retry the app quit during is still a retry the user may press
+ // again; a live one is answered with its status by `begin_retry`.
+ let interrupted_retry = file.state.phase == ImportPhase::Running && file.retrying;
+ if !(file.state.phase == ImportPhase::Done || interrupted_retry) || file.failed.is_empty() {
return Err(MemoryError::invalid(
"no failed items to retry: the import has not finished or skipped nothing",
));
@@ -145,6 +148,8 @@ async fn retry_run(
if let Some(failed) = file.failed.iter_mut().find(|f| f.id == id) {
*failed = again;
}
+ // Persisted as it changes, like a stored item.
+ write_file(workspace_dir, &file);
}
Err(error) => {
failure = Some(retry_stop_message(error));
diff --git a/crates/openhuman-core/src/memory/import_tests.rs b/crates/openhuman-core/src/memory/import_tests.rs
index 6037c8a6dc..cf8c82efe4 100644
--- a/crates/openhuman-core/src/memory/import_tests.rs
+++ b/crates/openhuman-core/src/memory/import_tests.rs
@@ -536,7 +536,7 @@ pub(super) fn always(paused: bool) -> PauseCheck {
}
/// Waits until no import run is live for `config`'s workspace.
-async fn wait_until_no_live_run(config: &Config) {
+pub(super) async fn wait_until_no_live_run(config: &Config) {
for _ in 0..400 {
let live = RUNNING.lock().unwrap().contains(&config.workspace_dir);
if !live {