Skip to content

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

test(memory): put each tree-runtime case on one door; delete the chunk-store reset

Shanu4e1a7486541c
diff --git a/src/openhuman/memory/direct_engine_refs_tests.rs b/src/openhuman/memory/direct_engine_refs_tests.rs
index f525ac9455..5bfbc2fa61 100644
--- a/src/openhuman/memory/direct_engine_refs_tests.rs
+++ b/src/openhuman/memory/direct_engine_refs_tests.rs
@@ -363,7 +363,7 @@ const ALLOWED: &[(&str, Verdict, &str)] = &[
(
"src/openhuman/memory/host_impls.rs",
Verdict::HostSide,
- "installs the seven host seams (embedding, chat, config, nlp, scheduler gate, shutdown, error reporter), plus the in-process chunk-store recovery door modules/memory_host.rs calls on StoreCorruptQuarantined — only this process can drop this process's cached handle. The seams have no in-process caller left at all now that the tree_runtime glob is deleted: they are reached from the far side of the bus, where modules/memory_host.rs serves the same seven for the loaded module, and unwiring them would fail that module's summariser run with 'no ChatHost installed'. Composio had an eighth seam here until tinymemory v1.13.4 deleted ComposioHost with the rest of the in-process pipeline",
+ "installs the seven host seams (embedding, chat, config, nlp, scheduler gate, shutdown, error reporter) and now nothing else. The seams have no in-process caller left at all now that the tree_runtime glob is deleted: they are reached from the far side of the bus, where modules/memory_host.rs serves the same seven for the loaded module, and unwiring them would fail that module's summariser run with 'no ChatHost installed'. The in-process chunk-store recovery door (engine::backend::chunks::recover_corrupt_db, called from the StoreCorruptQuarantined arm) was an eighth reason until #5560 deleted it: every in-process reader it protected had already migrated — sources::status onto MemoryChunks::source_ingest_status, recall onto the binding's driver — leaving only #[cfg(test)] openers, so it was the last production call that opened the host's chunk store rather than a door onto anything. Composio had a seam here too until tinymemory v1.13.4 deleted ComposioHost with the rest of the in-process pipeline",
),
// ── Retrieval: filters the seam's tree family has no room for ───────────
// ── Agent tools: chunk reads, source listing, people, source scope ──────
diff --git a/src/openhuman/memory/host_impls.rs b/src/openhuman/memory/host_impls.rs
index ca49c7fc00..dc650906cb 100644
--- a/src/openhuman/memory/host_impls.rs
+++ b/src/openhuman/memory/host_impls.rs
@@ -67,13 +67,28 @@
//! left between this file and that module: the host owns the local-AI /
//! cloud-opt-in precedence, and the seam is how the driver asks about it.
//!
-//! [`reset_in_process_chunk_store`] is the one function here with a caller that
-//! is not a seam install. It was originally justified by `memory::sources::
-//! status` reading the engine's chunk store over raw SQLite; that handler asks
-//! `MemoryChunks::source_ingest_status` now and names no engine. What keeps it
-//! is `modules::memory_host`'s `StoreCorruptQuarantined` arm — only this
-//! process can drop **this** process's cached handle, so no contract method can
-//! stand in for it however small the in-process reader set becomes.
+//! **Everything left in this file is a seam install (#5560).** There used to be
+//! one exception, `reset_in_process_chunk_store`, and the shape of its removal
+//! is worth keeping because it is the shape the rest of this file's removal
+//! takes. It dropped this process's cached SQLite handle after the *module*
+//! quarantined and rebuilt `chunks.db`, because the host's own engine copy still
+//! pointed at the renamed inode and every in-process read kept failing with
+//! `database disk image is malformed` until restart (openhuman#5820). It was
+//! originally justified by `memory::sources::status` reading that store over raw
+//! SQLite, and later by "only this process can drop **this** process's handle" —
+//! true, and beside the point once nothing in this process opens the store.
+//!
+//! That is now the case. `sources::status` asks
+//! `MemoryChunks::source_ingest_status`; recall resolves through
+//! `memory::binding` to the same module driver; and every surviving opener of
+//! the host's chunk store is `#[cfg(test)]` — `read_rpc::with_connection`,
+//! `tree::retrieval::test_support`, `security::credentials`'s ops tests and
+//! `memory::sync_pipeline`'s. So the reset had no reader left to protect, and
+//! `recover_corrupt_db` was itself the last production call that *opened* the
+//! in-process chunk store. Deleting it removes a door rather than leaving one
+//! ajar; the user-visible notice is untouched, because it was never the reset's
+//! — `modules::memory_host`'s `into_domain_event` publishes it and returns
+//! `None`, exactly as `memory::host`'s in-process sink does.
//!
//! **The question to re-ask is not "is the driver embedded" but "does any
//! production caller still reach an engine free function".** `grep -rn
@@ -464,40 +479,6 @@ pub fn install_memory_host_seams(config: Arc<Config>) {
/// overflows the 2 MiB test-thread stack. Building it on a thread with a stack
/// of its own keeps the cost off the caller entirely, and `Once` means it
/// happens exactly one time per test binary.
-/// Drop this process's cached handle to the chunk store and reopen it.
-///
-/// The loaded TinyMemory module and this process each embed their own copy of
-/// the engine, with their own connection cache. When the *module* quarantines a
-/// corrupt `chunks.db` it renames the file and rebuilds an empty one — but this
-/// process's cached connection still points at the old inode (now the
-/// `.corrupt-<ts>` copy), so every in-process read (`sources::status`, the
-/// session builder's recall) keeps failing with `database disk image is
-/// malformed` until restart. Seen live on openhuman#5820's fix: the module
-/// recovered, the host's status rows stayed red.
-///
-/// Delegates to the engine's own recovery entry point, which takes the
-/// per-path init lock, drops the cached connection, re-runs `quick_check` on
-/// what is on disk now (the rebuilt file, so no second quarantine), and
-/// reopens. Best-effort: a failure is logged, never propagated — the module's
-/// quarantine already happened and the notice is already on its way.
-pub(crate) fn reset_in_process_chunk_store(config: &Config) {
- let engine = tinymemory_core::engine::memory_config_from(config, config.workspace_dir.clone());
- match tinymemory_core::engine::backend::chunks::recover_corrupt_db(&engine) {
- Ok(false) => log::info!(
- "[memory:host] dropped the in-process chunk-store handle and reopened the \
- rebuilt file after the module's quarantine"
- ),
- Ok(true) => log::warn!(
- "[memory:host] the in-process chunk-store reset found the file corrupt as \
- well and quarantined it"
- ),
- Err(error) => log::warn!(
- "[memory:host] could not reset the in-process chunk-store handle after the \
- module's quarantine; in-process reads may keep failing until restart: {error:#}"
- ),
- }
-}
-
#[cfg(test)]
pub(crate) fn install_for_tests() {
use std::sync::Once;
@@ -516,7 +497,3 @@ pub(crate) fn install_for_tests() {
#[cfg(test)]
#[path = "host_impls_boot_seam_tests_tests.rs"]
mod boot_seam_tests;
-
-#[cfg(test)]
-#[path = "host_impls_chunk_store_reset_tests_tests.rs"]
-mod chunk_store_reset_tests;
diff --git a/src/openhuman/memory/host_impls_chunk_store_reset_tests_tests.rs b/src/openhuman/memory/host_impls_chunk_store_reset_tests_tests.rs
deleted file mode 100644
index 2657e99a7c..0000000000
--- a/src/openhuman/memory/host_impls_chunk_store_reset_tests_tests.rs
+++ /dev/null
@@ -1,23 +0,0 @@
-use super::*;
-
-/// The reset must be safe to run against a healthy (or absent) store: it
-/// drops the cached handle and reopens without quarantining anything.
-#[test]
-fn reset_reopens_a_healthy_or_absent_store_without_quarantining() {
- let tmp = tempfile::tempdir().unwrap();
- let mut config = Config::default();
- config.workspace_dir = tmp.path().join("workspace");
- std::fs::create_dir_all(config.workspace_dir.join("memory_tree")).unwrap();
-
- reset_in_process_chunk_store(&config);
-
- let entries: Vec<String> = std::fs::read_dir(config.workspace_dir.join("memory_tree"))
- .unwrap()
- .filter_map(|e| e.ok())
- .map(|e| e.file_name().to_string_lossy().into_owned())
- .collect();
- assert!(
- !entries.iter().any(|name| name.contains(".corrupt-")),
- "a healthy or absent store must never be quarantined by the reset: {entries:?}"
- );
-}
diff --git a/src/openhuman/memory/tools/search/hybrid_search.rs b/src/openhuman/memory/tools/search/hybrid_search.rs
index cadca4f4ce..b7fd7f04c0 100644
--- a/src/openhuman/memory/tools/search/hybrid_search.rs
+++ b/src/openhuman/memory/tools/search/hybrid_search.rs
@@ -36,9 +36,9 @@ pub struct MemoryHybridSearchTool;
/// Named hybrid-retrieval weight profiles (graph / vector / keyword /
/// freshness), resolved from this tool's `mode` argument.
///
-/// The final ranking score is the plain weighted sum
-/// `graph·graph_relevance + vector·vector_similarity + keyword·keyword_relevance
-/// + freshness·freshness`. Nothing here *enforces* that the four weights sum to
+/// The final ranking score is the plain weighted sum `graph·graph_relevance +
+/// vector·vector_similarity + keyword·keyword_relevance + freshness·freshness`.
+/// Nothing here *enforces* that the four weights sum to
/// `1.0` — the four built-ins are chosen that way by convention so scores land
/// in a familiar `[0.0, 1.0]`-ish range when every signal is itself in
/// `[0.0, 1.0]`. The constants are the engine's, value for value, so a query
diff --git a/src/openhuman/modules/memory_host.rs b/src/openhuman/modules/memory_host.rs
index 2099885d88..1500cfba59 100644
--- a/src/openhuman/modules/memory_host.rs
+++ b/src/openhuman/modules/memory_host.rs
@@ -312,18 +312,26 @@ struct RuntimeCallbacks(Arc<Config>);
#[tinybus::interface(name = "ai.tinyhumans.tinymemory.RuntimeHost")]
impl RuntimeCallbacks {
+ /// Bridge a module-side memory event onto this host.
+ ///
+ /// Every arm is [`into_domain_event`]'s: it either maps the event onto a
+ /// [`DomainEvent`](crate::core::events::DomainEvent) for the bus or handles
+ /// it web-channel-side and answers `None`. `StoreCorruptQuarantined` is the
+ /// second kind — it publishes the durable user error and returns `None`,
+ /// the same shape the in-process sink's arm has in `memory::host`.
+ ///
+ /// **There is deliberately no in-process chunk-store reset here any more
+ /// (#5560).** It existed because this process embedded a second copy of the
+ /// engine whose cached SQLite handle still pointed at the inode the module
+ /// had just renamed, so an in-process read kept failing with `database disk
+ /// image is malformed` until restart (openhuman#5820). Every in-process
+ /// reader it protected is gone: `sources::status` asks
+ /// `MemoryChunks::source_ingest_status`, recall goes through
+ /// `memory::binding` to this same driver, and the only surviving openers of
+ /// the host's chunk store are `#[cfg(test)]`. Nothing else in the corruption
+ /// path needs an engine either — `user_error`'s detectors classify text, and
+ /// `tree::tree::rpc`'s `latest_quarantine` reads the directory.
async fn publish_event(&self, event: MemoryEvent) -> tinybus::Result<()> {
- // openhuman#5820: the module just renamed and rebuilt `chunks.db`;
- // this process's own engine copy still holds a handle to the old
- // inode, so drop it before anything in-process reads the store again.
- if matches!(event, MemoryEvent::StoreCorruptQuarantined { .. }) {
- let config = Arc::clone(&self.0);
- tokio::task::spawn_blocking(move || {
- crate::openhuman::memory::host_impls::reset_in_process_chunk_store(&config);
- })
- .await
- .ok();
- }
if let Some(event) = into_domain_event(event) {
BUS.publish(event);
}
diff --git a/tests/raw_coverage/memory_threads_raw_coverage_e2e.rs b/tests/raw_coverage/memory_threads_raw_coverage_e2e.rs
index b793a399bb..93bf4e44fd 100644
--- a/tests/raw_coverage/memory_threads_raw_coverage_e2e.rs
+++ b/tests/raw_coverage/memory_threads_raw_coverage_e2e.rs
@@ -4510,11 +4510,51 @@ async fn memory_query_backend_and_tree_flush_wrappers_cover_public_edges() {
assert!(missing_flush.to_string().contains("no tree with id"));
}
+/// The `tree_summarizer_*` handlers' validation, query and provider-consent
+/// edges — every one of them driven through the handler.
+///
+/// # One door, and why it is the handler's (#5560)
+///
+/// The subject is `tree_runtime::ops`, so the production path is the door: the
+/// five handlers resolve `memory::binding` and ask the loaded module over the
+/// contract's six runtime-tree members. This case used to seed its query with
+/// `tree_runtime_store::write_node` — the engine copy the `[dev-dependencies]`
+/// entry links into *this* binary — and after `d2697f00a` that is a different
+/// store from the one the handler reads, so the query answered "node 'root' not
+/// found in namespace 'ops_ns'" over a node that had just been written.
+///
+/// # The one assertion that could not survive the door change
+///
+/// The seed existed to reach `tree_summarizer_query`'s **success** branch, and
+/// no handler on this surface can create a node: `runtime_summarize` /
+/// `runtime_rebuild` are the only writers and both fold on the driver's own chat
+/// provider, which a hermetic case has no model for — and which this case
+/// deliberately refuses anyway, two asserts below. Seeding the module's store
+/// from the host's engine to get the branch back is precisely the divergence
+/// #5560 exists to remove, so the branch is asserted where a driver can be bound
+/// instead: `memory::tree::tree_runtime::ops_tests::
+/// tree_summarizer_query_returns_node_and_children` pins the whole
+/// `{node, children}` envelope and the `queried node 'root'` log line.
+///
+/// What replaces it here is the assertion the seed was in the way of: that an
+/// **ingest is not a node**. Buffering content leaves `total_nodes` at zero and
+/// leaves `root` absent, and the refusal names the trimmed namespace — the
+/// handler's own trim, over a padded input, which is what tells a
+/// namespace-mangling bug from an empty tree.
#[tokio::test]
async fn tree_summarizer_ops_cover_validation_query_and_local_provider_guards() {
+ let _lock = env_lock();
let tmp = TempDir::new().expect("tempdir");
+ // The handlers resolve a bound memory driver; `module_workspace` is where
+ // that driver lives for this whole process, and the env var has to agree
+ // with the config or the two halves address different stores.
+ let _workspace = EnvVarGuard::set_to_path("OPENHUMAN_WORKSPACE", module_workspace());
let mut config = config_in(&tmp);
+ use_module_workspace(&mut config);
+ // Local AI off and cloud summarization un-opted-in: the state the two
+ // provider guards below assert on.
config.local_ai.runtime_enabled = false;
+ config.memory_tree.cloud_summarization_opt_in = false;
let empty_content =
openhuman_core::openhuman::memory::tree::tree_runtime::ops::tree_summarizer_ingest(
@@ -4548,15 +4588,21 @@ async fn tree_summarizer_ops_cover_validation_query_and_local_provider_guards()
assert_eq!(status.value["namespace"], "ops_ns");
assert_eq!(status.value["total_nodes"], 0);
- let node = tree_node("ops_ns", "root", "Root summary from ops");
- tree_runtime_store::write_node(&config, &node).expect("write ops node");
- let query = openhuman_core::openhuman::memory::tree::tree_runtime::ops::tree_summarizer_query(
- &config, "ops_ns", None,
- )
- .await
- .expect("query root");
- assert_eq!(query.value["node"]["node_id"], "root");
- assert!(query.logs[0].contains("queried node 'root'"));
+ // An ingest buffers; it does not build a node. The default `root` target is
+ // therefore still absent, and the refusal names the namespace **trimmed**,
+ // from a padded argument — the handler's own wording, over the driver's
+ // `Ok(None)`.
+ let unbuilt_root =
+ openhuman_core::openhuman::memory::tree::tree_runtime::ops::tree_summarizer_query(
+ &config, " ops_ns ", None,
+ )
+ .await
+ .unwrap_err();
+ assert_eq!(
+ unbuilt_root,
+ "node 'root' not found in namespace 'ops_ns'",
+ "buffering content must not create a tree node"
+ );
let missing =
openhuman_core::openhuman::memory::tree::tree_runtime::ops::tree_summarizer_query(
diff --git a/tests/raw_coverage/memory_tree_sync_raw_coverage_e2e.rs b/tests/raw_coverage/memory_tree_sync_raw_coverage_e2e.rs
index 9c24c8f390..02ee0f2f20 100644
--- a/tests/raw_coverage/memory_tree_sync_raw_coverage_e2e.rs
+++ b/tests/raw_coverage/memory_tree_sync_raw_coverage_e2e.rs
@@ -44,8 +44,12 @@ use tinymemory_core::tree::tree::bucket_seal::append_leaf;
use tinymemory_core::tree::tree::{
append_leaf_deferred, get_or_create_tree, store as tree_store, LabelStrategy, LeafRef,
};
-use openhuman_core::openhuman::memory::tree::tree_runtime::rpc as tree_runtime_rpc;
// As above: the host re-export is gone, the engine is named directly (#5560).
+//
+// `tree_runtime::rpc` is deliberately **not** imported here any more. Its five
+// handlers answer from the loaded module's store, and a case that mixed them
+// with these engine calls would be driving two stores that share no state — see
+// `tree_runtime_engine_rpc_and_walk_cover_success_and_edge_paths`.
use tinymemory_core::tree::tree_runtime::{engine, store as runtime_store};
use tinyinference::model::{ChatModel, ModelRequest, ModelResponse};
@@ -179,6 +183,34 @@ impl ChatModel<()> for ScriptedProvider {
}
}
+/// The engine's summarisation walk: buffer → hour leaves → propagated
+/// ancestors → rebuild, end to end against a scripted summariser.
+///
+/// # One door, and why it is the engine's (#5560)
+///
+/// This case used to seed and read through `tree_runtime::rpc`'s handlers while
+/// folding through `engine::run_summarization`, and after `d2697f00a` those are
+/// two different stores: the handlers answer from the **loaded module's** engine
+/// over the bus, `engine::` runs the copy the `[dev-dependencies]` entry links
+/// into this binary. The fold therefore drained a buffer the ingests had never
+/// written to and answered `None` — "last hour node".
+///
+/// The subject here is the walk, not the RPC envelope, so the whole case takes
+/// the engine door. That is also the only door it *can* take: `run_summarization`
+/// takes an explicit provider, and the contract's `runtime_summarize` does not —
+/// the fold runs on the driver's own chat provider, deliberately, so the
+/// [`ScriptedProvider`] below cannot cross the bus. Routing this through
+/// `tree_summarizer_run` would mean a real summarisation model in a hermetic
+/// suite.
+///
+/// Nothing is left uncovered by that choice. The handlers' side of the same
+/// ground is asserted where it belongs — against a bound driver — by
+/// `memory::tree::tree_runtime::ops_tests`
+/// (`tree_summarizer_status_reports_populated_tree_details` pins the same six
+/// nodes at depth five, `tree_summarizer_query_returns_node_and_children` the
+/// same node-plus-children envelope) and, module-routed, by
+/// `memory_tree_memory_round23_raw_coverage_e2e::
+/// tree_runtime_rpc_and_registered_handlers_cover_status_and_errors`.
#[tokio::test]
async fn tree_runtime_engine_rpc_and_walk_cover_success_and_edge_paths() {
let tmp = TempDir::new().expect("tempdir");
@@ -187,24 +219,36 @@ async fn tree_runtime_engine_rpc_and_walk_cover_success_and_edge_paths() {
let first_ts = Utc.with_ymd_and_hms(2026, 5, 29, 10, 15, 0).unwrap();
let second_ts = Utc.with_ymd_and_hms(2026, 5, 29, 11, 45, 0).unwrap();
- tree_runtime_rpc::tree_summarizer_ingest(
+ let first_path = runtime_store::buffer_write(
&cfg,
ns,
"deployment notes mention Alice and the launch room",
- Some(first_ts),
+ &first_ts,
Some(&json!({"source": "round14"})),
)
- .await
- .expect("ingest first");
- tree_runtime_rpc::tree_summarizer_ingest(
+ .expect("buffer first");
+ runtime_store::buffer_write(
&cfg,
ns,
"follow-up notes mention Bob and post-launch cleanup",
- Some(second_ts),
+ &second_ts,
None,
)
- .await
- .expect("ingest second");
+ .expect("buffer second");
+ // The two ingests are what the fold consumes, so observe them before it
+ // runs: this is the half `tree_summarizer_ingest` used to stand in for, and
+ // it is the half that silently stopped being observed once the handler
+ // started writing to the module's store instead of this one. Metadata is
+ // read off the file rather than out of `buffer_read`, which strips the
+ // frontmatter it is carried in.
+ let on_disk = std::fs::read_to_string(&first_path).expect("buffer file exists");
+ assert!(on_disk.contains("deployment notes mention Alice"));
+ assert!(on_disk.contains("\"source\":\"round14\""));
+ let buffered = runtime_store::buffer_read(&cfg, ns).expect("buffer read before drain");
+ assert_eq!(buffered.len(), 2);
+ assert!(buffered
+ .iter()
+ .any(|(_, body)| body.contains("post-launch cleanup")));
let provider = ScriptedProvider::new([
"hour 10 summary about Alice",
@@ -221,16 +265,19 @@ async fn tree_runtime_engine_rpc_and_walk_cover_success_and_edge_paths() {
.expect("buffer read after drain")
.is_empty());
- let status = tree_runtime_rpc::tree_summarizer_status(&cfg, ns)
- .await
- .expect("status");
- assert_eq!(status.value["total_nodes"], 6);
- assert_eq!(status.value["depth"], 5);
-
- let query = tree_runtime_rpc::tree_summarizer_query(&cfg, ns, Some("2026/05/29"))
- .await
- .expect("query day");
- assert_eq!(query.value["children"].as_array().unwrap().len(), 2);
+ let status = runtime_store::get_tree_status(&cfg, ns).expect("status");
+ assert_eq!(status.namespace, ns);
+ assert_eq!(status.total_nodes, 6);
+ assert_eq!(status.depth, 5);
+
+ // What `tree_summarizer_query` renders as `{node, children}`, read as the
+ // two store calls the handler now makes over the bus.
+ let day = runtime_store::read_node(&cfg, ns, "2026/05/29")
+ .expect("read day node")
+ .expect("day node exists");
+ assert_eq!(day.node_id, "2026/05/29");
+ let children = runtime_store::read_children(&cfg, ns, "2026/05/29").expect("read day children");
+ assert_eq!(children.len(), 2);
runtime_store::buffer_write(
&cfg,