Skip to content

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

feat(memory): read the backfill flag from the driver, not the host's static\n\nCodex's P2 on this PR, and the other half of the objection tinymemory#86\nanswered. That PR briefly carried `backfill_in_progress` as a `QueueStats`\nfield and dropped it, correctly: it is a process-global while `open_store`\nserves one store per memory subtree, so a per-store snapshot carrying it\npromised a scope it does not have.\n\nLeaving the host reading the global is not the answer either. Re-embedding\nruns in the module now, and a `cdylib` has its own statics, so the\nhost-linked copy reads `false` forever on that path — the frontend poll then\ncloses the re-embed modal during exactly the gap the flag exists to cover.\n\ntinymemory#89 resolves both with a standalone `Maintenance` member whose\nsignature states the process-wide scope. This wires it: a forwarder in\n`modules/memory.rs`, a `backfill_in_progress` helper beside `queue_stats`,\nand `backfill_status_rpc` reading the driver. A read failure degrades to the\ncounts rather than failing a polled RPC.\n\n`FixedDiagnostics` grows a `backfilling()` builder because the flag is not\nderivable from the counts and a test needs to set them independently. The new\ntest pins the instant the counts cannot express — nothing ready, nothing\nrunning, backfill still up — which is what the old code got wrong. The doc\nnote saying the empty case could not be asserted is gone with the global it\ndescribed.\n\nEngine pin advanced to the #89 merge. Neither lockfile moves; it adds no\ndependencies.\n\n

Shanu6037468b7da9
diff --git a/src/openhuman/memory/binding.rs b/src/openhuman/memory/binding.rs
index 8a66bc2c33..ceb736953c 100644
--- a/src/openhuman/memory/binding.rs
+++ b/src/openhuman/memory/binding.rs
@@ -493,6 +493,13 @@ pub(crate) struct FixedDiagnostics {
store: crate::openhuman::memory::api::provider::types::StoreStats,
queue: crate::openhuman::memory::api::provider::types::QueueStats,
failure: Option<crate::openhuman::memory::api::provider::types::QueueFailure>,
+ /// What this driver says about a backfill running in its process.
+ ///
+ /// Separate from [`Self::queue`] on purpose, mirroring the contract: the
+ /// flag is not derivable from the counts, and a test that needs the gap
+ /// between them — nothing ready, nothing running, backfill unfinished —
+ /// has to set the two independently.
+ backfill: bool,
}
#[cfg(test)]
@@ -520,6 +527,7 @@ mod fixed_diagnostics_impl {
store,
queue,
failure: None,
+ backfill: false,
retry_calls: std::sync::atomic::AtomicUsize::new(0),
retry_requeues: 0,
reembed_calls: std::sync::atomic::AtomicUsize::new(0),
@@ -532,6 +540,12 @@ mod fixed_diagnostics_impl {
self
}
+ /// Report a backfill running in this driver's process.
+ pub(crate) fn backfilling(mut self) -> Self {
+ self.backfill = true;
+ 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)
@@ -658,6 +672,10 @@ mod fixed_diagnostics_impl {
async fn latest_queue_failure(&self) -> Result<Option<QueueFailure>, MemoryError> {
Ok(self.failure.clone())
}
+
+ async fn backfill_in_progress(&self) -> Result<bool, MemoryError> {
+ Ok(self.backfill)
+ }
}
#[async_trait]
diff --git a/src/openhuman/memory/direct_engine_refs_tests.rs b/src/openhuman/memory/direct_engine_refs_tests.rs
index 81f11a5259..eac7becafe 100644
--- a/src/openhuman/memory/direct_engine_refs_tests.rs
+++ b/src/openhuman/memory/direct_engine_refs_tests.rs
@@ -591,7 +591,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, ingest_pipeline) has no capability family",
+ "ingest_pipeline and the chunk store's list/read helpers have no capability family; the queue reads left for the Maintenance members in tinymemory#85/#86/#89",
),
(
"src/openhuman/platform/doctor/core.rs",
diff --git a/src/openhuman/memory/tree/tree/rpc.rs b/src/openhuman/memory/tree/tree/rpc.rs
index 42ec35151f..2d52e4af2f 100644
--- a/src/openhuman/memory/tree/tree/rpc.rs
+++ b/src/openhuman/memory/tree/tree/rpc.rs
@@ -311,6 +311,31 @@ async fn queue_stats(
.map_err(|e| format!("queue_stats: {e}"))
}
+/// Whether the driver has a re-embed backfill chain running.
+///
+/// Scoped to the driver's process, not to this store — the contract member says
+/// so in its own signature, which is why it is a member rather than a field on
+/// [`queue_stats`]. A driver serving several stores answers the same for all of
+/// them.
+///
+/// A driver without Maintenance reports `false` rather than erroring, matching
+/// its siblings: "this driver runs no backfill" is true of it, not a fault the
+/// caller can act on.
+async fn backfill_in_progress(config: &Config) -> Result<bool, String> {
+ let binding = crate::openhuman::memory::binding::for_config(config)?;
+ let Some(maintenance) = binding.provider().as_maintenance() else {
+ log::debug!(
+ "[memory-tree][rpc] backfill_in_progress: driver '{}' does not serve Maintenance; reporting false",
+ binding.driver_id()
+ );
+ return Ok(false);
+ };
+ maintenance
+ .backfill_in_progress()
+ .await
+ .map_err(|e| format!("backfill_in_progress: {e}"))
+}
+
/// Response from the `memory_backfill_status` RPC (#1574 §4b). The frontend
/// polls this while the re-embed modal is open to surface progress and to
/// dismiss the modal once the new embedding space is fully covered.
@@ -346,13 +371,21 @@ pub async fn backfill_status_rpc(
// Ready + running, not `total - done`: a failed backfill job is finished
// with, and counting it as pending leaves the modal open forever.
let pending_jobs: u64 = queue.ready + queue.running;
- // Still the engine's process-global. It covers the instant between one
- // backfill link settling and the next being enqueued, which the counts
- // cannot see — but it is scoped to the process, not to this store, and a
- // second memory subtree running its own backfill would answer `true` here.
- // Putting it on `QueueStats` would have made a per-store API promise that
- // scoping; it stays a visibly global call until the engine can scope it.
- let in_progress = tinymemory_core::queue::backfill_in_progress() || pending_jobs > 0;
+ // Asked of the driver, not of the host-linked engine's process-global. That
+ // static covers the instant between one backfill link settling and the next
+ // being enqueued, which the counts cannot see — but re-embedding runs in the
+ // module now, and a `cdylib` has its own statics, so the host-side copy reads
+ // `false` forever and the modal closes while work is still being prepared.
+ //
+ // The member is process-wide rather than store-scoped, and says so in its
+ // signature; that is why it is not a `QueueStats` field, where a per-store
+ // snapshot would have implied a scoping it does not have. A read failure
+ // degrades to the counts rather than failing the polled RPC.
+ let driver_backfilling = backfill_in_progress(config).await.unwrap_or_else(|e| {
+ log::warn!("[memory::rpc] backfill_status: backfill_in_progress read failed: {e}");
+ false
+ });
+ let in_progress = driver_backfilling || pending_jobs > 0;
Ok(RpcOutcome::single_log(
BackfillStatusResponse {
in_progress,
@@ -1428,8 +1461,9 @@ mod tests {
/// queued for the backfill kind, and a non-zero count forces
/// `in_progress` so the modal stays open.
///
- /// `in_progress` for the empty case is intentionally not asserted — the
- /// underlying flag is a process-global shared across parallel tests.
+ /// The empty case now asserts `in_progress` too. It could not before: the
+ /// flag was a process-global that parallel tests shared. It comes from the
+ /// bound driver now, so it is this test's to set.
///
/// Ready + running, and deliberately not `total - done`: a backfill job
/// that failed is finished with, and counting it as pending would leave
@@ -1464,6 +1498,47 @@ mod tests {
assert!(s1.in_progress, "pending>0 forces in_progress=true");
}
+ /// The backfill flag is the driver's answer, not the host's engine static.
+ ///
+ /// This is the gap the counts cannot express: a backfill chain re-enqueues
+ /// itself, so between one link settling and the next being written there is
+ /// an instant with nothing ready, nothing running, and the work unfinished.
+ /// A poll that trusted the counts alone closes the re-embed modal there.
+ ///
+ /// It has to come from the driver rather than
+ /// `tinymemory_core::queue::backfill_in_progress()`, because re-embedding
+ /// runs in the module and a `cdylib` has its own statics — the host-linked
+ /// copy reads `false` forever on that path, which is worse than coarse.
+ #[tokio::test]
+ async fn backfill_status_reports_the_drivers_flag_when_the_counts_are_empty() {
+ use crate::openhuman::memory::api::provider::types::QueueStats;
+
+ let (_tmp, cfg) = test_config();
+
+ let driver = std::sync::Arc::new(
+ crate::openhuman::memory::binding::FixedDiagnostics::new(
+ Default::default(),
+ QueueStats::default(),
+ )
+ .backfilling(),
+ );
+ crate::openhuman::memory::binding::install_for_test(
+ &cfg.workspace_dir,
+ &cfg.subsystems.memory,
+ driver as std::sync::Arc<dyn crate::openhuman::memory::api::provider::MemoryProvider>,
+ );
+
+ let status = backfill_status_rpc(&cfg).await.unwrap().value;
+ assert_eq!(
+ status.pending_jobs, 0,
+ "precondition: the counts say the queue is empty"
+ );
+ assert!(
+ status.in_progress,
+ "and the driver still says a backfill is running, which is the whole point"
+ );
+ }
+
// ── pipeline_status / set_enabled (#1856 Part 1) ─────────────────────
/// `derive_pipeline_status` precedence is locked in here so the UI can
diff --git a/src/openhuman/modules/memory.rs b/src/openhuman/modules/memory.rs
index 5660f4ae99..9c5a854992 100644
--- a/src/openhuman/modules/memory.rs
+++ b/src/openhuman/modules/memory.rs
@@ -981,6 +981,9 @@ impl MemoryMaintenance for ModuleMemoryProvider {
async fn latest_queue_failure(&self) -> Result<Option<QueueFailure>, MemoryError> {
module_call!(self, "latest_queue_failure", "LatestQueueFailure", ())
}
+ async fn backfill_in_progress(&self) -> Result<bool, MemoryError> {
+ module_call!(self, "backfill_in_progress", "BackfillInProgress", ())
+ }
}
#[cfg(test)]
diff --git a/vendor/tinymemory b/vendor/tinymemory
index 3802f6caef..81dba6dfaa 160000
--- a/vendor/tinymemory
+++ b/vendor/tinymemory
@@ -1 +1 @@
-Subproject commit 3802f6caef5b4b77aec38bbc039c0df31c51cb50
+Subproject commit 81dba6dfaa009a6061c923843374dd3e96c92a4d