Skip to content

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

fix(memory): honest degraded state for a module that fails to load

Shanu1a40de4ad9ee
diff --git a/src/openhuman/memory/tree/health/user_error.rs b/src/openhuman/memory/tree/health/user_error.rs
index dea1db96d1..2923dd315d 100644
--- a/src/openhuman/memory/tree/health/user_error.rs
+++ b/src/openhuman/memory/tree/health/user_error.rs
@@ -69,6 +69,45 @@ pub(crate) fn store_corrupt_quarantined_user_error() -> WebChannelEvent {
/// and `SQLITE_NOTADB` (code 26) and survive every flattening the wire
/// applies. Mirrors the typed classifier inside `tinymemory-core` — the
/// module side classifies before the error is stringified; this is the
+/// Host-owned `error_type` for "the memory module failed to load".
+///
+/// Host-owned (not a `tinymemory_api::host` constant) because the engine can
+/// never emit it: a module that failed to load has no code running to report
+/// anything. Only the host's loader observes this state, so the constant lives
+/// with the only producer.
+pub(crate) const MEMORY_MODULE_UNAVAILABLE_KIND: &str = "memory_module_unavailable";
+
+/// The metadata-only `user_error` payload for a memory module that failed to
+/// load. Same no-leak contract as its siblings: a stable kind plus the source,
+/// never the loader's raw reason (which can carry URLs and filesystem paths).
+pub(crate) fn memory_module_unavailable_user_error() -> WebChannelEvent {
+ WebChannelEvent {
+ event: "user_error".to_string(),
+ client_id: "system".to_string(),
+ error_type: Some(MEMORY_MODULE_UNAVAILABLE_KIND.to_string()),
+ error_source: Some(MEMORY_USER_ERROR_SOURCE.to_string()),
+ ..Default::default()
+ }
+}
+
+/// Broadcast the module-unavailable user error once per process.
+///
+/// Once-guarded like [`notice_corrupt_store_once`]: the loader caches a load
+/// failure as terminal, so every subsequent memory call re-observes the same
+/// state, and a per-call broadcast would be a banner storm. `reason` is the
+/// loader's raw message — logged for the operator, never sent.
+pub(crate) fn notice_memory_module_unavailable_once(reason: &str) {
+ static ONCE: std::sync::Once = std::sync::Once::new();
+ ONCE.call_once(|| {
+ log::error!(
+ "[memory::host] action=broadcast_user_error kind={MEMORY_MODULE_UNAVAILABLE_KIND} source={MEMORY_USER_ERROR_SOURCE} reason={reason}"
+ );
+ crate::openhuman::web_chat::publish_web_channel_event(
+ memory_module_unavailable_user_error(),
+ );
+ });
+}
+
/// host-side fallback for paths that only ever see text.
pub(crate) fn is_corrupt_store_error(message: &str) -> bool {
let msg = message.to_ascii_lowercase();
diff --git a/src/openhuman/memory/tree/health/user_error_tests.rs b/src/openhuman/memory/tree/health/user_error_tests.rs
index 46b3a724d3..53081f2548 100644
--- a/src/openhuman/memory/tree/health/user_error_tests.rs
+++ b/src/openhuman/memory/tree/health/user_error_tests.rs
@@ -98,3 +98,27 @@ fn wire_notice_is_latched_once_per_process() {
notice_corrupt_store_once("test detector");
notice_corrupt_store_once("test detector");
}
+
+// ── memory module unavailable ────────────────────────────────────────────────
+
+/// Same no-leak contract as the corrupt-store payload: stable kind + source,
+/// and none of the loader's raw text (which carries release URLs and paths).
+#[test]
+fn module_unavailable_payload_is_metadata_only() {
+ let event = super::memory_module_unavailable_user_error();
+ assert_eq!(event.event, "user_error");
+ assert_eq!(event.client_id, "system");
+ assert_eq!(
+ event.error_type.as_deref(),
+ Some(super::MEMORY_MODULE_UNAVAILABLE_KIND)
+ );
+ assert_eq!(
+ event.error_source.as_deref(),
+ Some(tinymemory_api::host::MEMORY_USER_ERROR_SOURCE)
+ );
+ let wire = serde_json::to_string(&event).expect("payload serializes");
+ assert!(
+ !wire.contains("github") && !wire.contains("http") && !wire.contains('/'),
+ "no loader detail may reach the wire: {wire}"
+ );
+}
diff --git a/src/openhuman/modules/memory_part_01.rs b/src/openhuman/modules/memory_part_01.rs
index a4a1a34c03..8559362107 100644
--- a/src/openhuman/modules/memory_part_01.rs
+++ b/src/openhuman/modules/memory_part_01.rs
@@ -336,9 +336,22 @@ impl ModuleMemoryProvider {
// is admitted. Host callbacks must therefore exist before loading,
// including in tests and explicit-path overrides where no boot policy
// was available when the shared module runtime first started.
- ops::ensure_loaded(config, MODULE_ID)
- .await
- .map_err(|message| MemoryError::Other(anyhow::anyhow!(message)))?;
+ // A load failure is terminal for the process (the loader caches it),
+ // so every memory member would otherwise return the loader's raw
+ // message — release URLs, digest text, "restart the app" repeated per
+ // call. Map it once into the subsystem's honest degraded state: a
+ // user_error broadcast (once per process, metadata only) plus a
+ // stable, actionable error for the caller. The raw reason goes to the
+ // log, where an operator can act on it.
+ ops::ensure_loaded(config, MODULE_ID).await.map_err(|message| {
+ crate::openhuman::memory::tree::health::user_error::notice_memory_module_unavailable_once(
+ &message,
+ );
+ MemoryError::Backend(
+ "memory is unavailable: the memory module failed to load. Restart the app to retry; the reason is in the log."
+ .to_string(),
+ )
+ })?;
let record = registry::find(MODULE_ID)
.ok_or_else(|| MemoryError::Other(anyhow::anyhow!("unknown module '{MODULE_ID}'")))?;
diff --git a/tests/fixtures/memory_golden/README.md b/tests/fixtures/memory_golden/README.md
index f982adfb0e..32ee7ccd3d 100644
--- a/tests/fixtures/memory_golden/README.md
+++ b/tests/fixtures/memory_golden/README.md
@@ -5,8 +5,8 @@
| | |
| --- | --- |
-| Captured at commit | `c6e95c061b00234377eca647823ff7c2b3955e14` |
-| Captured on | 2026-08-31T07:09:48Z |
+| Captured at commit | `6996fa6bae2b35d81f2d3203a2a9f875dce34eda` |
+| Captured on | 2026-09-01T07:35:46Z |
| Generator | `regenerate_golden_fixture` in `tests/memory_golden_fixture_e2e.rs` |
| Seeder | `openhuman_core::openhuman::memory::store::golden::seed` |
diff --git a/tests/fixtures/memory_golden/workspace/memory/memory.db b/tests/fixtures/memory_golden/workspace/memory/memory.db
index b2a93f73e5..3ec9203f8f 100644
Binary files a/tests/fixtures/memory_golden/workspace/memory/memory.db and b/tests/fixtures/memory_golden/workspace/memory/memory.db differ
diff --git a/tests/fixtures/memory_golden/workspace/memory_tree/chunks.db b/tests/fixtures/memory_golden/workspace/memory_tree/chunks.db
index 931936e7b6..e9e09ff752 100644
Binary files a/tests/fixtures/memory_golden/workspace/memory_tree/chunks.db and b/tests/fixtures/memory_golden/workspace/memory_tree/chunks.db differ