Skip to content

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

Retry failed queue work through the driver, not the engine's queue\n\nTwo files leave the direct-reference ratchet with this — the first to leave it\nat all. `config/ops/model.rs` and `inference/embeddings/rpc.rs` now name\n`tinymemory_core` nowhere.\n\nBoth called `requeue_failed_after_provider_change`, which is\n`store::requeue_failed` plus a wake. The tree RPC's "retry failed" control\ncalled that same pair by hand. `Maintenance::retry_failed` is the pair, as one\noperation, because a caller that requeues and forgets the wake leaves rows on\n`ready` until the next scheduled window — which, to whoever pressed the button,\nis indistinguishable from a retry that did nothing.\n\nThe host keeps the gate in front of it. Only an embedder change un-parks\nanything; an unrelated model or memory-window save leaves terminally-failed\njobs parked rather than restarting them into the same external failure. That\nrule is the host's, so it stays here, and the two tests that pin it now pin it\ndirectly: they record whether the driver was asked, and read the count out of\nthe outcome line, instead of counting rows in `mem_tree_jobs`. Whether the ask\nmoves a row is the driver's, and the driver's suite has a real queue to prove\nit against.\n\n`FixedDiagnostics` grew the counters those tests read. Its `retry_failed` also\nreports a caller-chosen number, because "requeued 0" and "requeued 1" are\ndifferent answers to the user and a double that always said zero could not tell\nthem apart.\n\n`backfill_in_progress` deliberately stays a direct engine call, with the reason\nat the call site. It is a process-global, and the module serves one store per\nmemory subtree in a single process, so a second subtree's backfill would answer\n`true` for this one. Review upstream caught that when it was briefly a\n`QueueStats` field: a global behind a per-store API is harder to notice than a\nglobal that looks like one. Scoping it belongs in the engine.\n

Shanuf48c5f3ba7ac
diff --git a/src/openhuman/config/ops/model.rs b/src/openhuman/config/ops/model.rs
index 5ba45e79c5..41089503cf 100644
--- a/src/openhuman/config/ops/model.rs
+++ b/src/openhuman/config/ops/model.rs
@@ -265,7 +265,7 @@ pub async fn apply_model_settings(
// would read identically to "nothing was parked" and hide that the parked
// jobs are still stuck. Surface the error in the outcome line instead.
let requeued_note = if embedder_changed {
- match tinymemory_core::queue::requeue_failed_after_provider_change(config) {
+ match crate::openhuman::memory::ops::maintenance::retry_failed(config).await {
Ok(n) => n.to_string(),
Err(e) => format!("error ({e})"),
}
@@ -360,7 +360,7 @@ pub async fn apply_memory_settings(
// #5324: same as the model-settings path — keep the save successful but
// report an un-park failure instead of a misleading `requeued_failed=0`.
let requeued_note = if embedder_changed {
- match tinymemory_core::queue::requeue_failed_after_provider_change(config) {
+ match crate::openhuman::memory::ops::maintenance::retry_failed(config).await {
Ok(n) => n.to_string(),
Err(e) => format!("error ({e})"),
}
diff --git a/src/openhuman/config/ops_tests.rs b/src/openhuman/config/ops_tests.rs
index f244710367..03b487d2e2 100644
--- a/src/openhuman/config/ops_tests.rs
+++ b/src/openhuman/config/ops_tests.rs
@@ -473,29 +473,18 @@ async fn apply_model_settings_updates_fields_and_persists_snapshot() {
/// through this shared path must leave terminally-`failed` embedding jobs
/// parked, not restart them into the same external failure. Switching the
/// embeddings provider is what un-parks them.
+///
+/// The gate is the host's rule, so that is what this pins: whether the driver
+/// is asked at all, and what the outcome line reports. Whether the ask then
+/// moves a row from `failed` to `ready` is the driver's, and is pinned in the
+/// driver's own conformance suite against a real queue.
#[tokio::test]
async fn apply_model_settings_requeues_failed_jobs_only_on_embedder_change() {
- use crate::openhuman::memory::tree::health::{FailureCode, PipelineFailure};
- use tinymemory_core::queue::store;
- use tinymemory_core::queue::types::{FlushStalePayload, JobStatus, NewJob};
-
let tmp = tempdir().unwrap();
let mut cfg = tmp_config(&tmp);
+ let driver = crate::openhuman::memory::binding::install_retrying_driver_for_test(&cfg, 1);
- // Park a job exactly the way an exhausted managed budget does.
- let new_job = NewJob::flush_stale(&FlushStalePayload::default(), "2026-08-05", 3).unwrap();
- let id = store::enqueue(&cfg, &new_job).unwrap().expect("enqueue");
- let job = store::get_job(&cfg, &id).unwrap().expect("job exists");
- store::mark_failed_typed(
- &cfg,
- &job,
- "Insufficient budget",
- Some(&PipelineFailure::new(FailureCode::BudgetExhausted)),
- )
- .unwrap();
- assert_eq!(store::count_by_status(&cfg, JobStatus::Failed).unwrap(), 1);
-
- // Unrelated save (temperature only) — the job must stay parked.
+ // Unrelated save (temperature only) — the driver must not be asked.
let unrelated = ModelSettingsPatch {
default_temperature: Some(0.5),
..Default::default()
@@ -504,9 +493,9 @@ async fn apply_model_settings_requeues_failed_jobs_only_on_embedder_change() {
.await
.expect("apply");
assert_eq!(
- store::count_by_status(&cfg, JobStatus::Failed).unwrap(),
- 1,
- "an unrelated model save must not un-park failed embedding jobs"
+ driver.retry_calls(),
+ 0,
+ "an unrelated model save must not ask the driver to un-park anything"
);
assert!(
outcome.logs.iter().any(|m| m.contains("requeued_failed=0")),
@@ -515,21 +504,20 @@ async fn apply_model_settings_requeues_failed_jobs_only_on_embedder_change() {
);
// Now change the embeddings provider — this is the remediation, so the
- // parked job must be flipped back to `ready`.
+ // driver is asked and its count is reported.
let switch = ModelSettingsPatch {
embeddings_provider: Some("ollama:bge-m3".into()),
..Default::default()
};
let outcome = apply_model_settings(&mut cfg, switch).await.expect("apply");
assert_eq!(
- store::count_by_status(&cfg, JobStatus::Ready).unwrap(),
+ driver.retry_calls(),
1,
- "switching the embeddings provider must un-park the failed job"
+ "switching the embeddings provider must ask the driver to un-park"
);
- assert_eq!(store::count_by_status(&cfg, JobStatus::Failed).unwrap(), 0);
assert!(
outcome.logs.iter().any(|m| m.contains("requeued_failed=1")),
- "messages: {:?}",
+ "the driver's count reaches the outcome line: {:?}",
outcome.logs
);
}
@@ -540,25 +528,11 @@ async fn apply_model_settings_requeues_failed_jobs_only_on_embedder_change() {
/// the embedding provider un-parks them.
#[tokio::test]
async fn apply_memory_settings_requeues_failed_jobs_only_on_embedder_change() {
- use crate::openhuman::memory::tree::health::{FailureCode, PipelineFailure};
- use tinymemory_core::queue::store;
- use tinymemory_core::queue::types::{FlushStalePayload, JobStatus, NewJob};
-
let tmp = tempdir().unwrap();
let mut cfg = tmp_config(&tmp);
+ let driver = crate::openhuman::memory::binding::install_retrying_driver_for_test(&cfg, 1);
- let new_job = NewJob::flush_stale(&FlushStalePayload::default(), "2026-08-05", 3).unwrap();
- let id = store::enqueue(&cfg, &new_job).unwrap().expect("enqueue");
- let job = store::get_job(&cfg, &id).unwrap().expect("job exists");
- store::mark_failed_typed(
- &cfg,
- &job,
- "Insufficient budget",
- Some(&PipelineFailure::new(FailureCode::BudgetExhausted)),
- )
- .unwrap();
-
- // Unrelated save (memory window preset only) — job stays parked.
+ // Unrelated save (memory window preset only) — the driver is not asked.
let unrelated = MemorySettingsPatch {
memory_window: Some("balanced".into()),
..Default::default()
@@ -567,13 +541,13 @@ async fn apply_memory_settings_requeues_failed_jobs_only_on_embedder_change() {
.await
.expect("apply");
assert_eq!(
- store::count_by_status(&cfg, JobStatus::Failed).unwrap(),
- 1,
- "a memory-window save must not un-park failed embedding jobs"
+ driver.retry_calls(),
+ 0,
+ "a memory-window save must not ask the driver to un-park anything"
);
assert!(outcome.logs.iter().any(|m| m.contains("requeued_failed=0")));
- // Change the embedding provider — un-parks.
+ // Change the embedding provider — the driver is asked.
let switch = MemorySettingsPatch {
embedding_provider: Some("ollama".into()),
..Default::default()
@@ -582,11 +556,10 @@ async fn apply_memory_settings_requeues_failed_jobs_only_on_embedder_change() {
.await
.expect("apply");
assert_eq!(
- store::count_by_status(&cfg, JobStatus::Ready).unwrap(),
+ driver.retry_calls(),
1,
- "switching the embedding provider must un-park the failed job"
+ "switching the embedding provider must ask the driver to un-park"
);
- assert_eq!(store::count_by_status(&cfg, JobStatus::Failed).unwrap(), 0);
assert!(outcome.logs.iter().any(|m| m.contains("requeued_failed=1")));
}
diff --git a/src/openhuman/inference/embeddings/rpc.rs b/src/openhuman/inference/embeddings/rpc.rs
index 01e203b935..2a0a8a102c 100644
--- a/src/openhuman/inference/embeddings/rpc.rs
+++ b/src/openhuman/inference/embeddings/rpc.rs
@@ -400,7 +400,7 @@ pub async fn update_settings(
// fail the RPC, but it must be surfaced (not reported as `0`) so a queue
// that stayed parked isn't presented as remediated.
let requeue_result = if is_embedding_remediation {
- tinymemory_core::queue::requeue_failed_after_provider_change(&config)
+ crate::openhuman::memory::ops::maintenance::retry_failed(&config).await
} else {
Ok(0)
};
@@ -464,7 +464,7 @@ pub async fn set_api_key(
// separately discovers the "Retry failed" button. A store failure is
// surfaced (not reported as `0`) so the key-stored response can't imply the
// parked queue was recovered when it wasn't.
- let requeue_result = tinymemory_core::queue::requeue_failed_after_provider_change(config);
+ let requeue_result = crate::openhuman::memory::ops::maintenance::retry_failed(config).await;
let requeued_count = *requeue_result.as_ref().unwrap_or(&0);
let requeue_error = requeue_result.as_ref().err().cloned();
let requeued_note = match &requeue_error {
diff --git a/src/openhuman/memory/binding.rs b/src/openhuman/memory/binding.rs
index bbaac311ae..8a66bc2c33 100644
--- a/src/openhuman/memory/binding.rs
+++ b/src/openhuman/memory/binding.rs
@@ -476,6 +476,14 @@ pub fn for_workspace(
#[cfg(test)]
pub(crate) struct FixedDiagnostics {
inner: NullMemoryProvider,
+ /// How many times the host has asked this driver to retry failed work,
+ /// and how many jobs it should say it requeued when asked.
+ ///
+ /// The gate in front of the ask is host logic — only an embedder change
+ /// should un-park anything — so a test needs to see whether the ask
+ /// happened, separately from what the driver would have done.
+ retry_calls: std::sync::atomic::AtomicUsize,
+ retry_requeues: u64,
/// How many times the host has asked this driver to re-embed.
///
/// `reembed` enqueues work rather than doing it, so the host's side of that
@@ -512,10 +520,23 @@ mod fixed_diagnostics_impl {
store,
queue,
failure: None,
+ retry_calls: std::sync::atomic::AtomicUsize::new(0),
+ retry_requeues: 0,
reembed_calls: std::sync::atomic::AtomicUsize::new(0),
}
}
+ /// Report `requeued` jobs from [`MemoryMaintenance::retry_failed`].
+ pub(crate) fn requeueing(mut self, requeued: u64) -> Self {
+ self.retry_requeues = requeued;
+ self
+ }
+
+ /// How many times [`MemoryMaintenance::retry_failed`] has been called.
+ pub(crate) fn retry_calls(&self) -> usize {
+ self.retry_calls.load(std::sync::atomic::Ordering::SeqCst)
+ }
+
/// How many times [`MemoryMaintenance::reembed`] has been called.
pub(crate) fn reembed_calls(&self) -> usize {
self.reembed_calls.load(std::sync::atomic::Ordering::SeqCst)
@@ -597,6 +618,17 @@ mod fixed_diagnostics_impl {
#[async_trait]
impl MemoryMaintenance for FixedDiagnostics {
+ async fn retry_failed(&self) -> Result<MaintenanceReport, MemoryError> {
+ self.retry_calls
+ .fetch_add(1, std::sync::atomic::Ordering::SeqCst);
+ Ok(MaintenanceReport {
+ operation: "retry_failed".to_string(),
+ examined: self.retry_requeues,
+ changed: self.retry_requeues,
+ findings: Vec::new(),
+ })
+ }
+
async fn reembed(&self) -> Result<MaintenanceReport, MemoryError> {
self.reembed_calls
.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
@@ -671,6 +703,24 @@ pub(crate) fn install_diagnostics_for_test(
driver
}
+/// Bind a driver that reports `requeued` from `retry_failed` and counts the
+/// asks, for tests about *when* the host asks rather than what a queue does.
+#[cfg(test)]
+pub(crate) fn install_retrying_driver_for_test(
+ config: &crate::openhuman::config::Config,
+ requeued: u64,
+) -> Arc<FixedDiagnostics> {
+ let driver = Arc::new(
+ FixedDiagnostics::new(Default::default(), Default::default()).requeueing(requeued),
+ );
+ install_for_test(
+ &config.workspace_dir,
+ &config.subsystems.memory,
+ Arc::clone(&driver) as Arc<dyn MemoryProvider>,
+ );
+ driver
+}
+
/// Install `provider` as the binding a workspace resolves to.
///
/// The cache below is normally filled by [`build`], which binds the compiled
diff --git a/src/openhuman/memory/direct_engine_refs_tests.rs b/src/openhuman/memory/direct_engine_refs_tests.rs
index 2492bb11c2..02d2ccdcc0 100644
--- a/src/openhuman/memory/direct_engine_refs_tests.rs
+++ b/src/openhuman/memory/direct_engine_refs_tests.rs
@@ -111,9 +111,11 @@
//! a caller can depend on it and compile almost nothing. Only
//! `util::redact` (136 lines over `sha2`) is the clean case, and it costs
//! `sha2` in the contract crate.
-//! - **The re-embed queue** (~8 files) — `queue::{start, store, types,
-//! requeue_failed_after_provider_change, drain_until_idle, wake_workers,
-//! backfill_in_progress}`. No family.
+//! - **The re-embed queue** (~4 files) — `queue::{start, types,
+//! drain_until_idle}`, plus a bare `wake_workers` after a tree reset. What
+//! is left is queue *lifecycle* rather than queue operations: starting the
+//! worker belongs with driver construction, and the reset nudge is not
+//! paired with a requeue the way the retry path was.
//!
//! `ensure_reembed_backfill` is off this list, and how it left is the part
//! worth keeping: it needed no upstream work at all. `Maintenance::reembed`
@@ -392,11 +394,6 @@ const ALLOWED: &[(&str, Verdict, &str)] = &[
Verdict::NeedsWiderSeam,
"holds or boots the in-process engine handle (store); driver construction belongs to memory::binding and the seam has no door onto the live client",
),
- (
- "src/openhuman/config/ops/model.rs",
- Verdict::NeedsWiderSeam,
- "queue::requeue_failed_after_provider_change has no capability family; the enqueue half moved onto Maintenance::reembed, which already was this call",
- ),
(
"src/openhuman/cron/scheduler.rs",
Verdict::NeedsWiderSeam,
@@ -427,11 +424,6 @@ const ALLOWED: &[(&str, Verdict, &str)] = &[
Verdict::NeedsWiderSeam,
"engine-internal ingest pipeline entry (ingest_pipeline::ingest_document_with_scope); the ingest family covers documents and chat, not the scope-carrying pipeline variants",
),
- (
- "src/openhuman/inference/embeddings/rpc.rs",
- Verdict::NeedsWiderSeam,
- "queue::requeue_failed_after_provider_change has no capability family; the enqueue half moved onto Maintenance::reembed, which already was this call",
- ),
(
"src/openhuman/integrations/composio/ops/memory_cleanup.rs",
Verdict::NeedsWiderSeam,
@@ -585,7 +577,7 @@ const ALLOWED: &[(&str, Verdict, &str)] = &[
(
"src/openhuman/memory/tree/tree/rpc.rs",
Verdict::NeedsWiderSeam,
- "the re-embed queue (queue::store::requeue_failed, queue::backfill_in_progress, queue::wake_workers, ingest_pipeline) has no capability family, and chunk reads still need MemoryChunks widened (list_chunks/get_chunk); its queue and chunk *diagnostics* have moved onto Maintenance::{store_stats, queue_stats, latest_queue_failure} and no longer open a connection here",
+ "the ingest pipeline (ingest_pipeline, tinycortex canonicalize) has no capability family, chunk reads still need MemoryChunks widened (list_chunks/get_chunk), and queue::backfill_in_progress is a process-global the engine cannot yet scope per store; diagnostics moved onto Maintenance::{store_stats, queue_stats, latest_queue_failure} and retry onto Maintenance::retry_failed",
),
(
"src/openhuman/platform/doctor/core.rs",
diff --git a/src/openhuman/memory/ops/maintenance.rs b/src/openhuman/memory/ops/maintenance.rs
index b67c2bd4e9..dedf9bc3b7 100644
--- a/src/openhuman/memory/ops/maintenance.rs
+++ b/src/openhuman/memory/ops/maintenance.rs
@@ -54,6 +54,42 @@ pub async fn reembed(config: &Config) -> Result<u64, String> {
Ok(report.changed)
}
+/// Ask the bound driver to give terminally-failed queue work another attempt.
+///
+/// Answers how many jobs were requeued. The driver wakes whatever drains the
+/// queue as part of the same operation, so there is no second call to forget:
+/// jobs flipped back to `ready` that then wait for the next scheduled window
+/// look, to the user who pressed the button, exactly like a retry that did
+/// nothing.
+///
+/// A driver that does not serve `Maintenance` reports `0`, which is what it
+/// requeued.
+///
+/// # Errors
+///
+/// Whatever the driver reports.
+pub async fn retry_failed(config: &Config) -> Result<u64, String> {
+ let binding = binding::for_config(config)?;
+ let Some(maintenance) = binding.provider().as_maintenance() else {
+ log::debug!(
+ "[memory::maintenance] retry_failed: driver '{}' does not serve Maintenance; nothing requeued",
+ binding.driver_id()
+ );
+ return Ok(0);
+ };
+ let report = maintenance
+ .retry_failed()
+ .await
+ .map_err(|error| format!("retry_failed: {error}"))?;
+ log::debug!(
+ "[memory::maintenance] retry_failed: driver '{}' examined={} requeued={}",
+ binding.driver_id(),
+ report.examined,
+ report.changed
+ );
+ Ok(report.changed)
+}
+
/// Log-and-continue wrapper for the call sites that have nothing to report the
/// count to.
///