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): keep what a failed sync wrote in its history row
Shanue0ba19cee4a8
diff --git a/crates/openhuman-core/src/memory/sources/rpc/driver_run.rs b/crates/openhuman-core/src/memory/sources/rpc/driver_run.rsindex f1d34a8928..1f5546e894 100644--- a/crates/openhuman-core/src/memory/sources/rpc/driver_run.rs+++ b/crates/openhuman-core/src/memory/sources/rpc/driver_run.rs@@ -72,6 +72,54 @@ pub(in crate::memory::sources) fn bus_stage_publisher(}}+/// A failed run as `run_recorded` reports it: the error, and what the run had+/// done before it failed.+pub(in crate::memory::sources) trait RunFailure {+ /// Why the run failed.+ fn error(&self) -> &MemoryError;++ /// What the run had done when it failed, when it did anything.+ fn done(&self) -> Option<&SyncRunOutcome> {+ None+ }+}++/// A driver's own run reports only its error.+impl RunFailure for MemoryError {+ fn error(&self) -> &MemoryError {+ self+ }+}++/// A run that failed after some of its work: a host-side sync that wrote some+/// batches before one was refused. The run still failed, and its row says how+/// much it wrote first.+#[derive(Debug)]+pub(in crate::memory::sources) struct PartialFailure {+ pub(in crate::memory::sources) error: MemoryError,+ pub(in crate::memory::sources) done: SyncRunOutcome,+}++impl RunFailure for PartialFailure {+ fn error(&self) -> &MemoryError {+ &self.error+ }++ fn done(&self) -> Option<&SyncRunOutcome> {+ Some(&self.done)+ }+}++/// A failure before any work was done.+impl From<MemoryError> for PartialFailure {+ fn from(error: MemoryError) -> Self {+ Self {+ error,+ done: SyncRunOutcome::default(),+ }+ }+}+/// Run one driver-backed sync, publishing its start and finish and recording/// it in the host's run log.///@@ -82,7 +130,11 @@ pub(in crate::memory::sources) fn bus_stage_publisher(/// The row is written before the terminal stage is published, on purpose: the/// history panel refetches when that stage arrives, and a row written after it/// would miss that read.-pub(in crate::memory::sources) async fn run_recorded<Run, Fut, Describe, Publish>(+///+/// A failed row counts what the run wrote before it failed, so a run that+/// stored two batches and then was refused does not read as having stored+/// nothing. It is still a failure.+pub(in crate::memory::sources) async fn run_recorded<Run, Fut, Failure, Describe, Publish>(config: &Config,source_id: &str,entry: Option<&MemorySourceEntry>,@@ -92,7 +144,8 @@ pub(in crate::memory::sources) async fn run_recorded<Run, Fut, Describe, Publish) -> Result<SyncRunOutcome, String>whereRun: FnOnce() -> Fut,- Fut: Future<Output = Result<SyncRunOutcome, MemoryError>>,+ Fut: Future<Output = Result<SyncRunOutcome, Failure>>,+ Failure: RunFailure,Describe: FnOnce(&MemoryError) -> String,Publish: Fn(&str, Option<String>),{@@ -142,12 +195,19 @@ where);Ok(outcome)}- Err(error) => {- let message = describe(&error);- record(None, Some(message.clone()));+ Err(failure) => {+ let mut message = describe(failure.error());+ let done = failure.done();+ if done.is_some_and(|done| done.more_pending) {+ // Nothing in the row holds "more pending", so the message says+ // it: the run had already stopped at its budget when it failed.+ message.push_str(" (the run had stopped at its budget with more items pending)");+ }+ record(done, Some(message.clone()));tracing::warn!(source_id = %source_id,error = %message,+ written_before_failure = done.map_or(0, |done| done.records_ingested),"[memory_sources:driver_run] run failed");publish("failed", Some(message.clone()));diff --git a/crates/openhuman-core/src/memory/sources/rpc/driver_run_tests.rs b/crates/openhuman-core/src/memory/sources/rpc/driver_run_tests.rsindex 5dcf2fb3a7..e6265d026a 100644--- a/crates/openhuman-core/src/memory/sources/rpc/driver_run_tests.rs+++ b/crates/openhuman-core/src/memory/sources/rpc/driver_run_tests.rs@@ -41,7 +41,7 @@ async fn a_completed_run_publishes_its_start_and_finish_and_records_a_row() {"src_notes",Some(&entry),|| async {- Ok(SyncRunOutcome {+ Ok::<_, MemoryError>(SyncRunOutcome {records_ingested: 3,..SyncRunOutcome::default()})@@ -84,7 +84,7 @@ async fn a_completed_run_that_stopped_short_says_so_in_its_detail() {"src_capped",Some(&folder("src_capped")),|| async {- Ok(SyncRunOutcome {+ Ok::<_, MemoryError>(SyncRunOutcome {records_ingested: 50,more_pending: true,note: Some("per-source item limit reached".to_string()),@@ -147,6 +147,45 @@ async fn a_failed_run_publishes_the_described_failure_and_records_it() {assert_eq!(rows[0].items_fetched, 0);}+/// A run that wrote some batches before one was refused still fails, and its+/// row counts what it wrote first rather than reading as having stored+/// nothing; a budget stop before the failure is said in the message.+#[tokio::test]+async fn a_failure_after_partial_work_records_what_was_written() {+ let dir = tempfile::tempdir().expect("tempdir");+ let config = config_in(dir.path());+ let entry = folder("src_partial");+ let stages = Stages::default();++ let message = run_recorded(+ &config,+ "src_partial",+ Some(&entry),+ || async {+ Err(PartialFailure {+ error: MemoryError::Unavailable("memory API unavailable".to_string()),+ done: SyncRunOutcome {+ records_ingested: 25,+ more_pending: true,+ ..SyncRunOutcome::default()+ },+ })+ },+ |error| format!("described: {error}"),+ publisher(&stages),+ )+ .await+ .expect_err("the run failed");++ assert!(message.starts_with("described: "), "{message}");+ assert!(message.contains("more items pending"), "{message}");+ let rows = read_runs(dir.path(), KEEP_ROWS).expect("read the run log");+ assert_eq!(rows.len(), 1);+ assert!(!rows[0].success, "a partial run is still a failure");+ assert_eq!(rows[0].items_fetched, 25);+ assert_eq!(rows[0].error.as_deref(), Some(message.as_str()));+}+/// The history panel refetches when the terminal stage arrives, so the row/// has to be on disk by then.#[tokio::test]@@ -159,7 +198,7 @@ async fn the_row_is_on_disk_before_the_terminal_stage_goes_out() {&config,"src_unknown",None,- || async { Ok(SyncRunOutcome::default()) },+ || async { Ok::<_, MemoryError>(SyncRunOutcome::default()) },|_| unreachable!("a completed run has no failure to describe"),|stage: &str, _detail: Option<String>| {if stage == "completed" {