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): name the stale module binding instead of a bare NotFound
M3gA-Mind55d8ecfb90fb
diff --git a/src/core/runtime/context.rs b/src/core/runtime/context.rsindex a0602b4382..fe2e50c3f0 100644--- a/src/core/runtime/context.rs+++ b/src/core/runtime/context.rs@@ -99,6 +99,42 @@ struct WorkspaceBinding {memory_subsystem: crate::openhuman::config::schema::MemorySubsystemConfig,}+/// Say so when the workspace is rebound after the memory module has already+/// loaded.+///+/// The module is handed its `config_path` once, when it loads, and tinybus+/// never unloads a library — there is no shutdown path and nothing a shutdown+/// could reclaim (`modules/host.rs`). So a rebind after the module is `Ready`+/// leaves it reading the *previous* profile's source registry for the rest of+/// the process: the host writes `[[memory_sources]]` into the new profile's+/// `config.toml`, and every id it registers is unknown to the driver.+///+/// This is the boot-signed-out-then-log-in case. It cannot be repaired in+/// process, so this does not try. It makes the moment the binding went stale+/// visible in the log, beside the rebind that caused it, instead of leaving a+/// bare `NotFound` on a sync minutes later as the only evidence.+///+/// Best-effort and never fatal: a build without the modules feature, or a+/// process whose memory module never loaded, has nothing stale to report.+#[cfg(feature = "modules")]+fn warn_if_memory_module_outlived_its_profile(workspace_dir: &std::path::Path) {+ use crate::openhuman::modules::types::ModuleState;+ if crate::openhuman::modules::state_of(crate::openhuman::modules::memory::MODULE_ID)+ == ModuleState::Ready+ {+ log::warn!(+ "[core-context] workspace rebound to {} while the memory module is already loaded. \+ The module keeps the source registry it was given when it loaded and cannot be \+ rebound in this process, so memory sources registered under this profile will not \+ be visible to it until the app is restarted.",+ workspace_dir.display()+ );+ }+}++#[cfg(not(feature = "modules"))]+fn warn_if_memory_module_outlived_its_profile(_workspace_dir: &std::path::Path) {}+impl CoreContext {/// Run the core initialization sequence and return the context plus whether/// an operator-supplied RPC bearer exists (for the public-bind safety check@@ -482,6 +518,7 @@ impl CoreContext {workspace_dir: Some(workspace_dir.to_path_buf()),memory_subsystem,};+ warn_if_memory_module_outlived_its_profile(workspace_dir);Ok(())}diff --git a/src/openhuman/memory/sources/rpc_part_01.rs b/src/openhuman/memory/sources/rpc_part_01.rsindex 783df76326..574c252f20 100644--- a/src/openhuman/memory/sources/rpc_part_01.rs+++ b/src/openhuman/memory/sources/rpc_part_01.rs@@ -549,6 +549,41 @@ pub(crate) fn sync_dispatch(entry: &MemorySourceEntry) -> Result<SyncDispatch, S})}+/// Turn a source-sync failure into something a reader can act on.+///+/// A `NotFound` from the driver is ambiguous: either nobody ever registered the+/// id, or the driver is reading a different registry than the host is writing.+/// The second happens because the memory module is loaded once per process and+/// tinybus never unloads a library (`modules/ops.rs`), so the `config_path` it+/// is handed at load is the one it keeps for the life of the process. Boot+/// signed out, log in, and the host starts writing `[[memory_sources]]` into+/// the new profile's `config.toml` while the module still reads the pre-login+/// one — every id the host registers is then unknown to it, permanently.+///+/// The host can tell the two apart, because at this point it holds both halves+/// of the contradiction: `host_has_source` is its own registry's answer for the+/// same id. When the host has it and the driver does not, the registries+/// disagree, and the only in-process remedy is a restart — the same remedy+/// `ops` already states for a module that failed to load.+///+/// Every other failure is returned exactly as the driver stated it; inventing a+/// diagnosis for those would send the reader down the wrong path.+fn describe_source_sync_failure(+ source_id: &str,+ host_has_source: bool,+ error: &crate::openhuman::memory::api::error::MemoryError,+) -> String {+ match error {+ crate::openhuman::memory::api::error::MemoryError::NotFound(_) if host_has_source => format!(+ "the memory module cannot see source '{source_id}', but this profile has it \+ registered. The module is bound to a different profile's source registry — it \+ reads the config it was given when it first loaded, and that binding cannot be \+ changed while the app is running. Restart the app to rebind it."+ ),+ other => other.to_string(),+ }+}+pub async fn sync_rpc(req: SyncRequest) -> Result<RpcOutcome<SyncResponse>, String> {tracing::info!(source_id = %req.source_id, "[memory_sources] sync_rpc: entry");@@ -565,7 +600,11 @@ pub async fn sync_rpc(req: SyncRequest) -> Result<RpcOutcome<SyncResponse>, Stri// that refuse a disabled entry, and this RPC is the third caller, the one// behind the user's Sync button. Same words as `sync_source` so the UI// reads one message (#5820).- if let Some(entry) = super::registry::get_source_in(&config, &req.source_id)? {+ // Kept past the `if let` because the failure path below needs the host's own+ // answer for this id: a driver `NotFound` means something different when the+ // host has the source than when it does not.+ let host_entry = super::registry::get_source_in(&config, &req.source_id)?;+ if let Some(entry) = &host_entry {if !entry.enabled {return Err(format!("source '{}' is disabled", entry.id));}@@ -575,7 +614,7 @@ pub async fn sync_rpc(req: SyncRequest) -> Result<RpcOutcome<SyncResponse>, Striif let SyncDispatch::Connector {connection_id,max_items,- } = sync_dispatch(&entry)?+ } = sync_dispatch(entry)?{crate::openhuman::integrations::composio::ops::composio_sync_budgeted(&config,@@ -606,7 +645,9 @@ pub async fn sync_rpc(req: SyncRequest) -> Result<RpcOutcome<SyncResponse>, Stri})?;sync.run_source_sync(&req.source_id).await- .map_err(|error| error.to_string())?;+ .map_err(|error| {+ describe_source_sync_failure(&req.source_id, host_entry.is_some(), &error)+ })?;Ok(RpcOutcome::new(SyncResponse {diff --git a/src/openhuman/memory/sources/rpc_tests.rs b/src/openhuman/memory/sources/rpc_tests.rsindex cf8fffcf6e..e8bc5f0367 100644--- a/src/openhuman/memory/sources/rpc_tests.rs+++ b/src/openhuman/memory/sources/rpc_tests.rs@@ -9,6 +9,7 @@use super::*;use crate::core::subsystem::DriverClass;+use crate::openhuman::memory::api::error::MemoryError;// Needed to call the family accessors on the *concrete* null provider// below; the handlers above reach them through `dyn MemoryProvider`, where// the trait is in scope by construction.@@ -311,3 +312,63 @@ async fn add_generates_an_id_and_caps_a_request_that_left_its_limits_unset() {"the request's url");}++// ── Profile-drift diagnosis on sync (#5820 follow-up) ────────────────────────+//+// The memory module is loaded once per process and tinybus never unloads a+// library, so the `config_path` it is handed at load is the one it keeps. When+// the host rebinds its workspace mid-process — boot signed out, then log in —+// the host starts writing `[[memory_sources]]` into the new profile's+// config.toml while the module is still reading the old one. Every id the host+// registers is then unknown to the driver, and the user sees a bare+// `NotFound` that reads like a missing source rather than a stale binding.+//+// The host holds both halves of that contradiction at the point of failure: its+// own registry has the id, and the driver says it does not. Saying so is the+// difference between a ten-minute diagnosis and half a day.++#[test]+fn a_not_found_for_a_source_the_host_has_registered_reports_the_stale_binding() {+ let message = describe_source_sync_failure(+ "src_8cc5c81a3a7b482b8f832a84faaa6c4e",+ true,+ &MemoryError::NotFound(+ "no memory source registered as src_8cc5c81a3a7b482b8f832a84faaa6c4e".to_string(),+ ),+ );+ assert!(+ message.contains("different profile") || message.contains("restart"),+ "a NotFound for an id the host DID register must name the stale binding and the \+ remedy, not repeat the driver's 'no memory source registered' — got: {message}"+ );+ assert!(+ message.contains("src_8cc5c81a3a7b482b8f832a84faaa6c4e"),+ "the message must still name the source id: {message}"+ );+}++#[test]+fn a_not_found_for_an_id_the_host_never_registered_is_passed_through() {+ let message = describe_source_sync_failure(+ "src_never_existed",+ false,+ &MemoryError::NotFound("no memory source registered as src_never_existed".to_string()),+ );+ assert!(+ !message.contains("different profile"),+ "an id the host does not have either is a genuinely missing source, not drift — \+ diagnosing it as a stale binding would send the reader down the wrong path: {message}"+ );+}++#[test]+fn a_non_not_found_failure_is_passed_through_unchanged() {+ let inner = MemoryError::Backend("sqlite is locked".to_string());+ let message = describe_source_sync_failure("src_1", true, &inner);+ assert_eq!(+ message,+ inner.to_string(),+ "only NotFound is ambiguous between 'missing' and 'stale binding'; every other \+ failure must reach the caller as the driver stated it"+ );+}