Skip to content

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

build(memory): cut the engine out of the test build

Shanucc99ba9c6737
diff --git a/Cargo.lock b/Cargo.lock
index 07261ba1d3..3126149ad6 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -479,7 +479,7 @@ dependencies = [
"proc-macro2",
"quote",
"regex",
- "rustc-hash 2.1.3",
+ "rustc-hash",
"shlex 1.3.0",
"syn 2.0.119",
]
@@ -1595,22 +1595,6 @@ dependencies = [
"syn 2.0.119",
]
-[[package]]
-name = "dhat"
-version = "0.3.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "98cd11d84628e233de0ce467de10b8633f4ddaecafadefc86e13b84b8739b827"
-dependencies = [
- "backtrace",
- "lazy_static",
- "mintex",
- "parking_lot",
- "rustc-hash 1.1.0",
- "serde",
- "serde_json",
- "thousands",
-]
-
[[package]]
name = "digest"
version = "0.10.7"
@@ -3502,12 +3486,6 @@ dependencies = [
"simd-adler32",
]
-[[package]]
-name = "mintex"
-version = "0.1.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c505b3e17ed6b70a7ed2e67fbb2c560ee327353556120d6e72f5232b6880d536"
-
[[package]]
name = "mio"
version = "1.2.2"
@@ -4112,7 +4090,6 @@ dependencies = [
"cron",
"crossterm",
"curve25519-dalek",
- "dhat",
"directories",
"dirs 5.0.1",
"dotenvy",
@@ -4172,7 +4149,6 @@ dependencies = [
"tinychannels",
"tinychannels-bus",
"tinyconnectors-bus",
- "tinycortex",
"tinydocs-bus",
"tinyflows",
"tinyflows-catalog",
@@ -4187,9 +4163,7 @@ dependencies = [
"tinymemory-api",
"tinymemory-bus",
"tinymemory-conformance",
- "tinymemory-core",
"tinymemory-sources",
- "tinymemory-tinycortex",
"tinyruntime-bus",
"tinytools",
"tinyvoice-bus",
@@ -4819,7 +4793,7 @@ dependencies = [
"pin-project-lite",
"quinn-proto",
"quinn-udp",
- "rustc-hash 2.1.3",
+ "rustc-hash",
"rustls",
"socket2",
"thiserror 2.0.20",
@@ -4840,7 +4814,7 @@ dependencies = [
"rand 0.10.2",
"rand_pcg",
"ring",
- "rustc-hash 2.1.3",
+ "rustc-hash",
"rustls",
"rustls-pki-types",
"slab",
@@ -5317,12 +5291,6 @@ version = "0.1.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b74b56ffa8bb2830709a538c2cbcae9aa062db0d2a42563bfb09bdaae44020eb"
-[[package]]
-name = "rustc-hash"
-version = "1.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
-
[[package]]
name = "rustc-hash"
version = "2.1.3"
@@ -6306,12 +6274,6 @@ dependencies = [
"syn 3.0.4",
]
-[[package]]
-name = "thousands"
-version = "0.2.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3bf63baf9f5039dadc247375c29eb13706706cfde997d0330d05aa63a77d8820"
-
[[package]]
name = "thread_local"
version = "1.1.10"
@@ -6550,42 +6512,6 @@ dependencies = [
"serde_json",
]
-[[package]]
-name = "tinycortex"
-version = "0.1.2"
-dependencies = [
- "anyhow",
- "async-trait",
- "chrono",
- "dirs 6.0.0",
- "futures",
- "log",
- "parking_lot",
- "rand 0.10.2",
- "regex",
- "reqwest",
- "rusqlite",
- "schemars",
- "serde",
- "serde_json",
- "sha2 0.10.9",
- "thiserror 2.0.20",
- "tinycortex-api",
- "tinyinference",
- "tokio",
- "toml 1.1.4+spec-1.1.0",
- "tracing",
- "uuid",
- "walkdir",
-]
-
-[[package]]
-name = "tinycortex-api"
-version = "0.1.1"
-dependencies = [
- "tinymemory-api",
-]
-
[[package]]
name = "tinydocs-bus"
version = "0.1.15"
@@ -6767,38 +6693,6 @@ dependencies = [
"tinymemory-api",
]
-[[package]]
-name = "tinymemory-core"
-version = "0.1.0"
-dependencies = [
- "anyhow",
- "async-trait",
- "chrono",
- "dirs 6.0.0",
- "futures",
- "log",
- "parking_lot",
- "rand 0.10.2",
- "regex",
- "reqwest",
- "rusqlite",
- "serde",
- "serde_json",
- "sha2 0.11.0",
- "thiserror 2.0.20",
- "tinycortex",
- "tinycortex-api",
- "tinyinference",
- "tinymemory-api",
- "tinymemory-sources",
- "tinymemory-sync",
- "tokio",
- "tracing",
- "url",
- "uuid",
- "walkdir",
-]
-
[[package]]
name = "tinymemory-sources"
version = "0.1.0"
@@ -6820,35 +6714,6 @@ dependencies = [
"walkdir",
]
-[[package]]
-name = "tinymemory-sync"
-version = "0.1.0"
-dependencies = [
- "chrono",
- "log",
- "serde",
- "serde_json",
- "tracing",
-]
-
-[[package]]
-name = "tinymemory-tinycortex"
-version = "0.1.0"
-dependencies = [
- "anyhow",
- "async-trait",
- "chrono",
- "log",
- "rusqlite",
- "serde",
- "serde_json",
- "tinycortex",
- "tinymemory-api",
- "tinymemory-core",
- "tokio",
- "uuid",
-]
-
[[package]]
name = "tinyruntime-bus"
version = "0.2.4"
diff --git a/Cargo.toml b/Cargo.toml
index 63d36263d9..df457813f2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -54,21 +54,6 @@ path = "src/bin/fleet.rs"
# (no `http-server`) this target is skipped rather than failing to link.
required-features = ["http-server", "bin-tools"]
-# Embedded-RSS benchmark harness (#5046). Gated behind the default-OFF
-# `rss-bench` feature so no benchmark code enters the shipped build. Build with
-# `cargo build --release --features rss-bench --bin rss-bench`.
-[[bin]]
-name = "rss-bench"
-path = "src/bin/rss_bench.rs"
-required-features = ["rss-bench"]
-
-# Stateful library profiling workloads (memory ingestion + real sub-agent
-# delegation under a hermetic mock provider). Local/dev only.
-[[bin]]
-name = "library-profile"
-path = "src/bin/library_profile/main.rs"
-required-features = ["rss-bench"]
-
# ── Integration tests that need a PRODUCT gate ──────────────────────────────
#
# `[features] default` is the contributor set and no longer turns on `voice`,
@@ -228,47 +213,6 @@ tinyinference = { path = "vendor/tinyagents/vendor/tinyinference/crates/tinyinfe
# whole address — the same arrangement as `tinyhumans-sdk` and the `-bus`
# crates. After cloning: `git submodule update --init --recursive vendor/`.
tinytools = { path = "vendor/tinyagents/vendor/tinytools/crates/tinytools" }
-# TinyCortex — Rust core for the memory engine (store/chunks/tree/retrieval/
-# queue/ingest/score + long tail). No longer a submodule of this repo: the
-# `[patch.crates-io]` entry below resolves it to the copy `tinymemory` vendors
-# (`vendor/tinymemory/vendor/tinycortex`), so the engine the tests link is by
-# construction the one the prebuilt `tinymemory` module was built from.
-# OpenHuman's memory subsystem migrates onto this
-# crate through the adapter seam in `src/openhuman/tinycortex/` (mirroring the
-# tinyagents seam): engine logic (including provider sync pipelines) in the
-# crate; RPC, agent tools, sync scheduling/credentials/events, security gating,
-# and the global singleton stay host-side. rusqlite is aligned to the host pin
-# (=0.40) so one bundled SQLite links. The submodule intentionally tracks
-# reviewed upstream main commits; keep this semver requirement compatible with
-# the vendored crate version.
-# `git-diff` and `wiki-git` are NOT here, and there is no longer a gate that
-# turns them on: the `memory-git` feature and the `memory::diff` RPC/tool
-# surface it guarded were deleted, taking the git2/libgit2-sys/libz-sys cohort
-# out of every configuration. tinycortex remains the sole libgit2 link in the
-# graph, and nothing in this crate enables it. Everything else tinycortex needs
-# is unconditional.
-# `tinycortex` has left the product build (openhuman#5560). The engine still
-# runs — inside the prebuilt `tinymemory` TinyBus module, which links it and
-# enables its `contacts` feature for the macOS address-book reader. This host
-# reaches all of it through `tinymemory-api` over the bus.
-#
-# It is `optional` rather than deleted for one reason only: the two
-# `library_profile` bins measure the in-process engine and a `[[bin]]` cannot
-# use a dev-dependency, so `rss-bench` turns it on. `rss-bench` is NOT in
-# `scripts/ci/product-features.txt`, so nothing shipped enables it. Every test
-# that names the crate is served by the [dev-dependencies] entry instead.
-#
-# Its `[patch]` entry below stays, and that is not the same decision. Dropping
-# the direct dependency and dropping the patch are different things: the crate
-# is unpublished, and the engine crates still reached as [dev-dependencies]
-# name it by version requirement, so removing the patch fails *resolution* with
-# "no matching package named `tinycortex-api` found" long before anything is
-# compiled.
-tinycortex = { version = "0.1", optional = true, features = [
- "obsidian",
- "persona",
- "sync",
-] }
# The memory *contract* — value types, the thirteen capability families, the
# `MemoryProvider` driver trait, and the null reference driver. A direct path
# dependency rather than a re-export, because `tinycortex::memory` aliases back
@@ -336,48 +280,6 @@ tinyconnectors-bus = { path = "vendor/tinyconnectors/crates/tinyconnectors-bus"
# directly (EXTRACT_ENTITIES, EMBED_TEXT, EMBEDDER_SLUG) — prefer compile
# errors on renaming over MemberNotFound at runtime.
tinymemory-bus = { path = "vendor/tinymemory/crates/tinymemory-bus" }
-# DONE 2026-08-31, and the measurement that forced it is worth keeping, because
-# it is the trap anyone auditing a shed here will fall into next.
-#
-# This entry had **no production consumer** — every `tinymemory_tinycortex::`
-# reference in the tree is test code (`memory::test_support`,
-# `agent::harness::archivist_tests`, `tests/raw_coverage/`) — yet it was a
-# **second, independent normal edge onto `tinymemory-core`**: `cargo tree -e
-# normal -i tinymemory-core` reported two parents, `openhuman` and this crate.
-# Dropping the `tinymemory-core` entry alone would therefore NOT have taken the
-# engine out of the shipped graph; this line would still have pulled it. Both
-# halves had to move together, and they did.
-#
-# The general lesson, which the `rss-bench` comment further down states from the
-# other direction: **a manifest that reads correctly is not a shed.** Verify with
-# `cargo tree -e normal -i <crate>` under the product feature set — it prints
-# "nothing to print" when a crate is genuinely gone.
-# `tinymemory-tinycortex` is a dev-dependency now (see [dev-dependencies]).
-# Its only host uses are the test fixtures that stand up an in-process engine,
-# and cargo does not link dev-dependency features into the shipped binary —
-# the same precedent the root `tinywallet` crate already sets.
-# `tinymemory-core` is the *substance* of the memory subsystem, extracted out of
-# `src/openhuman/memory/` — the SQLite/vector store, the markdown summary tree,
-# the provider sync pipelines, ingestion, recall/query/search, the ingest queue,
-# conversations, people, goals and the tool-memory rules.
-#
-# What deliberately stayed behind in `src/openhuman/memory/` is the *host layer*
-# per the tinymemory README split: the RPC surface (`schemas/`, `read_rpc/`),
-# agent tools (`tools/`), the security/taint guard (`guard/`), the driver
-# binding (`driver/`), the memory agent, and the config mapping. Those reach
-# into this crate; this crate never names an OpenHuman type. Everything it needs
-# from the host arrives through the seam traits in `tinymemory_api::host`, whose
-# implementations live in `src/openhuman/memory/host.rs`.
-#
-# The `schemars` feature is enabled because the memory config *section* structs
-# (`MemoryConfig`, `MemoryTreeConfig`, …) now live in `tinymemory_api::host` and
-# are still fields of OpenHuman's `Config`, which derives `JsonSchema`.
-# `tinymemory-core` is optional and reached only by `rss-bench`, which is NOT
-# in `scripts/ci/product-features.txt` — so it is absent from the shipped
-# build. It is `optional` rather than dev-only because the two
-# `library_profile` bins need it and a bin target cannot use a
-# dev-dependency; every test is served by the [dev-dependencies] entry below.
-tinymemory-core = { path = "vendor/tinymemory/crates/tinymemory-core", optional = true }
# `tinymemory-sources` is the source registry, its types and its readers, in a
# crate of its own. Taken directly rather than through `tinymemory-core`
# (OpenHuman#5560): `tinymemory_core::sources` is a thin layer over it —
@@ -477,10 +379,6 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde_repr = "0.1"
serde_yaml = "0.9"
-# dhat — heap profiler for the offline `library-profile` benchmark binary only.
-# Default-OFF, dev-only: pulled in solely by the `rss-bench-dhat` feature so it
-# never enters the shipped desktop/library build (same posture as `rss-bench`).
-dhat = { version = "0.3", optional = true }
# (Removed `html2md` dep. dhat-rs profiling on real Gmail inboxes
# showed `html2md::walk` and `html2md::tables::handle` allocating
# ~894 MB peak heap on a 10 KB HTML input from Otter.ai-style emails
@@ -807,31 +705,6 @@ tinyflows-sqlite = { path = "vendor/tinyflows/crates/tinyflows-sqlite", features
tinywallet = { path = "vendor/tinywallet", default-features = false, features = ["key", "btc", "evm", "solana", "tron"] }
k256 = { version = "0.13", default-features = false, features = ["std", "ecdsa"] }
coins-bip39 = { version = "0.8" }
-# The host's own tests drive `tinymemory-core`'s test helpers
-# (`chat::test_override`, `StaticChatProvider`, `tool_memory::test_helpers`).
-# They were `#[cfg(test)]` items in this crate before the memory extraction; a
-# downstream test harness cannot see those across a crate boundary, so the
-# extracted crate exposes them behind `test-support` instead.
-tinymemory-core = { path = "vendor/tinymemory/crates/tinymemory-core", features = ["test-support"] }
-# `tinycortex` itself, for the ~11 test files that name it directly —
-# `memory::read_rpc`, the sync-pipeline and tree e2e suites, the archivist and
-# session suites, the composio user-scope tests. They reach engine-internal
-# canonicalisation and sync-state items (`memory::ingest::canonicalize::chat`,
-# `memory::sync::state::STATE_NAMESPACE`, `memory::tree::runtime`) that no
-# contract family exposes. The normal entry above is `optional` and off outside
-# `rss-bench`, so this is what keeps the crate available to `cargo test` — and
-# cargo does not link dev-dependency features into the shipped binary, which is
-# the whole point of the split.
-tinycortex = { version = "0.1", features = ["obsidian", "persona", "sync"] }
-# `tinymemory-tinycortex` moved here from `[dependencies]` (#5560). It is the
-# adapter between TinyCortex's contract types and TinyMemory's, and every
-# surviving host use of it is a test fixture standing up an in-process engine —
-# `memory::test_support`, `memory::ops::test_support` and the archivist /
-# session suites. Cargo does not link dev-dependency features into the shipped
-# binary, so this keeps the adapter (and the `tinycortex` it names by version
-# requirement) out of the product while the tests that need a real engine keep
-# working.
-tinymemory-tinycortex = { path = "vendor/tinymemory/crates/tinymemory-tinycortex" }
# The fake memory driver the host's own tests bind, in place of an in-process
# engine (openhuman#6161). It serves every optional family, so a handler that
# asks for one by accessor gets `Some` rather than taking the `None` arm as
@@ -926,33 +799,7 @@ proptest = "1"
# (`modules`: Contrib=ON, Product=ON) and with `scripts/ci/product-features.txt`,
# which already lists it. This does NOT move the kernel floor: that profile is
# `--no-default-features --features flows` and never reads this list.
-default = ["media", "skills", "flows", "mcp", "channels", "medulla", "http-server", "scheduler-gate", "file-logging", "modules", "memory-engine-seams"]
-# Compiles `memory::host_impls` and turns the optional `tinymemory-core` on with
-# it (openhuman#5560). Default-ON, product-OFF, allow-listed in
-# `INTENTIONALLY_NOT_FORWARDED` — forwarding it to the shell would undo the shed.
-#
-# **Why a feature and not `#[cfg(test)]`.** The seams install into an in-process
-# engine, and the crate's own unit tests reach them through `cfg(test)` happily.
-# A `tests/*.rs` integration target cannot: it links this lib as an ordinary
-# dependency, where `cfg(test)` is false and the module is invisible *however
-# the engine is declared*. Two dozen of those targets call
-# `install_memory_host_seams`, and the archivist / session-turn / memory-sync
-# cases in `raw_coverage_all` genuinely drive a real engine — they fail with
-# "no EmbeddingHost installed" when it is absent, which is the same failure the
-# first attempt at #5560 shipped to users. So the module needs a *feature*, and
-# a feature that turns the engine dependency on.
-#
-# **Why `default` and not the test lane.** Three separate places compose the
-# test feature string (`scripts/test-rust-with-mock.sh`,
-# `test-reusable.yml`, `scripts/ci/rust-coverage-changed.sh`) and one
-# `raw_coverage_all` invocation passes `--features` not at all. None of them
-# passes `--no-default-features`, so `default` reaches every one; a
-# test-lane-only feature would have to be added to each and would fail
-# confusingly wherever it was missed. It costs the contributor inner loop
-# nothing it was not already paying: before this change `tinycortex` and
-# `tinymemory-core` were unconditional normal dependencies, so a bare
-# `cargo check` linked them regardless.
-memory-engine-seams = ["dep:tinymemory-core"]
+default = ["media", "skills", "flows", "mcp", "channels", "medulla", "http-server", "scheduler-gate", "file-logging", "modules"]
# HTTP + Socket.IO server transport (#5048): the `/rpc` JSON-RPC endpoint and
# its auth middleware/CORS layer (`core::jsonrpc`, `core::auth`), the `/v1`
# OpenAI-compatible router (`inference::http`), the ad-hoc static-dir file
@@ -1421,30 +1268,6 @@ file-logging = ["dep:tracing-appender", "dep:tracing-log"]
scheduler-gate = ["dep:starship-battery"]
bin-tools = ["dep:clap", "dep:env_logger"]
-# That day arrived (#5560), and this is the other half of the flip.
-#
-# `src/bin/library_profile/scenarios/{cold_phases,memory_ingest}.rs` name
-# `tinymemory_core::` and `tinycortex::` on purpose — they measure the
-# in-process engine, and routing them through `memory::binding` would measure
-# the *null* driver instead — and **a `[[bin]]` cannot use a dev-dependency**.
-# So both crates stay in `[dependencies]` marked `optional = true` and are
-# reached only from here; without this list `--features rss-bench` would break
-# in a configuration no CI lane compiles.
-#
-# The warning this comment used to carry still stands for anyone reading it as
-# precedent: marking an entry `optional` while this list stayed empty was a
-# measured no-op, because the non-optional `[dev-dependencies]` entry activates
-# the optional normal one and `cargo tree -e normal -i tinymemory-core` came out
-# byte-identical. What made it real was draining the production callers first —
-# the appearance of a shed and an actual shed are only the same thing once
-# nothing in the product names the crate. Verify with `cargo tree -e normal -i`
-# under the product feature set, not by reading the manifest.
-rss-bench = ["dep:tinycortex", "dep:tinymemory-core"]
-# Adds dhat heap profiling on top of `rss-bench` for the `library-profile`
-# binary. Default-OFF, dev-only: installs dhat's global allocator, which
-# perturbs RSS/timing numbers, so it is a separate opt-in feature rather than
-# folded into `rss-bench`. Never forwarded to the shipped build.
-rss-bench-dhat = ["rss-bench", "dep:dhat"]
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage)'] }
@@ -1521,22 +1344,6 @@ tinyinference = { path = "vendor/tinyagents/vendor/tinyinference/crates/tinyinfe
# TinyFlows and TinyChannels are vendored beside TinyAgents so integration
# work can test crate changes against OpenHuman before publishing.
tinyflows = { path = "vendor/tinyflows/crates/tinyflows" }
-# TinyCortex is not a submodule of this repo. `tinymemory-core` and
-# `tinymemory-tinycortex` — the [dev-dependencies] engine — name `tinycortex`
-# and `tinycortex-api` by version requirement, i.e. from crates.io.
-# `tinycortex-api` was never published, so without a patch resolution fails
-# outright ("no matching package named `tinycortex-api` found") before anything
-# compiles — product build included, because lock resolution is feature-blind.
-# `tinycortex` IS on crates.io, as a stale 0.1.1 that declares none of the
-# features the engine crates ask for, so without a patch cargo would look there
-# instead of at the commit the module ships, and fail on the features.
-# tinymemory already vendors that exact commit, so the patch points into its
-# nested checkout rather than a second, hand-synchronised copy: one checkout,
-# one copy of the contract types, and a tinymemory re-pin moves the test
-# engine with it. Needs `git submodule update --init --recursive
-# vendor/tinymemory`; every CI lane that builds Rust checks out recursively.
-tinycortex = { path = "vendor/tinymemory/vendor/tinycortex" }
-tinycortex-api = { path = "vendor/tinymemory/vendor/tinycortex/api" }
tinychannels = { path = "vendor/tinychannels" }
# Emit just enough DWARF in release builds for Sentry to symbolicate Rust
diff --git a/scripts/lib/feature-forwarding.mjs b/scripts/lib/feature-forwarding.mjs
index aa5c146446..34c63e65f2 100644
--- a/scripts/lib/feature-forwarding.mjs
+++ b/scripts/lib/feature-forwarding.mjs
@@ -52,7 +52,6 @@ export const INTENTIONALLY_NOT_FORWARDED = {
// 'some-gate': 'Reason it must not ship in the desktop build.',
tui: 'Terminal UI subcommand (openhuman tui/chat); the desktop app ships its own Tauri UI and never runs the ratatui terminal front-end. NOTE: `tui` is also default-OFF, so it is in NEITHER the contributor nor the product set and no ordinary lane compiles it — the feature-gate-smoke lane checks it explicitly. Any future entry here in the same position needs the same treatment.',
medulla: 'Medulla orchestration-backend client; the desktop app is OpenHuman\'s own product and never dials a Medulla backend. Consumed by the Medulla TUI, which embeds this crate directly.',
- 'memory-engine-seams': 'Compiles `memory::host_impls` — the seven host seams for an IN-PROCESS `tinymemory-core` — and turns that optional engine dependency on. Forwarding it would undo openhuman#5560 exactly: the shipped app reaches memory through the loaded tinymemory TinyBus module over `tinymemory-api`, and a second in-process engine over the same `memory.db` is the duplicate this shed removed. It is in `default` (not the product set) because `tests/*.rs` integration targets link this lib as a NORMAL dependency, where `#[cfg(test)]` is false and the module would be invisible however the engine is declared — several of them do drive a real engine and fail with "no EmbeddingHost installed" without it.',
};
/**
diff --git a/src/bin/library_profile/harness.rs b/src/bin/library_profile/harness.rs
deleted file mode 100644
index e094462743..0000000000
--- a/src/bin/library_profile/harness.rs
+++ /dev/null
@@ -1,495 +0,0 @@
-//! Shared profiling harness: hermetic fixture, RSS sampling, and the
-//! `measure()` wrapper that every scenario runs its workload through.
-//!
-//! All diagnostics go to **stderr** (stdout must stay pure JSON) using the
-//! stable `[library-profile]` prefix.
-
-use std::sync::atomic::{AtomicU64, Ordering};
-use std::sync::{Arc, Mutex};
-use std::time::{Duration, Instant};
-
-use anyhow::{Context, Result};
-use openhuman_core::openhuman::config::Config;
-use openhuman_core::openhuman::platform::proc_metrics::{self, ProcSample, TreeSample};
-use serde::Serialize;
-
-/// One sampled point inside a measured workload. `delta_kib` is the RSS change
-/// versus the *previous* checkpoint (or the baseline for the first one).
-#[derive(Debug, Clone, Serialize)]
-pub struct Checkpoint {
- pub label: String,
- pub at_ms: u128,
- pub rss_kib: u64,
- pub delta_kib: i64,
-}
-
-/// Turn wall-latency percentiles (milliseconds) collected under overlapping
-/// load by the `fleet` scenario.
-#[derive(Debug, Clone, Copy, Serialize)]
-pub struct TurnLatency {
- pub p50: u128,
- pub p95: u128,
- pub p99: u128,
- pub max: u128,
-}
-
-/// Per-descendant RSS entry in a [`TreeReport`].
-#[derive(Debug, Clone, Serialize)]
-pub struct TreeChild {
- pub name: String,
- pub rss_kib: u64,
-}
-
-/// Process-*tree* RSS reporting: this process plus every descendant
-/// (interpreter children such as `node` / `python` a skill run spawns). Folds a
-/// [`TreeSample`] down to the reported shape. `tree_rss_kib` counts self + all
-/// descendants, so it exceeds `settled.rss_kib` whenever a child was live at
-/// sample time.
-#[derive(Debug, Clone, Serialize)]
-pub struct TreeReport {
- pub tree_rss_kib: u64,
- pub child_count: usize,
- pub children: Vec<TreeChild>,
-}
-
-impl TreeReport {
- pub fn from_sample(sample: &TreeSample) -> Self {
- Self {
- tree_rss_kib: sample.tree_rss_kib,
- child_count: sample.children.len(),
- children: sample
- .children
- .iter()
- .map(|child| TreeChild {
- name: child.name.clone(),
- rss_kib: child.rss_kib,
- })
- .collect(),
- }
- }
-}
-
-/// Fleet capacity budget math (purely informational — scripts turn `fits` into
-/// pass/fail). `projected_rss_mib_at_target = settled_base + marginal * target`.
-#[derive(Debug, Clone, Copy, Serialize)]
-pub struct FleetBudget {
- pub target_agents: u64,
- pub ram_budget_mib: u64,
- pub projected_rss_mib_at_target: f64,
- pub fits: bool,
-}
-
-/// Pinned JSON output contract (schema_version = 2). New optional fields are
-/// skipped when absent so the two original scenarios stay byte-identical.
-#[derive(Debug, Serialize)]
-pub struct ProfileResult {
- pub schema_version: u32,
- pub scenario: &'static str,
- pub workload_units: usize,
- pub duration_ms: u128,
- pub baseline: ProcSample,
- pub settled: ProcSample,
- pub peak_rss_kib: u64,
- pub retained_delta_kib: i64,
- pub peak_delta_kib: u64,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub turns: Option<usize>,
- /// (`fleet`) requested live-agent count.
- #[serde(skip_serializing_if = "Option::is_none")]
- pub agents: Option<usize>,
- /// (`fleet`) agents actually constructed (may be < `agents` on fd/OOM).
- #[serde(skip_serializing_if = "Option::is_none")]
- pub agents_built: Option<usize>,
- /// (`fleet`) marginal RSS cost per agent (`baseline → constructed`), KiB.
- #[serde(skip_serializing_if = "Option::is_none")]
- pub marginal_rss_kib_per_agent: Option<f64>,
- /// (`fleet`) user+system CPU delta over the 10 s idle window, ms.
- #[serde(skip_serializing_if = "Option::is_none")]
- pub idle_cpu_ms: Option<u64>,
- /// (`fleet`) turn wall-latency percentiles under overlapping load.
- #[serde(skip_serializing_if = "Option::is_none")]
- pub turn_latency_ms: Option<TurnLatency>,
- /// (`fleet`) capacity budget projection.
- #[serde(skip_serializing_if = "Option::is_none")]
- pub budget: Option<FleetBudget>,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub checkpoints: Option<Vec<Checkpoint>>,
- /// (`subagent-storm`) K parallel researcher subagents fanned out in the turn.
- #[serde(skip_serializing_if = "Option::is_none")]
- pub subagents: Option<usize>,
- /// (`skill-run`) process-tree RSS including interpreter child processes.
- /// Reports the richest tree seen — the peak-during-workload sample when a
- /// short-lived child (e.g. `node`) has already exited by settle time.
- #[serde(skip_serializing_if = "Option::is_none")]
- pub tree: Option<TreeReport>,
- /// Present (and `true`) only when the dhat heap profiler is active, since
- /// RSS/time numbers are perturbed by dhat's global allocator.
- #[serde(skip_serializing_if = "Option::is_none")]
- pub dhat: Option<bool>,
-}
-
-/// Restores (or removes) an environment variable on drop.
-pub struct EnvGuard {
- key: &'static str,
- old: Option<String>,
-}
-
-impl EnvGuard {
- pub fn set(key: &'static str, value: &str) -> Self {
- let old = std::env::var(key).ok();
- std::env::set_var(key, value);
- Self { key, old }
- }
-}
-
-impl Drop for EnvGuard {
- fn drop(&mut self) {
- match &self.old {
- Some(value) => std::env::set_var(self.key, value),
- None => std::env::remove_var(self.key),
- }
- }
-}
-
-/// A hermetic config rooted in a throwaway temp workspace. Local inference,
-/// Python, spaCy, and embeddings are all disabled so runs are offline.
-pub struct Fixture {
- pub config: Config,
- _workspace_env: EnvGuard,
- _keyring_env: EnvGuard,
- _action_env: EnvGuard,
- _tmp: tempfile::TempDir,
-}
-
-pub fn fixture() -> Result<Fixture> {
- let tmp = tempfile::tempdir().context("create profile workspace")?;
- let root = tmp.path();
- let workspace = root.join("workspace");
- std::fs::create_dir_all(&workspace)?;
- // A real, writable action sandbox so acting tools (e.g. `node_exec`, which
- // spawns `node` in the action dir) have a valid cwd. Harmless for scenarios
- // that never act.
- let action_dir = root.join("action");
- std::fs::create_dir_all(&action_dir)?;
-
- let mut config_toml = r#"api_url = "http://127.0.0.1:9"
-default_model = "profile-mock"
-default_temperature = 0.0
-chat_onboarding_completed = true
-
-[secrets]
-encrypt = false
-
-[local_ai]
-enabled = false
-runtime_enabled = false
-
-[runtime_python]
-enabled = false
-
-[memory_tree]
-spacy_enabled = false
-"#
- .to_string();
- if std::env::var_os("OPENHUMAN_PROFILE_DISABLE_MEMORY_WRITES").is_some() {
- config_toml.push_str(
- r#"
-[memory]
-auto_save = false
-
-[learning]
-episodic_capture_enabled = false
-"#,
- );
- }
- // `skill-run` executes real acting tools (`node_exec`); those need the Full
- // autonomy tier so the write-class gate does not park the turn on approval.
- // Config::load_or_init inside the detached workflow run re-reads this file,
- // so the tier must live in config.toml (not just the in-memory Config).
- if std::env::var_os("OPENHUMAN_PROFILE_FULL_AUTONOMY").is_some() {
- config_toml.push_str(
- r#"
-[autonomy]
-level = "full"
-"#,
- );
- }
- std::fs::write(root.join("config.toml"), &config_toml)?;
-
- let workspace_env = EnvGuard::set("OPENHUMAN_WORKSPACE", &root.to_string_lossy());
- let keyring_env = EnvGuard::set("OPENHUMAN_KEYRING_BACKEND", "file");
- let action_env = EnvGuard::set("OPENHUMAN_ACTION_DIR", &action_dir.to_string_lossy());
- let mut config: Config = toml::from_str(&config_toml)?;
- config.workspace_dir = workspace;
- config.action_dir = action_dir;
- config.memory_tree.embedding_endpoint = None;
- config.memory_tree.embedding_model = None;
- config.memory_tree.embedding_strict = false;
-
- Ok(Fixture {
- config,
- _workspace_env: workspace_env,
- _keyring_env: keyring_env,
- _action_env: action_env,
- _tmp: tmp,
- })
-}
-
-/// Background task that polls `proc_metrics::sample_self()` every 5 ms and
-/// keeps the running peak RSS.
-pub struct PeakSampler {
- peak: Arc<AtomicU64>,
- stop: Arc<AtomicU64>,
- task: tokio::task::JoinHandle<()>,
-}
-
-impl PeakSampler {
- pub fn start(initial_kib: u64) -> Self {
- let peak = Arc::new(AtomicU64::new(initial_kib));
- let stop = Arc::new(AtomicU64::new(0));
- let task_peak = Arc::clone(&peak);
- let task_stop = Arc::clone(&stop);
- let task = tokio::spawn(async move {
- while task_stop.load(Ordering::Relaxed) == 0 {
- if let Ok(sample) = proc_metrics::sample_self() {
- task_peak.fetch_max(sample.rss_kib, Ordering::Relaxed);
- }
- tokio::time::sleep(Duration::from_millis(5)).await;
- }
- });
- Self { peak, stop, task }
- }
-
- pub async fn stop(self) -> u64 {
- self.stop.store(1, Ordering::Relaxed);
- let _ = self.task.await;
- self.peak.load(Ordering::Relaxed)
- }
-}
-
-/// Background task that polls `proc_metrics::sample_tree()` and keeps the
-/// [`TreeSample`] with the highest `tree_rss_kib` seen — capturing the moment a
-/// short-lived interpreter child (e.g. a `node -e` step) is resident, which a
-/// settle-time-only sample would miss because the child has already exited.
-pub struct TreePeakSampler {
- best: Arc<Mutex<Option<TreeSample>>>,
- stop: Arc<AtomicU64>,
- task: tokio::task::JoinHandle<()>,
-}
-
-impl TreePeakSampler {
- pub fn start() -> Self {
- let best: Arc<Mutex<Option<TreeSample>>> = Arc::new(Mutex::new(None));
- let stop = Arc::new(AtomicU64::new(0));
- let task_best = Arc::clone(&best);
- let task_stop = Arc::clone(&stop);
- let task = tokio::spawn(async move {
- while task_stop.load(Ordering::Relaxed) == 0 {
- if let Ok(sample) = proc_metrics::sample_tree() {
- let mut guard = task_best.lock().expect("tree peak lock");
- let replace = guard
- .as_ref()
- .map(|prev| sample.tree_rss_kib > prev.tree_rss_kib)
- .unwrap_or(true);
- if replace {
- *guard = Some(sample);
- }
- }
- tokio::time::sleep(Duration::from_millis(15)).await;
- }
- });
- Self { best, stop, task }
- }
-
- pub async fn stop(self) -> Option<TreeSample> {
- self.stop.store(1, Ordering::Relaxed);
- let _ = self.task.await;
- self.best.lock().expect("tree peak lock").clone()
- }
-}
-
-/// Collects per-phase / per-turn checkpoints inside a measured workload.
-/// Cloneable (shares one buffer) so it can be handed to closures freely.
-#[derive(Clone)]
-pub struct Recorder {
- inner: Arc<Mutex<RecorderState>>,
- started: Instant,
-}
-
-struct RecorderState {
- checkpoints: Vec<Checkpoint>,
- last_rss_kib: u64,
-}
-
-impl Recorder {
- fn new(baseline_kib: u64, started: Instant) -> Self {
- Self {
- inner: Arc::new(Mutex::new(RecorderState {
- checkpoints: Vec::new(),
- last_rss_kib: baseline_kib,
- })),
- started,
- }
- }
-
- /// Sample RSS now and append a labelled checkpoint whose `delta_kib` is
- /// relative to the previous checkpoint (baseline for the first).
- pub fn checkpoint(&self, label: impl Into<String>) -> Result<()> {
- let label = label.into();
- let sample = proc_metrics::sample_self()?;
- let at_ms = self.started.elapsed().as_millis();
- let mut state = self.inner.lock().expect("recorder lock");
- let delta_kib = sample.rss_kib as i64 - state.last_rss_kib as i64;
- state.last_rss_kib = sample.rss_kib;
- eprintln!(
- "[library-profile] checkpoint label={label} at_ms={at_ms} rss_kib={} delta_kib={delta_kib}",
- sample.rss_kib
- );
- state.checkpoints.push(Checkpoint {
- label,
- at_ms,
- rss_kib: sample.rss_kib,
- delta_kib,
- });
- Ok(())
- }
-
- fn take(self) -> Vec<Checkpoint> {
- self.inner
- .lock()
- .expect("recorder lock")
- .checkpoints
- .clone()
- }
-}
-
-/// Run `workload` between a settled baseline and a settled post-run sample,
-/// tracking peak RSS throughout. `turns` and any checkpoints pushed via the
-/// `Recorder` are folded into the result (both `None`/omitted when unused).
-pub async fn measure<F, Fut>(
- scenario: &'static str,
- workload_units: usize,
- turns: Option<usize>,
- workload: F,
-) -> Result<ProfileResult>
-where
- F: FnOnce(Recorder) -> Fut,
- Fut: std::future::Future<Output = Result<()>>,
-{
- measure_impl(scenario, workload_units, turns, false, workload).await
-}
-
-/// Like [`measure`], but also samples the process **tree** (self + descendant
-/// interpreter processes). A [`TreePeakSampler`] runs alongside the RSS peak
-/// sampler, and the settle-time tree is captured too; the reported `tree` is
-/// whichever of the two has the higher `tree_rss_kib`, so a `node` child that
-/// exits before settle is still attributed. Used by `skill-run`.
-pub async fn measure_with_tree<F, Fut>(
- scenario: &'static str,
- workload_units: usize,
- turns: Option<usize>,
- workload: F,
-) -> Result<ProfileResult>
-where
- F: FnOnce(Recorder) -> Fut,
- Fut: std::future::Future<Output = Result<()>>,
-{
- measure_impl(scenario, workload_units, turns, true, workload).await
-}
-
-async fn measure_impl<F, Fut>(
- scenario: &'static str,
- workload_units: usize,
- turns: Option<usize>,
- sample_tree: bool,
- workload: F,
-) -> Result<ProfileResult>
-where
- F: FnOnce(Recorder) -> Fut,
- Fut: std::future::Future<Output = Result<()>>,
-{
- tokio::time::sleep(Duration::from_millis(250)).await;
- let baseline = proc_metrics::sample_self()?;
- if let Some(seconds) = std::env::var("OPENHUMAN_PROFILE_HOLD_BEFORE_SECS")
- .ok()
- .and_then(|value| value.parse::<u64>().ok())
- .filter(|seconds| *seconds > 0)
- {
- eprintln!(
- "[library-profile] pid={} holding at baseline for {seconds}s",
- std::process::id()
- );
- tokio::time::sleep(Duration::from_secs(seconds)).await;
- }
- let sampler = PeakSampler::start(baseline.rss_kib);
- let tree_sampler = if sample_tree {
- Some(TreePeakSampler::start())
- } else {
- None
- };
- let started = Instant::now();
- let recorder = Recorder::new(baseline.rss_kib, started);
- eprintln!("[library-profile] scenario={scenario} workload starting");
- workload(recorder.clone()).await?;
- let duration_ms = started.elapsed().as_millis();
- eprintln!("[library-profile] scenario={scenario} workload done duration_ms={duration_ms}");
- tokio::time::sleep(Duration::from_millis(500)).await;
- let settled = proc_metrics::sample_self()?;
- let peak_rss_kib = sampler.stop().await.max(settled.rss_kib);
-
- // Fold the process-tree samples (peak-during-workload + settle-time) into a
- // single report: whichever has the higher tree RSS wins, so a short-lived
- // interpreter child that already exited by settle is still attributed.
- let tree = if let Some(tree_sampler) = tree_sampler {
- let peak_tree = tree_sampler.stop().await;
- let settle_tree = proc_metrics::sample_tree().ok();
- let best = match (peak_tree, settle_tree) {
- (Some(peak), Some(settle)) => {
- if peak.tree_rss_kib >= settle.tree_rss_kib {
- Some(peak)
- } else {
- Some(settle)
- }
- }
- (peak, settle) => peak.or(settle),
- };
- if let Some(best) = best.as_ref() {
- eprintln!(
- "[library-profile] scenario={scenario} tree_rss_kib={} child_count={}",
- best.tree_rss_kib,
- best.children.len()
- );
- }
- best.map(|sample| TreeReport::from_sample(&sample))
- } else {
- None
- };
- let checkpoints = recorder.take();
- let checkpoints = if checkpoints.is_empty() {
- None
- } else {
- Some(checkpoints)
- };
- Ok(ProfileResult {
- schema_version: 2,
- scenario,
- workload_units,
- duration_ms,
- baseline,
- settled,
- peak_rss_kib,
- retained_delta_kib: settled.rss_kib as i64 - baseline.rss_kib as i64,
- peak_delta_kib: peak_rss_kib.saturating_sub(baseline.rss_kib),
- turns,
- agents: None,
- agents_built: None,
- marginal_rss_kib_per_agent: None,
- idle_cpu_ms: None,
- turn_latency_ms: None,
- budget: None,
- checkpoints,
- subagents: None,
- tree,
- dhat: None,
- })
-}
diff --git a/src/bin/library_profile/main.rs b/src/bin/library_profile/main.rs
deleted file mode 100644
index bbc5512bbb..0000000000
--- a/src/bin/library_profile/main.rs
+++ /dev/null
@@ -1,128 +0,0 @@
-//! Hermetic, Rust-only library profiling workloads.
-//!
-//! This binary never enters shipped builds (it requires the default-off
-//! `rss-bench` feature). It measures production code paths in fresh processes
-//! with network inference replaced by a deterministic provider.
-//!
-//! Scenarios (`library-profile <scenario>`):
-//! - `memory-ingest` — ingest 100 chat messages, drain the memory queue.
-//! - `agent-turn` — a single cold agent turn (minimal library unit).
-//! - `long-agent` — N warmed sequential turns with a per-turn checkpoint series.
-//! - `workflow` — a real flows trigger->transform->agent graph, end to end.
-//! - `cold-phases` — per-phase checkpoints of the cold bootstrap in one region.
-//! - `fleet` — N live agents: marginal RSS, idle CPU, fd/thread growth, turn latency.
-//! - `skill-run` — a skill step executing on a real `node` child: process-tree RSS.
-//! - `subagent-storm`— K parallel researcher subagents in one instance: marginal RSS per subagent.
-//!
-//! stdout is ALWAYS a single pretty JSON object (the pinned schema in
-//! `harness::ProfileResult`); every diagnostic goes to stderr with the stable
-//! `[library-profile]` prefix.
-//!
-//! With the `rss-bench-dhat` feature, dhat's global allocator + profiler are
-//! active: RSS/time numbers are perturbed, the result carries `"dhat": true`,
-//! and a `dhat-<scenario>.json` heap profile is written under
-//! `target/profile/rust-library/` (override via `OPENHUMAN_PROFILE_DHAT_OUT`).
-
-mod harness;
-mod mock;
-mod scenarios;
-
-use std::time::Duration;
-
-use anyhow::{Context, Result};
-
-use harness::ProfileResult;
-
-#[cfg(feature = "rss-bench-dhat")]
-#[global_allocator]
-static ALLOC: dhat::Alloc = dhat::Alloc;
-
-/// Builds the dhat profiler (feature-gated), writing to the requested path.
-/// Kept alive by the caller until after the JSON result is printed.
-#[cfg(feature = "rss-bench-dhat")]
-fn start_dhat(scenario: &str) -> Result<dhat::Profiler> {
- let out = std::env::var("OPENHUMAN_PROFILE_DHAT_OUT")
- .unwrap_or_else(|_| format!("target/profile/rust-library/dhat-{scenario}.json"));
- if let Some(parent) = std::path::Path::new(&out).parent() {
- std::fs::create_dir_all(parent).context("create dhat output directory")?;
- }
- eprintln!("[library-profile] dhat active — heap profile -> {out}");
- Ok(dhat::Profiler::builder().file_name(&out).build())
-}
-
-async fn dispatch(scenario: &str) -> Result<ProfileResult> {
- match scenario {
- "memory-ingest" => scenarios::memory_ingest::run().await,
- "agent-turn" => scenarios::agent_turn::run().await,
- "long-agent" => scenarios::long_agent::run().await,
- "workflow" => scenarios::workflow::run().await,
- "cold-phases" => scenarios::cold_phases::run().await,
- "fleet" => scenarios::fleet::run().await,
- "skill-run" => scenarios::skill_run::run().await,
- "subagent-storm" => scenarios::subagent_storm::run().await,
- other => anyhow::bail!("unknown scenario: {other}"),
- }
-}
-
-/// Build the tokio runtime. When `OPENHUMAN_PROFILE_WORKER_THREADS` is set the
-/// multi-thread runtime is built manually with that worker count (set to `2` to
-/// simulate the 2 vCPU box); otherwise the standard multi-thread default runs.
-fn build_runtime() -> Result<tokio::runtime::Runtime> {
- let mut builder = tokio::runtime::Builder::new_multi_thread();
- builder.enable_all();
- if let Some(workers) = std::env::var("OPENHUMAN_PROFILE_WORKER_THREADS")
- .ok()
- .and_then(|value| value.parse::<usize>().ok())
- .filter(|n| *n > 0)
- {
- eprintln!("[library-profile] tokio worker_threads={workers}");
- builder.worker_threads(workers);
- }
- builder.build().context("build tokio runtime")
-}
-
-fn main() -> Result<()> {
- // Parse args BEFORE building the runtime so `OPENHUMAN_PROFILE_WORKER_THREADS`
- // can size the worker pool (the `fleet` scenario simulates the 2 vCPU box).
- let scenario = std::env::args().nth(1).context(
- "usage: library-profile \
- <memory-ingest|agent-turn|long-agent|workflow|cold-phases|fleet|\
- skill-run|subagent-storm>",
- )?;
-
- // Profiler must outlive the whole run + the JSON print so its Drop writes
- // the complete heap profile last.
- #[cfg(feature = "rss-bench-dhat")]
- let _dhat = start_dhat(&scenario)?;
-
- eprintln!(
- "[library-profile] pid={} scenario={scenario} start",
- std::process::id()
- );
-
- let runtime = build_runtime()?;
- runtime.block_on(async move {
- #[cfg_attr(not(feature = "rss-bench-dhat"), allow(unused_mut))]
- let mut result = dispatch(&scenario).await?;
-
- #[cfg(feature = "rss-bench-dhat")]
- {
- result.dhat = Some(true);
- }
-
- println!("{}", serde_json::to_string_pretty(&result)?);
-
- if let Some(seconds) = std::env::var("OPENHUMAN_PROFILE_HOLD_SECS")
- .ok()
- .and_then(|value| value.parse::<u64>().ok())
- .filter(|seconds| *seconds > 0)
- {
- eprintln!(
- "[library-profile] pid={} holding for {seconds}s",
- std::process::id()
- );
- tokio::time::sleep(Duration::from_secs(seconds)).await;
- }
- Ok(())
- })
-}
diff --git a/src/bin/library_profile/mock.rs b/src/bin/library_profile/mock.rs
deleted file mode 100644
index 9e7c3fbef2..0000000000
--- a/src/bin/library_profile/mock.rs
+++ /dev/null
@@ -1,498 +0,0 @@
-//! Deterministic offline `ChatModel` mocks installed via
-//! `test_provider_override` (honoured only under the `rss-bench` feature).
-
-use std::sync::atomic::{AtomicU64, Ordering};
-use std::sync::{Arc, Mutex};
-use std::time::Duration;
-
-use async_trait::async_trait;
-use openhuman_core::openhuman::inference::provider::types::{ChatResponse, ToolCall};
-use tinyinference::message::{AssistantMessage, ContentBlock, Message};
-use tinyinference::model::{ChatModel, ModelRequest, ModelResponse};
-use tinyinference::tool::ToolCall as TinyAgentsToolCall;
-
-/// A plain `ChatResponse` carrying only text (no tool calls).
-pub fn response(text: &str) -> ChatResponse {
- ChatResponse {
- text: Some(text.into()),
- tool_calls: Vec::new(),
- usage: None,
- reasoning_content: None,
- }
-}
-
-fn joined_request(request: &ModelRequest) -> String {
- request
- .messages
- .iter()
- .map(|message| {
- let role = match message {
- Message::System(_) => "system",
- Message::User(_) => "user",
- Message::Assistant(_) => "assistant",
- Message::Tool(_) => "tool",
- };
- format!("{role}: {}", message.text())
- })
- .collect::<Vec<_>>()
- .join("\n")
-}
-
-fn model_response(response: ChatResponse) -> ModelResponse {
- let content = response
- .text
- .filter(|text| !text.is_empty())
- .map(|text| vec![ContentBlock::Text(text)])
- .unwrap_or_default();
- let tool_calls = response
- .tool_calls
- .into_iter()
- .map(|call| {
- TinyAgentsToolCall::new(
- call.id,
- call.name,
- serde_json::from_str(&call.arguments).unwrap_or(serde_json::Value::Null),
- )
- })
- .collect::<Vec<_>>();
- ModelResponse {
- finish_reason: (!tool_calls.is_empty()).then(|| "tool_calls".to_string()),
- message: AssistantMessage {
- id: None,
- content,
- tool_calls,
- usage: None,
- },
- usage: None,
- raw: None,
- resolved_model: None,
- continue_turn: None,
- served_from_cache: false,
- }
-}
-
-/// Records every prompt it sees so scenarios can assert what ran.
-fn record(prompts: &Mutex<Vec<String>>, joined: &str) {
- prompts
- .lock()
- .expect("mock prompt lock")
- .push(joined.into());
-}
-
-/// Read `key` as a `u64`, falling back to `default` when unset/unparsable.
-fn env_u64(key: &str, default: u64) -> u64 {
- std::env::var(key)
- .ok()
- .and_then(|value| value.parse::<u64>().ok())
- .unwrap_or(default)
-}
-
-/// Stable per-researcher marker embedded in a delegated subagent's prompt.
-/// Zero-padded so `..._001` is never a substring of `..._011` — the storm mock
-/// routes by exact marker containment across K up to 32.
-pub fn subagent_marker(index: usize) -> String {
- format!("LIB_PROFILE_SUBAGENT_{index:03}")
-}
-
-/// The finding text a delegated researcher returns for `index`. The merge turn
-/// is detected by all K of these being present in the conversation.
-pub fn finding_text(index: usize) -> String {
- format!("Finding {index:03}: researcher {index} reports healthy.")
-}
-
-/// Text the orchestrator returns once it has merged every researcher finding;
-/// its arrival in the parent (subconscious) conversation ends the storm turn.
-pub const MERGE_SENTINEL: &str = "STORM_MERGE_COMPLETE";
-
-/// Shared, dependency-free latency sampler driven by the standard env knobs
-/// (`OPENHUMAN_PROFILE_MOCK_LATENCY_MS` mean, `OPENHUMAN_PROFILE_MOCK_JITTER_MS`
-/// jitter, default `mean / 4`). Reused by both [`LatencyMock`] and
-/// [`SubagentMock`] so a delegated subagent turn can carry realistic latency.
-pub struct LatencyKnobs {
- mean_ms: u64,
- jitter_ms: u64,
- counter: AtomicU64,
-}
-
-impl LatencyKnobs {
- pub fn from_env() -> Self {
- let mean_ms = env_u64("OPENHUMAN_PROFILE_MOCK_LATENCY_MS", 0);
- let jitter_ms = env_u64("OPENHUMAN_PROFILE_MOCK_JITTER_MS", mean_ms / 4);
- eprintln!("[library-profile] LatencyKnobs mean_ms={mean_ms} jitter_ms={jitter_ms}");
- Self {
- mean_ms,
- jitter_ms,
- counter: AtomicU64::new(0),
- }
- }
-
- /// Sample `mean ± jitter` (clamped at zero) via a seeded xorshift step. The
- /// seed advances per call so successive turns get distinct latencies.
- pub fn sample_ms(&self) -> u64 {
- if self.mean_ms == 0 && self.jitter_ms == 0 {
- return 0;
- }
- let seed = self.counter.fetch_add(1, Ordering::Relaxed).wrapping_add(1);
- // xorshift64 — deterministic, dependency-free pseudo-randomness.
- let mut x = seed.wrapping_mul(0x9E37_79B9_7F4A_7C15);
- x ^= x >> 12;
- x ^= x << 25;
- x ^= x >> 27;
- let span = self.jitter_ms.saturating_mul(2).saturating_add(1);
- let delta = (x % span) as i64 - self.jitter_ms as i64;
- (self.mean_ms as i64 + delta).max(0) as u64
- }
-
- /// Sleep a sampled latency and return the ms slept (0 when disabled).
- pub async fn sleep_sampled(&self) -> u64 {
- let ms = self.sample_ms();
- if ms > 0 {
- tokio::time::sleep(Duration::from_millis(ms)).await;
- }
- ms
- }
-}
-
-/// Orchestration mock: the first (orchestrator) turn emits a
-/// `spawn_parallel_agents` tool call fanning out to **K** researchers; each
-/// researcher turn returns its finding; the final merge turn returns plain
-/// text once all K findings are present.
-///
-/// `width` = K parallel researchers. `new()` keeps the original two-researcher
-/// shape (K = 2, no injected latency, driven from the subconscious which has no
-/// `spawn_parallel_agents` — the tool call is rejected and its markers echo
-/// back, which is all the `subagents` scenario asserts). `with_width(k)` drives
-/// the **orchestrator directly** and scripts the full delegation chain, so it
-/// must first hand off via `delegate_orchestrator`-free direct fan-out — this is
-/// the `subagent-storm` fuzz-width path.
-pub struct SubagentMock {
- pub prompts: Mutex<Vec<String>>,
- /// Actual wall-time (ms) of each *researcher* chat call, for percentiles.
- pub researcher_latencies_ms: Mutex<Vec<u128>>,
- width: usize,
- latency: LatencyKnobs,
- /// `true` for `with_width` (orchestrator-driven storm): route the full
- /// agent-aware chain. `false` for `new` (subconscious-driven `subagents`):
- /// the original simple routing that emits the fan-out directly.
- orchestrator_driven: bool,
- /// Increments per fan-out so successive `spawn_parallel_agents` calls carry
- /// distinct task prompts.
- spawn_nonce: AtomicU64,
-}
-
-impl SubagentMock {
- /// K researchers with per-researcher latency drawn from the env knobs, driven
- /// directly against the orchestrator agent (full agent-aware chain).
- pub fn with_width(width: usize) -> Arc<Self> {
- Arc::new(Self {
- prompts: Mutex::new(Vec::new()),
- researcher_latencies_ms: Mutex::new(Vec::new()),
- width: width.max(1),
- latency: LatencyKnobs::from_env(),
- orchestrator_driven: true,
- spawn_nonce: AtomicU64::new(0),
- })
- }
-
- /// Which researcher (1-based) this prompt is for, if any. A researcher
- /// prompt embeds exactly one `subagent_marker`.
- fn researcher_index(&self, joined: &str) -> Option<usize> {
- (1..=self.width).find(|&i| joined.contains(&subagent_marker(i)))
- }
-
- /// True once every researcher's finding is present — the merge turn.
- fn is_merge(&self, joined: &str) -> bool {
- (1..=self.width).all(|i| joined.contains(&finding_text(i)))
- }
-
- /// True when this call is a real researcher worker turn: exactly one task
- /// marker is present and the executing agent is neither the orchestrator nor
- /// the subconscious (their Tool Policy Boundary headers name them, and their
- /// merge/echo turns also carry every marker). The researcher agent's system
- /// prompt names it `Researcher`, so it matches neither header string.
- fn is_researcher_turn(&self, joined: &str) -> bool {
- self.researcher_index(joined).is_some()
- && !joined.contains("Agent: orchestrator")
- && !joined.contains("Agent: subconscious")
- }
-
- /// Build the fan-out tool call delegating to K parallel researchers. Only
- /// valid on an **orchestrator** turn — the subconscious has no
- /// `spawn_parallel_agents` tool, so we `delegate_orchestrator` there first.
- fn spawn_call(&self) -> ChatResponse {
- let nonce = self.spawn_nonce.fetch_add(1, Ordering::Relaxed);
- let tasks: Vec<serde_json::Value> = (1..=self.width)
- .map(|i| {
- serde_json::json!({
- "agent_id": "researcher",
- // The nonce keeps each fan-out's tasks byte-distinct so the
- // parallel-graph result cache can't short-circuit a re-spawn.
- "prompt": format!("{} [spawn {nonce}]: inspect subsystem {i}", subagent_marker(i)),
- "ownership": format!("scope: subsystem-{i}-spawn-{nonce}")
- })
- })
- .collect();
- ChatResponse {
- text: Some(format!("Delegating to {} researchers.", self.width)),
- tool_calls: vec![ToolCall {
- id: "profile-parallel-call".into(),
- name: "spawn_parallel_agents".into(),
- arguments: serde_json::json!({ "tasks": tasks }).to_string(),
- extra_content: None,
- }],
- usage: None,
- reasoning_content: None,
- }
- }
-
- /// The subconscious's first turn: hand the task to the orchestrator (which
- /// owns `spawn_parallel_agents` and allows the `researcher` subagent).
- fn delegate_orchestrator_call(&self) -> ChatResponse {
- ChatResponse {
- text: Some("Delegating to the orchestrator for a parallel research fan-out.".into()),
- tool_calls: vec![ToolCall {
- id: "profile-delegate-orchestrator".into(),
- name: "delegate_orchestrator".into(),
- arguments: serde_json::json!({
- "prompt": "Research every subsystem in parallel and merge the findings."
- })
- .to_string(),
- extra_content: None,
- }],
- usage: None,
- reasoning_content: None,
- }
- }
-
- /// Classify the turn by the *executing agent* (from the Tool Policy Boundary
- /// header) and script the real delegation chain:
- /// subconscious → `delegate_orchestrator` → orchestrator →
- /// `spawn_parallel_agents(K)` → K researchers → orchestrator merge →
- /// subconscious final. No latency/recording here — the async `chat` wrappers
- /// handle sleeping + latency capture around this.
- fn reply(&self, joined: &str) -> ChatResponse {
- if self.orchestrator_driven {
- return self.reply_orchestrator_driven(joined);
- }
- // Original `subagents` routing (subconscious-driven): merge once both
- // findings are present, answer a researcher's marker with its finding,
- // else emit the fan-out directly. The subconscious rejects the unknown
- // `spawn_parallel_agents`, echoing the markers back — which is all the
- // `subagents` scenario asserts.
- if self.is_merge(joined) {
- return response("Merged all researcher findings.");
- }
- if let Some(i) = self.researcher_index(joined) {
- return response(&finding_text(i));
- }
- self.spawn_call()
- }
-
- /// Agent-aware routing for the orchestrator-driven storm.
- fn reply_orchestrator_driven(&self, joined: &str) -> ChatResponse {
- // Researcher worker: return its finding.
- if self.is_researcher_turn(joined) {
- let i = self
- .researcher_index(joined)
- .expect("researcher turn has a marker");
- return response(&finding_text(i));
- }
- // Orchestrator: fan out, then merge once every finding is back.
- if joined.contains("Agent: orchestrator") {
- if self.is_merge(joined) {
- return response(MERGE_SENTINEL);
- }
- return self.spawn_call();
- }
- // Parent (subconscious / any other): finish once the orchestrator's
- // merged result has flowed back; otherwise delegate to the orchestrator.
- if joined.contains(MERGE_SENTINEL) {
- return response("Storm complete: merged every researcher's finding.");
- }
- self.delegate_orchestrator_call()
- }
-}
-
-#[async_trait]
-impl ChatModel<()> for SubagentMock {
- async fn invoke(
- &self,
- _state: &(),
- request: ModelRequest,
- ) -> Result<ModelResponse, tinyinference::Error> {
- Ok(model_response(
- self.dispatch(&joined_request(&request)).await,
- ))
- }
-}
-
-impl SubagentMock {
- /// Record the prompt, sleep a sampled latency for *researcher* calls (and
- /// capture their wall time), then return the classified response.
- async fn dispatch(&self, joined: &str) -> ChatResponse {
- record(&self.prompts, joined);
- let is_researcher = self.is_researcher_turn(joined);
- let started = std::time::Instant::now();
- if is_researcher {
- self.latency.sleep_sampled().await;
- }
- let resp = self.reply(joined);
- if is_researcher {
- self.researcher_latencies_ms
- .lock()
- .expect("mock latency lock")
- .push(started.elapsed().as_millis());
- }
- resp
- }
-}
-
-/// Latency-configurable text-only mock used by the `fleet` scenario. Before
-/// returning its fixed answer it sleeps a sampled latency: a mean from
-/// `OPENHUMAN_PROFILE_MOCK_LATENCY_MS` (default `0` = no sleep) with jitter
-/// `± OPENHUMAN_PROFILE_MOCK_JITTER_MS` (default `mean / 4`). Per-call jitter is
-/// derived from a seeded xorshift counter — deterministic and dependency-free
-/// (no `rand` crate).
-pub struct LatencyMock {
- text: String,
- latency: LatencyKnobs,
- pub prompts: Mutex<Vec<String>>,
-}
-
-impl LatencyMock {
- /// Build from the standard env knobs.
- pub fn from_env(text: impl Into<String>) -> Arc<Self> {
- Arc::new(Self {
- text: text.into(),
- latency: LatencyKnobs::from_env(),
- prompts: Mutex::new(Vec::new()),
- })
- }
-}
-
-#[async_trait]
-impl ChatModel<()> for LatencyMock {
- async fn invoke(
- &self,
- _state: &(),
- request: ModelRequest,
- ) -> Result<ModelResponse, tinyinference::Error> {
- self.latency.sleep_sampled().await;
- let joined = joined_request(&request);
- record(&self.prompts, &joined);
- Ok(model_response(response(&self.text)))
- }
-}
-
-/// Text-only mock: always returns a fixed direct answer, never a tool call.
-/// Used by the single-turn / workflow scenarios that must NOT delegate.
-pub struct PlainTextMock {
- text: String,
- pub prompts: Mutex<Vec<String>>,
-}
-
-impl PlainTextMock {
- pub fn new(text: impl Into<String>) -> Arc<Self> {
- Arc::new(Self {
- text: text.into(),
- prompts: Mutex::new(Vec::new()),
- })
- }
-}
-
-#[async_trait]
-impl ChatModel<()> for PlainTextMock {
- async fn invoke(
- &self,
- _state: &(),
- request: ModelRequest,
- ) -> Result<ModelResponse, tinyinference::Error> {
- let joined = joined_request(&request);
- record(&self.prompts, &joined);
- Ok(model_response(response(&self.text)))
- }
-}
-
-/// The stdout marker the profiling `node` step prints. Its presence in the run
-/// conversation proves the real interpreter child executed (not merely that a
-/// tool call was emitted).
-pub const NODE_MARKER: &str = "PROFILE_NODE_RESULT";
-
-/// Skill-run mock: the first turn emits a `node_exec` tool call running a short,
-/// real JavaScript computation (which spawns a genuine `node` child process);
-/// once its printed JSON (carrying [`NODE_MARKER`]) rides back into the
-/// conversation, the mock returns a plain final answer so the agent turn
-/// completes. This scripts exactly the tool call the code-executor specialist
-/// needs to spawn the language runtime whose cost we measure.
-pub struct SkillRunMock {
- code: String,
- node_call_emitted: AtomicU64,
- node_output_seen: AtomicU64,
- pub prompts: Mutex<Vec<String>>,
-}
-
-impl SkillRunMock {
- pub fn new() -> Arc<Self> {
- // A real computation, a live allocation, and a ~1.2s busy-wait so the
- // child stays resident long enough for the tree sampler (15 ms poll) to
- // catch it. The JSON it prints carries NODE_MARKER.
- let code = format!(
- "const start = Date.now();\n\
- const buf = [];\n\
- let sum = 0;\n\
- for (let i = 0; i < 500000; i++) {{ buf.push(i % 97); sum += i; }}\n\
- while (Date.now() - start < 1200) {{ sum += buf.length; }}\n\
- console.log(JSON.stringify({{ marker: '{NODE_MARKER}', sum, kept: buf.length }}));\n"
- );
- Arc::new(Self {
- code,
- node_call_emitted: AtomicU64::new(0),
- node_output_seen: AtomicU64::new(0),
- prompts: Mutex::new(Vec::new()),
- })
- }
-
- /// True once the `node_exec` tool call has been emitted.
- pub fn node_call_emitted(&self) -> bool {
- self.node_call_emitted.load(Ordering::Relaxed) > 0
- }
-
- /// True once the node child's printed output flowed back into the turn —
- /// i.e. the interpreter child actually ran and printed.
- pub fn node_output_seen(&self) -> bool {
- self.node_output_seen.load(Ordering::Relaxed) > 0
- }
-
- fn reply(&self, joined: &str) -> ChatResponse {
- record(&self.prompts, joined);
- if joined.contains(NODE_MARKER) {
- self.node_output_seen.store(1, Ordering::Relaxed);
- return response(
- "Skill complete: the Node.js step computed the value and it checks out.",
- );
- }
- self.node_call_emitted.store(1, Ordering::Relaxed);
- ChatResponse {
- text: Some("Running the JavaScript computation step.".into()),
- tool_calls: vec![ToolCall {
- id: "profile-node-call".into(),
- name: "node_exec".into(),
- arguments: serde_json::json!({ "inline_code": self.code }).to_string(),
- extra_content: None,
- }],
- usage: None,
- reasoning_content: None,
- }
- }
-}
-
-#[async_trait]
-impl ChatModel<()> for SkillRunMock {
- async fn invoke(
- &self,
- _state: &(),
- request: ModelRequest,
- ) -> Result<ModelResponse, tinyinference::Error> {
- Ok(model_response(self.reply(&joined_request(&request))))
- }
-}
diff --git a/src/bin/library_profile/scenarios/agent_turn.rs b/src/bin/library_profile/scenarios/agent_turn.rs
deleted file mode 100644
index ff565c8d3f..0000000000
--- a/src/bin/library_profile/scenarios/agent_turn.rs
+++ /dev/null
@@ -1,31 +0,0 @@
-//! `agent-turn`: the minimal "embed OpenHuman as a library" unit — a single
-//! cold agent turn built directly from config, with a plain-text mock provider
-//! (no tool calls, no delegation).
-
-use anyhow::Result;
-use openhuman_core::openhuman::agent::harness::AgentDefinitionRegistry;
-use openhuman_core::openhuman::agent::Agent;
-use openhuman_core::openhuman::inference::provider::factory::test_provider_override;
-
-use crate::harness::{fixture, measure, ProfileResult};
-use crate::mock::PlainTextMock;
-
-pub async fn run() -> Result<ProfileResult> {
- let fixture = fixture()?;
- openhuman_core::core::bus::init().await.expect("bus init");
- openhuman_core::openhuman::agent::bus::register_agent_handlers();
- let _ = AgentDefinitionRegistry::init_global_builtins();
- let mock = PlainTextMock::new("The Phoenix migration is healthy and on track.");
- let _provider = test_provider_override::install_model(mock.clone());
- eprintln!("[library-profile] agent-turn: registries ready, mock installed");
-
- measure("agent-turn", 1, None, |_rec| async {
- let mut agent = Agent::from_config_for_agent(&fixture.config, "subconscious")?;
- let reply = agent
- .run_single("Give me a one-line status on the Phoenix migration.")
- .await?;
- anyhow::ensure!(!reply.trim().is_empty(), "empty agent reply");
- Ok(())
- })
- .await
-}
diff --git a/src/bin/library_profile/scenarios/cold_phases.rs b/src/bin/library_profile/scenarios/cold_phases.rs
deleted file mode 100644
index b582e71c73..0000000000
--- a/src/bin/library_profile/scenarios/cold_phases.rs
+++ /dev/null
@@ -1,90 +0,0 @@
-//! `cold-phases`: sequential per-phase checkpoints of the cold bootstrap, all
-//! inside one measured region. Each phase is sampled right after it completes
-//! so the JSON `checkpoints` series attributes the cold-start cost per phase.
-//!
-//! # Why this still names the engine crate (#5560)
-//!
-//! Phase (e) exists to time **opening the SQLite memory store**, and
-//! `MemoryClient` is the thing that opens it. `memory::binding::for_config`
-//! would resolve the null driver in this binary — no module is loaded — so the
-//! checkpoint would report the cost of binding a driver that opens nothing, and
-//! the cold-start series would silently lose its heaviest I/O phase rather than
-//! gain a migration. `MemoryClient` is also `tinymemory-core`'s own type, not a
-//! re-export of a TinyCortex one, so there is no path swap available either.
-//!
-//! Same conclusion as the sibling `memory_ingest` scenario: this is a
-//! **feature-gate** case, not a migration. See that module's note for what the
-//! manifest needs (`tinymemory-core` optional, enabled by `rss-bench`).
-
-use std::time::Duration;
-
-use anyhow::Result;
-use openhuman_core::openhuman::agent::harness::AgentDefinitionRegistry;
-use openhuman_core::openhuman::agent::Agent;
-use openhuman_core::openhuman::inference::provider::factory::test_provider_override;
-use tinymemory_core::store::MemoryClient;
-
-use crate::harness::{fixture, measure, ProfileResult};
-use crate::mock::PlainTextMock;
-
-/// config, event-bus, agent-registry, detectors, memory-store, agent-build,
-/// first-turn, warm-turn, teardown.
-const PHASE_COUNT: usize = 9;
-
-pub async fn run() -> Result<ProfileResult> {
- measure("cold-phases", PHASE_COUNT, None, |rec| async move {
- // a. config — hermetic fixture parse (see deviation note in the report:
- // kept as fixture parsing rather than `Config::load_or_init` to
- // guarantee we never touch the real ~/.openhuman).
- let fixture = fixture()?;
- rec.checkpoint("config-parse")?;
-
- // b. event-bus (plus agent-handler registration so turns can run).
- openhuman_core::core::bus::init().await.expect("bus init");
- openhuman_core::openhuman::agent::bus::register_agent_handlers();
- rec.checkpoint("event-bus")?;
-
- // c. agent-registry.
- let _ = AgentDefinitionRegistry::init_global_builtins();
- rec.checkpoint("agent-registry")?;
-
- // d. detectors — force the lazy PII + prompt-injection statics.
- let _ = openhuman_core::openhuman::security::pii::scan("");
- let _ =
- openhuman_core::openhuman::security::prompt_injection::scan_tool_definition("x", "");
- rec.checkpoint("detectors")?;
-
- // e. memory-store — build and hold a unified-memory client until teardown.
- let mem = MemoryClient::from_workspace_dir(fixture.config.workspace_dir.clone())
- .map_err(anyhow::Error::msg)?;
- rec.checkpoint("memory-store")?;
-
- // Model mock for the two turns below (not itself a phase).
- let mock = PlainTextMock::new("Phoenix migration is healthy and on track.");
- let _provider = test_provider_override::install_model(mock.clone());
-
- // f. agent-build.
- let mut agent = Agent::from_config_for_agent(&fixture.config, "subconscious")?;
- rec.checkpoint("agent-build")?;
-
- // g. first-turn (cold).
- let first = agent
- .run_single("Give me a one-line status on the Phoenix migration.")
- .await?;
- anyhow::ensure!(!first.trim().is_empty(), "empty first-turn reply");
- rec.checkpoint("first-turn")?;
-
- // h. warm-turn (second, same agent).
- let warm = agent.run_single("Any change since the last check?").await?;
- anyhow::ensure!(!warm.trim().is_empty(), "empty warm-turn reply");
- rec.checkpoint("warm-turn")?;
-
- // i. teardown — drop the agent + memory client, settle, sample.
- drop(agent);
- drop(mem);
- tokio::time::sleep(Duration::from_millis(300)).await;
- rec.checkpoint("teardown")?;
- Ok(())
- })
- .await
-}
diff --git a/src/bin/library_profile/scenarios/fleet.rs b/src/bin/library_profile/scenarios/fleet.rs
deleted file mode 100644
index bd6dc86780..0000000000
--- a/src/bin/library_profile/scenarios/fleet.rs
+++ /dev/null
@@ -1,297 +0,0 @@
-//! `fleet`: can OpenHuman host 100–1000 live agents on a 2 GB / 2 vCPU box?
-//!
-//! Answers four questions in one process: (1) marginal RSS per live agent
-//! (`baseline → constructed`), (2) idle CPU of parked agents (CPU delta over a
-//! 10 s do-nothing window), (3) thread + fd growth vs N (rides along in
-//! `ProcSample`), and (4) turn latency percentiles under overlapping load.
-//!
-//! Env knobs:
-//! - `OPENHUMAN_PROFILE_AGENTS` (default 100) — live agents to construct.
-//! - `OPENHUMAN_PROFILE_TURNS` (default 3) — turns per agent under load.
-//! - `OPENHUMAN_PROFILE_MOCK_LATENCY_MS` / `_JITTER_MS` — mock reply latency.
-//! - `OPENHUMAN_PROFILE_TARGET_AGENTS` (default 1000) — budget projection target.
-//! - `OPENHUMAN_PROFILE_RAM_BUDGET_MIB` (default 2048) — budget ceiling.
-//!
-//! `OPENHUMAN_PROFILE_WORKER_THREADS` is honoured in `main` (runtime built
-//! manually) rather than here.
-
-use std::sync::{Arc, Mutex};
-use std::time::{Duration, Instant};
-
-use anyhow::Result;
-use openhuman_core::openhuman::agent::harness::AgentDefinitionRegistry;
-use openhuman_core::openhuman::agent::Agent;
-use openhuman_core::openhuman::inference::provider::factory::test_provider_override;
-use openhuman_core::openhuman::platform::proc_metrics;
-
-use crate::harness::{fixture, measure, FleetBudget, ProfileResult, Recorder, TurnLatency};
-use crate::mock::LatencyMock;
-
-const DEFAULT_AGENTS: usize = 100;
-const DEFAULT_TURNS: usize = 3;
-const DEFAULT_TARGET_AGENTS: u64 = 1000;
-const DEFAULT_RAM_BUDGET_MIB: u64 = 2048;
-const IDLE_WINDOW: Duration = Duration::from_secs(10);
-
-fn env_usize(key: &str, default: usize) -> usize {
- std::env::var(key)
- .ok()
- .and_then(|v| v.parse::<usize>().ok())
- .filter(|n| *n > 0)
- .unwrap_or(default)
-}
-
-fn env_u64(key: &str, default: u64) -> u64 {
- std::env::var(key)
- .ok()
- .and_then(|v| v.parse::<u64>().ok())
- .filter(|n| *n > 0)
- .unwrap_or(default)
-}
-
-/// Raise `RLIMIT_NOFILE` toward its hard cap so N agents (each opening SQLite
-/// etc.) don't exhaust the default macOS 256 soft limit. Logs old/new to stderr.
-fn raise_fd_limit() {
- use std::mem::MaybeUninit;
- let mut lim = MaybeUninit::<libc::rlimit>::uninit();
- // SAFETY: `getrlimit` initialises `lim` on success.
- if unsafe { libc::getrlimit(libc::RLIMIT_NOFILE, lim.as_mut_ptr()) } != 0 {
- eprintln!("[library-profile] fleet: getrlimit(RLIMIT_NOFILE) failed");
- return;
- }
- // SAFETY: initialised by the successful `getrlimit`.
- let mut lim = unsafe { lim.assume_init() };
- let old_soft = lim.rlim_cur;
- lim.rlim_cur = lim.rlim_max;
- // SAFETY: raising the soft limit to the existing hard limit is always valid.
- let rc = unsafe { libc::setrlimit(libc::RLIMIT_NOFILE, &lim) };
- eprintln!(
- "[library-profile] fleet: RLIMIT_NOFILE soft {old_soft} -> {} (hard {}) setrlimit_rc={rc}",
- lim.rlim_cur, lim.rlim_max
- );
-}
-
-/// Shared metrics captured inside the measured closure and read back after.
-#[derive(Default)]
-struct FleetMetrics {
- agents_built: usize,
- baseline_rss_kib: u64,
- constructed_rss_kib: u64,
- idle_cpu_ms: u64,
- latency_ms: Vec<u128>,
-}
-
-/// Percentile (nearest-rank) of an already-sorted slice. `p` in `[0,100]`.
-fn percentile(sorted: &[u128], p: u128) -> u128 {
- if sorted.is_empty() {
- return 0;
- }
- let rank = ((p * sorted.len() as u128) + 99) / 100; // ceil(p% * n)
- let idx = rank.saturating_sub(1).min(sorted.len() as u128 - 1) as usize;
- sorted[idx]
-}
-
-fn latency_summary(mut samples: Vec<u128>) -> Option<TurnLatency> {
- if samples.is_empty() {
- return None;
- }
- samples.sort_unstable();
- Some(TurnLatency {
- p50: percentile(&samples, 50),
- p95: percentile(&samples, 95),
- p99: percentile(&samples, 99),
- max: *samples.last().unwrap(),
- })
-}
-
-/// Build agents sequentially, checkpointing the marginal-RSS curve. On a
-/// mid-construction failure, records `construction-failed-<count>` and returns
-/// what was built rather than crashing.
-fn build_agents(
- config: &openhuman_core::openhuman::config::Config,
- n: usize,
- rec: &Recorder,
-) -> Result<Vec<Agent>> {
- let stride = (n / 10).max(1);
- let mut agents = Vec::with_capacity(n);
- for i in 0..n {
- match Agent::from_config_for_agent(config, "subconscious") {
- Ok(agent) => agents.push(agent),
- Err(err) => {
- eprintln!(
- "[library-profile] fleet: construction failed at agent {} — {err}",
- i + 1
- );
- rec.checkpoint(format!("construction-failed-{}", agents.len()))?;
- break;
- }
- }
- let built = i + 1;
- if built % stride == 0 || built == n {
- rec.checkpoint(format!("built-{built}"))?;
- }
- }
- Ok(agents)
-}
-
-pub async fn run() -> Result<ProfileResult> {
- let agents_requested = env_usize("OPENHUMAN_PROFILE_AGENTS", DEFAULT_AGENTS);
- let turns = env_usize("OPENHUMAN_PROFILE_TURNS", DEFAULT_TURNS);
- let target_agents = env_u64("OPENHUMAN_PROFILE_TARGET_AGENTS", DEFAULT_TARGET_AGENTS);
- let ram_budget_mib = env_u64("OPENHUMAN_PROFILE_RAM_BUDGET_MIB", DEFAULT_RAM_BUDGET_MIB);
-
- raise_fd_limit();
-
- let fixture = fixture()?;
- openhuman_core::core::bus::init().await.expect("bus init");
- openhuman_core::openhuman::agent::bus::register_agent_handlers();
- let _ = AgentDefinitionRegistry::init_global_builtins();
- let mock = LatencyMock::from_env("Fleet agent: nothing needs your attention.");
- let _provider = test_provider_override::install_model(mock.clone());
- eprintln!(
- "[library-profile] fleet: agents={agents_requested} turns={turns} \
- target={target_agents} budget_mib={ram_budget_mib}"
- );
-
- let metrics = Arc::new(Mutex::new(FleetMetrics::default()));
- let config = fixture.config.clone();
- let metrics_for_workload = Arc::clone(&metrics);
-
- let mut result = measure(
- "fleet",
- agents_requested,
- Some(turns),
- move |rec| async move {
- rec.checkpoint("baseline")?;
- let baseline_rss = proc_metrics::sample_self()?.rss_kib;
-
- // (b) construct N agents sequentially, curve visible via checkpoints.
- let mut agents = build_agents(&config, agents_requested, &rec)?;
- let agents_built = agents.len();
- rec.checkpoint("constructed")?;
- let constructed_rss = proc_metrics::sample_self()?.rss_kib;
-
- {
- let mut m = metrics_for_workload.lock().expect("metrics lock");
- m.agents_built = agents_built;
- m.baseline_rss_kib = baseline_rss;
- m.constructed_rss_kib = constructed_rss;
- }
- eprintln!(
- "[library-profile] fleet: built {agents_built}/{agents_requested} agents; \
- baseline_rss={baseline_rss} constructed_rss={constructed_rss}"
- );
-
- // (d) idle phase — park all agents, measure CPU drift over 10 s.
- rec.checkpoint("idle-start")?;
- let idle_start = proc_metrics::sample_self()?;
- tokio::time::sleep(IDLE_WINDOW).await;
- rec.checkpoint("idle-end")?;
- let idle_end = proc_metrics::sample_self()?;
- let idle_cpu_ms = (idle_end.cpu_user_ms + idle_end.cpu_system_ms)
- .saturating_sub(idle_start.cpu_user_ms + idle_start.cpu_system_ms);
- metrics_for_workload
- .lock()
- .expect("metrics lock")
- .idle_cpu_ms = idle_cpu_ms;
- eprintln!("[library-profile] fleet: idle CPU over 10s = {idle_cpu_ms} ms");
-
- // (e) load phase — TURNS turns per agent, one task each, staggered.
- let mut handles = Vec::with_capacity(agents.len());
- for (idx, mut agent) in agents.drain(..).enumerate() {
- let stagger = Duration::from_millis(((idx as u64) * 10).min(2000));
- handles.push(tokio::spawn(async move {
- tokio::time::sleep(stagger).await;
- let mut latencies = Vec::with_capacity(turns);
- for _ in 0..turns {
- let started = Instant::now();
- let reply = agent.run_single("Give me a one-line status update.").await;
- let elapsed = started.elapsed().as_millis();
- match reply {
- Ok(text) if !text.trim().is_empty() => latencies.push(elapsed),
- Ok(_) => eprintln!("[library-profile] fleet: empty reply agent={idx}"),
- Err(err) => {
- eprintln!("[library-profile] fleet: turn error agent={idx} — {err}")
- }
- }
- }
- latencies
- }));
- }
-
- let mut all_latencies = Vec::new();
- for handle in handles {
- match handle.await {
- Ok(mut latencies) => all_latencies.append(&mut latencies),
- Err(err) => eprintln!("[library-profile] fleet: task join error — {err}"),
- }
- }
- metrics_for_workload
- .lock()
- .expect("metrics lock")
- .latency_ms = all_latencies;
- rec.checkpoint("load-done")?;
- Ok(())
- },
- )
- .await?;
-
- // Fold fleet-specific metrics into the pinned result.
- let metrics = Arc::try_unwrap(metrics)
- .map(|m| m.into_inner().expect("metrics lock"))
- .unwrap_or_default();
-
- let agents_built = metrics.agents_built;
- let marginal = if agents_built > 0 {
- Some(
- (metrics.constructed_rss_kib as f64 - metrics.baseline_rss_kib as f64)
- / agents_built as f64,
- )
- } else {
- None
- };
-
- // (4) budget projection: settled base + marginal * target.
- let base_mib = metrics.baseline_rss_kib as f64 / 1024.0;
- let marginal_mib = marginal.unwrap_or(0.0) / 1024.0;
- let projected = base_mib + marginal_mib * target_agents as f64;
- let budget = FleetBudget {
- target_agents,
- ram_budget_mib,
- projected_rss_mib_at_target: projected,
- fits: projected <= ram_budget_mib as f64,
- };
-
- result.agents = Some(agents_requested);
- result.agents_built = Some(agents_built);
- result.marginal_rss_kib_per_agent = marginal;
- result.idle_cpu_ms = Some(metrics.idle_cpu_ms);
- result.turn_latency_ms = latency_summary(metrics.latency_ms);
- result.budget = Some(budget);
- Ok(result)
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn percentiles_nearest_rank() {
- let mut v: Vec<u128> = (1..=100).collect();
- v.sort_unstable();
- assert_eq!(percentile(&v, 50), 50);
- assert_eq!(percentile(&v, 95), 95);
- assert_eq!(percentile(&v, 99), 99);
- assert_eq!(percentile(&v, 100), 100);
- assert_eq!(percentile(&[], 50), 0);
- assert_eq!(percentile(&[7], 99), 7);
- }
-
- #[test]
- fn latency_summary_none_when_empty() {
- assert!(latency_summary(Vec::new()).is_none());
- let s = latency_summary(vec![10, 20, 30]).unwrap();
- assert_eq!(s.max, 30);
- assert_eq!(s.p50, 20);
- }
-}
diff --git a/src/bin/library_profile/scenarios/long_agent.rs b/src/bin/library_profile/scenarios/long_agent.rs
deleted file mode 100644
index 7f7c88e202..0000000000
--- a/src/bin/library_profile/scenarios/long_agent.rs
+++ /dev/null
@@ -1,53 +0,0 @@
-//! `long-agent`: steady-state many-turn loop on ONE warmed agent — models a
-//! long-running opencompany agent. Builds the agent and runs one warm-up turn
-//! BEFORE the measured region, then runs N sequential turns inside it, pushing
-//! a per-turn checkpoint so the plateau/leak curve is visible.
-
-use anyhow::Result;
-use openhuman_core::openhuman::agent::harness::AgentDefinitionRegistry;
-use openhuman_core::openhuman::agent::Agent;
-use openhuman_core::openhuman::inference::provider::factory::test_provider_override;
-
-use crate::harness::{fixture, measure, ProfileResult};
-use crate::mock::PlainTextMock;
-
-const DEFAULT_TURNS: usize = 25;
-
-const PROMPTS: &[&str] = &[
- "Summarise today's Phoenix migration standup in one line.",
- "What is the current staging p99 latency and error rate?",
- "Who owns the rollback runbook and on-call coordination?",
- "When does the phoenix_v2_enabled flag ramp, and what gates it?",
- "Draft a one-sentence status update for the billing-ledger team.",
-];
-
-pub async fn run() -> Result<ProfileResult> {
- let turns = std::env::var("OPENHUMAN_PROFILE_TURNS")
- .ok()
- .and_then(|value| value.parse::<usize>().ok())
- .filter(|n| *n > 0)
- .unwrap_or(DEFAULT_TURNS);
-
- let fixture = fixture()?;
- openhuman_core::core::bus::init().await.expect("bus init");
- openhuman_core::openhuman::agent::bus::register_agent_handlers();
- let _ = AgentDefinitionRegistry::init_global_builtins();
- let mock = PlainTextMock::new("Phoenix migration is healthy; no action needed.");
- let _provider = test_provider_override::install_model(mock.clone());
-
- let mut agent = Agent::from_config_for_agent(&fixture.config, "subconscious")?;
- eprintln!("[library-profile] long-agent: warming agent with one pre-measure turn");
- let warm = agent.run_single("Warm-up: confirm you are ready.").await?;
- anyhow::ensure!(!warm.trim().is_empty(), "empty warm-up reply");
-
- measure("long-agent", turns, Some(turns), move |rec| async move {
- for i in 0..turns {
- let prompt = PROMPTS[i % PROMPTS.len()];
- let reply = agent.run_single(prompt).await?;
- anyhow::ensure!(!reply.trim().is_empty(), "empty reply on turn {i}");
- rec.checkpoint(format!("turn-{i}"))?;
- }
- Ok(())
- })
- .await
-}
diff --git a/src/bin/library_profile/scenarios/memory_ingest.rs b/src/bin/library_profile/scenarios/memory_ingest.rs
deleted file mode 100644
index 9ddf890ae9..0000000000
--- a/src/bin/library_profile/scenarios/memory_ingest.rs
+++ /dev/null
@@ -1,75 +0,0 @@
-//! `memory-ingest`: canonicalise and ingest 100 chat messages, then drain the
-//! real extraction/admission/tree queue.
-//!
-//! # Why this still names the engine crate (#5560)
-//!
-//! It is measuring the in-process engine on purpose, and routing it through
-//! `memory::binding` would not be a migration — it would be a different
-//! measurement. `MemoryIngest::ingest_chat` on the contract hands items to
-//! whatever driver the workspace bound, which in this binary is the **null**
-//! driver (no module is loaded), so the number would be the cost of doing
-//! nothing. And `queue::drain_until_idle` has no contract member at all: the
-//! queue is not a capability family, and the point of this scenario is that the
-//! extraction/admission/tree jobs actually run before the timer stops.
-//!
-//! So the honest fix here is a **feature gate, not a migration** — this binary
-//! carries `required-features = ["rss-bench"]` and is local/dev only, and
-//! `rss-bench` is deliberately absent from `scripts/ci/product-features.txt`,
-//! so nothing here is in the shipped product graph. What it needs from the
-//! manifest is for `tinymemory-core` to become `optional = true` with
-//! `rss-bench` enabling it; a bin target cannot use dev-dependencies, so
-//! demoting the crate to dev-only without that would break this build with the
-//! gate on, in a configuration no CI lane compiles.
-
-use anyhow::Result;
-use chrono::{TimeZone, Utc};
-use tinycortex::memory::ingest::canonicalize::chat::{ChatBatch, ChatMessage};
-use tinymemory_core::ingest_pipeline::ingest_chat;
-use tinymemory_core::queue::drain_until_idle;
-
-use crate::harness::{fixture, measure, ProfileResult};
-
-const INGEST_MESSAGE_COUNT: usize = 100;
-
-fn ingestion_batch() -> ChatBatch {
- let messages = (0..INGEST_MESSAGE_COUNT)
- .map(|index| ChatMessage {
- author: if index % 2 == 0 { "alice" } else { "bob" }.into(),
- timestamp: Utc
- .timestamp_millis_opt(1_700_000_000_000 + index as i64 * 60_000)
- .single()
- .expect("valid profile timestamp"),
- text: format!(
- "Phoenix migration update {index}: staging p99 is 12ms and error rate is 0.001%. \
- Alice owns the rollback runbook, Bob owns on-call coordination, and the \
- phoenix_v2_enabled flag ramps Friday after billing-ledger verification."
- ),
- source_ref: Some(format!("profile://message/{index}")),
- })
- .collect();
- ChatBatch {
- platform: "profile".into(),
- channel_label: "library-benchmark".into(),
- messages,
- }
-}
-
-pub async fn run() -> Result<ProfileResult> {
- let fixture = fixture()?;
- openhuman_core::core::bus::init().await.expect("bus init");
- eprintln!("[library-profile] memory-ingest: fixture + event bus ready");
- measure("memory-ingest", INGEST_MESSAGE_COUNT, None, |_rec| async {
- let result = ingest_chat(
- &fixture.config,
- "profile:chat:100",
- "profile-user",
- vec!["profile".into()],
- ingestion_batch(),
- )
- .await?;
- anyhow::ensure!(result.chunks_written > 0, "ingestion wrote no chunks");
- drain_until_idle(&fixture.config).await?;
- Ok(())
- })
- .await
-}
diff --git a/src/bin/library_profile/scenarios/mod.rs b/src/bin/library_profile/scenarios/mod.rs
deleted file mode 100644
index 2c612d6800..0000000000
--- a/src/bin/library_profile/scenarios/mod.rs
+++ /dev/null
@@ -1,11 +0,0 @@
-//! One module per profiling scenario. Each exposes a single
-//! `run() -> Result<ProfileResult>` entry point dispatched from `main`.
-
-pub mod agent_turn;
-pub mod cold_phases;
-pub mod fleet;
-pub mod long_agent;
-pub mod memory_ingest;
-pub mod skill_run;
-pub mod subagent_storm;
-pub mod workflow;
diff --git a/src/bin/library_profile/scenarios/skill_run.rs b/src/bin/library_profile/scenarios/skill_run.rs
deleted file mode 100644
index 87efa05279..0000000000
--- a/src/bin/library_profile/scenarios/skill_run.rs
+++ /dev/null
@@ -1,241 +0,0 @@
-//! `skill-run`: the true, process-*tree* cost of a skill step that executes on
-//! a real language runtime — the interpreter child process included — and the
-//! regression instrument for the shared runtime pool (issue #5106).
-//!
-//! ## What it actually runs
-//!
-//! A skill run's orchestrator (`spawn_workflow_run_background` → the
-//! `orchestrator` agent) deliberately owns **no** `node_exec` tool: the
-//! chat-tier orchestrator never executes code itself, it delegates every code
-//! step to the `code_executor` specialist (the only builtin whose allow-list
-//! carries `node_exec` / `npm_exec`). So the agent that genuinely spawns the
-//! language runtime *is* `code_executor`. This scenario drives that specialist
-//! directly — one turn, one scripted `node_exec` call — which is the real
-//! node-executing path, not a bare `std::process` spawn.
-//!
-//! ## Concurrency knob (K parallel skill runs)
-//!
-//! `OPENHUMAN_PROFILE_SKILL_RUN_CONCURRENCY=K` (default 1) drives **K**
-//! `code_executor` turns in parallel, each emitting its own `node_exec` call.
-//! The point of #5106: with the runtime pool **on**, K concurrent skill runs
-//! share a small bounded set of warm `node` workers, so the process tree grows
-//! by ~one pooled worker — **not** K interpreters. This scenario asserts that
-//! (`tree.child_count <= max_workers`) whenever pooling is on and K > 1, so a
-//! regression that reintroduces per-run forking fails the profiling suite.
-//!
-//! Toggle for an A/B baseline:
-//!
-//! * `OPENHUMAN_PROFILE_SKILL_RUN_POOL=off` — disable the pool (legacy per-call
-//! spawn); the tree then shows ~K resident `node` children at peak.
-//! * `OPENHUMAN_PROFILE_SKILL_RUN_POOL_WORKERS=W` — pool size (default 1, for a
-//! tight, deterministic bound).
-//!
-//! ## No interpreter download
-//!
-//! `node.prefer_system = true` (the default) means a host `node` whose **major**
-//! matches the configured target is reused rather than downloaded. This
-//! scenario **requires** a system `node` and bails with a clear stderr error +
-//! nonzero exit if none is on `PATH` — it must never pull a runtime.
-//!
-//! The measured cost lands in `result.tree` (`tree_rss_kib`, `child_count`,
-//! per-child RSS), captured at the workload peak.
-
-use anyhow::{Context, Result};
-use openhuman_core::openhuman::agent::harness::AgentDefinitionRegistry;
-use openhuman_core::openhuman::agent::Agent;
-use openhuman_core::openhuman::config::Config;
-use openhuman_core::openhuman::inference::provider::factory::test_provider_override;
-use openhuman_core::openhuman::security::AutonomyLevel;
-
-use crate::harness::{fixture, measure_with_tree, EnvGuard, ProfileResult};
-use crate::mock::SkillRunMock;
-
-/// The specialist agent that owns `node_exec` and spawns the runtime child.
-const CODE_AGENT: &str = "code_executor";
-
-/// Probe for a usable system `node`. Returns its version on success; on failure
-/// prints a clear `[library-profile]` stderr error and returns `Err` (which
-/// propagates to a nonzero process exit). We must NOT download an interpreter.
-fn require_system_node() -> Result<String> {
- match std::process::Command::new("node").arg("--version").output() {
- Ok(output) if output.status.success() => {
- let version = String::from_utf8_lossy(&output.stdout).trim().to_string();
- eprintln!("[library-profile] skill-run: using system node {version}");
- Ok(version)
- }
- Ok(output) => {
- let stderr = String::from_utf8_lossy(&output.stderr);
- eprintln!(
- "[library-profile] skill-run: `node --version` failed (status {:?}): {stderr}",
- output.status.code()
- );
- anyhow::bail!("skill-run requires a working system `node`, but `node --version` failed")
- }
- Err(err) => {
- eprintln!(
- "[library-profile] skill-run: `node` not found on PATH: {err}. Install Node.js — \
- the profiler will NOT download an interpreter."
- );
- anyhow::bail!("skill-run requires a system `node` on PATH; none found")
- }
- }
-}
-
-/// Read a `>= 1` usize from the environment. Absent ⇒ `default`; present but not
-/// a positive integer ⇒ a hard error (silently coercing a bad `0`/garbage value
-/// would change the workload and bypass the `K > 1` pool gate).
-fn env_usize(key: &str, default: usize) -> Result<usize> {
- match std::env::var(key) {
- Err(_) => Ok(default),
- Ok(raw) => {
- let n: usize = raw
- .trim()
- .parse()
- .with_context(|| format!("{key}={raw:?} is not a valid integer"))?;
- anyhow::ensure!(n >= 1, "{key}={raw:?} must be >= 1");
- Ok(n)
- }
- }
-}
-
-/// Apply the `[runtime_pool]` settings to the in-memory fixture config. The exec
-/// tools snapshot `config.runtime_pool` at construction (the pool config is
-/// injected, never re-read from disk on the hot path), so mutating the config
-/// the agent is built from is what toggles pooling for the scenario.
-fn apply_pool_config(config: &mut Config, pool_enabled: bool, workers: usize) {
- config.runtime_pool.enabled = pool_enabled;
- config.runtime_pool.node.max_workers = workers;
- config.runtime_pool.node.idle_ttl_secs = 300;
- config.runtime_pool.node.recycle_after_jobs = 0;
-}
-
-pub async fn run() -> Result<ProfileResult> {
- // Hard requirement: a system node must be present (no download).
- require_system_node()?;
-
- let concurrency = env_usize("OPENHUMAN_PROFILE_SKILL_RUN_CONCURRENCY", 1)?;
- let pool_enabled = std::env::var("OPENHUMAN_PROFILE_SKILL_RUN_POOL")
- .map(|v| !v.trim().eq_ignore_ascii_case("off"))
- .unwrap_or(true);
- let pool_workers = env_usize("OPENHUMAN_PROFILE_SKILL_RUN_POOL_WORKERS", 1)?;
-
- // `node_exec` is a Write-class acting tool. Full autonomy keeps the gate
- // from parking the turn on approval; the gate is also opted out explicitly.
- let mut fixture = fixture()?;
- fixture.config.autonomy.level = AutonomyLevel::Full;
- apply_pool_config(&mut fixture.config, pool_enabled, pool_workers);
- let _approval_env = EnvGuard::set("OPENHUMAN_APPROVAL_GATE", "0");
-
- openhuman_core::core::bus::init().await.expect("bus init");
- openhuman_core::openhuman::agent::bus::register_agent_handlers();
- let _ = AgentDefinitionRegistry::init_global_builtins();
-
- let mock = SkillRunMock::new();
- let _provider = test_provider_override::install_model(mock.clone());
- eprintln!(
- "[library-profile] skill-run: registries ready, node_exec mock installed \
- (agent={CODE_AGENT}, concurrency={concurrency}, pool={}, pool_workers={pool_workers})",
- if pool_enabled { "on" } else { "off" }
- );
-
- let mock_for_workload = mock.clone();
- let config = fixture.config.clone();
- let mut result = measure_with_tree("skill-run", concurrency, None, move |rec| async move {
- rec.checkpoint("turn-start")?;
- // Drive K code_executor turns concurrently. `join_all` gives real
- // process-level parallelism (each node_exec awaits its own child /
- // pooled job) without requiring the agent future to be `Send`.
- let futures = (0..concurrency).map(|idx| {
- let config = config.clone();
- async move {
- let mut agent = Agent::from_config_for_agent(&config, CODE_AGENT)
- .with_context(|| format!("building code_executor agent #{idx}"))?;
- let reply = agent
- .run_single(
- "Run a short JavaScript computation with node_exec and report the JSON it prints.",
- )
- .await
- .with_context(|| format!("code_executor turn #{idx}"))?;
- anyhow::ensure!(!reply.trim().is_empty(), "empty code_executor reply #{idx}");
- Ok::<(), anyhow::Error>(())
- }
- });
- let outcomes = futures::future::join_all(futures).await;
- for outcome in outcomes {
- outcome?;
- }
- rec.checkpoint("turn-done")?;
- anyhow::ensure!(
- mock_for_workload.node_call_emitted(),
- "the node_exec tool call was never emitted"
- );
- anyhow::ensure!(
- mock_for_workload.node_output_seen(),
- "the node child's output never flowed back — the interpreter child did not run/print"
- );
- Ok(())
- })
- .await?;
-
- match result.tree.as_ref() {
- Some(tree) if tree.child_count >= 1 => {
- eprintln!(
- "[library-profile] skill-run: captured tree_rss_kib={} child_count={} \
- concurrency={concurrency} pool={} children={:?}",
- tree.tree_rss_kib,
- tree.child_count,
- if pool_enabled { "on" } else { "off" },
- tree.children
- );
- }
- Some(tree) => {
- eprintln!(
- "[library-profile] skill-run: tree captured but no child resident at peak \
- (tree_rss_kib={}). With the pool on this is expected between jobs; with the \
- pool off the node child may have been too short-lived.",
- tree.tree_rss_kib
- );
- }
- None => {
- eprintln!("[library-profile] skill-run: WARNING no process-tree sample captured");
- }
- }
-
- // DoD gate (#5106): with pooling on, K concurrent skill runs must not fork K
- // interpreters — the tree grows by ~one pooled worker. A regression that
- // reintroduces per-run forking makes child_count scale with K and fails here.
- if pool_enabled && concurrency > 1 {
- // Require a real measurement: a missing tree or zero children would let
- // the gate "pass" without ever observing an interpreter. With the
- // scenario's 300 s idle TTL the pooled worker is resident at sample time,
- // so this must hold.
- let tree = result.tree.as_ref().ok_or_else(|| {
- anyhow::anyhow!(
- "pool gate: no process-tree sample captured for K={concurrency}; cannot verify \
- the pooled worker (tree sampling is required for this gate)"
- )
- })?;
- anyhow::ensure!(
- tree.child_count >= 1,
- "pool gate: process tree captured zero interpreter children at K={concurrency}; \
- the pooled worker was not observed"
- );
- anyhow::ensure!(
- tree.child_count <= pool_workers,
- "runtime pool failed to bound interpreters: child_count={} exceeds max_workers={} \
- at concurrency K={} — expected warm-worker reuse, not K forked children",
- tree.child_count,
- pool_workers,
- concurrency
- );
- eprintln!(
- "[library-profile] skill-run: POOL OK — {} node worker(s) served {concurrency} \
- concurrent skill runs (would be ~{concurrency} interpreters unpooled)",
- tree.child_count
- );
- }
-
- // Fold in scenario-visible fields (schema stays additive).
- result.workload_units = concurrency;
- Ok(result)
-}
diff --git a/src/bin/library_profile/scenarios/subagent_storm.rs b/src/bin/library_profile/scenarios/subagent_storm.rs
deleted file mode 100644
index 32fcbe80ac..0000000000
--- a/src/bin/library_profile/scenarios/subagent_storm.rs
+++ /dev/null
@@ -1,186 +0,0 @@
-//! `subagent-storm`: fuzz the *width* of delegation inside ONE core instance.
-//!
-//! One orchestrator turn fans out to **K** parallel researcher subagents (all
-//! in-process tokio tasks, not child processes) via `spawn_parallel_agents`.
-//! K comes from `OPENHUMAN_PROFILE_SUBAGENTS` (default 8; tested up to 32), and
-//! each researcher carries per-subagent mock latency drawn from the shared
-//! `OPENHUMAN_PROFILE_MOCK_LATENCY_MS` / `_JITTER_MS` knobs.
-//!
-//! ## Measurement shape (and a hard constraint we hit)
-//!
-//! The intended shape was: prewarm one width-K fan-out, then measure a second on
-//! the same warm process so the delta is attributable to the K children rather
-//! than cold bootstrap. That is **not achievable** here: the parallel-spawn
-//! machinery is effectively one-shot per process. Once a fan-out's run ledger is
-//! finalized, a second `spawn_parallel_agents` returns an empty result and the
-//! orchestrator just re-calls the tool without re-running the workers. Worse,
-//! merely *constructing* an orchestrator/researcher agent beforehand perturbs
-//! the fan-out the same way. The only shape that reliably executes all K real
-//! researcher subagents is a single fan-out as the process's first agent
-//! activity.
-//!
-//! So this scenario measures exactly that: one cold width-K fan-out. `retained_delta_kib`
-//! therefore includes the shared per-process bootstrap (~20–30 MiB every
-//! scenario pays once) amortized across K, so a single run's
-//! `marginal_rss_kib_per_agent = retained_delta_kib / K` is an **upper bound**,
-//! not the true marginal. Read the true marginal by comparing runs: the fixed
-//! bootstrap amortizes, so `(retained(K₂) - retained(K₁)) / (K₂ - K₁)` across
-//! two widths (e.g. K=8 vs K=32) isolates the genuine per-additional-subagent
-//! cost. `peak_delta_kib` additionally captures the K-concurrent peak.
-//!
-//! Reported fields: `subagents = K`, `marginal_rss_kib_per_agent` (retained/K,
-//! upper bound), `checkpoints` (baseline → storm-turn-done), and
-//! `turn_latency_ms` (percentiles across the K researcher child executions).
-//! The workload asserts all K researcher subagents actually executed.
-
-use anyhow::Result;
-use openhuman_core::openhuman::agent::harness::AgentDefinitionRegistry;
-use openhuman_core::openhuman::agent::Agent;
-use openhuman_core::openhuman::inference::provider::factory::test_provider_override;
-
-use crate::harness::{fixture, measure, ProfileResult, TurnLatency};
-use crate::mock::{subagent_marker, SubagentMock};
-
-const DEFAULT_SUBAGENTS: usize = 8;
-
-/// The orchestrator's top-level task. The mock ignores the wording and always
-/// fans out to K researchers.
-const STORM_PROMPT: &str = "Research every subsystem in parallel and merge the findings.";
-
-/// Positive identity anchor for a researcher *worker* turn — its own system
-/// prompt names it. Distinguishes a real worker from the orchestrator turns that
-/// also echo every task marker in the fan-out tool call / result.
-const RESEARCHER_IDENTITY: &str = "You are the **Researcher** agent";
-
-fn env_usize(key: &str, default: usize) -> usize {
- std::env::var(key)
- .ok()
- .and_then(|value| value.parse::<usize>().ok())
- .filter(|n| *n > 0)
- .unwrap_or(default)
-}
-
-/// Nearest-rank percentile of an already-sorted slice. `p` in `[0, 100]`.
-fn percentile(sorted: &[u128], p: u128) -> u128 {
- if sorted.is_empty() {
- return 0;
- }
- let rank = ((p * sorted.len() as u128) + 99) / 100; // ceil(p% * n)
- let idx = rank.saturating_sub(1).min(sorted.len() as u128 - 1) as usize;
- sorted[idx]
-}
-
-fn latency_summary(mut samples: Vec<u128>) -> Option<TurnLatency> {
- if samples.is_empty() {
- return None;
- }
- samples.sort_unstable();
- Some(TurnLatency {
- p50: percentile(&samples, 50),
- p95: percentile(&samples, 95),
- p99: percentile(&samples, 99),
- max: *samples.last().unwrap(),
- })
-}
-
-pub async fn run() -> Result<ProfileResult> {
- let width = env_usize("OPENHUMAN_PROFILE_SUBAGENTS", DEFAULT_SUBAGENTS);
-
- let mut fixture = fixture()?;
- // `spawn_parallel_agents` rejects a fan-out wider than the orchestrator's
- // `max_parallel_tools` (default 4). Raise it to K so the full width actually
- // spawns instead of erroring back to a re-spawn loop.
- fixture.config.agent.max_parallel_tools = width.max(4);
- openhuman_core::core::bus::init().await.expect("bus init");
- openhuman_core::openhuman::agent::bus::register_agent_handlers();
- let _ = AgentDefinitionRegistry::init_global_builtins();
-
- let mock = SubagentMock::with_width(width);
- let _provider = test_provider_override::install_model(mock.clone());
- eprintln!("[library-profile] subagent-storm: width={width} — single cold width-K fan-out");
-
- // We drive the `orchestrator` agent directly: it owns `spawn_parallel_agents`
- // and allows the `researcher` subagent (the chat-tier subconscious has
- // neither, and would reject the fan-out). One orchestrator turn fans out to
- // K real researcher subagents via the parallel graph. This fan-out MUST be
- // the process's first agent activity — see the module docs for why prewarming
- // is not possible here.
- let config = fixture.config.clone();
- let mock_for_workload = mock.clone();
- let mut result = measure("subagent-storm", width, None, move |rec| async move {
- rec.checkpoint("baseline")?;
- let mut agent = Agent::from_config_for_agent(&config, "orchestrator")?;
- let reply = agent.run_single(STORM_PROMPT).await?;
- rec.checkpoint("storm-turn-done")?;
- anyhow::ensure!(!reply.trim().is_empty(), "empty storm-turn response");
- // Every one of the K researcher subagents must have actually executed as
- // its own worker turn: for each i there must be a prompt that carries the
- // researcher identity anchor AND that researcher's task marker — not
- // merely an orchestrator turn echoing every marker in the fan-out call.
- let prompts = mock_for_workload.prompts.lock().expect("mock prompt lock");
- for i in 1..=width {
- anyhow::ensure!(
- prompts
- .iter()
- .any(|p| p.contains(RESEARCHER_IDENTITY) && p.contains(&subagent_marker(i))),
- "researcher subagent {i}/{width} never executed as its own worker turn"
- );
- }
- Ok(())
- })
- .await?;
-
- // Marginal per subagent = retained / K. An UPPER BOUND: `retained_delta_kib`
- // still carries the one-time per-process bootstrap (see module docs), so the
- // true marginal is the cross-width delta `(retained(K₂)-retained(K₁))/(K₂-K₁)`.
- let marginal = if width > 0 {
- Some(result.retained_delta_kib as f64 / width as f64)
- } else {
- None
- };
- let latencies = mock
- .researcher_latencies_ms
- .lock()
- .expect("mock latency lock")
- .clone();
- eprintln!(
- "[library-profile] subagent-storm: width={width} retained_delta_kib={} \
- marginal_rss_kib_per_agent={:?} researcher_executions={}",
- result.retained_delta_kib,
- marginal,
- latencies.len()
- );
-
- result.subagents = Some(width);
- result.marginal_rss_kib_per_agent = marginal;
- result.turn_latency_ms = latency_summary(latencies);
- Ok(result)
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn percentiles_nearest_rank() {
- let v: Vec<u128> = (1..=100).collect();
- assert_eq!(percentile(&v, 50), 50);
- assert_eq!(percentile(&v, 95), 95);
- assert_eq!(percentile(&v, 99), 99);
- assert_eq!(percentile(&v, 100), 100);
- assert_eq!(percentile(&[], 50), 0);
- }
-
- #[test]
- fn latency_summary_none_when_empty() {
- assert!(latency_summary(Vec::new()).is_none());
- let s = latency_summary(vec![10, 20, 30]).unwrap();
- assert_eq!(s.max, 30);
- assert_eq!(s.p50, 20);
- }
-
- #[test]
- fn env_usize_falls_back_on_zero_or_unset() {
- assert_eq!(env_usize("OPENHUMAN_PROFILE_STORM_UNSET_XYZ", 8), 8);
- }
-}
diff --git a/src/bin/library_profile/scenarios/workflow.rs b/src/bin/library_profile/scenarios/workflow.rs
deleted file mode 100644
index 2ae42e6fb7..0000000000
--- a/src/bin/library_profile/scenarios/workflow.rs
+++ /dev/null
@@ -1,71 +0,0 @@
-//! `workflow`: run a real flows-domain workflow end to end. A
-//! trigger -> transform -> agent graph is created OUTSIDE the measured region
-//! (recorded as a checkpoint), then `flows_run` is measured as the workload.
-//! The agent node's LLM routes through the plain-text mock provider.
-
-use anyhow::Result;
-use openhuman_core::openhuman::agent::harness::AgentDefinitionRegistry;
-use openhuman_core::openhuman::flows::ops::{flows_create, flows_run};
-use openhuman_core::openhuman::flows::FlowRunTrigger;
-use openhuman_core::openhuman::inference::provider::factory::test_provider_override;
-use serde_json::json;
-
-use crate::harness::{fixture, measure, ProfileResult};
-use crate::mock::PlainTextMock;
-
-pub async fn run() -> Result<ProfileResult> {
- let fixture = fixture()?;
- openhuman_core::core::bus::init().await.expect("bus init");
- openhuman_core::openhuman::agent::bus::register_agent_handlers();
- let _ = AgentDefinitionRegistry::init_global_builtins();
- let mock = PlainTextMock::new("Phoenix migration status: healthy, ramp on Friday.");
- let _provider = test_provider_override::install_model(mock.clone());
-
- let graph = json!({
- "name": "profile-workflow",
- "nodes": [
- { "id": "t", "kind": "trigger", "name": "Trigger" },
- { "id": "prep", "kind": "transform", "name": "Prep",
- "config": { "set": { "topic": "Phoenix migration" } } },
- { "id": "summarize", "kind": "agent", "name": "Summarize",
- "config": { "agent_ref": "researcher",
- "prompt": "Summarise the Phoenix migration status in one line." } }
- ],
- "edges": [
- { "from_node": "t", "to_node": "prep" },
- { "from_node": "prep", "to_node": "summarize" }
- ]
- });
-
- eprintln!("[library-profile] workflow: creating flow (outside measured region)");
- let flow = flows_create(&fixture.config, "profile-workflow".into(), graph, false)
- .await
- .map_err(anyhow::Error::msg)?
- .value;
- let flow_id = flow.id.clone();
-
- measure("workflow", 1, None, move |_rec| async move {
- let outcome = flows_run(
- &fixture.config,
- &flow_id,
- json!({ "topic": "Phoenix migration" }),
- serde_json::Map::new(),
- FlowRunTrigger::Rpc,
- )
- .await
- .map_err(anyhow::Error::msg)?;
- let output = outcome.value.get("output");
- anyhow::ensure!(
- output.is_some() && !output.unwrap().is_null(),
- "workflow run produced no output: {}",
- outcome.value
- );
- anyhow::ensure!(
- outcome.value.get("note").is_none(),
- "workflow with an actionable agent node unexpectedly reported nothing-to-run: {}",
- outcome.value
- );
- Ok(())
- })
- .await
-}
diff --git a/src/bin/rss_bench.rs b/src/bin/rss_bench.rs
deleted file mode 100644
index 70d2d3b51c..0000000000
--- a/src/bin/rss_bench.rs
+++ /dev/null
@@ -1,424 +0,0 @@
-//! `rss-bench` — steady-state RSS benchmark for an embedded `openhuman_core`
-//! agent roster (#5046).
-//!
-//! Mirrors the OpenCompany embedding contract: a bare [`Agent`] built directly
-//! via [`Agent::builder`] (no `CoreBuilder`, no RPC, no background services)
-//! with an injected mock model, an in-process `"none"` memory backend, and a
-//! per-agent temp workspace. Builds a 1-agent and an 8-agent roster, runs one
-//! deterministic warm-up turn per agent to fault in lazy allocations, settles,
-//! then samples `/proc/self/{status,smaps_rollup}`.
-//!
-//! Two modes:
-//! * `--child --roster N` builds one roster in a **fresh process**, warms up,
-//! settles, and prints one [`ProcSample`] JSON line. This is the isolated
-//! measured workload.
-//! * default (parent) re-execs itself `--repeat` times per roster size to get
-//! independent cold samples, aggregates, writes the raw JSON report
-//! (`--out`), and prints a human summary.
-//!
-//! Gated behind the default-OFF `rss-bench` feature so no benchmark code enters
-//! the shipped desktop/library build. Build & run:
-//! `cargo build --release --features rss-bench --bin rss-bench`.
-//!
-//! The pure sampling/aggregation logic lives in
-//! [`openhuman_core::openhuman::platform::proc_metrics`]; this binary is the fixture +
-//! process driver.
-
-use anyhow::{Context, Result};
-use async_trait::async_trait;
-use openhuman_core::openhuman::agent::dispatcher::NativeToolDispatcher;
-use openhuman_core::openhuman::agent::Agent;
-use openhuman_core::openhuman::memory::{
- Memory, MemoryCategory, MemoryEntry, NamespaceSummary, RecallOpts,
-};
-use openhuman_core::openhuman::platform::proc_metrics::{
- self, BenchReport, ProcSample, RosterResult, REPORT_SCHEMA_VERSION, RSS_BUDGET_KIB,
- RSS_HARD_CAP_KIB,
-};
-use openhuman_core::openhuman::tools::{Tool, ToolResult};
-use std::path::PathBuf;
-use std::process::Stdio;
-use std::sync::Arc;
-use std::time::Duration;
-use tempfile::TempDir;
-use tinyinference::model::{ChatModel, ModelRequest, ModelResponse};
-
-/// Roster sizes measured by default: the 1-agent baseline and the
-/// representative 8-agent company roster from #5046.
-const DEFAULT_ROSTER_SIZES: &[usize] = &[1, 8];
-/// Fresh processes sampled per roster size (≥ 5 per the issue).
-const DEFAULT_REPEAT: usize = 5;
-/// Per-child wall-clock budget. A child does bounded work (build a roster, one
-/// warm-up turn, a ≤2 s settle), so anything beyond this is a stall — kill it and
-/// fail the run rather than letting one bad child block the whole benchmark until
-/// the outer CI job timeout.
-const CHILD_TIMEOUT: Duration = Duration::from_secs(120);
-
-/// Model that never touches the network: returns a fixed assistant message
-/// with a `stop` shape (no tool calls) so a turn completes in one round-trip.
-struct MockModel;
-
-#[async_trait]
-impl ChatModel<()> for MockModel {
- async fn invoke(
- &self,
- _state: &(),
- _request: ModelRequest,
- ) -> tinyinference::Result<ModelResponse> {
- Ok(ModelResponse::assistant("ok"))
- }
-}
-
-/// Trivial host-supplied tool so the roster mirrors a real embedding (the host
-/// injects its own tools). Never invoked — the model returns no tool calls.
-struct EchoTool;
-
-#[async_trait]
-impl Tool for EchoTool {
- fn name(&self) -> &str {
- "echo"
- }
-
- fn description(&self) -> &str {
- "echo"
- }
-
- fn parameters_schema(&self) -> serde_json::Value {
- serde_json::json!({ "type": "object" })
- }
-
- async fn execute(&self, _args: serde_json::Value) -> Result<ToolResult> {
- Ok(ToolResult::success("echo"))
- }
-}
-
-/// Zero-allocation no-op `Memory` for the fixture.
-///
-/// The benchmark measures a bare agent under the OpenCompany embedding contract
-/// (host supplies its own `Memory` over its context store), *not* a memory
-/// store. `create_memory(MemoryConfig{ backend: "none", .. })` does **not**
-/// select a no-op backend — it always builds a `UnifiedMemory` (SQLite + the
-/// default cloud embedder), which would inflate the measured RSS with
-/// memory-store setup. Injecting a real no-op keeps the reading on the agent
-/// harness itself.
-struct NoopMemory;
-
-#[async_trait]
-impl Memory for NoopMemory {
- fn name(&self) -> &str {
- "noop"
- }
- async fn store(
- &self,
- _namespace: &str,
- _key: &str,
- _content: &str,
- _category: MemoryCategory,
- _session_id: Option<&str>,
- ) -> Result<()> {
- Ok(())
- }
- async fn recall(
- &self,
- _query: &str,
- _limit: usize,
- _opts: RecallOpts<'_>,
- ) -> Result<Vec<MemoryEntry>> {
- Ok(Vec::new())
- }
- async fn get(&self, _namespace: &str, _key: &str) -> Result<Option<MemoryEntry>> {
- Ok(None)
- }
- async fn list(
- &self,
- _namespace: Option<&str>,
- _category: Option<&MemoryCategory>,
- _session_id: Option<&str>,
- ) -> Result<Vec<MemoryEntry>> {
- Ok(Vec::new())
- }
- async fn forget(&self, _namespace: &str, _key: &str) -> Result<bool> {
- Ok(false)
- }
- async fn namespace_summaries(&self) -> Result<Vec<NamespaceSummary>> {
- Ok(Vec::new())
- }
- async fn count(&self) -> Result<usize> {
- Ok(0)
- }
- async fn health_check(&self) -> bool {
- true
- }
-}
-
-/// A built roster plus the temp workspaces that must outlive it — dropping the
-/// `TempDir`s would delete the agents' workspaces mid-measurement.
-struct Roster {
- agents: Vec<Agent>,
- _workspaces: Vec<TempDir>,
-}
-
-/// Build `n` bare agents, each with its own temp workspace, mock model,
-/// `"none"` memory backend, and a single host-supplied tool.
-fn build_roster(n: usize) -> Result<Roster> {
- let mut agents = Vec::with_capacity(n);
- let mut workspaces = Vec::with_capacity(n);
- for i in 0..n {
- let workspace = TempDir::new().context("create temp workspace")?;
- let path = workspace.path().to_path_buf();
-
- let memory: Arc<dyn Memory> = Arc::new(NoopMemory);
-
- let agent = Agent::builder()
- .chat_model(Arc::new(MockModel))
- .tools(vec![Box::new(EchoTool)])
- .memory(memory)
- .tool_dispatcher(Box::new(NativeToolDispatcher))
- .model_name("bench-mock".into())
- .agent_definition_name(format!("bench-{i}"))
- .workspace_dir(path.clone())
- .action_dir(path)
- .auto_save(false)
- .build()
- .context("build bench agent")?;
- agents.push(agent);
- workspaces.push(workspace);
- }
- Ok(Roster {
- agents,
- _workspaces: workspaces,
- })
-}
-
-/// One deterministic warm-up turn per agent, forcing first-touch allocations
-/// (prompt build, tokenizer, model seam) to fault in before measuring.
-async fn warm_up(roster: &mut Roster) -> Result<()> {
- for agent in &mut roster.agents {
- let _ = agent.turn("warmup").await.context("warm-up turn")?;
- }
- Ok(())
-}
-
-/// Poll RSS until it stops climbing (Δ < 256 KiB between reads ~200 ms apart)
-/// or a 2 s cap, draining async task-allocation jitter. No-op off Linux.
-async fn settle() {
- let deadline = tokio::time::Instant::now() + Duration::from_secs(2);
- let mut last = proc_metrics::sample_self().map(|s| s.rss_kib).unwrap_or(0);
- loop {
- tokio::time::sleep(Duration::from_millis(200)).await;
- let now = proc_metrics::sample_self()
- .map(|s| s.rss_kib)
- .unwrap_or(last);
- if now.abs_diff(last) < 256 || tokio::time::Instant::now() >= deadline {
- break;
- }
- last = now;
- }
-}
-
-/// Child mode: build one roster in this fresh process, warm up, settle, sample,
-/// and print the sample as a single JSON line on stdout.
-async fn run_child(roster_size: usize) -> Result<()> {
- // Diagnostics go to stderr so they never corrupt the single JSON line the
- // parent parses from stdout.
- eprintln!("[rss-bench] child: building {roster_size}-agent roster");
- let mut roster = build_roster(roster_size)?;
- eprintln!("[rss-bench] child: warming up {roster_size} agent(s)");
- warm_up(&mut roster).await?;
- eprintln!("[rss-bench] child: settling");
- settle().await;
- let sample = proc_metrics::sample_self()?;
- eprintln!(
- "[rss-bench] child: sampled rss={}KiB threads={}",
- sample.rss_kib, sample.threads
- );
- println!("{}", serde_json::to_string(&sample)?);
- drop(roster); // keep the roster alive until after the sample is taken
- Ok(())
-}
-
-/// Parent mode: re-exec the child `repeat` times per roster size, aggregate, and
-/// write the report.
-async fn run_parent(out: Option<PathBuf>, repeat: usize, roster_sizes: &[usize]) -> Result<()> {
- let exe = std::env::current_exe().context("resolve current exe")?;
- let mut rosters = Vec::with_capacity(roster_sizes.len());
- for &size in roster_sizes {
- let mut samples = Vec::with_capacity(repeat);
- for run in 0..repeat {
- eprintln!("[rss-bench] spawn child roster={size} run={run}");
- // `kill_on_drop` + a `timeout` around `wait_with_output` gives a
- // robust kill-and-reap: on timeout the cancelled future drops the
- // child, `kill_on_drop` sends SIGKILL, and the tokio runtime reaps it.
- let child = tokio::process::Command::new(&exe)
- .arg("--child")
- .arg("--roster")
- .arg(size.to_string())
- .stdout(Stdio::piped())
- .stderr(Stdio::piped())
- .kill_on_drop(true)
- .spawn()
- .with_context(|| format!("spawn child roster={size} run={run}"))?;
- let output = match tokio::time::timeout(CHILD_TIMEOUT, child.wait_with_output()).await {
- Ok(res) => res.with_context(|| format!("await child roster={size} run={run}"))?,
- Err(_) => {
- eprintln!(
- "[rss-bench] child roster={size} run={run} timed out after {}s; killed",
- CHILD_TIMEOUT.as_secs()
- );
- anyhow::bail!(
- "child roster={size} run={run} timed out after {}s",
- CHILD_TIMEOUT.as_secs()
- );
- }
- };
- if !output.status.success() {
- eprintln!("[rss-bench] child roster={size} run={run} exited non-zero");
- anyhow::bail!(
- "child roster={size} run={run} failed: {}",
- String::from_utf8_lossy(&output.stderr)
- );
- }
- let stdout = String::from_utf8_lossy(&output.stdout);
- let line = stdout
- .lines()
- .rev()
- .find(|l| !l.trim().is_empty())
- .unwrap_or("")
- .trim();
- let sample: ProcSample = serde_json::from_str(line)
- .with_context(|| format!("parse child sample (roster={size}): {line:?}"))?;
- eprintln!(
- "[rss-bench] child roster={size} run={run} ok rss={}KiB",
- sample.rss_kib
- );
- samples.push(sample);
- }
- rosters.push(RosterResult::from_samples(size, samples));
- }
-
- let report = BenchReport {
- schema_version: REPORT_SCHEMA_VERSION,
- git_sha: git_sha(),
- kernel: kernel(),
- rss_budget_kib: RSS_BUDGET_KIB,
- rss_hard_cap_kib: RSS_HARD_CAP_KIB,
- rosters,
- };
-
- if let Some(path) = out {
- std::fs::write(&path, serde_json::to_string_pretty(&report)?)
- .with_context(|| format!("write report to {}", path.display()))?;
- }
- println!("{}", proc_metrics::human_summary(&report));
- Ok(())
-}
-
-/// Best-effort commit id for the report header (`GITHUB_SHA` in CI).
-fn git_sha() -> String {
- std::env::var("GITHUB_SHA").unwrap_or_else(|_| "unknown".into())
-}
-
-/// Best-effort kernel version for the report header.
-fn kernel() -> String {
- std::fs::read_to_string("/proc/sys/kernel/osrelease")
- .map(|s| s.trim().to_string())
- .unwrap_or_else(|_| std::env::consts::OS.to_string())
-}
-
-/// Minimal flag parse — avoids a clap dependency for four flags.
-struct Args {
- child: bool,
- roster: usize,
- repeat: usize,
- out: Option<PathBuf>,
-}
-
-fn parse_args() -> Result<Args> {
- let mut child = false;
- let mut roster = 1usize;
- let mut repeat = DEFAULT_REPEAT;
- let mut out = None;
- let mut it = std::env::args().skip(1);
- while let Some(arg) = it.next() {
- match arg.as_str() {
- "--child" => child = true,
- "--roster" => {
- roster = it
- .next()
- .context("--roster needs a value")?
- .parse()
- .context("--roster value")?;
- }
- "--repeat" => {
- repeat = it
- .next()
- .context("--repeat needs a value")?
- .parse()
- .context("--repeat value")?;
- }
- "--out" => out = Some(PathBuf::from(it.next().context("--out needs a path")?)),
- other => anyhow::bail!("unknown argument: {other}"),
- }
- }
- Ok(Args {
- child,
- roster,
- repeat,
- out,
- })
-}
-
-#[tokio::main]
-async fn main() -> Result<()> {
- let args = parse_args()?;
- if args.child {
- run_child(args.roster).await
- } else {
- run_parent(args.out, args.repeat, DEFAULT_ROSTER_SIZES).await
- }
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn build_roster_constructs_bare_agents_with_isolated_workspaces() {
- let roster = build_roster(8).expect("8-agent roster builds");
- assert_eq!(roster.agents.len(), 8);
- assert_eq!(roster._workspaces.len(), 8);
- // Each agent got a distinct workspace directory.
- let mut dirs: Vec<_> = roster
- ._workspaces
- .iter()
- .map(|w| w.path().to_path_buf())
- .collect();
- dirs.sort();
- dirs.dedup();
- assert_eq!(dirs.len(), 8, "workspaces must be isolated per agent");
- }
-
- #[test]
- fn warm_up_turn_completes_without_network() {
- // The agent-turn future is large in debug builds. Run it on a worker
- // with explicit stack headroom instead of libtest's smaller default.
- let runtime = tokio::runtime::Builder::new_multi_thread()
- .worker_threads(1)
- .enable_all()
- .thread_stack_size(8 * 1024 * 1024)
- .build()
- .expect("test runtime builds");
- runtime
- .block_on(runtime.spawn(async {
- let mut roster = build_roster(1).expect("1-agent roster builds");
- warm_up(&mut roster).await.expect("warm-up turn completes");
- // The mock provider reports usage, so last_turn_usage is populated —
- // proving the embedding cost-metering contract works on the bare Agent.
- assert!(
- roster.agents[0].last_turn_usage().is_some(),
- "usage should be readable after a turn"
- );
- }))
- .expect("warm-up task joins");
- }
-}
diff --git a/src/openhuman/agent/agent_tests.rs b/src/openhuman/agent/agent_tests.rs
index 6f8abd0d9a..495b816ce9 100644
--- a/src/openhuman/agent/agent_tests.rs
+++ b/src/openhuman/agent/agent_tests.rs
@@ -37,7 +37,6 @@ use anyhow::Result;
use async_trait::async_trait;
use std::sync::{Arc, Mutex};
use tinyinference::model::{ChatModel, ModelProfile, ModelRequest, ModelResponse};
-use tinymemory_core::store as memory_store;
// ═══════════════════════════════════════════════════════════════════════════
// Test Helpers — Mock Provider, Mock Tool, Mock Memory
@@ -228,7 +227,6 @@ impl Tool for CountingTool {
fn make_memory() -> (Arc<dyn Memory>, tempfile::TempDir) {
// The embedding seam fails loudly when unwired; before the memory
// extraction this was a direct call and needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
let tmp = tempfile::TempDir::new().unwrap();
let cfg = MemoryConfig {
backend: "none".into(),
@@ -236,15 +234,13 @@ fn make_memory() -> (Arc<dyn Memory>, tempfile::TempDir) {
};
// The embedding seam fails loudly when unwired; before the memory
// extraction this was a direct call and needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
- let mem = Arc::from(memory_store::create_memory(&cfg, tmp.path()).unwrap());
+ let mem = crate::openhuman::memory::test_support::noop_memory();
(mem, tmp)
}
fn make_sqlite_memory() -> (Arc<dyn Memory>, tempfile::TempDir) {
// The embedding seam fails loudly when unwired; before the memory
// extraction this was a direct call and needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
let tmp = tempfile::TempDir::new().unwrap();
let cfg = MemoryConfig {
backend: "sqlite".into(),
@@ -252,8 +248,7 @@ fn make_sqlite_memory() -> (Arc<dyn Memory>, tempfile::TempDir) {
};
// The embedding seam fails loudly when unwired; before the memory
// extraction this was a direct call and needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
- let mem = Arc::from(memory_store::create_memory(&cfg, tmp.path()).unwrap());
+ let mem = crate::openhuman::memory::test_support::noop_memory();
(mem, tmp)
}
diff --git a/src/openhuman/agent/experience/store_tests.rs b/src/openhuman/agent/experience/store_tests.rs
index bfdb2aa7ec..c7d1073936 100644
--- a/src/openhuman/agent/experience/store_tests.rs
+++ b/src/openhuman/agent/experience/store_tests.rs
@@ -84,117 +84,6 @@ async fn put_list_and_dismiss_round_trip() {
assert!(listed[0].dismissed);
}
-/// Regression for #5209. `Memory::store` runs document content through the
-/// free-text secret/PII sanitizer, whose credit-card (Luhn-gated) pattern
-/// matches any 13–19-digit run. A serialized experience carries bare 13-digit
-/// millisecond timestamps, so a Luhn-valid timestamp used to be rewritten to
-/// a `[REDACTED_PII_*]` token — corrupting the JSON so the record silently
-/// vanished on read (~10% of writes, whichever `now_ms()` happened to be
-/// Luhn-valid). Exercised over the *real* `UnifiedMemory` because `MockMemory`
-/// does not sanitize. `1785148840502` is a Luhn-valid 13-digit ms timestamp;
-/// `put` preserves a positive `created_at_ms`, so the corruption is forced
-/// deterministically rather than depending on the wall clock.
-#[tokio::test]
-async fn experience_survives_content_sanitizer_with_luhn_valid_timestamp() {
- use crate::openhuman::inference::embeddings::NoopEmbedding;
- use crate::openhuman::memory::Memory;
- use tinymemory_core::store::UnifiedMemory;
-
- let tmp = tempfile::TempDir::new().unwrap();
- let memory: Arc<dyn Memory> =
- Arc::new(UnifiedMemory::new(tmp.path(), Arc::new(NoopEmbedding), None).unwrap());
- let store = AgentExperienceStore::new(memory);
-
- let mut experience = sample_experience(
- "exp_luhn",
- "Deploy the Rust service safely",
- vec![],
- vec![],
- 0.9,
- );
- // Luhn-valid 13-digit ms timestamp; preserved by `put` (positive value),
- // so the vulnerable numeric field is present on every run.
- experience.created_at_ms = 1_785_148_840_502;
- experience.lesson = "Legacy shared deployment guidance".into();
-
- store.put(experience).await.unwrap();
-
- let listed = store.list().await.unwrap();
- assert_eq!(
- listed.len(),
- 1,
- "experience must survive the memory content sanitizer round-trip"
- );
- assert_eq!(listed[0].lesson, "Legacy shared deployment guidance");
- assert_eq!(listed[0].created_at_ms, 1_785_148_840_502);
-}
-
-/// Security regression for PR #5211 review (P1). Base64-encoding the payload
-/// makes the memory layer's store-time content scrubber a no-op over the
-/// stored bytes, so the store must run the full scrubber over free-text
-/// fields itself before serialization ([`redact_experience`]). A secret in a
-/// captured free-text field must be redacted in the recalled record (so it
-/// is neither stored nor returned reversibly), while the numeric timestamp
-/// survives intact. Exercised over the real `UnifiedMemory` (the store path
-/// that base64 now shields).
-#[tokio::test]
-async fn secrets_in_free_text_are_redacted_before_storage() {
- use crate::openhuman::inference::embeddings::NoopEmbedding;
- use crate::openhuman::memory::Memory;
- use tinymemory_core::store::UnifiedMemory;
-
- let tmp = tempfile::TempDir::new().unwrap();
- let memory: Arc<dyn Memory> =
- Arc::new(UnifiedMemory::new(tmp.path(), Arc::new(NoopEmbedding), None).unwrap());
- let store = AgentExperienceStore::new(memory);
-
- let mut experience = sample_experience("exp_secret", "deploy the service", vec![], vec![], 0.9);
- // Luhn-valid 13-digit ms timestamp; must survive intact (the #5209 fix).
- experience.created_at_ms = 1_785_148_840_502;
- experience.lesson = "provider token sk_live_12345678901234567890 then dial +15551234567".into();
- experience.reuse_hint =
- "-----BEGIN PRIVATE KEY-----\nMIIabc123\n-----END PRIVATE KEY-----".into();
- experience.error_class = Some("phone leaked: +15551234567".into());
-
- store.put(experience).await.unwrap();
-
- let listed = store.list().await.unwrap();
- assert_eq!(listed.len(), 1, "record must still parse and round-trip");
- let recalled = &listed[0];
-
- // (a) secrets are redacted in the recalled free-text fields.
- assert!(
- !recalled.lesson.contains("sk_live_12345678901234567890"),
- "Stripe key must be redacted, got: {}",
- recalled.lesson
- );
- assert!(
- !recalled.lesson.contains("+15551234567"),
- "phone number must be redacted, got: {}",
- recalled.lesson
- );
- assert!(
- !recalled.reuse_hint.contains("PRIVATE KEY"),
- "private-key block must be redacted, got: {}",
- recalled.reuse_hint
- );
- assert!(
- recalled
- .error_class
- .as_deref()
- .is_none_or(|e| !e.contains("+15551234567")),
- "phone in error_class must be redacted, got: {:?}",
- recalled.error_class
- );
- assert!(
- recalled.lesson.contains("REDACTED") && recalled.reuse_hint.contains("REDACTED"),
- "expected redaction markers in scrubbed fields"
- );
-
- // (b) the numeric timestamp survives intact and the record parses.
- assert_eq!(recalled.created_at_ms, 1_785_148_840_502);
-}
-
#[tokio::test]
async fn generated_ids_partition_identical_experiences_by_profile() {
let (store, _) = fresh_store();
diff --git a/src/openhuman/agent/harness/archivist/lifecycle.rs b/src/openhuman/agent/harness/archivist/lifecycle.rs
index 05eca97fe3..11fb2a1a54 100644
--- a/src/openhuman/agent/harness/archivist/lifecycle.rs
+++ b/src/openhuman/agent/harness/archivist/lifecycle.rs
@@ -33,8 +33,6 @@ impl ArchivistHook {
boundary_config: BoundaryConfig::default(),
config: None,
summariser_available: false,
- #[cfg(test)]
- chat_provider: None,
}
}
@@ -113,8 +111,6 @@ impl ArchivistHook {
boundary_config: BoundaryConfig::default(),
config: None,
summariser_available: false,
- #[cfg(test)]
- chat_provider: None,
}
}
diff --git a/src/openhuman/agent/harness/archivist/mod.rs b/src/openhuman/agent/harness/archivist/mod.rs
index 89d4ae1462..2c5ff7c604 100644
--- a/src/openhuman/agent/harness/archivist/mod.rs
+++ b/src/openhuman/agent/harness/archivist/mod.rs
@@ -27,8 +27,6 @@ mod recap;
// called it — see the module's own docs for the round trip and for why the
// contract's episodic family is not where it belongs (#5560).
mod store;
-#[cfg(test)]
-mod test_constructors;
mod tree_ingest;
mod types;
@@ -40,7 +38,3 @@ pub(crate) use crate::openhuman::agent::hooks::PostTurnHook;
pub(crate) use helpers::extract_profile_key;
#[cfg(test)]
pub(crate) use std::sync::Arc;
-
-#[cfg(test)]
-#[path = "../archivist_tests.rs"]
-mod tests;
diff --git a/src/openhuman/agent/harness/archivist/recap.rs b/src/openhuman/agent/harness/archivist/recap.rs
index 2b06bbbac8..f23fdd1269 100644
--- a/src/openhuman/agent/harness/archivist/recap.rs
+++ b/src/openhuman/agent/harness/archivist/recap.rs
@@ -9,18 +9,6 @@ use crate::openhuman::memory::api::provider::{
// contract's owned ones and `tree_kind` is the wire string the driver
// validates rather than the engine's `TreeKind` enum (#5560).
//
-// The engine `summarise` survives under `cfg(test)` only, where the recap
-// tests install a deterministic chat provider through the engine's own
-// task-local; see [`ArchivistHook::summarize_entries`] for why that arm cannot
-// go through the driver. Named on the engine crate directly: the host's
-// `memory::tree` re-export shim stopped serving production and was deleted
-// (#5560), so a test-only reach into the engine spells the crate out.
-#[cfg(test)]
-use std::sync::Arc;
-#[cfg(test)]
-use tinymemory_core::tree::summarise::summarise;
-#[cfg(test)]
-use tinymemory_core::tree::tree::TreeKind;
/// Total input/context budget for one summarisation fold.
///
@@ -58,7 +46,6 @@ const SUMMARY_OVERHEAD_RESERVE_TOKENS: u32 = 2_048;
/// the fold itself failed with. Every one of them lands on the caller's
/// existing error arm — the heuristic bookend — which is exactly where an
/// engine error landed before.
-#[cfg(not(test))]
async fn fold_through_driver(
inputs: &[SummaryInput],
context: &SummaryContext,
@@ -272,60 +259,15 @@ impl ArchivistHook {
// recorded as the boolean it always was. See `lifecycle::with_config`.
if self.summariser_available {
if let Some(ref config) = self.config {
- // Read only by the `cfg(test)` arm below, now that production
- // folds through the driver. The `Some` gate stays because it is
- // the one this function has always had: no config, no LLM
- // recap, heuristic bookend instead.
- #[cfg(not(test))]
+ // The `Some` gate stays because it is the one this function
+ // has always had: no config, no LLM recap, heuristic bookend
+ // instead. Nothing reads the config now that every build folds
+ // through the driver.
let _ = config;
tracing::debug!(
"[archivist] summarize_entries: LLM recap segment={segment_id} entries={}",
entries.len()
);
- // Test-only: the engine's `summarise` builds its own chat
- // provider, and `build_chat_runtime` consults this task-local
- // before building one. Scoping the call is what keeps the recap
- // tests off the network, and it is why this arm cannot go
- // through the driver: the override is a static inside the
- // engine crate this binary links for tests, which a module in
- // its own process would not see. Production has no such
- // override and never names the engine's chat module (#5560).
- #[cfg(test)]
- let summary_result = {
- let engine_inputs: Vec<_> = corpus_inputs
- .iter()
- .map(|input| tinymemory_core::tree::summarise::SummaryInput {
- id: input.id.clone(),
- content: input.content.clone(),
- token_count: input.token_count,
- entities: input.entities.clone(),
- topics: input.topics.clone(),
- time_range_start: input.time_range_start,
- time_range_end: input.time_range_end,
- score: input.score,
- })
- .collect();
- let engine_ctx = tinymemory_core::tree::summarise::SummaryContext {
- tree_id: &summary_ctx.tree_id,
- tree_kind: TreeKind::parse(&summary_ctx.tree_kind)
- .expect("summarize_entries builds a tree_kind the engine knows"),
- target_level: summary_ctx.target_level,
- token_budget: summary_ctx.token_budget,
- input_token_budget: summary_ctx.input_token_budget,
- overhead_reserve_tokens: summary_ctx.overhead_reserve_tokens,
- ask: summary_ctx.ask.as_deref(),
- };
- if let Some(provider) = self.chat_provider.as_ref() {
- tinymemory_core::chat::test_override::with_provider(
- Arc::clone(provider),
- summarise(config, &engine_inputs, &engine_ctx),
- )
- .await
- } else {
- summarise(config, &engine_inputs, &engine_ctx).await
- }
- };
- #[cfg(not(test))]
let summary_result = fold_through_driver(&corpus_inputs, &summary_ctx).await;
match summary_result {
diff --git a/src/openhuman/agent/harness/archivist/recap_tests.rs b/src/openhuman/agent/harness/archivist/recap_tests.rs
index 4a9ed34642..50551d1e25 100644
--- a/src/openhuman/agent/harness/archivist/recap_tests.rs
+++ b/src/openhuman/agent/harness/archivist/recap_tests.rs
@@ -44,25 +44,6 @@ fn segment_membership_uses_sequence_instead_of_rounded_timestamp() {
assert!(!entry(Some(16), None, 100.001).is_in_segment(&segment));
}
-/// The two summariser budgets are copies of the engine's constants — see
-/// [`super::INPUT_TOKEN_BUDGET`] for why they had to be copied rather than
-/// imported. This is the pin that makes a drift a failing test instead of a
-/// silent change to the prompt budget of every recap the archivist produces.
-///
-/// The engine stays a `dev-dependency`, so naming it in a test is fine; naming
-/// it in `recap.rs` is the thing being removed (#5560).
-#[test]
-fn summary_budget_constants_match_the_engine() {
- assert_eq!(
- INPUT_TOKEN_BUDGET,
- tinycortex::memory::config::INPUT_TOKEN_BUDGET
- );
- assert_eq!(
- SUMMARY_OVERHEAD_RESERVE_TOKENS,
- tinycortex::memory::config::SUMMARY_OVERHEAD_RESERVE_TOKENS
- );
-}
-
#[test]
fn segment_membership_falls_back_to_episodic_id() {
let mut segment = segment();
diff --git a/src/openhuman/agent/harness/archivist/store.rs b/src/openhuman/agent/harness/archivist/store.rs
index 86bdb8c275..80fb604359 100644
--- a/src/openhuman/agent/harness/archivist/store.rs
+++ b/src/openhuman/agent/harness/archivist/store.rs
@@ -379,6 +379,3 @@ fn write_if_new(abs_path: &Path, bytes: &[u8]) -> Result<bool> {
}
}
-#[cfg(test)]
-#[path = "store_tests.rs"]
-mod tests;
diff --git a/src/openhuman/agent/harness/archivist/store_tests.rs b/src/openhuman/agent/harness/archivist/store_tests.rs
deleted file mode 100644
index b9d3880739..0000000000
--- a/src/openhuman/agent/harness/archivist/store_tests.rs
+++ /dev/null
@@ -1,349 +0,0 @@
-//! Tests for the archivist's md-backed episodic capture store.
-//!
-//! Two halves, and the second one is the point.
-//!
-//! The first half is the behaviour suite the store came home with: round
-//! trips, sequence assignment, concurrent writers, session isolation.
-//!
-//! The second half is the **migration proof**. This store was moved out of
-//! `tinycortex` and back, and every turn any user has ever archived is already
-//! on disk in the format the engine's copy wrote. "The port is faithful" is
-//! therefore not a claim to assert, it is a claim to *check against the thing
-//! being replaced* — so [`derived_paths_and_bytes_match_the_engine_store`]
-//! writes the same turns through both implementations into two workspaces and
-//! compares the resulting trees byte for byte, and the two cross-read tests
-//! pin that each implementation reads the other's files.
-//!
-//! The engine stays a `dev-dependency` for exactly this kind of fixture, which
-//! is why naming `tinycortex` here is fine while naming it in `hook_impl.rs`
-//! is the thing being removed.
-
-use super::*;
-use std::collections::BTreeMap;
-use tempfile::TempDir;
-
-fn turn(session: &str, role: &str, content: &str) -> ArchivedTurn {
- ArchivedTurn {
- session_id: session.into(),
- seq: 0,
- timestamp_ms: 1_700_000_000_000,
- role: role.into(),
- content: content.into(),
- lesson: None,
- tool_calls_json: None,
- cost_microdollars: 0,
- }
-}
-
-#[test]
-fn round_trip_single_turn() {
- let tmp = TempDir::new().unwrap();
- let stored = record_turn(tmp.path(), turn("s1", "user", "hello world")).unwrap();
- assert_eq!(stored.seq, 0);
- let read = session_entries(tmp.path(), "s1").unwrap();
- assert_eq!(read.len(), 1);
- assert_eq!(read[0].content, "hello world");
- assert_eq!(read[0].role, "user");
- assert_eq!(read[0].session_id, "s1");
- assert_eq!(read[0].seq, 0);
-}
-
-#[test]
-fn append_increments_seq() {
- let tmp = TempDir::new().unwrap();
- let a = record_turn(tmp.path(), turn("s1", "user", "one")).unwrap();
- let b = record_turn(tmp.path(), turn("s1", "assistant", "two")).unwrap();
- let c = record_turn(tmp.path(), turn("s1", "user", "three")).unwrap();
- assert_eq!((a.seq, b.seq, c.seq), (0, 1, 2));
- let read = session_entries(tmp.path(), "s1").unwrap();
- assert_eq!(
- read.iter().map(|t| t.seq).collect::<Vec<_>>(),
- vec![0, 1, 2]
- );
- assert_eq!(read[1].role, "assistant");
- assert_eq!(read[2].content, "three");
-}
-
-#[test]
-fn concurrent_record_turn_retries_sequence_collisions_without_loss() {
- let tmp = TempDir::new().unwrap();
- let writers = 24;
- let barrier = std::sync::Arc::new(std::sync::Barrier::new(writers));
- let mut threads = Vec::new();
- for index in 0..writers {
- let workspace = tmp.path().to_path_buf();
- let barrier = barrier.clone();
- threads.push(std::thread::spawn(move || {
- barrier.wait();
- record_turn(&workspace, turn("shared", "user", &format!("turn-{index}"))).unwrap()
- }));
- }
- let mut assigned = Vec::new();
- for thread in threads {
- assigned.push(thread.join().unwrap().seq);
- }
- assigned.sort_unstable();
- assert_eq!(assigned, (0..writers as u32).collect::<Vec<_>>());
-
- let entries = session_entries(tmp.path(), "shared").unwrap();
- assert_eq!(entries.len(), writers);
- let contents: std::collections::HashSet<_> =
- entries.into_iter().map(|entry| entry.content).collect();
- assert_eq!(contents.len(), writers);
-}
-
-#[test]
-fn missing_session_returns_empty() {
- let tmp = TempDir::new().unwrap();
- assert!(session_entries(tmp.path(), "never").unwrap().is_empty());
-}
-
-#[test]
-fn preserves_lesson_and_tool_calls() {
- let tmp = TempDir::new().unwrap();
- let mut t = turn("s1", "assistant", "did the thing");
- t.lesson = Some("be careful with X: it bites".into());
- t.tool_calls_json = Some(r#"[{"name":"bash","args":{"cmd":"ls"}}]"#.into());
- t.cost_microdollars = 1234;
- record_turn(tmp.path(), t.clone()).unwrap();
- let read = session_entries(tmp.path(), "s1").unwrap();
- assert_eq!(
- read[0].lesson.as_deref(),
- Some("be careful with X: it bites")
- );
- assert_eq!(
- read[0].tool_calls_json.as_deref(),
- Some(r#"[{"name":"bash","args":{"cmd":"ls"}}]"#)
- );
- assert_eq!(read[0].cost_microdollars, 1234);
-}
-
-#[test]
-fn front_matter_round_trips_multiline_and_delimiter_like_scalars() {
- let tmp = TempDir::new().unwrap();
- let mut t = turn("session:one", "assistant\nadmin", "body stays separate");
- t.lesson = Some("first line\n---\nsecond: line\\tail".into());
- record_turn(tmp.path(), t.clone()).unwrap();
-
- let read = session_entries(tmp.path(), &t.session_id).unwrap();
- assert_eq!(read.len(), 1);
- assert_eq!(read[0].session_id, t.session_id);
- assert_eq!(read[0].role, t.role);
- assert_eq!(read[0].lesson, t.lesson);
- assert_eq!(read[0].content, t.content);
-}
-
-#[test]
-fn unsafe_session_ids_have_collision_resistant_directories() {
- let tmp = TempDir::new().unwrap();
- record_turn(tmp.path(), turn("a/b", "user", "slash")).unwrap();
- record_turn(tmp.path(), turn("a?b", "user", "question")).unwrap();
-
- assert_eq!(
- session_entries(tmp.path(), "a/b").unwrap()[0].content,
- "slash"
- );
- assert_eq!(
- session_entries(tmp.path(), "a?b").unwrap()[0].content,
- "question"
- );
-}
-
-#[test]
-fn distinct_sessions_dont_mix() {
- let tmp = TempDir::new().unwrap();
- record_turn(tmp.path(), turn("a", "user", "hi a")).unwrap();
- record_turn(tmp.path(), turn("b", "user", "hi b")).unwrap();
- record_turn(tmp.path(), turn("a", "user", "more a")).unwrap();
- let a = session_entries(tmp.path(), "a").unwrap();
- let b = session_entries(tmp.path(), "b").unwrap();
- assert_eq!(a.len(), 2);
- assert_eq!(b.len(), 1);
- assert_eq!(b[0].content, "hi b");
-}
-
-/// The literal path an archived turn lands at, spelled out rather than
-/// derived, so a change to `content_root` / the `{:06}` filename fails here
-/// instead of silently orphaning every existing archive.
-#[test]
-fn derived_path_is_the_documented_one() {
- let tmp = TempDir::new().unwrap();
- record_turn(tmp.path(), turn("sess-1", "user", "hi")).unwrap();
- let expected = tmp
- .path()
- .join("memory_tree")
- .join("content")
- .join("episodic")
- .join("sess-1")
- .join("000000.md");
- assert!(expected.is_file(), "expected {}", expected.display());
-}
-
-// ── Engine-equivalence: the migration proof ──────────────────────────────────
-
-/// The turns both implementations are driven with. Deliberately covers every
-/// branch the on-disk bytes can take: the two optional front-matter keys
-/// present and absent, a body with and without a trailing newline, a scalar
-/// that has to be escaped, a session id that has to be sanitised, and a
-/// non-zero cost.
-fn equivalence_fixtures() -> Vec<ArchivedTurn> {
- let mut with_extras = turn("sess-a", "assistant", "did the thing");
- with_extras.lesson = Some("careful: it\nbites\n---\nstill".into());
- with_extras.tool_calls_json = Some(r#"[{"name":"bash","args":{"cmd":"ls"}}]"#.into());
- with_extras.cost_microdollars = 4_242;
-
- let mut trailing_newline = turn("sess-a", "user", "body already ends in a newline\n");
- trailing_newline.timestamp_ms = -1;
-
- vec![
- turn("sess-a", "user", "plain body"),
- with_extras,
- trailing_newline,
- turn("weird/id?x", "user", "sanitised session directory"),
- turn("", "system", "empty session id"),
- turn(
- "s\u{00e9}ance-\u{4e2d}\u{6587}",
- "user",
- "unicode session id",
- ),
- ]
-}
-
-/// Same shape as [`ArchivedTurn`], on the engine's type, so both stores are
-/// driven with the identical payload.
-fn to_engine(turn: &ArchivedTurn) -> tinycortex::memory::archivist::types::ArchivedTurn {
- tinycortex::memory::archivist::types::ArchivedTurn {
- session_id: turn.session_id.clone(),
- seq: turn.seq,
- timestamp_ms: turn.timestamp_ms,
- role: turn.role.clone(),
- content: turn.content.clone(),
- lesson: turn.lesson.clone(),
- tool_calls_json: turn.tool_calls_json.clone(),
- cost_microdollars: turn.cost_microdollars,
- }
-}
-
-/// Every file under `root`, keyed by its path relative to `root` (forward
-/// slashes) and valued by its exact bytes.
-fn tree_snapshot(root: &Path) -> BTreeMap<String, Vec<u8>> {
- fn walk(dir: &Path, root: &Path, out: &mut BTreeMap<String, Vec<u8>>) {
- let Ok(entries) = std::fs::read_dir(dir) else {
- return;
- };
- for entry in entries.flatten() {
- let path = entry.path();
- if path.is_dir() {
- walk(&path, root, out);
- } else {
- let rel = path
- .strip_prefix(root)
- .expect("walked path is under root")
- .components()
- .map(|c| c.as_os_str().to_string_lossy().into_owned())
- .collect::<Vec<_>>()
- .join("/");
- out.insert(rel, std::fs::read(&path).unwrap());
- }
- }
- }
- let mut out = BTreeMap::new();
- walk(root, root, &mut out);
- out
-}
-
-/// **The load-bearing test.** Drive both implementations with the same turns
-/// into two workspaces and assert the resulting trees are identical — same
-/// relative paths, same bytes. A one-character difference in the front matter,
-/// the filename width, the sanitiser's digest, or the content root fails here.
-#[test]
-fn derived_paths_and_bytes_match_the_engine_store() {
- let host_ws = TempDir::new().unwrap();
- let engine_ws = TempDir::new().unwrap();
- let engine_cfg = tinycortex::memory::MemoryConfig::new(engine_ws.path().to_path_buf());
-
- for fixture in equivalence_fixtures() {
- let host_seq = record_turn(host_ws.path(), fixture.clone()).unwrap().seq;
- let engine_seq =
- tinycortex::memory::archivist::store::record_turn(&engine_cfg, to_engine(&fixture))
- .unwrap()
- .seq;
- assert_eq!(
- host_seq, engine_seq,
- "assigned seq diverged for session {:?}",
- fixture.session_id
- );
- }
-
- let host_tree = tree_snapshot(host_ws.path());
- let engine_tree = tree_snapshot(engine_ws.path());
-
- assert!(
- !host_tree.is_empty(),
- "snapshot is empty — the walker, not the store, is what this would be testing"
- );
- assert_eq!(
- host_tree.keys().collect::<Vec<_>>(),
- engine_tree.keys().collect::<Vec<_>>(),
- "derived on-disk paths diverged from the engine store"
- );
- for (path, host_bytes) in &host_tree {
- assert_eq!(
- String::from_utf8_lossy(host_bytes),
- String::from_utf8_lossy(&engine_tree[path]),
- "file contents diverged from the engine store at {path}"
- );
- }
-}
-
-/// Turns already on disk — written by the engine's copy before the move — must
-/// read back through the store that replaced it. This is the upgrade path.
-#[test]
-fn reads_back_turns_the_engine_store_wrote() {
- let workspace = TempDir::new().unwrap();
- let engine_cfg = tinycortex::memory::MemoryConfig::new(workspace.path().to_path_buf());
- for fixture in equivalence_fixtures() {
- tinycortex::memory::archivist::store::record_turn(&engine_cfg, to_engine(&fixture))
- .unwrap();
- }
-
- for fixture in equivalence_fixtures() {
- let read = session_entries(workspace.path(), &fixture.session_id).unwrap();
- let found = read
- .iter()
- .find(|t| t.content == fixture.content.trim_end())
- .unwrap_or_else(|| panic!("no engine-written turn matched {:?}", fixture.content));
- assert_eq!(found.session_id, fixture.session_id);
- assert_eq!(found.role, fixture.role);
- assert_eq!(found.lesson, fixture.lesson);
- assert_eq!(found.tool_calls_json, fixture.tool_calls_json);
- assert_eq!(found.cost_microdollars, fixture.cost_microdollars);
- assert_eq!(found.timestamp_ms, fixture.timestamp_ms);
- }
-}
-
-/// And the other direction: a rollback, or a workspace shared with any engine
-/// build still running the old code, must still read what this store wrote.
-#[test]
-fn the_engine_store_reads_back_turns_this_store_wrote() {
- let workspace = TempDir::new().unwrap();
- for fixture in equivalence_fixtures() {
- record_turn(workspace.path(), fixture.clone()).unwrap();
- }
-
- let engine_cfg = tinycortex::memory::MemoryConfig::new(workspace.path().to_path_buf());
- for fixture in equivalence_fixtures() {
- let read =
- tinycortex::memory::archivist::store::session_entries(&engine_cfg, &fixture.session_id)
- .unwrap();
- assert!(
- read.iter().any(|t| t.content == fixture.content.trim_end()
- && t.role == fixture.role
- && t.lesson == fixture.lesson
- && t.tool_calls_json == fixture.tool_calls_json
- && t.cost_microdollars == fixture.cost_microdollars),
- "the engine store could not read back {:?}",
- fixture.content
- );
- }
-}
diff --git a/src/openhuman/agent/harness/archivist/test_constructors.rs b/src/openhuman/agent/harness/archivist/test_constructors.rs
deleted file mode 100644
index 795a545be3..0000000000
--- a/src/openhuman/agent/harness/archivist/test_constructors.rs
+++ /dev/null
@@ -1,62 +0,0 @@
-//! Test-only constructors for `ArchivistHook` that inject stub providers
-//! directly, bypassing `with_config`'s provider-build logic.
-//!
-//! This module is `#[cfg(test)]` at its declaration in `archivist/mod.rs`, so
-//! the engine-crate import below is not linked by a production build — the
-//! engine is a dev-dependency for exactly this kind of fixture (#5560). The
-//! `ChatProvider` it injects is an override for the memory summariser's own
-//! chat task-local, not a handle the archivist calls; see
-//! `types::ArchivistHook::chat_provider`.
-
-use super::boundary::BoundaryConfig;
-use super::types::ArchivistHook;
-use crate::openhuman::config::Config;
-use crate::openhuman::memory::api::provider::MemoryProvider;
-use std::sync::Arc;
-use tinymemory_core::chat::ChatProvider;
-
-#[cfg(test)]
-impl ArchivistHook {
- /// Test-only constructor that injects a stub `ChatProvider` directly,
- /// bypassing `with_config`'s provider-build logic. Used by Phase 1 tests to
- /// verify LLM recap and embedding paths without hitting a real LLM or Ollama
- /// daemon. Embedding is driven through `provider.as_scoring()` at call time.
- /// Exposed as `pub(crate)` so Phase 3 STM recall integration tests can drive
- /// the full archivist path.
- pub(crate) fn new_with_stubs(
- provider: Arc<dyn MemoryProvider>,
- chat_provider: Arc<dyn ChatProvider>,
- ) -> Self {
- Self {
- provider: Some(provider),
- enabled: true,
- boundary_config: BoundaryConfig::default(),
- config: Some(Config::default()),
- // Injecting a stub is the assertion that the LLM path runs, so the
- // availability flag `with_config` would have probed is set here.
- summariser_available: true,
- chat_provider: Some(chat_provider),
- }
- }
-
- /// Test-only constructor that injects stub providers AND a `Config`, so the
- /// Phase 2 segment-tree ingest path (gated by
- /// `config.learning.chat_to_tree_enabled`) can be exercised hermetically.
- ///
- /// `config.learning.chat_to_tree_enabled` must be set to `true` by the caller
- /// for the tree ingest to fire; the hook does NOT force it on.
- pub(crate) fn new_with_stubs_and_config(
- provider: Arc<dyn MemoryProvider>,
- chat_provider: Arc<dyn ChatProvider>,
- config: Config,
- ) -> Self {
- Self {
- provider: Some(provider),
- enabled: true,
- boundary_config: BoundaryConfig::default(),
- config: Some(config),
- summariser_available: true,
- chat_provider: Some(chat_provider),
- }
- }
-}
diff --git a/src/openhuman/agent/harness/archivist/tree_ingest.rs b/src/openhuman/agent/harness/archivist/tree_ingest.rs
index d16bd14a45..26aee39b52 100644
--- a/src/openhuman/agent/harness/archivist/tree_ingest.rs
+++ b/src/openhuman/agent/harness/archivist/tree_ingest.rs
@@ -8,8 +8,6 @@ use crate::openhuman::memory::api::chunks::{DataSource, SourceRef};
use crate::openhuman::memory::api::provider::types::IngestItem;
use crate::openhuman::memory::api::provider::{ConversationSegment, EpisodicTurn};
use crate::openhuman::memory::api::types::MemoryTaint;
-#[cfg(test)]
-use std::sync::Arc;
impl ArchivistHook {
/// Pipe a closed segment's raw prose turns into the memory tree as
@@ -142,26 +140,6 @@ impl ArchivistHook {
// here any more — the driver owns chunking and extraction.
let _ = config;
- // Test-only. The ingest above is a contract call, but the driver behind
- // it runs an extraction LLM of its own, built from `Config` rather than
- // handed in — so a test that did not scope this task-local would reach
- // the managed backend over the network, and the ingest swallows its own
- // failures (below), which surfaces as zero tree chunks rather than as a
- // network error. `tinymemory_core::chat::build_chat_runtime` consults
- // the override before building anything, which is what makes these
- // deterministic. Production has no override and never names the engine's
- // chat module (#5560); the engine is a dev-dependency for this fixture.
- #[cfg(test)]
- let ingest_result = if let Some(provider) = self.chat_provider.as_ref() {
- tinymemory_core::chat::test_override::with_provider(
- Arc::clone(provider),
- ingest.ingest_chat(messages),
- )
- .await
- } else {
- ingest.ingest_chat(messages).await
- };
- #[cfg(not(test))]
let ingest_result = ingest.ingest_chat(messages).await;
match ingest_result {
diff --git a/src/openhuman/agent/harness/archivist/types.rs b/src/openhuman/agent/harness/archivist/types.rs
index 8bde2aa139..e3d8096d14 100644
--- a/src/openhuman/agent/harness/archivist/types.rs
+++ b/src/openhuman/agent/harness/archivist/types.rs
@@ -4,10 +4,6 @@ use super::boundary::BoundaryConfig;
use crate::openhuman::config::Config;
use crate::openhuman::memory::api::provider::MemoryProvider;
use std::sync::Arc;
-// Test-only. See [`ArchivistHook::chat_provider`] for why the engine's chat
-// trait is still named here and why it is not named in a production build.
-#[cfg(test)]
-use tinymemory_core::chat::ChatProvider;
/// Post-turn hook that indexes conversation turns and manages segments.
pub struct ArchivistHook {
@@ -42,24 +38,4 @@ pub struct ArchivistHook {
/// host's own inference factory rather than the memory engine's wrapper
/// around it (#5560). See `with_config` for why those two answer alike.
pub(super) summariser_available: bool,
- /// Test-only deterministic chat provider, installed into the engine's chat
- /// task-local for the duration of a summarise or ingest call.
- ///
- /// **This is an override, not a dependency**, which is why it is
- /// `#[cfg(test)]` and why nothing in a production build names
- /// `tinymemory_core::chat`. `summarise` and the driver's `ingest_chat` both
- /// construct their own provider; `tinymemory_core::chat::build_chat_runtime`
- /// consults a task-local before building one, and scoping a call through it
- /// is the only way to keep these tests off the network.
- ///
- /// It cannot be re-pointed at the host's own chat seam
- /// (`modules::memory_host`'s `ChatHost` bus interface): that seam is served
- /// to a **loaded module**, and a module cannot be loaded by these tests at
- /// all — `dlopen` is a process singleton, so a second module-loading test in
- /// one process hangs rather than fails. The driver under test is the
- /// in-process `TinycortexProvider`, which reaches its LLM through
- /// `tinymemory-core`, so the engine's task-local is the seam that exists.
- /// The engine stays a dev-dependency for exactly this kind of fixture.
- #[cfg(test)]
- pub(super) chat_provider: Option<Arc<dyn ChatProvider>>,
}
diff --git a/src/openhuman/agent/harness/archivist_tests.rs b/src/openhuman/agent/harness/archivist_tests.rs
deleted file mode 100644
index e8b4a4a397..0000000000
--- a/src/openhuman/agent/harness/archivist_tests.rs
+++ /dev/null
@@ -1,490 +0,0 @@
-use super::*;
-use crate::openhuman::agent::hooks::{ToolCallRecord, TurnContext};
-use crate::openhuman::memory::api::provider::MemoryProvider;
-use std::sync::OnceLock;
-use tinymemory_core::chat::ChatPrompt;
-// Assertion reads go straight at the engine's tables through the same client
-// the provider wraps. Production writes through the provider; the *proof* that
-// a row landed may still read the store directly — this is a `_tests.rs` file,
-// by-path exempt from the direct-refs ratchet, and a raw read cannot be
-// satisfied by anything but the row actually existing.
-use tinymemory_core::store::{events as ev, fts5, segments as seg, MemoryClient};
-use tinymemory_tinycortex::engine::{EngineRuntimeConfig, TinycortexProvider};
-
-static TREE_INGEST_TEST_LOCK: OnceLock<tokio::sync::Mutex<()>> = OnceLock::new();
-
-/// Runs `fut` with the memory chat provider pinned to a deterministic stub.
-///
-/// These tree-ingest tests look hermetic but are not. `ingest_chat` builds its
-/// **own** chat provider from `Config` — `memory::tinycortex::ingest::context`
-/// → `scoring_config` → `build_chat_provider` — so it ignores the
-/// `StubChatProvider` wired into the hook and reaches the managed backend over
-/// the network. The ingest treats its own failure as non-fatal (logged and
-/// swallowed in `tree_ingest.rs`), so a slow or failed call surfaces only as
-/// zero tree chunks, which reads as a wrong assertion rather than a network
-/// problem. Under a loaded parallel suite that call's timing varies, which is
-/// what made these tests flaky.
-///
-/// `build_chat_runtime` checks this task-local override before building
-/// anything, so scoping the whole test body through it keeps the ingest
-/// offline and deterministic.
-async fn with_stub_chat_provider<F, T>(fut: F) -> T
-where
- F: std::future::Future<Output = T>,
-{
- // `test_override` is task-local, but tree ingest also builds shared
- // runtime state. Keep these integration-style tests isolated from each
- // other so a concurrent provider construction cannot escape the stub.
- let lock = TREE_INGEST_TEST_LOCK.get_or_init(|| tokio::sync::Mutex::new(()));
- let _guard = lock.lock().await;
- // Tree ingest builds a memory store, which reaches the embedding seam.
- // Installing it here rather than relying on some earlier test having done
- // so is what makes these deterministic — the `test_override` below still
- // keeps the *chat* side offline, since `build_chat_runtime` checks it
- // before building anything.
- crate::openhuman::memory::host_impls::install_for_tests();
- tinymemory_core::chat::test_override::with_provider(
- Arc::new(tinymemory_core::chat::StaticChatProvider::new("{}")),
- fut,
- )
- .await
-}
-
-/// A real TinyCortex provider over a fresh workspace, plus the engine client
-/// for raw assertion reads and the tempdir keeping both alive.
-///
-/// The archivist writes through `Arc<dyn MemoryProvider>` now, so the fixture
-/// is the same shape production binds — the in-process driver here, the
-/// loaded module there — rather than a bare connection the hook can no longer
-/// accept.
-fn setup_provider() -> (TempDir, Arc<MemoryClient>, Arc<dyn MemoryProvider>) {
- let tmp = TempDir::new().unwrap();
- let workspace = tmp.path().join("ws");
- let (client, provider) = provider_over(&workspace);
- (tmp, client, provider)
-}
-
-/// The same driver over a caller-owned workspace.
-///
-/// The tree-ingest tests need the provider and their `Config` to share ONE
-/// workspace — the hook ingests through the provider while the assertions
-/// count chunks through the config, and two tempdirs would make every count
-/// read a store nothing wrote to.
-fn provider_over(workspace: &std::path::Path) -> (Arc<MemoryClient>, Arc<dyn MemoryProvider>) {
- crate::openhuman::memory::host_impls::install_for_tests();
- let workspace = workspace.to_path_buf();
- std::fs::create_dir_all(&workspace).unwrap();
- let client = Arc::new(MemoryClient::from_workspace_dir(workspace.clone()).unwrap());
- let config = EngineRuntimeConfig {
- workspace_dir: workspace.clone(),
- config_path: workspace.join("config.toml"),
- memory: Default::default(),
- memory_tree: Default::default(),
- scheduler_gate: Default::default(),
- local_ai: Default::default(),
- embeddings_provider: None,
- memory_provider: None,
- default_model: None,
- default_temperature: 0.2,
- output_language: None,
- memory_sources: serde_json::Value::Null,
- // Added by tinymemory#100, which moved the periodic sync loops into the
- // module. A test fixture wants the same "no cadence configured" default
- // the module answers for an older host that sends nothing.
- memory_sync_interval_secs: None,
- composio_mode: String::new(),
- composio_entity_id: String::new(),
- // Added by tinymemory#103: proxied Composio addresses the backend with
- // this. Empty means the host named none, and the request then fails in the
- // HTTP client rather than falling back to a guessed host.
- backend_api_url: String::new(),
- };
- let provider: Arc<dyn MemoryProvider> = Arc::new(TinycortexProvider::new(
- "tinycortex".into(),
- config,
- Arc::clone(&client),
- ));
- (client, provider)
-}
-
-// ── Phase 1: LLM recap + finalize-time embedding ─────────────────────────────
-
-/// Stub ChatProvider that returns a fixed recap string without hitting
-/// any real LLM, so the test is hermetic.
-struct StubChatProvider;
-
-#[async_trait::async_trait]
-impl tinymemory_core::chat::ChatProvider for StubChatProvider {
- fn name(&self) -> &str {
- "stub:test"
- }
-
- async fn chat_for_json(&self, _prompt: &ChatPrompt) -> anyhow::Result<String> {
- Ok("stub recap: discussed Rust ownership model".to_string())
- }
-
- async fn chat_for_text(&self, _prompt: &ChatPrompt) -> anyhow::Result<String> {
- Ok("stub recap: discussed Rust ownership model".to_string())
- }
-}
-
-/// Build an ArchivistHook with a stub ChatProvider injected directly.
-/// Uses the test-only `new_with_stubs` constructor to bypass `with_config`.
-fn hook_with_stubs(provider: Arc<dyn MemoryProvider>) -> ArchivistHook {
- ArchivistHook::new_with_stubs(provider, Arc::new(StubChatProvider))
-}
-
-// ── Phase 2: segment-granularity tree ingest ─────────────────────────────────
-//
-// The following tests verify:
-// a) No per-turn tree write fires from on_turn_complete (no double-write).
-// b) Exactly ONE tree ingest fires when a segment closes (not N per turn).
-// c) The ingested batch contains all the segment's raw prose turns.
-// d) The `source_id` is the constant "conversations:agent".
-// e) Each leaf message carries session/segment/episodic-span provenance.
-// f) The ingested content is raw prose, NOT the LLM recap.
-// g) flush_open_segment also triggers tree ingest.
-
-use crate::openhuman::config::Config;
-use tempfile::TempDir;
-use tinymemory_core::store::chunks::store::{count_chunks, list_chunks, ListChunksQuery};
-
-/// Build a Config that points at a temp workspace, suitable for tree-ingest tests.
-/// The memory_tree DB and content dir are created under `tmp.path()`.
-fn test_config_with_tree() -> (TempDir, Config) {
- let tmp = TempDir::new().unwrap();
- let mut cfg = Config::default();
- cfg.workspace_dir = tmp.path().to_path_buf();
- // Route the embedder to `InertEmbedder`. This is the knob that actually
- // takes ingest offline: the tree reads `memory.embedding_model`
- // (`memory::tinycortex::config::memory_config_from`), which defaults to the
- // CLOUD model `embedding-v1` — so the three `memory_tree.embedding_*` lines
- // below never disabled anything, and ingest was really calling out to the
- // managed embedding service. `ingest_chat`'s failure is swallowed as
- // non-fatal in `tree_ingest.rs`, so a slow or failed call surfaced only as
- // "got 0 chunks", which reads as a broken assertion rather than a network
- // timeout — that is what made these tests flaky under a loaded suite.
- // See `memory::tree_e2e_tests::pipeline_works_with_embeddings_disabled`,
- // which pins that "none" routes to `InertEmbedder`.
- cfg.embeddings_provider = Some("none".into());
- // Kept: these govern the memory_tree-specific embedding path.
- cfg.memory_tree.embedding_endpoint = None;
- cfg.memory_tree.embedding_model = None;
- cfg.memory_tree.embedding_strict = false;
- // Ensure the tree ingest gate is on.
- cfg.learning.chat_to_tree_enabled = true;
- (tmp, cfg)
-}
-
-/// Build a hook that has both stub providers AND a real-enough Config wired in,
-/// so the Phase 2 tree ingest path is exercised hermetically.
-fn hook_with_stubs_and_tree_config(
- provider: Arc<dyn MemoryProvider>,
- cfg: Config,
-) -> ArchivistHook {
- ArchivistHook::new_with_stubs_and_config(provider, Arc::new(StubChatProvider), cfg)
-}
-
-async fn phase2_no_per_turn_tree_write_inner() {
- let (_tmp, cfg) = test_config_with_tree();
- let (client, provider) = provider_over(&cfg.workspace_dir);
- let conn = client.profile_conn();
- let hook = hook_with_stubs_and_tree_config(provider.clone(), cfg.clone());
-
- let session = "phase2-no-per-turn";
-
- // Single turn — no segment close fires, so no tree ingest should happen.
- hook.on_turn_complete(&TurnContext {
- user_message: "What is Rust?".into(),
- assistant_response: "Rust is a systems programming language.".into(),
- tool_calls: vec![],
- turn_duration_ms: 100,
- session_id: Some(session.into()),
- agent_id: None,
- entrypoint: None,
- iteration_count: 1,
- })
- .await
- .unwrap();
-
- // Segment is still open (no boundary fired) — tree must have 0 chunks.
- let open_seg = seg::open_segment_for_session(&conn, session).unwrap();
- assert!(
- open_seg.is_some(),
- "Expected an open segment (no boundary should have fired)"
- );
-
- let chunk_count = count_chunks(&cfg).unwrap();
- assert_eq!(
- chunk_count, 0,
- "Expected 0 tree chunks after a single turn (no segment close): \
- per-turn tree write must not exist (Phase 2)"
- );
-}
-
-async fn phase2_exactly_one_tree_ingest_per_segment_close_inner() {
- let (_tmp, cfg) = test_config_with_tree();
- let (_client, provider) = provider_over(&cfg.workspace_dir);
- let hook = hook_with_stubs_and_tree_config(provider.clone(), cfg.clone());
-
- let session = "phase2-one-ingest";
-
- // Turn 1 — opens first segment.
- hook.on_turn_complete(&TurnContext {
- user_message: "Tell me about Rust ownership".into(),
- assistant_response: "Rust ownership prevents memory bugs.".into(),
- tool_calls: vec![],
- turn_duration_ms: 100,
- session_id: Some(session.into()),
- agent_id: None,
- entrypoint: None,
- iteration_count: 1,
- })
- .await
- .unwrap();
-
- // Turn 2 — stays in same segment.
- hook.on_turn_complete(&TurnContext {
- user_message: "What about the borrow checker?".into(),
- assistant_response: "The borrow checker enforces ownership at compile time.".into(),
- tool_calls: vec![],
- turn_duration_ms: 100,
- session_id: Some(session.into()),
- agent_id: None,
- entrypoint: None,
- iteration_count: 2,
- })
- .await
- .unwrap();
-
- // No tree write yet — segment still open.
- let pre_close_chunks = count_chunks(&cfg).unwrap();
- assert_eq!(
- pre_close_chunks, 0,
- "Expected 0 tree chunks before any segment close; got {pre_close_chunks}"
- );
-
- // Turn 3 — topic change triggers boundary → closes first segment → tree ingest fires.
- hook.on_turn_complete(&TurnContext {
- user_message: "Switching to a completely different topic: tell me about Python asyncio."
- .into(),
- assistant_response: "Python asyncio enables concurrent coroutines.".into(),
- tool_calls: vec![],
- turn_duration_ms: 100,
- session_id: Some(session.into()),
- agent_id: None,
- entrypoint: None,
- iteration_count: 3,
- })
- .await
- .unwrap();
-
- // Segment closed → exactly one ingest for the closed segment (containing turns 1+2).
- // The ingest packs the messages into one or more chunks (greedy packing),
- // but chunks_written >= 1 confirms ingest happened.
- let post_close_chunks = count_chunks(&cfg).unwrap();
- assert!(
- post_close_chunks >= 1,
- "Expected ≥ 1 tree chunk after segment close; got {post_close_chunks}"
- );
-
- // List the chunks and check they come from the constant source_id.
- let chunks = list_chunks(
- &cfg,
- &ListChunksQuery {
- source_id: Some("conversations:agent".to_string()),
- ..Default::default()
- },
- )
- .unwrap();
- assert!(
- !chunks.is_empty(),
- "Expected chunks under source_id='conversations:agent'"
- );
-}
-
-async fn phase2_provenance_stamped_on_leaf_and_source_id_is_constant_inner() {
- let (_tmp, cfg) = test_config_with_tree();
- let (client, provider) = provider_over(&cfg.workspace_dir);
- let conn = client.profile_conn();
- let hook = hook_with_stubs_and_tree_config(provider.clone(), cfg.clone());
-
- let session = "phase2-provenance";
-
- // Two turns in the first segment.
- for i in 1..=2 {
- hook.on_turn_complete(&TurnContext {
- user_message: format!("Ownership question {i}"),
- assistant_response: format!("Ownership answer {i}"),
- tool_calls: vec![],
- turn_duration_ms: 50,
- session_id: Some(session.into()),
- agent_id: None,
- entrypoint: None,
- iteration_count: i,
- })
- .await
- .unwrap();
- }
-
- // Force a segment close via flush_open_segment.
- hook.flush_open_segment(session).await;
-
- // Retrieve the closed segment to extract its ID.
- let all_segs = seg::segments_by_namespace(&conn, "global", 10).unwrap();
- let closed = all_segs
- .iter()
- .find(|s| {
- s.session_id == session
- && s.status != tinymemory_core::store::segments::SegmentStatus::Open
- })
- .expect("Expected a closed segment after flush");
-
- let segment_id = &closed.segment_id;
- let start_ep = closed.start_episodic_id;
- let end_ep = closed.end_episodic_id.unwrap_or(start_ep);
-
- // Chunks should be present.
- let chunks = list_chunks(&cfg, &ListChunksQuery::default()).unwrap();
- assert!(
- !chunks.is_empty(),
- "Expected tree chunks after flush_open_segment"
- );
-
- // source_id must be the constant — never per-session or per-segment.
- for chunk in &chunks {
- assert_eq!(
- chunk.metadata.source_id, "conversations:agent",
- "source_id must be the constant 'conversations:agent', got: {}",
- chunk.metadata.source_id
- );
- }
-
- // The source_ref on at least one chunk must contain the provenance pattern.
- let expected_provenance =
- format!("agent://session/{session}/segment/{segment_id}#ep{start_ep}-{end_ep}");
- let has_provenance = chunks.iter().any(|chunk| {
- chunk
- .metadata
- .source_ref
- .as_ref()
- .map(|r| {
- r.value
- .contains(&format!("agent://session/{session}/segment/{segment_id}"))
- })
- .unwrap_or(false)
- });
- assert!(
- has_provenance,
- "Expected at least one chunk with source_ref containing provenance pattern \
- '{expected_provenance}'; found: {:?}",
- chunks
- .iter()
- .map(|c| c.metadata.source_ref.as_ref().map(|r| r.value.as_str()))
- .collect::<Vec<_>>()
- );
-}
-
-async fn phase2_ingested_content_is_raw_prose_not_recap_inner() {
- let (_tmp, cfg) = test_config_with_tree();
- let (_client, provider) = provider_over(&cfg.workspace_dir);
- let hook = hook_with_stubs_and_tree_config(provider.clone(), cfg.clone());
-
- let session = "phase2-raw-prose";
-
- // The stub recap always returns "stub recap: discussed Rust ownership model".
- // The raw user messages contain very different text.
- let user_msg = "My specific question about lifetimes in Rust code";
- let asst_msg = "Lifetimes annotate how long references are valid in memory";
-
- hook.on_turn_complete(&TurnContext {
- user_message: user_msg.into(),
- assistant_response: asst_msg.into(),
- tool_calls: vec![],
- turn_duration_ms: 100,
- session_id: Some(session.into()),
- agent_id: None,
- entrypoint: None,
- iteration_count: 1,
- })
- .await
- .unwrap();
-
- // Flush to close the segment and trigger tree ingest.
- hook.flush_open_segment(session).await;
-
- let chunks = list_chunks(&cfg, &ListChunksQuery::default()).unwrap();
- assert!(
- !chunks.is_empty(),
- "Expected tree chunks after flush_open_segment"
- );
-
- // The stub recap text must NOT appear in any chunk body.
- let stub_recap_text = "stub recap: discussed Rust ownership model";
- for chunk in &chunks {
- assert!(
- !chunk.content.contains(stub_recap_text),
- "Chunk content must NOT contain the recap text (evidence-vs-interpretation policy). \
- Found recap text in chunk id={}: {:?}",
- chunk.id,
- &chunk.content[..chunk.content.len().min(200)]
- );
- }
-
- // The raw prose text MUST appear in at least one chunk.
- let has_user_prose = chunks
- .iter()
- .any(|c| c.content.to_ascii_lowercase().contains("lifetimes"));
- assert!(
- has_user_prose,
- "Expected at least one chunk body to contain raw prose from the turn \
- (keyword 'lifetimes'); found: {:?}",
- chunks
- .iter()
- .map(|c| &c.content[..c.content.len().min(100)])
- .collect::<Vec<_>>()
- );
-}
-
-async fn phase2_flush_also_triggers_tree_ingest_inner() {
- let (_tmp, cfg) = test_config_with_tree();
- let (_client, provider) = provider_over(&cfg.workspace_dir);
- let hook = hook_with_stubs_and_tree_config(provider.clone(), cfg.clone());
-
- let session = "phase2-flush-tree";
-
- // Two turns — no boundary fires, segment stays open.
- for i in 1..=2 {
- hook.on_turn_complete(&TurnContext {
- user_message: format!("Rust borrowing question {i}"),
- assistant_response: format!("Borrowing answer {i}"),
- tool_calls: vec![],
- turn_duration_ms: 50,
- session_id: Some(session.into()),
- agent_id: None,
- entrypoint: None,
- iteration_count: i,
- })
- .await
- .unwrap();
- }
-
- // Confirm no tree chunks yet (segment still open).
- let before = count_chunks(&cfg).unwrap();
- assert_eq!(
- before, 0,
- "Expected 0 tree chunks before flush; got {before}"
- );
-
- // Flush should close the segment and trigger tree ingest.
- hook.flush_open_segment(session).await;
-
- let after = count_chunks(&cfg).unwrap();
- assert!(
- after >= 1,
- "Expected ≥ 1 tree chunk after flush_open_segment triggers segment ingest; got {after}"
- );
-}
-
-#[path = "archivist_tests_part_01_tests.rs"]
-mod part_01_tests;
diff --git a/src/openhuman/agent/harness/session/builder/builder_tests_part_01_tests.rs b/src/openhuman/agent/harness/session/builder/builder_tests_part_01_tests.rs
index e0e2b10891..6b812f762e 100644
--- a/src/openhuman/agent/harness/session/builder/builder_tests_part_01_tests.rs
+++ b/src/openhuman/agent/harness/session/builder/builder_tests_part_01_tests.rs
@@ -4,7 +4,6 @@ use super::*;
fn recovery_tool_joins_a_named_allowlist() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::inference::tokenjuice::RETRIEVE_TOOL_NAME as RECOVERY_TOOL_NAME;
use std::collections::HashSet;
@@ -27,7 +26,6 @@ fn recovery_tool_joins_a_named_allowlist() {
fn empty_allowlist_stays_empty() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
use std::collections::HashSet;
// Empty == "no filter" (all tools visible) AND the deliberately tool-less
// Named([]) case — both must stay empty so the invariant holds.
@@ -40,7 +38,6 @@ fn empty_allowlist_stays_empty() {
fn drops_duplicates_first_wins() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
// Real-world collision: researcher's `delegate_name = "research"`
// synthesises a delegate tool that shadows a same-named skill.
// Anthropic 400s on duplicate tool names; the dedup helper must
@@ -65,7 +62,6 @@ fn drops_duplicates_first_wins() {
fn passes_through_when_no_duplicates() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
let specs = vec![spec("a"), spec("b"), spec("c")];
let deduped = dedup_visible_tool_specs(specs);
assert_eq!(deduped.len(), 3);
@@ -78,7 +74,6 @@ fn passes_through_when_no_duplicates() {
fn handles_empty_input() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
let deduped = dedup_visible_tool_specs(Vec::<ToolSpec>::new());
assert!(deduped.is_empty());
}
@@ -87,7 +82,6 @@ fn handles_empty_input() {
fn preserves_full_spec_content_for_kept_entries() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
// Description + parameters must survive the dedup pass intact —
// the LLM uses both for tool-call decisions, and corrupting them
// would silently degrade function-calling quality.
@@ -112,7 +106,6 @@ fn preserves_full_spec_content_for_kept_entries() {
fn automatic_memory_policy_does_not_synthesize_delegate_tools() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
let defs = crate::openhuman::agent::registry::agents::load_builtins().unwrap();
let help = defs
.iter()
@@ -137,7 +130,6 @@ fn automatic_memory_policy_does_not_synthesize_delegate_tools() {
async fn build_session_agent_applies_extended_policy_definition_cap() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::agent::harness::session::types::Agent;
let tmp = tempfile::TempDir::new().unwrap();
@@ -171,7 +163,6 @@ async fn build_session_agent_applies_extended_policy_definition_cap() {
async fn build_session_agent_applies_strict_cap_below_global_default() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::agent::harness::session::types::Agent;
let tmp = tempfile::TempDir::new().unwrap();
@@ -199,7 +190,6 @@ async fn build_session_agent_applies_strict_cap_below_global_default() {
async fn build_session_agent_falls_back_to_global_default_when_no_definition() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::agent::harness::session::types::Agent;
let tmp = tempfile::TempDir::new().unwrap();
@@ -225,7 +215,6 @@ async fn build_session_agent_falls_back_to_global_default_when_no_definition() {
async fn build_session_agent_carries_active_profile_id_when_profile_present() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::agent::harness::session::types::Agent;
let tmp = tempfile::TempDir::new().unwrap();
@@ -257,7 +246,6 @@ async fn build_session_agent_carries_active_profile_id_when_profile_present() {
async fn profile_allowed_tools_restrict_shared_session_builder() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::agent::harness::session::types::Agent;
let tmp = tempfile::TempDir::new().unwrap();
@@ -294,7 +282,6 @@ async fn profile_allowed_tools_restrict_shared_session_builder() {
async fn channel_ceiling_does_not_inherit_orchestrator_role_visibility() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::agent::harness::session::types::Agent;
let tmp = tempfile::TempDir::new().unwrap();
@@ -331,7 +318,6 @@ async fn channel_ceiling_does_not_inherit_orchestrator_role_visibility() {
async fn dedicated_memory_profile_scopes_tree_and_transcript_storage() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::agent::harness::session::types::Agent;
let tmp = tempfile::TempDir::new().unwrap();
@@ -359,7 +345,6 @@ async fn dedicated_memory_profile_scopes_tree_and_transcript_storage() {
async fn build_session_agent_leaves_active_profile_id_none_without_profile() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::agent::harness::session::types::Agent;
let tmp = tempfile::TempDir::new().unwrap();
@@ -380,7 +365,6 @@ async fn build_session_agent_leaves_active_profile_id_none_without_profile() {
async fn build_session_agent_routes_dedicated_memory_to_profile_subtree() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::agent::harness::session::types::Agent;
let tmp = tempfile::TempDir::new().unwrap();
@@ -425,7 +409,6 @@ async fn build_session_agent_routes_dedicated_memory_to_profile_subtree() {
async fn build_session_agent_profile_less_uses_shared_memory_subtree() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::agent::harness::session::types::Agent;
let tmp = tempfile::TempDir::new().unwrap();
@@ -463,7 +446,6 @@ async fn build_session_agent_profile_less_uses_shared_memory_subtree() {
async fn build_session_agent_injects_profile_soul_into_prompt() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::agent::context::prompt::LearnedContextData;
use crate::openhuman::agent::harness::session::types::Agent;
@@ -507,7 +489,6 @@ async fn build_session_agent_injects_profile_soul_into_prompt() {
async fn build_session_agent_uses_profile_memory_instead_of_root_memory() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::agent::context::prompt::LearnedContextData;
use crate::openhuman::agent::harness::session::types::Agent;
@@ -546,7 +527,6 @@ async fn build_session_agent_uses_profile_memory_instead_of_root_memory() {
/// off (the default) whenever a retrieval tool is registered and visible.
#[tokio::test]
async fn memory_access_instruction_is_present_with_learning_disabled() {
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::agent::context::prompt::LearnedContextData;
use crate::openhuman::agent::harness::session::types::Agent;
use crate::openhuman::agent::learning::MEMORY_ACCESS_INSTRUCTION;
@@ -595,7 +575,6 @@ async fn memory_access_instruction_is_present_with_learning_disabled() {
async fn from_config_for_agent_synthesizes_custom_registry_entry_with_named_scope() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::agent::harness::session::types::Agent;
use crate::openhuman::agent::registry::types::{
AgentRegistryEntry, AgentRegistrySource, AgentSubagentPolicy,
diff --git a/src/openhuman/agent/harness/session/builder/builder_tests_part_02_tests.rs b/src/openhuman/agent/harness/session/builder/builder_tests_part_02_tests.rs
index 4117f247ca..b8ccf50241 100644
--- a/src/openhuman/agent/harness/session/builder/builder_tests_part_02_tests.rs
+++ b/src/openhuman/agent/harness/session/builder/builder_tests_part_02_tests.rs
@@ -4,7 +4,6 @@ use super::*;
async fn build_session_agent_injects_default_profile_soul_into_prompt() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::agent::context::prompt::LearnedContextData;
use crate::openhuman::agent::harness::session::types::Agent;
@@ -42,7 +41,6 @@ async fn build_session_agent_injects_default_profile_soul_into_prompt() {
async fn build_session_agent_profile_less_prompt_has_no_personality_soul() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::agent::context::prompt::LearnedContextData;
use crate::openhuman::agent::harness::session::types::Agent;
@@ -70,7 +68,6 @@ async fn build_session_agent_profile_less_prompt_has_no_personality_soul() {
async fn from_config_for_agent_still_errors_for_a_genuinely_unknown_id() {
// Building a session agent constructs a memory store, which reaches
// the embedding seam; before the extraction this needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::agent::harness::session::types::Agent;
let tmp = tempfile::TempDir::new().unwrap();
diff --git a/src/openhuman/agent/harness/session/builder/builder_tests_part_03_tests.rs b/src/openhuman/agent/harness/session/builder/builder_tests_part_03_tests.rs
index 25d5e73f46..0958dcec7e 100644
--- a/src/openhuman/agent/harness/session/builder/builder_tests_part_03_tests.rs
+++ b/src/openhuman/agent/harness/session/builder/builder_tests_part_03_tests.rs
@@ -9,7 +9,6 @@ use super::*;
#[tokio::test]
async fn memory_write_instruction_is_present_with_learning_disabled() {
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::agent::context::prompt::LearnedContextData;
use crate::openhuman::agent::harness::session::types::Agent;
@@ -41,7 +40,6 @@ async fn memory_write_instruction_is_present_with_learning_disabled() {
#[tokio::test]
async fn memory_write_instruction_is_absent_when_no_write_tool_is_visible() {
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::agent::context::prompt::LearnedContextData;
use crate::openhuman::agent::harness::session::types::Agent;
@@ -79,7 +77,6 @@ async fn memory_write_instruction_is_absent_when_no_write_tool_is_visible() {
/// exists to prevent.
#[tokio::test]
async fn memory_write_instruction_names_only_the_write_tool_a_scoped_agent_holds() {
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::agent::context::prompt::LearnedContextData;
use crate::openhuman::agent::harness::session::types::Agent;
diff --git a/src/openhuman/agent/harness/session/runtime_tests.rs b/src/openhuman/agent/harness/session/runtime_tests.rs
index 4be97902ec..8d587a8d38 100644
--- a/src/openhuman/agent/harness/session/runtime_tests.rs
+++ b/src/openhuman/agent/harness/session/runtime_tests.rs
@@ -102,7 +102,6 @@ impl ChatModel<()> for PersistentErrModel {
fn make_agent(model: Arc<dyn ChatModel<()>>) -> Agent {
// The embedding seam fails loudly when unwired; before the memory
// extraction this was a direct call and needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
let workspace = tempfile::TempDir::new().expect("temp workspace");
let workspace_path = workspace.path().to_path_buf();
std::mem::forget(workspace);
@@ -111,7 +110,7 @@ fn make_agent(model: Arc<dyn ChatModel<()>>) -> Agent {
..crate::openhuman::config::MemoryConfig::default()
};
let mem: Arc<dyn Memory> =
- Arc::from(tinymemory_core::store::create_memory(&memory_cfg, &workspace_path).unwrap());
+ crate::openhuman::memory::test_support::noop_memory();
Agent::builder()
.chat_model(model)
diff --git a/src/openhuman/agent/harness/session/session_tests.rs b/src/openhuman/agent/harness/session/session_tests.rs
index 9437488206..0a7ab7206b 100644
--- a/src/openhuman/agent/harness/session/session_tests.rs
+++ b/src/openhuman/agent/harness/session/session_tests.rs
@@ -178,7 +178,6 @@ fn _assert_builder_is_exported() -> AgentBuilder {
fn build_minimal_agent_with_definition_name(definition_name: Option<&str>) -> Agent {
// The embedding seam fails loudly when unwired; before the memory
// extraction this was a direct call and needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
let workspace = tempfile::TempDir::new().expect("temp workspace");
let workspace_path = workspace.path().to_path_buf();
@@ -191,7 +190,7 @@ fn build_minimal_agent_with_definition_name(definition_name: Option<&str>) -> Ag
..crate::openhuman::config::MemoryConfig::default()
};
let mem: Arc<dyn Memory> =
- Arc::from(tinymemory_core::store::create_memory(&memory_cfg, &workspace_path).unwrap());
+ crate::openhuman::memory::test_support::noop_memory();
let mut builder = Agent::builder()
.chat_model(provider)
@@ -226,7 +225,6 @@ fn integration_delegate_toolkit_enum(agent: &Agent) -> Vec<String> {
async fn turn_dispatches_spawn_subagent_through_full_path_inner() {
// The embedding seam fails loudly when unwired; before the memory
// extraction this was a direct call and needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::agent::harness::AgentDefinitionRegistry;
use crate::openhuman::tools::SpawnSubagentTool;
@@ -278,7 +276,7 @@ async fn turn_dispatches_spawn_subagent_through_full_path_inner() {
..crate::openhuman::config::MemoryConfig::default()
};
let mem: Arc<dyn Memory> =
- Arc::from(tinymemory_core::store::create_memory(&memory_cfg, &workspace_path).unwrap());
+ crate::openhuman::memory::test_support::noop_memory();
// Tools include SpawnSubagentTool so the parent can call it.
let tools: Vec<Box<dyn Tool>> = vec![Box::new(SpawnSubagentTool::new())];
@@ -460,7 +458,7 @@ fn agent_with_fake_locator(
..crate::openhuman::config::MemoryConfig::default()
};
let mem: Arc<dyn Memory> =
- Arc::from(tinymemory_core::store::create_memory(&memory_cfg, workspace).unwrap());
+ crate::openhuman::memory::test_support::noop_memory();
let agent = Agent::builder()
.chat_model(Arc::new(MockProvider {
responses: Mutex::new(vec![]),
diff --git a/src/openhuman/agent/harness/session/session_tests_part_01_tests.rs b/src/openhuman/agent/harness/session/session_tests_part_01_tests.rs
index 98c978b47f..ee3bf6d69f 100644
--- a/src/openhuman/agent/harness/session/session_tests_part_01_tests.rs
+++ b/src/openhuman/agent/harness/session/session_tests_part_01_tests.rs
@@ -311,7 +311,6 @@ async fn skill_listener_closed_channel_nulls_rx_and_is_not_a_signal() {
fn refresh_workflows_picks_up_skill_installed_on_disk() {
// The embedding seam fails loudly when unwired; before the memory
// extraction this was a direct call and needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::skills::ops_types::{SKILL_MD, TRUST_MARKER};
// Isolated, trusted workspace with one project-scope skill on disk.
@@ -335,7 +334,7 @@ fn refresh_workflows_picks_up_skill_installed_on_disk() {
..crate::openhuman::config::MemoryConfig::default()
};
let mem: Arc<dyn Memory> =
- Arc::from(tinymemory_core::store::create_memory(&memory_cfg, &wsp).unwrap());
+ crate::openhuman::memory::test_support::noop_memory();
let provider = Arc::new(MockProvider {
responses: Mutex::new(vec![]),
});
@@ -383,7 +382,6 @@ fn refresh_workflows_picks_up_skill_installed_on_disk() {
fn refresh_workflows_retracts_skill_removed_from_disk() {
// The embedding seam fails loudly when unwired; before the memory
// extraction this was a direct call and needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::skills::ops_types::{SKILL_MD, TRUST_MARKER};
let ws = tempfile::TempDir::new().expect("temp workspace");
@@ -408,7 +406,7 @@ fn refresh_workflows_retracts_skill_removed_from_disk() {
..crate::openhuman::config::MemoryConfig::default()
};
let mem: Arc<dyn Memory> =
- Arc::from(tinymemory_core::store::create_memory(&memory_cfg, &wsp).unwrap());
+ crate::openhuman::memory::test_support::noop_memory();
let provider = Arc::new(MockProvider {
responses: Mutex::new(vec![]),
});
@@ -492,7 +490,6 @@ fn refresh_workflows_retracts_skill_removed_from_disk() {
async fn turn_without_tools_returns_text() {
// The embedding seam fails loudly when unwired; before the memory
// extraction this was a direct call and needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
let workspace = tempfile::TempDir::new().expect("temp workspace");
let workspace_path = workspace.path().to_path_buf();
@@ -510,7 +507,7 @@ async fn turn_without_tools_returns_text() {
..crate::openhuman::config::MemoryConfig::default()
};
let mem: Arc<dyn Memory> =
- Arc::from(tinymemory_core::store::create_memory(&memory_cfg, &workspace_path).unwrap());
+ crate::openhuman::memory::test_support::noop_memory();
let mut agent = Agent::builder()
.chat_model(provider)
@@ -534,7 +531,6 @@ async fn turn_without_tools_returns_text() {
async fn last_turn_usage_is_public_and_non_draining() {
// The embedding seam fails loudly when unwired; before the memory
// extraction this was a direct call and needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
let workspace = tempfile::TempDir::new().expect("temp workspace");
let workspace_path = workspace.path().to_path_buf();
@@ -558,7 +554,7 @@ async fn last_turn_usage_is_public_and_non_draining() {
..crate::openhuman::config::MemoryConfig::default()
};
let mem: Arc<dyn Memory> =
- Arc::from(tinymemory_core::store::create_memory(&memory_cfg, &workspace_path).unwrap());
+ crate::openhuman::memory::test_support::noop_memory();
let mut agent = Agent::builder()
.chat_model(provider)
diff --git a/src/openhuman/agent/harness/session/session_tests_part_02_tests.rs b/src/openhuman/agent/harness/session/session_tests_part_02_tests.rs
index e8d951b69f..feb0fe949d 100644
--- a/src/openhuman/agent/harness/session/session_tests_part_02_tests.rs
+++ b/src/openhuman/agent/harness/session/session_tests_part_02_tests.rs
@@ -4,7 +4,6 @@ use super::*;
async fn turn_with_native_dispatcher_handles_tool_results_variant() {
// The embedding seam fails loudly when unwired; before the memory
// extraction this was a direct call and needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
let workspace = tempfile::TempDir::new().expect("temp workspace");
let workspace_path = workspace.path().to_path_buf();
@@ -35,7 +34,7 @@ async fn turn_with_native_dispatcher_handles_tool_results_variant() {
..crate::openhuman::config::MemoryConfig::default()
};
let mem: Arc<dyn Memory> =
- Arc::from(tinymemory_core::store::create_memory(&memory_cfg, &workspace_path).unwrap());
+ crate::openhuman::memory::test_support::noop_memory();
let mut agent = Agent::builder()
.chat_model(provider)
@@ -58,7 +57,6 @@ async fn turn_with_native_dispatcher_handles_tool_results_variant() {
async fn turn_with_native_dispatcher_persists_fallback_tool_calls() {
// The embedding seam fails loudly when unwired; before the memory
// extraction this was a direct call and needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
let workspace = tempfile::TempDir::new().expect("temp workspace");
let workspace_path = workspace.path().to_path_buf();
@@ -87,7 +85,7 @@ async fn turn_with_native_dispatcher_persists_fallback_tool_calls() {
..crate::openhuman::config::MemoryConfig::default()
};
let mem: Arc<dyn Memory> =
- Arc::from(tinymemory_core::store::create_memory(&memory_cfg, &workspace_path).unwrap());
+ crate::openhuman::memory::test_support::noop_memory();
let mut agent = Agent::builder()
.chat_model(provider)
@@ -182,7 +180,6 @@ fn turn_dispatches_spawn_subagent_through_full_path() {
async fn system_prompt_and_model_are_byte_stable_across_turns() {
// The embedding seam fails loudly when unwired; before the memory
// extraction this was a direct call and needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
let workspace = tempfile::TempDir::new().expect("temp workspace");
let workspace_path = workspace.path().to_path_buf();
@@ -215,7 +212,7 @@ async fn system_prompt_and_model_are_byte_stable_across_turns() {
..crate::openhuman::config::MemoryConfig::default()
};
let mem: Arc<dyn Memory> =
- Arc::from(tinymemory_core::store::create_memory(&memory_cfg, &workspace_path).unwrap());
+ crate::openhuman::memory::test_support::noop_memory();
let mut agent = Agent::builder()
.chat_model(provider.clone() as Arc<dyn ChatModel<()>>)
diff --git a/src/openhuman/agent/harness/session/session_tests_part_03_tests.rs b/src/openhuman/agent/harness/session/session_tests_part_03_tests.rs
index 4d6d96ac10..4ab1f798d4 100644
--- a/src/openhuman/agent/harness/session/session_tests_part_03_tests.rs
+++ b/src/openhuman/agent/harness/session/session_tests_part_03_tests.rs
@@ -10,7 +10,6 @@ use super::*;
fn seed_resume_from_thread_transcript_preserves_tool_calls_and_reasoning() {
// The embedding seam fails loudly when unwired; before the memory
// extraction this was a direct call and needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
use super::super::transcript::{self, MessageUsage, TranscriptMeta, TurnUsage};
use crate::openhuman::agent::messages::ChatMessage;
use crate::openhuman::inference::provider::ToolCall;
@@ -84,7 +83,7 @@ fn seed_resume_from_thread_transcript_preserves_tool_calls_and_reasoning() {
..crate::openhuman::config::MemoryConfig::default()
};
let mem: Arc<dyn Memory> =
- Arc::from(tinymemory_core::store::create_memory(&memory_cfg, &wsp).unwrap());
+ crate::openhuman::memory::test_support::noop_memory();
let mut agent = Agent::builder()
.chat_model(Arc::new(MockProvider {
responses: Mutex::new(vec![]),
diff --git a/src/openhuman/agent/harness/session/turn_tests.rs b/src/openhuman/agent/harness/session/turn_tests.rs
index 3983078a9e..36387dbf67 100644
--- a/src/openhuman/agent/harness/session/turn_tests.rs
+++ b/src/openhuman/agent/harness/session/turn_tests.rs
@@ -382,7 +382,6 @@ impl Drop for WorkspaceEnvGuard {
fn make_agent(visible_tool_names: Option<HashSet<String>>) -> Agent {
// The embedding seam fails loudly when unwired; before the memory
// extraction this was a direct call and needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
let workspace = tempfile::TempDir::new().expect("temp workspace");
let workspace_path = workspace.path().to_path_buf();
std::mem::forget(workspace);
@@ -396,9 +395,8 @@ fn make_agent(visible_tool_names: Option<HashSet<String>>) -> Agent {
// runs the startup wiring that installs it, so the helper installs it
// itself. `install_for_tests` is idempotent (a `Once`), so every helper in
// this file calling it costs one install for the whole binary.
- crate::openhuman::memory::host_impls::install_for_tests();
let mem: Arc<dyn Memory> =
- Arc::from(tinymemory_core::store::create_memory(&memory_cfg, &workspace_path).unwrap());
+ crate::openhuman::memory::test_support::noop_memory();
let mut builder = Agent::builder()
.chat_model(Arc::new(DummyProvider))
@@ -452,9 +450,8 @@ fn make_agent_with_builder_and_dispatcher(
..crate::openhuman::config::MemoryConfig::default()
};
// The embedding seam, as above.
- crate::openhuman::memory::host_impls::install_for_tests();
let mem: Arc<dyn Memory> =
- Arc::from(tinymemory_core::store::create_memory(&memory_cfg, &workspace_path).unwrap());
+ crate::openhuman::memory::test_support::noop_memory();
Agent::builder()
.chat_model(provider)
@@ -508,8 +505,7 @@ fn make_agent_with_memory(
fn make_real_memory(workspace: &std::path::Path) -> Arc<dyn Memory> {
use crate::openhuman::inference::embeddings::NoopEmbedding;
- use tinymemory_core::store::UnifiedMemory;
- Arc::new(UnifiedMemory::new(workspace, Arc::new(NoopEmbedding), None).unwrap())
+ Arc::new(crate::openhuman::memory::tool_memory::test_helpers::MockMemory::default())
}
// ── bound_cached_transcript_messages — TAURI-RUST-7 trailing-strip ─────
diff --git a/src/openhuman/agent/harness/session/turn_tests_part_01_tests.rs b/src/openhuman/agent/harness/session/turn_tests_part_01_tests.rs
index 68a596af7e..4d8d750878 100644
--- a/src/openhuman/agent/harness/session/turn_tests_part_01_tests.rs
+++ b/src/openhuman/agent/harness/session/turn_tests_part_01_tests.rs
@@ -152,102 +152,6 @@ fn build_parent_context_has_no_descriptor_without_profile_or_parent() {
assert!(parent.workspace_descriptor.is_none());
}
-#[tokio::test]
-async fn collect_tree_root_summaries_maps_namespace_body_and_timestamp() {
- // #2944: the wrapper must carry the root node's `updated_at` from the
- // store tuple into the `NamespaceSummary` the prompt renderer stamps.
- //
- // Asserted over a **profile** subtree since #5560: the mapping is the same
- // one both arms share, and the profile arm is the one that still scans a
- // caller-named workspace. The shared `"memory"` arm now answers from the
- // bound driver, which has no way to be pointed at this temp directory.
- use crate::openhuman::config::Config;
- use tinycortex::memory::tree::runtime::{
- derive_parent_id, estimate_tokens, level_from_node_id, TreeNode,
- };
- use tinymemory_core::tree::tree_runtime::store::write_node;
-
- let tmp = tempfile::TempDir::new().unwrap();
- let workspace = tmp.path().join("workspace");
- std::fs::create_dir_all(&workspace).unwrap();
- let config = Config {
- workspace_dir: workspace.clone(),
- ..Config::default()
- };
-
- let updated_at = chrono::DateTime::parse_from_rfc3339("2026-05-25T09:00:00Z")
- .unwrap()
- .with_timezone(&chrono::Utc);
- let summary = "Distilled activities summary.";
- let node = TreeNode {
- node_id: "root".to_string(),
- namespace: "activities".to_string(),
- level: level_from_node_id("root"),
- parent_id: derive_parent_id("root"),
- summary: summary.to_string(),
- token_count: estimate_tokens(summary),
- child_count: 0,
- created_at: updated_at,
- updated_at,
- metadata: None,
- };
- write_node(&config, &node).unwrap();
- // `write_node` only knows `<workspace>/memory`; rename it into the profile
- // layout the host-local arm reads.
- std::fs::rename(workspace.join("memory"), workspace.join("memory-alice")).unwrap();
-
- let summaries = collect_tree_root_summaries(&workspace, "memory-alice", 8_000, 32_000).await;
- assert_eq!(summaries.len(), 1);
- assert_eq!(summaries[0].namespace, "activities");
- assert_eq!(summaries[0].body, summary);
- assert_eq!(summaries[0].updated_at, updated_at);
-}
-
-#[tokio::test]
-async fn collect_tree_root_summaries_reads_only_profile_memory_subtree() {
- use crate::openhuman::config::Config;
- use tinycortex::memory::tree::runtime::{
- derive_parent_id, estimate_tokens, level_from_node_id, TreeNode,
- };
- use tinymemory_core::tree::tree_runtime::store::write_node;
-
- let tmp = tempfile::TempDir::new().unwrap();
- let workspace = tmp.path().join("workspace");
- std::fs::create_dir_all(&workspace).unwrap();
- let config = Config {
- workspace_dir: workspace.clone(),
- ..Config::default()
- };
- let now = chrono::Utc::now();
- let node = TreeNode {
- node_id: "root".into(),
- namespace: "private".into(),
- level: level_from_node_id("root"),
- parent_id: derive_parent_id("root"),
- summary: "Alice-only context".into(),
- token_count: estimate_tokens("Alice-only context"),
- child_count: 0,
- created_at: now,
- updated_at: now,
- metadata: None,
- };
- write_node(&config, &node).unwrap();
- std::fs::rename(workspace.join("memory"), workspace.join("memory-alice")).unwrap();
-
- // A *different* profile's subtree, not `"memory"`: since #5560 the shared
- // arm answers from the bound driver rather than from this temp workspace,
- // so asking it here would be asserting about a store this test never
- // wrote. Bob is the isolation the assertion is actually about.
- assert!(
- collect_tree_root_summaries(&workspace, "memory-bob", 8_000, 32_000)
- .await
- .is_empty()
- );
- let summaries = collect_tree_root_summaries(&workspace, "memory-alice", 8_000, 32_000).await;
- assert_eq!(summaries.len(), 1);
- assert_eq!(summaries[0].body, "Alice-only context");
-}
-
#[tokio::test]
async fn transcript_roundtrip_work() {
let mut agent = make_agent(None);
@@ -519,10 +423,8 @@ async fn turn_runs_full_tool_cycle_with_context_and_hooks() {
#[tokio::test]
async fn turn_triggers_configured_memory_agent_before_parent_prompt() {
- crate::openhuman::memory::host_impls::install_for_tests();
// The embedding seam fails loudly when unwired; before the memory
// extraction this was a direct call and needed no setup.
- crate::openhuman::memory::host_impls::install_for_tests();
crate::openhuman::agent::harness::definition::AgentDefinitionRegistry::init_global_builtins()
.expect("built-in agent definitions should load");
assert!(
@@ -563,9 +465,8 @@ async fn turn_triggers_configured_memory_agent_before_parent_prompt() {
..crate::openhuman::config::MemoryConfig::default()
};
// The embedding seam, as above.
- crate::openhuman::memory::host_impls::install_for_tests();
let mem: Arc<dyn Memory> =
- Arc::from(tinymemory_core::store::create_memory(&memory_cfg, &workspace_path).unwrap());
+ crate::openhuman::memory::test_support::noop_memory();
let mut agent = Agent::builder()
.chat_model(provider)
diff --git a/src/openhuman/agent/harness/session/turn_tests_part_02_tests.rs b/src/openhuman/agent/harness/session/turn_tests_part_02_tests.rs
index b231d7b14b..907b6583e3 100644
--- a/src/openhuman/agent/harness/session/turn_tests_part_02_tests.rs
+++ b/src/openhuman/agent/harness/session/turn_tests_part_02_tests.rs
@@ -62,7 +62,6 @@ async fn turn_without_override_offers_tools_and_resets_after_a_suppressed_turn()
/// greeting is a SINGLE provider call with no "## Memory agent context" block.
#[tokio::test]
async fn turn_override_suppress_memory_agent_skips_memory_trigger() {
- crate::openhuman::memory::host_impls::install_for_tests();
crate::openhuman::agent::harness::definition::AgentDefinitionRegistry::init_global_builtins()
.expect("built-in agent definitions should load");
@@ -85,9 +84,8 @@ async fn turn_override_suppress_memory_agent_skips_memory_trigger() {
..crate::openhuman::config::MemoryConfig::default()
};
// The embedding seam, as above.
- crate::openhuman::memory::host_impls::install_for_tests();
let mem: Arc<dyn Memory> =
- Arc::from(tinymemory_core::store::create_memory(&memory_cfg, &workspace_path).unwrap());
+ crate::openhuman::memory::test_support::noop_memory();
let mut agent = Agent::builder()
.chat_model(provider)
diff --git a/src/openhuman/agent/harness/session/turn_tests_part_05_tests.rs b/src/openhuman/agent/harness/session/turn_tests_part_05_tests.rs
index 029b1ffdae..20e9ff5368 100644
--- a/src/openhuman/agent/harness/session/turn_tests_part_05_tests.rs
+++ b/src/openhuman/agent/harness/session/turn_tests_part_05_tests.rs
@@ -115,9 +115,8 @@ fn make_agent_with_auto_recall(
backend: "none".into(),
..crate::openhuman::config::MemoryConfig::default()
};
- crate::openhuman::memory::host_impls::install_for_tests();
let mem: Arc<dyn Memory> =
- Arc::from(tinymemory_core::store::create_memory(&memory_cfg, &workspace_path).unwrap());
+ crate::openhuman::memory::test_support::noop_memory();
Agent::builder()
.chat_model(provider)
diff --git a/src/openhuman/agent/learning/startup_tests.rs b/src/openhuman/agent/learning/startup_tests.rs
index 096decee5f..aec0208c73 100644
--- a/src/openhuman/agent/learning/startup_tests.rs
+++ b/src/openhuman/agent/learning/startup_tests.rs
@@ -17,7 +17,6 @@ use tempfile::TempDir;
/// an unwired embedding host fails loudly by design. `install_for_tests` is
/// `Once`-guarded, so calling it here is free when another test already has.
fn test_workspace() -> TempDir {
- crate::openhuman::memory::host_impls::install_for_tests();
TempDir::new().expect("tempdir")
}
diff --git a/src/openhuman/agent/orchestration/tools/spawn_parallel_agents_tests.rs b/src/openhuman/agent/orchestration/tools/spawn_parallel_agents_tests.rs
index 50ba80073d..df8af3d504 100644
--- a/src/openhuman/agent/orchestration/tools/spawn_parallel_agents_tests.rs
+++ b/src/openhuman/agent/orchestration/tools/spawn_parallel_agents_tests.rs
@@ -489,7 +489,6 @@ async fn agent_turn_runs_long_parallel_subagent_flow_with_many_nested_tool_calls
// binary happened to run first — and failed outright under any filter
// narrow enough to exclude them all. `install_for_tests` is `Once`-guarded,
// so calling it here is free when a sibling already did.
- crate::openhuman::memory::host_impls::install_for_tests();
AgentDefinitionRegistry::init_global_builtins().unwrap();
let workspace = tempfile::TempDir::new().expect("temp workspace");
@@ -502,7 +501,7 @@ async fn agent_turn_runs_long_parallel_subagent_flow_with_many_nested_tool_calls
..crate::openhuman::config::MemoryConfig::default()
};
let mem: Arc<dyn Memory> =
- Arc::from(tinymemory_core::store::create_memory(&memory_cfg, &workspace_path).unwrap());
+ crate::openhuman::memory::test_support::noop_memory();
let tools: Vec<Box<dyn Tool>> = vec![
Box::new(SpawnParallelAgentsTool::new()),
diff --git a/src/openhuman/agent/prompts/render_helpers_part_01.rs b/src/openhuman/agent/prompts/render_helpers_part_01.rs
index 0158fda538..735e821641 100644
--- a/src/openhuman/agent/prompts/render_helpers_part_01.rs
+++ b/src/openhuman/agent/prompts/render_helpers_part_01.rs
@@ -103,16 +103,6 @@ pub fn render_datetime(ctx: &PromptContext<'_>) -> Result<String> {
/// session. The static grounding *rule* that tells the model to read this
/// line lives in [`DateTimeSection`] / [`render_datetime`].
pub fn current_datetime_line() -> String {
- #[cfg(feature = "rss-bench")]
- if std::env::var_os("OPENHUMAN_PROFILE_FORCE_UTC").is_some() {
- let now = chrono::Utc::now();
- return format!(
- "Current Date & Time: {} UTC (UTC, UTC+00:00), {}",
- now.format("%Y-%m-%d %H:%M:%S"),
- now.format("%A"),
- );
- }
-
// When the host resolves an IANA zone, stamp local time + that zone. When
// it can't (CI, stripped containers), fall back to true UTC — formatting
// `Utc::now()` so the time, offset, and zone label all agree rather than
diff --git a/src/openhuman/agent/tools/save_preference_tests.rs b/src/openhuman/agent/tools/save_preference_tests.rs
index 05e661a327..0962e726af 100644
--- a/src/openhuman/agent/tools/save_preference_tests.rs
+++ b/src/openhuman/agent/tools/save_preference_tests.rs
@@ -3,7 +3,7 @@
use super::*;
use crate::openhuman::memory::guard::MemoryGuard;
-use crate::openhuman::memory::ops::{ensure_shared_memory_client, GLOBAL_MEMORY_TEST_LOCK};
+use crate::openhuman::memory::ops::{shared_memory_test_workspace, GLOBAL_MEMORY_TEST_LOCK};
use crate::openhuman::security::SecurityPolicy;
use serde_json::json;
use std::sync::Arc;
@@ -21,7 +21,7 @@ fn test_security() -> Arc<SecurityPolicy> {
/// the duration, and this clears the two lanes so a leftover row from an
/// earlier test cannot satisfy (or break) an assertion here.
async fn fresh_guard() -> Arc<MemoryGuard> {
- ensure_shared_memory_client();
+ shared_memory_test_workspace();
let guard = crate::openhuman::memory::ops::guard::active_memory_guard()
.await
.expect("guard resolves");
diff --git a/src/openhuman/channels/tests/memory.rs b/src/openhuman/channels/tests/memory.rs
index 52096088d7..9690438016 100644
--- a/src/openhuman/channels/tests/memory.rs
+++ b/src/openhuman/channels/tests/memory.rs
@@ -12,7 +12,6 @@ use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use tempfile::TempDir;
use tinymemory_api::provider::MemoryCore as _;
-use tinymemory_core::store::UnifiedMemory;
fn conversation_memory_key_uses_message_id() {
let msg = traits::ChannelMessage {
@@ -55,58 +54,6 @@ fn conversation_memory_key_is_unique_per_message() {
);
}
-#[tokio::test]
-async fn autosave_keys_preserve_multiple_conversation_facts() {
- let tmp = TempDir::new().unwrap();
- let mem = UnifiedMemory::new(tmp.path(), Arc::new(NoopEmbedding), None).unwrap();
-
- let msg1 = traits::ChannelMessage {
- id: "msg_1".into(),
- sender: "U123".into(),
- reply_target: "C456".into(),
- content: "I'm Paul".into(),
- channel: "slack".into(),
- timestamp: 1,
- thread_ts: None,
- };
- let msg2 = traits::ChannelMessage {
- id: "msg_2".into(),
- sender: "U123".into(),
- reply_target: "C456".into(),
- content: "I'm 45".into(),
- channel: "slack".into(),
- timestamp: 2,
- thread_ts: None,
- };
-
- mem.store(
- "",
- &conversation_memory_key(&msg1),
- &msg1.content,
- MemoryCategory::Conversation,
- None,
- )
- .await
- .unwrap();
- mem.store(
- "",
- &conversation_memory_key(&msg2),
- &msg2.content,
- MemoryCategory::Conversation,
- None,
- )
- .await
- .unwrap();
-
- assert_eq!(mem.count().await.unwrap(), 2);
-
- let recalled = mem
- .recall("45", 5, crate::openhuman::memory::RecallOpts::default())
- .await
- .unwrap();
- assert!(recalled.iter().any(|entry| entry.content.contains("45")));
-}
-
#[tokio::test]
async fn build_memory_context_includes_recalled_entries() {
let (_provider, mem) = crate::openhuman::memory::guard::in_memory::guarded_in_memory();
diff --git a/src/openhuman/config/migration_helpers/ops_tests.rs b/src/openhuman/config/migration_helpers/ops_tests.rs
index 9070115c9b..c53a2047c0 100644
--- a/src/openhuman/config/migration_helpers/ops_tests.rs
+++ b/src/openhuman/config/migration_helpers/ops_tests.rs
@@ -5,7 +5,6 @@ fn test_config(tmp: &TempDir) -> Config {
// Apply-mode migrations create unified-memory entries. The memory
// engine's host seams are explicit, so install the test wiring before
// constructing a configuration that can exercise that path.
- crate::openhuman::memory::host_impls::install_for_tests();
Config {
workspace_dir: tmp.path().join("workspace"),
action_dir: tmp.path().join("workspace"),
@@ -60,7 +59,6 @@ async fn migrate_openclaw_apply_imports_markdown_entries_into_target_workspace()
// seam installed. In the default build another test installs the
// process-global host first; under `--no-default-features` those tests
// are gated out, so this test must install it itself (idempotent).
- crate::openhuman::memory::host_impls::install_for_tests();
let tmp = TempDir::new().unwrap();
let config = test_config(&tmp);
@@ -248,7 +246,6 @@ async fn migrate_hermes_dry_run_on_empty_source_returns_report() {
async fn migrate_hermes_apply_imports_markdown_entries() {
// Apply does real memory work; install the embedding host seam so this
// test stands on its own under `--no-default-features` (idempotent).
- crate::openhuman::memory::host_impls::install_for_tests();
let tmp = TempDir::new().unwrap();
let config = test_config(&tmp);
diff --git a/src/openhuman/cron/scheduler_tests_part_01_tests.rs b/src/openhuman/cron/scheduler_tests_part_01_tests.rs
index 3ffcd86a90..4ef56d384b 100644
--- a/src/openhuman/cron/scheduler_tests_part_01_tests.rs
+++ b/src/openhuman/cron/scheduler_tests_part_01_tests.rs
@@ -70,7 +70,6 @@ async fn attributed_cron_build_retains_profile_gates() {
// than relied upon from another test: `install_for_tests` is
// `Once`-guarded, so a test that omits it passes only while some
// earlier test in the same binary happened to run first.
- crate::openhuman::memory::host_impls::install_for_tests();
crate::openhuman::agent::harness::definition::AgentDefinitionRegistry::init_global_builtins()
.expect("init built-in agent definitions");
let tmp = TempDir::new().unwrap();
@@ -107,7 +106,6 @@ async fn attributed_cron_build_applies_profile_temperature_and_prompt_defaults()
// than relied upon from another test: `install_for_tests` is
// `Once`-guarded, so a test that omits it passes only while some
// earlier test in the same binary happened to run first.
- crate::openhuman::memory::host_impls::install_for_tests();
crate::openhuman::agent::harness::definition::AgentDefinitionRegistry::init_global_builtins()
.expect("init built-in agent definitions");
let tmp = TempDir::new().unwrap();
diff --git a/src/openhuman/cron/scheduler_tests_part_02_tests.rs b/src/openhuman/cron/scheduler_tests_part_02_tests.rs
index b3317c49c3..807955b35f 100644
--- a/src/openhuman/cron/scheduler_tests_part_02_tests.rs
+++ b/src/openhuman/cron/scheduler_tests_part_02_tests.rs
@@ -331,7 +331,6 @@ async fn cron_agent_job_uses_agent_definition_tool_scope() {
// than relied upon from another test: `install_for_tests` is
// `Once`-guarded, so a test that omits it passes only while some
// earlier test in the same binary happened to run first.
- crate::openhuman::memory::host_impls::install_for_tests();
crate::openhuman::agent::harness::definition::AgentDefinitionRegistry::init_global_builtins()
.expect("init built-in agent definitions");
let tmp = TempDir::new().unwrap();
diff --git a/src/openhuman/flows/memory_tools_tests.rs b/src/openhuman/flows/memory_tools_tests.rs
index d1ad38253a..5b50f824ff 100644
--- a/src/openhuman/flows/memory_tools_tests.rs
+++ b/src/openhuman/flows/memory_tools_tests.rs
@@ -2,7 +2,6 @@ use super::*;
use crate::openhuman::inference::embeddings::NoopEmbedding;
use crate::openhuman::security::AutonomyLevel;
use tempfile::TempDir;
-use tinymemory_core::store::UnifiedMemory;
// Seeding still goes through the engine handle (`UnifiedMemory` above),
// but the value types are the CONTRACT's: `tinymemory_core` re-exports
@@ -52,7 +51,7 @@ fn test_security() -> Arc<SecurityPolicy> {
fn test_mem() -> (TempDir, Arc<dyn crate::openhuman::memory::Memory>) {
let tmp = TempDir::new().unwrap();
- let mem = UnifiedMemory::new(tmp.path(), Arc::new(NoopEmbedding), None).unwrap();
+ let mem = crate::openhuman::memory::tool_memory::test_helpers::MockMemory::default();
(tmp, Arc::new(mem))
}
diff --git a/src/openhuman/flows/ops_tests.rs b/src/openhuman/flows/ops_tests.rs
index 45bf46e98a..4fdb2dbd9b 100644
--- a/src/openhuman/flows/ops_tests.rs
+++ b/src/openhuman/flows/ops_tests.rs
@@ -4,7 +4,6 @@ use serde_json::json;
use tempfile::TempDir;
fn test_config(tmp: &TempDir) -> Config {
- crate::openhuman::memory::host_impls::install_for_tests();
let config = Config {
workspace_dir: tmp.path().join("workspace"),
action_dir: tmp.path().join("workspace"),
diff --git a/src/openhuman/flows/ops_tests_part_10_tests.rs b/src/openhuman/flows/ops_tests_part_10_tests.rs
index d72815275d..2ed04e4f9c 100644
--- a/src/openhuman/flows/ops_tests_part_10_tests.rs
+++ b/src/openhuman/flows/ops_tests_part_10_tests.rs
@@ -441,7 +441,6 @@ async fn flows_build_hides_the_live_run_tool_from_the_builder_belt() {
// Building an agent constructs a memory client, which needs the host seams
// wired. `Once`-guarded, so this is free when another test got there first.
- crate::openhuman::memory::host_impls::install_for_tests();
crate::openhuman::agent::harness::AgentDefinitionRegistry::init_global(&config.workspace_dir)
.expect("agent registry init");
let mut agent =
@@ -540,7 +539,6 @@ async fn flows_build_copilot_toolset_unhides_the_live_run_tools() {
// Building an agent constructs a memory client, which needs the host seams
// wired. `Once`-guarded, so this is free when another test got there first.
- crate::openhuman::memory::host_impls::install_for_tests();
crate::openhuman::agent::harness::AgentDefinitionRegistry::init_global(&config.workspace_dir)
.expect("agent registry init");
let mut agent =
@@ -602,7 +600,6 @@ async fn flows_build_applies_the_builder_definitions_effective_iteration_cap() {
// Building an agent constructs a memory client, which needs the host seams
// wired. `Once`-guarded, so this is free when another test got there first.
- crate::openhuman::memory::host_impls::install_for_tests();
crate::openhuman::agent::harness::AgentDefinitionRegistry::init_global(&config.workspace_dir)
.expect("agent registry init");
let def = crate::openhuman::agent::harness::AgentDefinitionRegistry::global()
diff --git a/src/openhuman/flows/ops_tests_part_11_tests.rs b/src/openhuman/flows/ops_tests_part_11_tests.rs
index 35903bf0ef..8189fcd54c 100644
--- a/src/openhuman/flows/ops_tests_part_11_tests.rs
+++ b/src/openhuman/flows/ops_tests_part_11_tests.rs
@@ -14,7 +14,6 @@ async fn flows_discover_applies_the_flow_discovery_definitions_effective_iterati
// Building an agent constructs a memory client, which needs the host seams
// wired. `Once`-guarded, so this is free when another test got there first.
- crate::openhuman::memory::host_impls::install_for_tests();
crate::openhuman::agent::harness::AgentDefinitionRegistry::init_global(&config.workspace_dir)
.expect("agent registry init");
let def = crate::openhuman::agent::harness::AgentDefinitionRegistry::global()
diff --git a/src/openhuman/flows/tinyflows/memory_node_e2e_tests.rs b/src/openhuman/flows/tinyflows/memory_node_e2e_tests.rs
index 3eb6409cdf..74c24cd8bb 100644
--- a/src/openhuman/flows/tinyflows/memory_node_e2e_tests.rs
+++ b/src/openhuman/flows/tinyflows/memory_node_e2e_tests.rs
@@ -36,7 +36,7 @@
//!
//! **Real store, not a stub.** `memory` here is the process-global
//! `MemoryClient` (`crate::openhuman::memory::global`), bound to the shared
-//! temp workspace `memory::ops::test_support::ensure_shared_memory_client`
+//! temp workspace `memory::ops::test_support::shared_memory_test_workspace`
//! already uses for every other `memory::ops` real-store test — the SAME
//! on-disk `UnifiedMemory`-backed store `flows_run` writes to in production.
//! Serialized against sibling tests with `GLOBAL_MEMORY_TEST_LOCK`, exactly
@@ -65,7 +65,7 @@ use super::build_capabilities;
/// One on-disk SQLite store is shared across every test thread in this
/// binary (`memory::global` is a process-global `OnceLock`), so concurrent
/// `init`/read/write from sibling tests races on schema init and can bleed
-/// data across tests. `GLOBAL_MEMORY_TEST_LOCK` + `ensure_shared_memory_client`
+/// data across tests. `GLOBAL_MEMORY_TEST_LOCK` + `shared_memory_test_workspace`
/// is the crate's existing, proven pattern for this (see
/// `memory::ops::documents::tests::ensure_memory_client` and
/// `composio::ops_tests::init_memory_client`) — reused verbatim here rather
@@ -74,7 +74,7 @@ async fn lock_shared_memory() -> tokio::sync::MutexGuard<'static, ()> {
let guard = crate::openhuman::memory::ops::GLOBAL_MEMORY_TEST_LOCK
.lock()
.await;
- crate::openhuman::memory::ops::ensure_shared_memory_client();
+ crate::openhuman::memory::ops::shared_memory_test_workspace();
guard
}
@@ -267,137 +267,6 @@ async fn memory_node_remember_then_recall_round_trips_through_the_real_engine_an
// ── 3. security invariant end-to-end: scope:"user" writes are rejected,
// and the user's real memory store is never touched ────────────────────────
-#[tokio::test]
-async fn memory_node_remember_user_scope_is_rejected_and_never_touches_user_memory() {
- let _serial = lock_shared_memory().await;
- let (_tmp, config) = full_autonomy_config();
- let flow_id = unique_flow_id("e2e-security");
- let caps = build_capabilities(config, format!("flow:{flow_id}"));
-
- // A unique key so this assertion can't collide with real content any
- // other test in this shared workspace may have written under
- // GLOBAL_NAMESPACE.
- let forbidden_key = format!("forbidden-{}", uuid::Uuid::new_v4());
-
- // ── (a) validate-time rejection: tinyflows' own structural validator
- // rejects a `remember`/`scope: "user"` node BEFORE compile ever
- // succeeds, so a graph shaped this way can never even reach a run. ──
- let user_scope_graph = trigger_to_memory(json!({
- "operation": "remember",
- "scope": "user",
- "key": forbidden_key,
- "value": "must never be written to user memory"
- }));
- let compile_err = tinyflows::compiler::compile(&user_scope_graph)
- .expect_err("scope: \"user\" on a remember node must be rejected at validate/compile time");
- assert!(
- compile_err.to_string().to_lowercase().contains("user"),
- "expected the validator's scope:\"user\" rejection, got: {compile_err}"
- );
-
- // ── (b) defense-in-depth: even bypassing tinyflows' validator entirely
- // and calling straight through to the adapter build_capabilities wired
- // (the exact instance a real run would dispatch to), OpenHumanMemory's
- // own remember() hard-refuses anything but scope: "flow". ──
- let direct_err = turn_origin::with_origin(
- workflow_origin(&flow_id),
- caps.memory
- .as_ref()
- .expect("build_capabilities must wire a memory capability")
- .remember("user", &forbidden_key, json!("must never be written")),
- )
- .await
- .expect_err("the adapter itself must independently refuse scope: \"user\"");
- assert!(direct_err
- .to_string()
- .contains("only supports scope \"flow\""));
-
- // ── (c) the user's real, durable GLOBAL_NAMESPACE store is untouched by
- // either attempt above. ──
- let memory = tinymemory_core::global::client_if_ready()
- .expect("global memory client must be initialized by lock_shared_memory")
- .memory_handle();
- let entry = memory
- .get(tinycortex::memory::GLOBAL_NAMESPACE, &forbidden_key)
- .await
- .expect("get should not error");
- assert!(
- entry.is_none(),
- "the memory node must never write to the user's GLOBAL_NAMESPACE store, found: {entry:?}"
- );
-}
-
// ── 4. dry_run_workflow still works with a memory node: MockMemory returns
// shaped data without ever touching the real store ─────────────────────────
-#[tokio::test]
-async fn memory_node_dry_run_uses_mock_memory_and_never_touches_the_real_store() {
- let _serial = lock_shared_memory().await;
- let flow_id = unique_flow_id("e2e-dryrun");
-
- let memory = tinymemory_core::global::client_if_ready()
- .expect("global memory client must be initialized by lock_shared_memory")
- .memory_handle();
-
- // Nothing under this flow's namespace exists yet.
- assert!(memory
- .get(&flow_namespace(&flow_id), "item-42")
- .await
- .unwrap()
- .is_none());
-
- // The SAME round-trip graph shape as the real-adapter test above, but
- // run against `tinyflows::caps::mock::mock_capabilities()` — exactly
- // what `DryRunWorkflowTool::execute` wires (`Capabilities::memory`
- // defaults to `MockMemory` there; see the crate's own doc comment on
- // `mock_capabilities`).
- let mock_caps = tinyflows::caps::mock::mock_capabilities();
-
- let remember_graph = trigger_to_memory(json!({
- "operation": "remember",
- "scope": "flow",
- "key": "item-42",
- "value": "should never reach the real store in a dry run"
- }));
- let compiled_remember =
- tinyflows::compiler::compile(&remember_graph).expect("compile remember graph");
- let remember_outcome = tinyflows::engine::run(&compiled_remember, Value::Null, &mock_caps)
- .await
- .expect("dry-run remember should succeed against MockMemory");
- assert_eq!(
- remember_outcome.output["nodes"]["mem"]["items"][0]["json"]["json"]["ok"],
- json!(true)
- );
-
- // The real store never saw this write — MockMemory::remember is a no-op.
- assert!(
- memory
- .get(&flow_namespace(&flow_id), "item-42")
- .await
- .unwrap()
- .is_none(),
- "dry_run_workflow's MockMemory must never touch the real on-disk store"
- );
-
- // recall through the same mock returns MockMemory's fixed shaped echo —
- // proving a graph containing a `memory` node still dry-runs cleanly end
- // to end, without ever reaching the real adapter or store.
- let recall_graph = trigger_to_memory(json!({
- "operation": "recall",
- "scope": "flow",
- "query": "item-42"
- }));
- let compiled_recall =
- tinyflows::compiler::compile(&recall_graph).expect("compile recall graph");
- let recall_outcome = tinyflows::engine::run(&compiled_recall, Value::Null, &mock_caps)
- .await
- .expect("dry-run recall should succeed against MockMemory");
- let results = recall_outcome.output["nodes"]["mem"]["items"][0]["json"]["json"]["results"]
- .as_array()
- .cloned()
- .unwrap_or_default();
- assert!(
- results.iter().any(|hit| hit["id"] == json!("mem_1")),
- "expected MockMemory's fixed shaped echo (not real-store content), got: {results:?}"
- );
-}
diff --git a/src/openhuman/integrations/composio/ops/mod.rs b/src/openhuman/integrations/composio/ops/mod.rs
index f9532a46fa..02fd1fa9d1 100644
--- a/src/openhuman/integrations/composio/ops/mod.rs
+++ b/src/openhuman/integrations/composio/ops/mod.rs
@@ -113,8 +113,6 @@ pub(crate) use error_utils::{
pub(crate) use memory_cleanup::{composio_memory_targets_for_connection, MemoryCleanupTarget};
#[cfg(test)]
pub(crate) use providers_ops::parse_sync_reason;
-#[cfg(test)]
-pub(crate) use tinymemory_core::store::MemoryClient;
#[cfg(test)]
#[path = "../ops_tests.rs"]
diff --git a/src/openhuman/integrations/composio/ops/user_scopes_tests.rs b/src/openhuman/integrations/composio/ops/user_scopes_tests.rs
index 3beb291cbb..2fe7071615 100644
--- a/src/openhuman/integrations/composio/ops/user_scopes_tests.rs
+++ b/src/openhuman/integrations/composio/ops/user_scopes_tests.rs
@@ -24,25 +24,6 @@
use super::*;
-use tinycortex::memory::sync::state::STATE_NAMESPACE as ENGINE_SYNC_STATE_NAMESPACE;
-
-/// The scopes namespace is the literal the engine writes, and it is not the
-/// sync-state namespace.
-///
-/// If either constant ever moved onto the other, prefs and Composio sync
-/// cursors would overwrite each other row for row.
-#[test]
-fn user_scopes_namespace_is_the_engine_literal_and_not_sync_state() {
- assert_eq!(
- KV_NAMESPACE, "composio-user-scopes",
- "must stay the literal tinymemory-core's user_scopes::KV_NAMESPACE holds"
- );
- assert_ne!(
- KV_NAMESPACE, ENGINE_SYNC_STATE_NAMESPACE,
- "prefs must not share a namespace with Composio sync state"
- );
-}
-
/// `kv_key` trims and ASCII-lowercases, exactly as the engine's does — the RPC
/// takes free text from a settings toggle, so `"GitHub"`, `" github "` and
/// `"github"` have to reach one row.
diff --git a/src/openhuman/integrations/composio/ops_tests_part_02_tests.rs b/src/openhuman/integrations/composio/ops_tests_part_02_tests.rs
index 775c1cd7a9..23e5ba1d60 100644
--- a/src/openhuman/integrations/composio/ops_tests_part_02_tests.rs
+++ b/src/openhuman/integrations/composio/ops_tests_part_02_tests.rs
@@ -1,38 +1,5 @@
use super::*;
-#[tokio::test]
-async fn drive_cleanup_targets_are_connection_scoped() {
- // The embedding seam fails loudly when unwired; same reasoning as the
- // notion tests above.
- crate::openhuman::memory::host_impls::install_for_tests();
- let tmp = tempfile::tempdir().unwrap();
- let config = test_config(&tmp);
- // The drive arm never touches the store, but discovery takes the caller's
- // client unconditionally — the parameter is the seam the notion tests
- // inject through.
- let _drive_memory = std::sync::Arc::new(
- MemoryClient::from_workspace_dir(config.workspace_dir.clone())
- .expect("memory client should initialise"),
- );
-
- let targets = composio_memory_targets_for_connection(&config, Some("google_drive"), "conn-1")
- .await
- .expect("drive cleanup targets should resolve");
-
- assert!(targets.contains(&MemoryCleanupTarget::Exact(
- SourceKind::Document,
- "drive:conn-1".to_string()
- )));
- assert!(targets.contains(&MemoryCleanupTarget::Prefix(
- SourceKind::Document,
- "googledrive:conn-1:".to_string()
- )));
- assert!(targets.contains(&MemoryCleanupTarget::Prefix(
- SourceKind::Document,
- "google_drive:conn-1/".to_string()
- )));
-}
-
#[tokio::test]
async fn composio_get_user_profile_via_mock_returns_provider_profile() {
let _serialised = module_guard().await;
@@ -40,7 +7,6 @@ async fn composio_get_user_profile_via_mock_returns_provider_profile() {
// than relied upon from another test: `install_for_tests` is
// `Once`-guarded, so a test that omits it passes only while some
// earlier test in the same binary happened to run first.
- crate::openhuman::memory::host_impls::install_for_tests();
use crate::openhuman::config::TEST_ENV_LOCK;
let _cache_guard = cache_guard();
let _env_guard = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
diff --git a/src/openhuman/memory/binding_tests_part_01_tests.rs b/src/openhuman/memory/binding_tests_part_01_tests.rs
index ed9df62c9b..158660101b 100644
--- a/src/openhuman/memory/binding_tests_part_01_tests.rs
+++ b/src/openhuman/memory/binding_tests_part_01_tests.rs
@@ -188,59 +188,6 @@ fn for_workspace_caches_binding_per_workspace() {
);
}
-#[cfg(feature = "modules")]
-#[tokio::test]
-async fn unrelated_test_binding_cannot_capture_the_module_workspace() {
- let _serial = crate::openhuman::memory::ops::GLOBAL_MEMORY_TEST_LOCK
- .lock()
- .await;
- crate::openhuman::memory::ops::ensure_shared_memory_client();
- let unrelated = tempfile::tempdir().expect("unrelated workspace");
- let binding =
- for_workspace(unrelated.path(), &MemorySubsystemConfig::default()).expect("module binding");
- let guard = binding.guard();
- let documents = guard.as_documents().expect("documents capability");
- let namespace = format!("memory-binding-test-{}", uuid::Uuid::new_v4());
- let key = format!(
- "shared{}",
- &uuid::Uuid::new_v4().as_simple().to_string()[..12]
- );
-
- documents
- .put_document(
- crate::openhuman::memory::api::types::NamespaceDocumentInput {
- namespace: namespace.clone(),
- key: key.clone(),
- title: "Shared test module workspace".into(),
- content: "The module must share the process-global test store.".into(),
- source_type: "doc".into(),
- priority: "normal".into(),
- tags: vec![],
- metadata: serde_json::Value::Null,
- category: "general".into(),
- session_id: None,
- document_id: None,
- taint: MemoryTaint::Internal,
- },
- )
- .await
- .expect("module-backed put");
-
- let client = tinymemory_core::global::client().expect("shared test client");
- let raw = client
- .list_documents(Some(&namespace))
- .await
- .expect("raw list");
- assert!(
- raw["documents"]
- .as_array()
- .expect("documents array")
- .iter()
- .any(|document| document["key"] == key),
- "an unrelated binding must not split the native module from the shared test store"
- );
-}
-
#[test]
fn same_workspace_with_changed_config_binds_fresh() {
// `CoreContext::rebind_workspace` treats "same workspace, changed
diff --git a/src/openhuman/memory/bypass_allowlist_tests.rs b/src/openhuman/memory/bypass_allowlist_tests.rs
index 5483eb0e93..f9e2aa13ec 100644
--- a/src/openhuman/memory/bypass_allowlist_tests.rs
+++ b/src/openhuman/memory/bypass_allowlist_tests.rs
@@ -135,12 +135,6 @@ const BYPASS_PATTERNS: &[(&str, &str)] = &[
/// Sorted by path, then pattern — [`scan`] returns a `BTreeSet`, so keeping the
/// literal in the same order makes diffs readable.
const ALLOWED: &[(&str, &str, &str)] = &[
- // ── Standalone binaries: their own process, no ambient CoreContext ──
- (
- "src/bin/library_profile/scenarios/cold_phases.rs",
- "MemoryClient::from_workspace_dir(",
- "profiling harness; boots its own client outside the guard's process model",
- ),
// ── Metadata-only reads: driver identity, never memory content ──
(
"src/core/cli_capability.rs",
diff --git a/src/openhuman/memory/direct_engine_refs_tests.rs b/src/openhuman/memory/direct_engine_refs_tests.rs
deleted file mode 100644
index 05128d305f..0000000000
--- a/src/openhuman/memory/direct_engine_refs_tests.rs
+++ /dev/null
@@ -1,613 +0,0 @@
-//! Enforcement lint: the set of production files that call `tinymemory-core`
-//! **directly**, around the module seam, must not grow.
-//!
-//! # Why a second path to memory is a correctness problem, not a size problem
-//!
-//! `memory::binding` says it plainly: "the built-in driver is the compiled
-//! TinyMemory TinyBus module. The host no longer exposes an embedded engine
-//! class for memory." Every call that goes over that bus is round-tripped
-//! through [`crate::openhuman::memory::api::wire`]'s error table — the one
-//! `modules/memory.rs` keeps shared "because reimplementing the mapping here is
-//! what would let a `PathEscape` arrive as an `Invalid`, silently reclassifying
-//! a sandbox escape as a caller mistake" — and is filtered by the capability
-//! set `ModuleMemoryProvider::verify` cross-checks against the module's own
-//! answer.
-//!
-//! A direct `tinymemory_core::…` call gets neither. It is a second, unpoliced
-//! door into the same subsystem, and two doors into one capability is a
-//! capability whose behaviour can diverge. That is the disease, and it is the
-//! only reason this lint still exists.
-//!
-//! **The symptom is gone: `tinymemory-core` is no longer linked into the
-//! shipped binary** (#5560). It used to cost 1.44 MB of `.text` as the 7th
-//! largest crate, and that sentence stood here for as long as any entry
-//! remained. It no longer follows. The crate left `[dependencies]` on
-//! 2026-08-31 while this list still held nine entries, because **every
-//! surviving entry is test-only code**, served by the `[dev-dependencies]`
-//! entry that cargo does not link into the product. `cargo tree -e normal -i
-//! tinymemory-core` under the product feature set prints "nothing to print".
-//!
-//! Read the consequence carefully, because it inverts what this file used to
-//! assume: **a non-empty list no longer means a linked engine.** Draining the
-//! rest is still worth doing — a second door is a correctness problem whether
-//! or not it ships — but it buys no bytes, and nobody should size it as though
-//! it did.
-//!
-//! # This lint is a ratchet, not an invariant
-//!
-//! Same shape and same reasoning as [`super::bypass_allowlist_tests`], and as
-//! `INTENTIONALLY_NOT_FORWARDED` in `scripts/lib/feature-forwarding.mjs`: the
-//! current direct callers are enumerated in [`ALLOWED`] with a classification
-//! and a reason each, and **that list may shrink but must never grow**. A lint
-//! that was red on day one would be `#[ignore]`d within a week; a green ratchet
-//! converges.
-//!
-//! # The classification, and why most of the list cannot move yet
-//!
-//! Each entry carries a [`Verdict`], which is the inventory the migration is
-//! driven from:
-//!
-//! - [`Verdict::SeamExpressible`] — the existing `MemoryProvider` surface
-//! already covers this. These are the ones to migrate; a non-empty set here
-//! is a to-do list, not a steady state.
-//! - [`Verdict::NeedsWiderSeam`] — the call wants something the thirteen
-//! capability families do not expose. **These are blocked upstream, not
-//! here.** `modules::registry` pins the TinyMemory module to a released,
-//! SHA-256-verified artifact (v1.0.1 at the time of writing), so a new bus
-//! method is a `tinymemory` release plus a registry re-pin before it is a
-//! host change. Adding the trait method alone would produce a driver that
-//! answers `Unsupported` — strictly worse than the direct call it replaced,
-//! because the failure moves from compile time to run time.
-//! - [`Verdict::HostSide`] — not a driver call at all. Re-export shims,
-//! host-seam installation, and inert type imports. These are correct as they
-//! stand and are counted only so "deliberate" stays distinguishable from
-//! "forgotten".
-//!
-//! ## The concrete gaps, for whoever picks the upstream work up
-//!
-//! **This list was drained on 2026-08-23 and the shape of the problem changed.**
-//! It used to enumerate four things the seam could not express — retrieval
-//! filters, chunk reads, an entity-kind filter, and source listing — plus the
-//! people domain and the `source_scope` task-local. Every one of those now has
-//! a home:
-//!
-//! - **Retrieval filters, chunk reads, entity-kind search** — `MemoryRetrieval`
-//! (`fast_retrieve`, `cover_window`, `retrieve_source`, `retrieve_children`,
-//! `retrieve_leaves`, `recall_namespace_scored`, `search_entities`) and
-//! `MemoryChunks` (`list_chunks`, `get_chunk`, `chunk_detail`,
-//! `storage_kinds`, `chunk_embeddings`).
-//! - **The people domain** — `MemoryPeople`, seven methods.
-//! - **Profile/facets** — `MemoryProfile`, eleven methods, which
-//! `memory::guard`'s docs separately described as a missing "fourteenth
-//! family".
-//! - **`source_scope`** — not a seam gap at all. It is host policy; it lives in
-//! `memory::source_scope`, and the scope crosses the bus as a `SourceScope`
-//! value on every scoped method.
-//!
-//! `ModuleMemoryProvider` implements all of these bar `as_episodic`, and
-//! `MemoryGuard` wraps all fifteen families.
-//!
-//! **So what blocks the migration is release lag, not seam width.**
-//! `modules::registry` pins a SHA-256-verified artifact, and the five families
-//! above shipped in no release until v1.2.0. Before migrating a call site onto
-//! one, check the *tag* rather than the vendored source — the submodule is
-//! routinely ahead of what is pinned. A method the pinned artifact does not
-//! serve answers `Unsupported` at run time, which is strictly worse than the
-//! direct call it replaced.
-//!
-//! What genuinely has no bus representation yet, and is the next upstream ask:
-//! the ingest `queue`, the `chat` runtime seam, the composio sync pipelines,
-//! and **recency recall**. The first three live inside `tinymemory-core` and
-//! would each need a design pass, not just a trait method.
-//!
-//! Recency recall is the subtle one, and it is worth spelling out because the
-//! obvious migration is wrong. `MemoryRetrieval::recall_namespace_scored` looks
-//! like the twin for `memory.recall_context` and `memory.recall_memories`, and
-//! it is not:
-//!
-//! - `recall_namespace_scored` resolves to
-//! `query_namespace_hits_excluding_session(ns, query, limit, exclude)` — the
-//! **query-ranked** path.
-//! - Both handlers call `recall_namespace_memories(ns, limit)` — a distinct
-//! **recency** path. `recall_namespace_context_data` is just that plus a
-//! rendered `context_text` wrapper.
-//!
-//! Passing an empty query to the scored method does not degrade to recency; it
-//! runs the ranking path with nothing to rank against. The two share a prefix
-//! (`load_documents_for_scope` + `kv_records_for_scope`) and diverge after it,
-//! so the swap compiles, returns plausible hits, and quietly changes what the
-//! user gets back. `memory.query_namespace` *is* safely expressible, because it
-//! has a real query — pass `exclude_session_id: None` there to preserve the
-//! current no-exclusion behaviour, since an RPC handler is not an agent turn.
-//!
-//! The upstream ask is a `RecallNamespaceRecent`-shaped method on
-//! `MemoryRetrieval`.
-//!
-//! ## What the 2026-08-22 audit added to that list
-//!
-//! Draining `FacadeRevealed` turned 82 unexamined files into evidence, and it
-//! widened the ask rather than narrowing it. Grouped by what blocks them, so
-//! the upstream work can be sized per gap instead of per file:
-//!
-//! - **The engine handle itself** (~28 files) — `global::{init, client,
-//! client_if_ready}`, `store::{UnifiedMemory, MemoryClient, MemoryClientRef}`
-//! and `store::factories::create_memory`. These construct or hold the
-//! in-process engine. Nothing routes here: the seam has no door onto a live
-//! client, and it should not grow one — this is `memory::binding`'s job, and
-//! the ask is that every caller take the binding's provider instead.
-//! - **Chunk writes and transactions** (~21 files) —
-//! `store::chunks::store::{with_connection, upsert_chunks,
-//! upsert_staged_chunks_tx, get_or_init_connection}`, plus `store::{fts5,
-//! segments, profile, events, content}`. `MemoryChunks` is a read family;
-//! this is the write half, and `with_connection` hands out a SQLite handle,
-//! which no engine-neutral contract can promise. **Moving these subsystems
-//! behind the bus is the only shape that keeps a supermemory/mem0/cognee
-//! driver implementable** — a contract with `with_connection` in it is a
-//! SQLite contract wearing a trait.
-//! - **Host policy reached through the engine crate** — **drained.** The
-//! scrubbers (`store::safety::{sanitize_text, sanitize_json,
-//! has_likely_secret}`), `util::redact::redact`, `source_scope::*` and the
-//! Obsidian vault-registration probe (`store::content::obsidian_registry`)
-//! all live host-side now, in `memory::safety`, `util::redact`,
-//! `memory::source_scope` and `memory::obsidian_registry`. The route each
-//! took is the shape to reuse, and it is **not** "move it to
-//! `tinymemory-api`": a scrubber costs `regex` + `serde_json`,
-//! `util::redact` costs `sha2`, and the vault probe costs `dirs` +
-//! `serde_json`, in a crate whose whole point is that a caller can depend on
-//! it and compile almost nothing — and `source_scope` is a
-//! `tokio::task_local`, which would put tokio there too. None of the four is
-//! contract vocabulary — nothing crosses the bus as a `SanitizationReport`,
-//! a log hash or a `VaultRegistration`, and "is my content root a registered
-//! Obsidian vault" is not a capability a second driver would answer
-//! differently — so each is simply the host's, with the engine keeping its
-//! own copy for its own callers. Independent copies are the design: neither
-//! side reads the other's output.
-//! - **The re-embed queue** (~8 files) — `queue::{start, store, types,
-//! ensure_reembed_backfill, requeue_failed_after_provider_change,
-//! drain_until_idle, wake_workers, backfill_in_progress}`. No family.
-//! - **Engine-shaped integration internals** (~11 files) —
-//! `tinycortex::{memory_config_from, run_composio_connection,
-//! load_composio_sync_state, HostSyncAdapter, CodingSession*}`. Named after
-//! the engine, so no engine-neutral family can express them as they stand.
-//! - **Engine-owned types** — `store::trees::types::TreeKind`, and
-//! `store::{NamespaceDocumentInput, NamespaceRetrievalContext,
-//! GraphRelationRecord}` (`store::chunks::types::SourceKind`/`SourceRef`
-//! were on this list and are **done** — see below). A type import links the
-//! crate exactly as a call does, so the shed needs these in
-//! `tinymemory-api`. `MemoryCategory`/`MemoryEntry`/`MemoryTaint` already
-//! are — `tinymemory_core::traits` re-exports them — so those call sites can
-//! name the contract today.
-//!
-//! `rpc_models` was on this list and is **done**: all forty-five types were
-//! named by this host and by nothing inside `tinymemory`, so they moved to
-//! `memory::rpc_models` rather than into the contract. That is the shape to
-//! look for first in what remains — a type the engine crate defines but only
-//! the host uses does not need a contract to live in, it needs to come home.
-//! `SourceKind`/`SourceRef` were called out here as emphatically **not**
-//! such a case, on the grounds that the engine path resolved to a
-//! `tinycortex-api` type distinct from the contract's. That is no longer
-//! true: `tinycortex-api` is a deprecated re-export of `tinymemory-bus` and
-//! the two paths resolve to the **same item**, verified by a compile-time
-//! identity probe and then by repointing every call site. Prefer
-//! `tinymemory_api::chunks::…` in new code. The general warning still holds
-//! for *other* near-identical pairs — probe before assuming, either way.
-//! - **Chat, ingest pipeline and preferences** (~12 files) —
-//! `chat::{ChatProvider, build_chat_provider, test_override}`,
-//! `ingest_pipeline::{ingest_chat, ingest_document_with_scope}`,
-//! `preferences::{STANDING_PREFS_LIMIT, load_general_preferences,
-//! recall_situational_preferences}`.
-//!
-//! The order that follows from this: relocate the pure helpers and types to
-//! `tinymemory-api` (no bus surface, no release coupling), then move the
-//! queue and chunk-write subsystems behind the module, and only then can the
-//! handle-holding callers take the binding's provider and the crate leave the
-//! build. Nothing here is a host-side routing pass, which is what the original
-//! scope assumed.
-//!
-//! # Known weaknesses, stated rather than hidden
-//!
-//! - **One needle, two crates — and #5560 sheds both.** [`NEEDLE`] is
-//! `tinymemory_core::` alone, but `tinycortex` is a direct dependency of this
-//! crate in its own right, not something reached through the engine crate. So
-//! repointing a file from `tinymemory_core::x` to `tinycortex::x` clears its
-//! entry here while leaving an engine linked, and the ratchet reads as
-//! progress. **That is not a migration; it is the lint losing sight of the
-//! file.** `memory::tree::health` moved that way legitimately — the taxonomy
-//! was always `tinycortex`'s and the engine crate only re-exported it — and
-//! `memory::tools::flavour` was a `tinycortex` caller this lint never saw at
-//! all until it moved onto `MemoryTree::flavour_profile`. Before concluding
-//! the crates have left the build, run the scan for **both** spellings; at
-//! the time of writing `tinycortex::` finds one production file
-//! (`src/bin/library_profile/scenarios/memory_ingest.rs`) and it is already
-//! listed below for the other needle.
-//! - **The lint sees text, not types.** A reference reached through a
-//! re-export under another name is invisible to it — and the memory tree is
-//! full of those on purpose: `memory/mod.rs` re-exports twenty-five engine
-//! modules, and ~687 `memory::store::…` / `memory::tree::…` paths elsewhere
-//! resolve into the crate through them. **This lint deliberately does not
-//! count those.** It counts the sites that *name* the crate, because those
-//! are the ones a migration edits. The re-export surface is a separate,
-//! larger problem tracked in the issue, and pretending this number covers it
-//! would be the worst outcome.
-//! - **By-path test files are out of scope** (`*_tests.rs`, `tests.rs`,
-//! `test_support/`), matching the sibling lint. Several inline
-//! `#[cfg(test)]` modules do name the crate (`query::drill_down`,
-//! `query::fetch_leaves`, `query::query_source` each assert a tool's result
-//! against a direct engine call); those files are listed, and the entry says
-//! so.
-//! - **Comment lines are skipped**, so the many doc comments that reference
-//! `tinymemory_core::…` by path do not inflate the count.
-
-use std::collections::BTreeSet;
-use std::path::{Path, PathBuf};
-
-/// Why a file may name the engine crate today.
-#[derive(Clone, Copy, PartialEq, Eq, Debug)]
-pub(crate) enum Verdict {
- /// The existing `MemoryProvider` surface covers this. Migrate it.
- SeamExpressible,
- /// Blocked on a wider bus surface, which means an upstream `tinymemory`
- /// release and a `modules::registry` re-pin.
- NeedsWiderSeam,
- /// Not a driver call: a re-export shim, host-seam installation, or an
- /// inert type import.
- HostSide,
- /// The file's engine dependency **predates this branch** and was hidden
- /// behind `memory/mod.rs`'s re-export facade; deleting that facade made it
- /// textually visible to this lint without changing what the file does.
- ///
- /// It is a deliberately unflattering label. These are not audited, and the
- /// bucket exists so that "nobody has looked at this yet" cannot be mistaken
- /// for one of the three considered verdicts above. Draining it means
- /// re-classifying each entry as one of those three, not deleting the
- /// variant.
- ///
- /// **Drained 2026-08-22.** All 82 entries were audited into the three
- /// considered verdicts; none turned out to be [`Verdict::SeamExpressible`],
- /// which is the finding rather than a formality — every one of them is
- /// blocked on a contract the module does not yet expose, so the remaining
- /// #5560 work is upstream in `tinymemory` and not a routing pass here. The
- /// variant is kept rather than removed for the reason it was added: if a
- /// re-export facade grows back and hides engine users again, the label for
- /// them already exists and already says what it means.
- #[allow(
- dead_code,
- reason = "drained 2026-08-22; retained as the landing spot if a facade regrows"
- )]
- FacadeRevealed,
-}
-
-/// The literal this lint searches for. A single needle, deliberately: the
-/// question is "does this file name the engine crate", not "which item".
-const NEEDLE: &str = "tinymemory_core::";
-
-/// `(repo-relative path, verdict, why it names the engine today)`.
-///
-/// Adding an entry is a decision, not a way to silence the lint. Sorted by
-/// path — [`scan`] returns a `BTreeSet`, so keeping the literal in the same
-/// order makes diffs readable.
-const ALLOWED: &[(&str, Verdict, &str)] = &[
- // ── Revealed by deleting the `memory/mod.rs` re-export facade ───────────
- //
- // This lint was calibrated against a tree where `memory/mod.rs` re-exported
- // ~24 engine names, so a file writing `crate::openhuman::memory::UnifiedMemory`
- // did not match the `tinymemory_core::` needle. Those files were direct
- // engine users the whole time; the facade just spelled the dependency
- // differently. Deleting it — so that `grep tinymemory_core` *is* the
- // inventory — is what surfaced them, and the count of real engine
- // dependencies did not grow by one.
- //
- // Audited individually on 2026-08-22 and re-classified out of
- // `FacadeRevealed`; each entry now names the symbols it actually reaches
- // for, so the verdict is checkable against the code rather than taken on
- // trust. The audit's finding is that none of them is `SeamExpressible`.
- (
- "src/bin/library_profile/scenarios/cold_phases.rs",
- Verdict::NeedsWiderSeam,
- "holds or boots the in-process engine handle (store::MemoryClient); driver construction belongs to memory::binding and the seam has no door onto the live client",
- ),
- (
- "src/bin/library_profile/scenarios/memory_ingest.rs",
- Verdict::NeedsWiderSeam,
- "engine-internal ingest pipeline entry (ingest_pipeline::ingest_chat, queue::drain_until_idle); the ingest family covers documents and chat, not the scope-carrying pipeline variants",
- ),
- (
- "src/openhuman/agent/harness/archivist/recap.rs",
- Verdict::NeedsWiderSeam,
- "the engine-side chat provider seam (chat::test_override) plus the engine fold it scopes (tree::summarise::{summarise, SummaryInput, SummaryContext}, tree::tree::TreeKind), all named only from the `#[cfg(test)]` recap arm: the deterministic provider those tests install is a task-local inside this binary's copy of the engine, which a module in its own process cannot see. Named engine-direct since the memory::tree shims were deleted. The production fold is MemoryTree::summarise",
- ),
- (
- "src/openhuman/agent/harness/archivist/test_constructors.rs",
- Verdict::NeedsWiderSeam,
- "the engine-side chat provider seam (chat::ChatProvider); MemoryIngest has no provider-override door",
- ),
- (
- "src/openhuman/agent/harness/archivist/tree_ingest.rs",
- Verdict::NeedsWiderSeam,
- "reaches engine storage below the contract (store::fts5, store::segments::ConversationSegment, ingest_pipeline); MemoryChunks is read-only (list_chunks/get_chunk/chunk_detail/storage_kinds/chunk_embeddings) with no write or transaction door",
- ),
- (
- "src/openhuman/agent/harness/archivist/types.rs",
- Verdict::NeedsWiderSeam,
- "the engine-side chat provider seam (chat::ChatProvider); MemoryIngest has no provider-override door",
- ),
- (
- "src/openhuman/channels/tests/memory.rs",
- Verdict::NeedsWiderSeam,
- "holds or boots the in-process engine handle (store::UnifiedMemory); driver construction belongs to memory::binding and the seam has no door onto the live client",
- ),
- (
- "src/openhuman/integrations/composio/ops/mod.rs",
- Verdict::NeedsWiderSeam,
- "holds or boots the in-process engine handle (store::MemoryClient); driver construction belongs to memory::binding and the seam has no door onto the live client",
- ),
- (
- "src/openhuman/memory/read_rpc/mod.rs",
- Verdict::NeedsWiderSeam,
- "one `#[cfg(test)]` re-export of store::chunks::store::with_connection, the raw SQLite door the read_rpc tests assert written rows through — asserting storage rather than re-reading through the handler under test. MemoryChunks is read-only (list_chunks/get_chunk/chunk_detail/storage_kinds/chunk_embeddings) with no transaction door, and a contract that had one would be a SQLite contract wearing a trait. Nothing production-side in read_rpc names the engine: SourceKind is tinymemory_api::chunks::SourceKind, and wipe_all/delete_source/flush_source_tree are purge_all, forget_matching and Tree::flush_source_tree",
- ),
- // ── Re-export shims: `pub use tinymemory_core::<domain>::*;` ────────────
- //
- // **Drained.** Four of these existed — `tree/mod.rs`, `tree/health/mod.rs`,
- // `tree/tree/mod.rs` and `tree/tree_runtime/mod.rs` — carrying the
- // historical-path aliases `memory/mod.rs` documented. The first three had
- // no production consumer left, only tests; those tests name the engine
- // crates directly now (served by the `[dev-dependencies]` tinymemory-core
- // entry) and the globs went with them.
- //
- // `tree_runtime` was the last, and the only one that was still production-
- // live: five `tree_summarizer_*` RPC handlers, the `tree-summarizer` CLI,
- // `memory::ops::learn` and the channels-startup subscriber ran the markdown
- // time tree in-process through it. It is gone because the seam grew the six
- // doors it needed — `RuntimeBufferWrite`, `RuntimeReadNode`,
- // `RuntimeReadChildren`, `RuntimeTreeStatus`, `RuntimeSummarize`,
- // `RuntimeRebuild` — in tinymemory PR #123 (contract 4.0). That is the
- // shape every remaining `NeedsWiderSeam` entry below is waiting for, and
- // the first one to complete the loop: upstream door, host migration,
- // entry deleted.
- //
- // ── Host-seam installation: the host handing itself TO the engine ───────
- //
- // The direction of these is inbound, not outbound: they install embedding /
- // chat / config / NLP / scheduler / shutdown / error-reporting callbacks
- // into the in-process engine. `modules/memory_host.rs` is the same seam
- // served over the bus. They are what an embedded engine needs, and they
- // are the last thing to remove, not the first.
- (
- "src/openhuman/memory/host_impls.rs",
- Verdict::HostSide,
- "installs the seven host seams (embedding, chat, config, nlp, scheduler gate, shutdown, error reporter) into an in-process engine, and the whole module sits behind the default-ON/product-OFF `memory-engine-seams` feature since #5560 — it is listed here only because this lint scans source text and does not track cfg. A feature rather than #[cfg(test)] because a tests/ integration target links this crate as an ordinary dependency, where cfg(test) is false and the module would be invisible however the engine is declared, and two dozen of them install these seams. Its production callers are gone: runtime::context, memory_cli and agent::debug install memory::host::install_memory_event_sink() instead, which is a tinymemory-api seam (still a normal dependency) with a live host-side publisher in memory::sync::composio::bus. That split is load-bearing — tinymemory_api::events::publish drops silently when unwired, so folding the sink in here would have removed a live event path with no error anywhere. What still needs these installs is install_for_tests, whose ~90 callers stand up a real in-process engine from the [dev-dependencies] entry. The seams themselves are also served for the LOADED module by modules/memory_host.rs, over the module's own inbound interfaces — a separate mechanism, since a cdylib has its own statics and never saw what was set here",
- ),
- // ── Retrieval: filters the seam's tree family has no room for ───────────
- // ── Agent tools: chunk reads, source listing, people, source scope ──────
-];
-
-/// True for source files the lint deliberately does not scan.
-///
-/// By-path only, matching [`super::bypass_allowlist_tests`] — see that module
-/// for why inline `#[cfg(test)]` blocks are left in scope rather than
-/// brace-tracked.
-fn is_test_path(path: &Path) -> bool {
- if path.components().any(|c| c.as_os_str() == "test_support") {
- return true;
- }
- match path.file_name().and_then(|n| n.to_str()) {
- Some(name) => name == "tests.rs" || name.ends_with("_tests.rs"),
- None => false,
- }
-}
-
-fn collect_rs_files(dir: &Path, out: &mut Vec<PathBuf>) {
- let Ok(entries) = std::fs::read_dir(dir) else {
- return;
- };
- for entry in entries.flatten() {
- let path = entry.path();
- if path.is_dir() {
- collect_rs_files(&path, out);
- } else if path.extension().is_some_and(|ext| ext == "rs") && !is_test_path(&path) {
- out.push(path);
- }
- }
-}
-
-/// Every repo-relative path in this crate's `src` that names the engine crate
-/// outside a comment.
-fn scan() -> BTreeSet<String> {
- let root = Path::new(env!("CARGO_MANIFEST_DIR"));
- let mut files = Vec::new();
- collect_rs_files(&root.join("src"), &mut files);
-
- let mut found = BTreeSet::new();
- for path in &files {
- let Ok(text) = std::fs::read_to_string(path) else {
- continue;
- };
- let rel = path
- .strip_prefix(root)
- .unwrap_or(path)
- .to_string_lossy()
- .replace('\\', "/");
- for line in text.lines() {
- if line.trim_start().starts_with("//") {
- continue;
- }
- if line.contains(NEEDLE) {
- found.insert(rel.clone());
- break;
- }
- }
- }
- found
-}
-
-fn allowed_set() -> BTreeSet<String> {
- ALLOWED
- .iter()
- .map(|(path, _, _)| (*path).to_string())
- .collect()
-}
-
-fn render(paths: impl IntoIterator<Item = String>) -> String {
- paths.into_iter().map(|p| format!("\n {p}")).collect()
-}
-
-/// A scanner that silently found nothing would turn every other test here into
-/// a rubber stamp, so refuse to pass vacuously.
-///
-/// `memory/host_impls.rs` is the most stable pin available now that the
-/// `memory/mod.rs` re-export block has been drained: it installs the seven host
-/// seams, so it names the crate by construction for as long as the engine is
-/// linked at all. If the scanner stops seeing it, the scanner is broken — fix
-/// it, do not relax this assertion.
-#[test]
-fn direct_reference_scanner_is_not_vacuous() {
- let found = scan();
- let allowed = allowed_set();
-
- // The canary only holds while the allowlist still names it. Asserting it
- // unconditionally would turn the last migration in this file into a
- // failure, which is backwards: draining the list is the goal.
- if allowed.contains("src/openhuman/memory/host_impls.rs") {
- assert!(
- found.contains("src/openhuman/memory/host_impls.rs"),
- "scanner found no direct engine reference in memory/host_impls.rs, which installs \
- the host seams; the scanner is broken"
- );
- }
-
- // The real vacuity risk is `scan()` silently returning nothing — a broken
- // walk, a moved `src/`, a needle that stopped matching — which would turn
- // `no_new_files_call_the_engine_directly` into a rubber stamp. Pin it to
- // the allowlist rather than to a literal, so the assertion stays true as
- // the list drains instead of having to be hand-edited on every migration.
- //
- // It was a literal (`found.len() > 20`) until 2026-08-31, by which point
- // ALLOWED itself had shrunk to exactly 20 — and because the two difference
- // tests below force `found == allowed`, `20 > 20` made this test
- // unsatisfiable on `main`. A ratchet that cannot pass is not a ratchet.
- assert!(
- !allowed.is_empty() || found.is_empty(),
- "the allowlist is empty but the scanner still found {} file(s): {}",
- found.len(),
- render(found.iter().cloned())
- );
- assert!(
- allowed.is_empty() || !found.is_empty(),
- "scanner found nothing while the allowlist still names {} file(s); the scanner is broken",
- allowed.len()
- );
-}
-
-/// **The ratchet.** A new file naming `tinymemory_core::` fails here.
-///
-/// If the new call is genuinely unavoidable, add it to [`ALLOWED`] with a
-/// [`Verdict`] and a reason. If it is not, route it through
-/// `CoreContext::memory()` and the `MemoryProvider` seam.
-#[test]
-fn no_new_files_call_the_engine_directly() {
- let found = scan();
- let allowed = allowed_set();
- let unexpected: Vec<String> = found.difference(&allowed).cloned().collect();
- assert!(
- unexpected.is_empty(),
- "new direct `tinymemory_core::` reference(s) — route these through the MemoryProvider seam, \
- or add them to ALLOWED with a Verdict and a reason:{}",
- render(unexpected)
- );
-}
-
-/// The staleness half. An allowlist that outlives its entries rots into dead
-/// strings that document nothing — the same failure `INTENTIONALLY_NOT_FORWARDED`
-/// guards against. A migrated file must be *removed* from the list, so the
-/// count is always the real one.
-#[test]
-fn allowlist_has_no_stale_entries() {
- let found = scan();
- let allowed = allowed_set();
- let stale: Vec<String> = allowed.difference(&found).cloned().collect();
- assert!(
- stale.is_empty(),
- "ALLOWED names file(s) that no longer reference the engine — delete these entries so the \
- ratchet reflects reality:{}",
- render(stale)
- );
-}
-
-/// Every entry carries a reason, and no path is listed twice. A blank reason is
-/// an allowlist entry that documents nothing, which is what the list exists to
-/// prevent.
-#[test]
-fn allowlist_entries_are_well_formed() {
- let mut seen = BTreeSet::new();
- for (path, _, reason) in ALLOWED {
- assert!(
- !reason.trim().is_empty(),
- "{path} is allowlisted with no reason"
- );
- assert!(
- seen.insert(*path),
- "{path} is listed twice; one entry per file"
- );
- }
-}
-
-/// The migration to-do list must be empty, and stay empty by being *worked*
-/// rather than re-labelled.
-///
-/// A [`Verdict::SeamExpressible`] entry says "the seam already covers this and
-/// nobody moved it". That is a bug with a known fix, so it fails here rather
-/// than sitting in a list nobody reads. Downgrading an entry to
-/// [`Verdict::NeedsWiderSeam`] to silence this is the one edit that would make
-/// the lint lie — [`no_new_files_call_the_engine_directly`] would still pass,
-/// and the gap would vanish from view.
-#[test]
-fn nothing_is_left_migratable() {
- let pending: Vec<&str> = ALLOWED
- .iter()
- .filter(|(_, verdict, _)| *verdict == Verdict::SeamExpressible)
- .map(|(path, _, _)| *path)
- .collect();
- assert!(
- pending.is_empty(),
- "these files can already be expressed through MemoryProvider and should be migrated: {pending:?}"
- );
-}
-
-/// The blocked set is the upstream ask, so it must be non-empty for as long as
-/// any file still names the engine crate — and empty when none does.
-///
-/// **This test was written to be self-proving and was not.** Its premise was
-/// that "the crate is dropped" and "`ALLOWED` empties" are the same event, so
-/// that the day one happened the other would force the module docs above to be
-/// rewritten. #5560 falsified that on 2026-08-31: `tinymemory-core` left
-/// `[dependencies]` with **nine entries still listed**, and this assertion did
-/// not move, because [`scan`] reads source text and every surviving entry is
-/// test-only code that the `[dev-dependencies]` entry still compiles.
-///
-/// The rewrite happened anyway — by hand, not because a test demanded it. Do
-/// not restore the old wording, and do not add an assertion tying this list to
-/// the manifest: the two are genuinely independent now, and a lint that claimed
-/// otherwise would fail for a build that is correct.
-///
-/// What it still buys is the honest half: a list that empties while files
-/// remain, or files that remain while the list empties, is a broken scanner.
-#[test]
-fn the_blocked_set_matches_the_engine_still_being_linked() {
- let blocked = ALLOWED
- .iter()
- .filter(|(_, verdict, _)| *verdict == Verdict::NeedsWiderSeam)
- .count();
- let host_side = ALLOWED
- .iter()
- .filter(|(_, verdict, _)| *verdict == Verdict::HostSide)
- .count();
- assert!(
- blocked > 0 || host_side > 0,
- "nothing references tinymemory-core any more — drop the remaining \
- [dev-dependencies] entry from Cargo.toml and rewrite this module's docs. \
- The [dependencies] entry, the cargo-machete `ignored` list and \
- scripts/kernel-floor.limits were all settled in #5560, when the crate left \
- the product build with this list still non-empty"
- );
-}
diff --git a/src/openhuman/memory/host_impls.rs b/src/openhuman/memory/host_impls.rs
deleted file mode 100644
index 2ce1d6c002..0000000000
--- a/src/openhuman/memory/host_impls.rs
+++ /dev/null
@@ -1,543 +0,0 @@
-//! Host implementations of the seam traits `tinymemory-core` declares.
-//!
-//! The extracted memory subsystem reaches back into OpenHuman through nine
-//! traits (see `tinymemory_api::host` and the `*_host` modules in
-//! `tinymemory_core`). [`super::host`] carries the two that are about *data* —
-//! `MemoryHostConfig` and `MemoryEventSink`. This module carries the seven that
-//! are about *capability*: building providers, loading config, running spaCy,
-//! throttling background work, reporting errors.
-//!
-//! # This whole module is behind `memory-engine-seams` (#5560)
-//!
-//! `tinymemory-core` has left the product build. It is a `[dev-dependencies]`
-//! entry plus an `optional = true` normal one that only `memory-engine-seams`
-//! and `rss-bench` turn on, so the engine these seams install into does not
-//! exist in anything shipped — and neither does this module.
-//!
-//! The gate is a **feature** rather than `#[cfg(test)]`, and the reason is
-//! worth knowing before "simplifying" it: a `tests/*.rs` integration target
-//! links this crate as an ordinary dependency, where `cfg(test)` is false, so a
-//! `#[cfg(test)]` module is invisible to it however the engine is declared. Two
-//! dozen of those targets call [`install_memory_host_seams`], and several of
-//! them drive a real in-process engine — the archivist, session-turn and
-//! memory-sync cases in `raw_coverage_all` fail with "no EmbeddingHost
-//! installed" without it, which is the same failure the first attempt at #5560
-//! shipped to users. `memory-engine-seams` is default-ON, product-OFF and
-//! allow-listed in `INTENTIONALLY_NOT_FORWARDED`.
-//!
-//! **The feature makes the engine available, not used.** In a default build
-//! nothing in production reaches it: the boot sites install only the contract
-//! event sink, so a linked-but-unwired engine is never called and the seams'
-//! fail-loud behaviour is never triggered.
-//!
-//! Production reaches the engine through the loaded TinyMemory module over the
-//! bus, and
-//! `modules::memory_host` serves the same seven capabilities there through the
-//! module's own inbound interfaces, which are a different mechanism entirely: a
-//! `cdylib` has its own statics, so nothing installed here was ever visible to
-//! it, and nothing it installs is visible here.
-//!
-//! **The contract event sink is not one of these seams and is not gated.** It
-//! installs into `tinymemory_api`, which is still a normal dependency, and
-//! `memory::sync::composio::bus` publishes `ComposioIntegrationsChanged`
-//! through it from production host code. Each boot site calls
-//! [`super::host::install_memory_event_sink`] directly for that reason —
-//! `tinymemory_api::events::publish` drops silently when unwired, so folding it
-//! in here would have removed a live event path without a single error.
-//!
-//! # They are process-globals, installed once
-//!
-//! Every one is reached through a `set_*` installer that
-//! [`install_memory_host_seams`] calls, before any memory work begins. That
-//! mirrors the shape the subsystem had before the extraction, when these were
-//! free functions it called directly; [`install_for_tests`] is the one caller
-//! that matters now.
-//!
-//! # Why several of them capture an `Arc<Config>`
-//!
-//! Four of the seams take a config on the seam side but delegate to a host
-//! function whose signature does not (`resolve_api_key`, `ollama_base_url`,
-//! `api_key`). Those impls hold the config the installer was given. It is the
-//! startup config: a mid-session settings change is *not* reflected, which
-//! matches how the pre-extraction call sites behaved — they read the same
-//! ambient config — but is worth knowing before adding a seam method that
-//! should be live. Seams that must be live (`ConfigLoader`) take a `&Config`
-//! argument and re-read instead.
-//!
-//! # How this came to be test-only, and the wrong argument for it (#5560)
-//!
-//! `memory::binding` refuses `DriverClass::Embedded` outright — "embedded
-//! memory drivers are no longer supported; use the 'tinymemory' module driver"
-//! — and `modules::memory_host` serves this same set of seven over the bus for
-//! the module. Both facts together read like an argument that the in-process
-//! installs below are only reached from tests, and #5560 acted on exactly that
-//! reading once and had to be reverted. **The driver class was the wrong thing
-//! to check**: it governs what answers a `MemoryProvider` call and says nothing
-//! about the free-function engine surface a call site can reach around the
-//! binding entirely — the "second unpoliced door" `memory::direct_engine_refs`
-//! is a ratchet over. The argument that eventually held is the one below:
-//! caller by caller, until the free-function surface had no production reader
-//! and the crate could leave the manifest.
-//!
-//! **Every production path this section used to name is now gone.** They went
-//! one contract round at a time, and the list is worth keeping because it is
-//! the shape the remaining work takes:
-//!
-//! - `agent::harness::archivist::recap` folds through `MemoryTree::summarise`.
-//! - `memory::tools::doctor` runs through `MemoryMaintenance::diagnose`.
-//! - `memory::tree::tree_runtime` — the last production glob
-//! (`pub use tinymemory_core::tree::tree_runtime::*`) — is deleted. Its five
-//! `tree_summarizer_*` RPC handlers, the `openhuman tree-summarizer` CLI,
-//! `memory::ops::learn` and the channels-startup subscriber ran the markdown
-//! time tree in *this* process and built its fold through
-//! `chat_host::create_chat_model_with_model_id`; they go over the bus now,
-//! through the six runtime-tree doors.
-//! - `memory::tools::flavour` reached `tinycortex::memory::tree` directly and
-//! is on `MemoryTree::flavour_profile`.
-//!
-//! So **no production caller reaches an in-process engine fold any more**, and
-//! [`ChatHost`] below is reached only from the far side of the bus, where
-//! `modules::memory_host` serves it for the loaded module. That is not the same
-//! thing as the installs being dead: unwire them and the module's own
-//! summariser run fails with "no ChatHost installed", which is the failure
-//! #5560 shipped once as "no EmbeddingHost installed" on the chat hot path. The
-//! seams fail **loudly** rather than degrading, which is a property to keep.
-//!
-//! [`ChatHost::summarizer_available`] still delegates into
-//! `tree_runtime::ops::summarizer_available`, and that is now the *only* edge
-//! 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.
-//!
-//! **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 was not "is the driver embedded" but "does any
-//! production caller still reach an engine free function".** That inventory is
-//! now empty, and it was emptied rather than argued away: `session::builder::
-//! factory` stopped booting `global::init(workspace).memory_handle()`,
-//! `ops::helpers::active_memory_client` was deleted, and `memory_cli`'s
-//! `ingest`/`query` engine-client resolver went with it. What is left naming
-//! `tinymemory_core::` is `#[cfg(test)]`, which the `[dev-dependencies]` entry
-//! serves and the shipped binary does not link.
-//!
-//! **That grep is not the inventory for #5560 as a whole, and the difference
-//! matters.** #5560 sheds two crates, and `memory::direct_engine_refs` ratchets
-//! one needle. `tinycortex` is a direct dependency of this crate in its own
-//! right — not something reached through `tinymemory-core` — so repointing a
-//! file from `tinymemory_core::x` to `tinycortex::x` drops it out of that lint
-//! while the engine stays linked. `memory::tree::health` did exactly that, on
-//! the sound reasoning that the taxonomy was always `tinycortex`'s and the
-//! engine crate only re-exported it. Add `tinycortex::` to the grep before
-//! concluding the engine has left the build — at the time of writing the only
-//! production file it still finds is `src/bin/library_profile/scenarios/
-//! memory_ingest.rs`, which names both crates.
-//!
-//! # Composio no longer has a seam here
-//!
-//! `tinymemory_core::composio_host` was deleted in tinymemory v1.13.4 along
-//! with the whole in-process Composio sync pipeline: reaching a connected
-//! account needs a credential this crate must not hold. Composio sync is now
-//! host-initiated — `memory::sync::composio` drives it through the
-//! `tinyconnectors` module (see `modules::connectors`) and hands the resulting
-//! records to the driver through `MemorySourceSink::accept_source_items`,
-//! rather than the driver calling back into a host-installed seam.
-
-use std::sync::Arc;
-
-use async_trait::async_trait;
-use tinymemory_api::host::{
- EmbeddingHost, EmbeddingProvider, ErrorReporter, Policy, SpacyResponse, UsageInfo,
-};
-use tinymemory_core::chat_host::ChatHost;
-use tinymemory_core::config_loader::ConfigLoader;
-use tinymemory_core::nlp_host::NlpHost;
-use tinymemory_core::scheduler_gate::SchedulerGate;
-use tinymemory_core::shutdown::{ShutdownHook, ShutdownHost};
-use tokio::sync::Notify;
-
-use crate::openhuman::config::Config;
-
-/// Type alias for the seam's config trait object, to keep signatures readable.
-///
-/// Named on the contract crate rather than on `tinymemory_core::Config`, which
-/// is nothing but `pub type Config = dyn tinymemory_api::host::
-/// MemoryHostConfig;` — the same trait object under a longer chain. Spelling it
-/// this way is not cosmetic: it means every remaining `tinymemory_core::` line
-/// in this file is a *seam trait*, a *seam installation* or the in-process
-/// recovery door, so the direct-reference inventory reads as what actually
-/// keeps the engine linked here rather than as a mix of those and inert
-/// aliases (#5560).
-///
-/// `SpacyResponse` and `Policy` were the two aliases that still broke that
-/// rule, and they are imported from `tinymemory_api::host` above for the same
-/// reason. It is the identical item either way — `tinymemory_core::nlp_host`
-/// and `::scheduler_gate` are each a `pub use` of the contract's type — so the
-/// repoint is free, and what it buys is that a reader counting engine
-/// references in this file counts only things that would have to be *replaced*
-/// rather than merely *renamed*. The traits themselves (`ChatHost`,
-/// `ConfigLoader`, `NlpHost`, `SchedulerGate`, `ShutdownHost`) have no contract
-/// declaration and cannot follow: they are the in-process embedding seam, which
-/// is the half of `tinymemory_api::host` that never crosses the bus.
-type SeamConfig = dyn tinymemory_api::host::MemoryHostConfig;
-
-// ── Embeddings ──────────────────────────────────────────────────────────────
-
-/// Builds embedding providers for the memory subsystem.
-#[derive(Debug)]
-pub struct OpenHumanEmbeddingHost {
- config: Arc<Config>,
-}
-
-impl EmbeddingHost for OpenHumanEmbeddingHost {
- fn resolve_api_key(&self, provider: &str) -> Option<String> {
- let key = crate::openhuman::inference::embeddings::resolve_api_key(&self.config, provider);
- // The host returns "" for "no credential stored"; the seam distinguishes
- // absence from an empty key so callers can report the difference.
- (!key.is_empty()).then_some(key)
- }
-
- fn ollama_base_url(&self) -> String {
- crate::openhuman::inference::local::ollama_base_url_from_config(&self.config)
- }
-
- fn default_embedding_provider(&self) -> Arc<dyn EmbeddingProvider> {
- // Scope the managed embedder to THIS host's config credential store, not
- // the keyless `default_state_dir()` hardcode. The memory client caches
- // this provider for the process lifetime, so a keyless scope that misses
- // the signed-in user's `app-session` token makes every ingested
- // document persist vector-less while "Test connection" (config-scoped)
- // still passes — #5501.
- crate::openhuman::inference::embeddings::default_embedding_provider_with_config(
- &self.config,
- )
- }
-
- fn create_embedding_provider_with_credentials(
- &self,
- provider: &str,
- model: &str,
- dims: usize,
- api_key: &str,
- custom_endpoint: Option<&str>,
- ) -> Result<Box<dyn EmbeddingProvider>, String> {
- crate::openhuman::inference::embeddings::create_embedding_provider_with_credentials(
- provider,
- model,
- dims,
- api_key,
- custom_endpoint,
- )
- .map_err(|e| format!("{e:#}"))
- }
-
- fn model_supports_dimensions(&self, model: &str) -> bool {
- crate::openhuman::inference::embeddings::model_supports_dimensions(model)
- }
-
- fn cloud_embedding_provider(
- &self,
- model: &str,
- dims: usize,
- ) -> Result<Box<dyn EmbeddingProvider>, String> {
- Ok(Box::new(
- crate::openhuman::inference::embeddings::cloud::OpenHumanCloudEmbedding::new(
- None,
- self.config
- .config_path
- .parent()
- .map(std::path::PathBuf::from),
- self.config.secrets.encrypt,
- model,
- dims,
- ),
- ))
- }
-
- fn default_cloud_embedding_model(&self) -> &str {
- crate::openhuman::inference::embeddings::DEFAULT_CLOUD_EMBEDDING_MODEL
- }
-
- fn default_cloud_embedding_dimensions(&self) -> usize {
- crate::openhuman::inference::embeddings::DEFAULT_CLOUD_EMBEDDING_DIMENSIONS
- }
-
- fn ollama_embedding_provider(
- &self,
- base_url: &str,
- model: &str,
- dims: usize,
- ) -> Result<Box<dyn EmbeddingProvider>, String> {
- self.create_embedding_provider_with_credentials("ollama", model, dims, "", Some(base_url))
- }
-}
-
-// ── Chat models ─────────────────────────────────────────────────────────────
-
-/// Builds chat models for summarisation and the memory chat helper.
-///
-/// Routing reads BYOK fallbacks, per-role routes and credentials, so it needs
-/// the host's own `Config` — recovered from the trait object with
-/// [`host_config`]. The captured config is only the fallback for a caller that
-/// handed us somebody else's implementation.
-#[derive(Debug)]
-pub struct OpenHumanChatHost {
- config: Arc<Config>,
-}
-
-impl ChatHost for OpenHumanChatHost {
- fn provider_for_role(&self, role: &str, config: &SeamConfig) -> String {
- crate::openhuman::inference::provider::provider_for_role(
- role,
- host_config(config, &self.config),
- )
- }
-
- fn create_chat_model_with_model_id(
- &self,
- role: &str,
- config: &SeamConfig,
- temperature: f64,
- ) -> Result<(Arc<dyn tinyinference::model::ChatModel<()>>, String), String> {
- crate::openhuman::inference::provider::create_chat_model_with_model_id(
- role,
- host_config(config, &self.config),
- temperature,
- )
- .map_err(|e| format!("{e:#}"))
- }
-
- fn usage_from_response(
- &self,
- response: &tinyinference::model::ModelResponse,
- ) -> Option<UsageInfo> {
- crate::openhuman::agent::tinyagents::model::usage_info_from_response(response)
- }
-
- fn summarizer_available(&self, config: &SeamConfig) -> (bool, &'static str) {
- crate::openhuman::memory::tree::tree_runtime::ops::summarizer_available(host_config(
- config,
- &self.config,
- ))
- }
-}
-
-// ── Config loading ──────────────────────────────────────────────────────────
-
-/// Loads host configs for the memory subsystem's background loops.
-#[derive(Debug)]
-pub struct OpenHumanConfigLoader;
-
-#[async_trait]
-impl ConfigLoader for OpenHumanConfigLoader {
- async fn load(&self) -> Result<Box<SeamConfig>, String> {
- Ok(Box::new(
- crate::openhuman::config::rpc::load_config_with_timeout().await?,
- ))
- }
-
- async fn reload_snapshot(&self, snapshot: &SeamConfig) -> Result<Arc<SeamConfig>, String> {
- // Addressed by path, not by the whole config: the caller holds the
- // seam's trait object and cannot hand us a concrete `Config`.
- let config = crate::openhuman::config::rpc::reload_config_from_paths(
- snapshot.config_path(),
- snapshot.workspace_dir(),
- )
- .await?;
- Ok(Arc::new(config))
- }
-}
-
-// ── spaCy ───────────────────────────────────────────────────────────────────
-
-/// Runs spaCy extraction through the host's Python runtime.
-#[derive(Debug)]
-pub struct OpenHumanNlpHost;
-
-#[async_trait]
-impl NlpHost for OpenHumanNlpHost {
- async fn extract_spacy(
- &self,
- config: &SeamConfig,
- text: &str,
- ) -> Result<SpacyResponse, String> {
- let config = live_config(config).await?;
- crate::openhuman::runtime::python_server::extract_spacy(&config, text)
- .await
- .map_err(|e| format!("{e:#}"))
- }
-}
-
-// ── Scheduler gate ──────────────────────────────────────────────────────────
-
-/// Exposes the host's background-AI throttle.
-#[derive(Debug)]
-pub struct OpenHumanSchedulerGate;
-
-#[async_trait]
-impl SchedulerGate for OpenHumanSchedulerGate {
- fn current_policy(&self) -> Policy {
- crate::openhuman::cron::scheduler_gate::gate::current_policy()
- }
-
- fn resume_notify(&self) -> Arc<Notify> {
- crate::openhuman::cron::scheduler_gate::gate::resume_notify()
- }
-
- async fn wait_for_capacity(&self) -> Option<Box<dyn Send>> {
- crate::openhuman::cron::scheduler_gate::wait_for_capacity()
- .await
- .map(|permit| Box::new(permit) as Box<dyn Send>)
- }
-}
-
-// ── Shutdown ────────────────────────────────────────────────────────────────
-
-/// Registers memory shutdown hooks with the host's shutdown sequencer.
-#[derive(Debug)]
-pub struct OpenHumanShutdownHost;
-
-impl ShutdownHost for OpenHumanShutdownHost {
- fn register(&self, hook: ShutdownHook) {
- let hook = Arc::new(hook);
- crate::core::shutdown::register(move || {
- let hook = Arc::clone(&hook);
- async move { hook().await }
- });
- }
-}
-
-// ── Error reporting ─────────────────────────────────────────────────────────
-
-/// Routes memory error reports into the host's observability pipeline.
-#[derive(Debug)]
-pub struct OpenHumanErrorReporter;
-
-impl ErrorReporter for OpenHumanErrorReporter {
- fn report_error(&self, rendered: &str, domain: &str, operation: &str, tags: &[(&str, &str)]) {
- crate::core::observability::report_error(rendered, domain, operation, tags);
- }
-
- fn report_error_or_expected(
- &self,
- rendered: &str,
- domain: &str,
- operation: &str,
- tags: &[(&str, &str)],
- ) {
- crate::core::observability::report_error_or_expected(rendered, domain, operation, tags);
- }
-}
-
-// ── Wiring ──────────────────────────────────────────────────────────────────
-
-/// Recover the host's concrete `Config` from the seam's trait object.
-///
-/// Returns `fallback` when the config is some other implementor — a test
-/// double, say. That is not an error: it means there is no host config to
-/// recover, and the one the seam was installed with is the best answer.
-fn host_config<'a>(config: &'a SeamConfig, fallback: &'a Config) -> &'a Config {
- config.as_any().downcast_ref::<Config>().unwrap_or(fallback)
-}
-
-/// Re-read the host's concrete `Config` from the paths the seam points at.
-///
-/// The seam is `dyn MemoryHostConfig` and the host functions these impls
-/// delegate to want `&Config`. Recovering one is a file read, so it is only
-/// available to the **async** seam methods; the sync ones use the `Arc<Config>`
-/// captured at install time instead, and say so on their impl.
-///
-/// Deliberately not a downcast: `TestHostConfig` and any future implementor are
-/// not the host's `Config`, and a downcast would turn them into a silent `None`
-/// rather than an honest re-read.
-///
-/// # Errors
-///
-/// Returns `Err` when the config file cannot be read.
-async fn live_config(config: &SeamConfig) -> Result<Config, String> {
- crate::openhuman::config::rpc::reload_config_from_paths(
- config.config_path(),
- config.workspace_dir(),
- )
- .await
-}
-
-/// Install every host seam into `tinymemory-core`.
-///
-/// Call once during startup wiring, **before any memory work begins** — the
-/// embedding, chat and config seams all fail loudly when unwired, by design,
-/// because degrading quietly would corrupt an embedding space or make a sync
-/// run look empty rather than broken. Composio has no seam here any more —
-/// see the module docs.
-pub fn install_memory_host_seams(config: Arc<Config>) {
- tinymemory_core::embedding_host::set_embedding_host(Arc::new(OpenHumanEmbeddingHost {
- config: Arc::clone(&config),
- }));
- tinymemory_core::chat_host::set_chat_host(Arc::new(OpenHumanChatHost {
- config: Arc::clone(&config),
- }));
- tinymemory_core::config_loader::set_config_loader(Arc::new(OpenHumanConfigLoader));
- tinymemory_core::nlp_host::set_nlp_host(Arc::new(OpenHumanNlpHost));
- tinymemory_core::scheduler_gate::set_scheduler_gate(Arc::new(OpenHumanSchedulerGate));
- tinymemory_core::shutdown::set_shutdown_host(Arc::new(OpenHumanShutdownHost));
- tinymemory_core::observability::set_error_reporter(Arc::new(OpenHumanErrorReporter));
- super::host::install_memory_event_sink();
- log::debug!("[memory:host] all seam implementations installed");
-}
-
-/// Install the seams for this crate's own tests.
-///
-/// Before the extraction, memory code called `inference::embeddings` and the
-/// provider factory directly, so any test that built a memory client got the
-/// real implementations for free. The seams made that wiring explicit — which
-/// is the point at runtime, but it means a test that builds a client now has to
-/// say so. This installs exactly what used to be implicit: the real host impls,
-/// over a default config.
-///
-/// Idempotent, and safe to call from many test threads.
-///
-/// # Why the thread
-///
-/// `Config` is a large struct, and `Config::default()` materialises one on the
-/// caller's stack before it reaches the `Arc`. Most callers here are
-/// `#[tokio::test]` async fns whose futures are already deep; adding it inline
-/// 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.
-#[cfg(test)]
-pub(crate) fn install_for_tests() {
- use std::sync::Once;
- static INIT: Once = Once::new();
- INIT.call_once(|| {
- std::thread::Builder::new()
- .name("memory-seam-install".to_string())
- .stack_size(8 * 1024 * 1024)
- .spawn(|| install_memory_host_seams(Arc::new(Config::default())))
- .expect("spawn seam installer")
- .join()
- .expect("seam installer panicked");
- });
-}
-
-#[cfg(test)]
-#[path = "host_impls_boot_seam_tests_tests.rs"]
-mod boot_seam_tests;
diff --git a/src/openhuman/memory/host_impls_boot_seam_tests_tests.rs b/src/openhuman/memory/host_impls_boot_seam_tests_tests.rs
deleted file mode 100644
index eae4780671..0000000000
--- a/src/openhuman/memory/host_impls_boot_seam_tests_tests.rs
+++ /dev/null
@@ -1,48 +0,0 @@
-use super::*;
-
-/// Installing the seams must satisfy the engine's `require_embedding_host`.
-///
-/// This began as the regression for an outage #5560 shipped and had to take
-/// back: the seam install was removed from all three boot sites on the
-/// reasoning that "this process embeds no engine, so there is nothing to call
-/// back". At the time it did embed one — `session::builder::factory` reached
-/// `store::factories::create_session_memory_with_local_ai`, which calls
-/// `require_embedding_host()` — and every chat turn died with
-///
-/// no EmbeddingHost installed — the host must call
-/// memory::embedding_host::set_embedding_host during startup wiring
-///
-/// **That caller is gone, and so is the production install.** `tinymemory-core`
-/// is out of the product build now — a `[dev-dependencies]` entry plus an
-/// `optional` normal one that only `memory-engine-seams` and `rss-bench` turn
-/// on — and [`super`] is gated on the same feature. What the assertion guards
-/// has therefore changed, and it is worth being exact about which claim is
-/// still being tested: not that *boot* wires the engine, but that
-/// [`install_for_tests`] does — the ~90 test call sites that stand up an
-/// in-process engine all depend on it, and nothing in a build or a type check
-/// says whether the `set_*` globals actually took.
-///
-/// The original reason for asserting the engine's own accessor rather than a
-/// local flag is unchanged, and is why this survived the migration rather than
-/// being deleted with the boot sites: it keeps testing the thing the engine
-/// actually reads.
-///
-/// The production half of the old claim now lives in
-/// `runtime::context::init_stores`, which still installs the *contract* event
-/// sink — a `tinymemory-api` seam with a live host-side publisher in
-/// `memory::sync::composio::bus`, and one that drops silently rather than
-/// loudly when unwired.
-#[test]
-fn installing_the_seams_satisfies_the_engines_embedding_host() {
- install_for_tests();
-
- assert!(
- tinymemory_core::embedding_host::embedding_host().is_some(),
- "install_for_tests installed no EmbeddingHost; every test that stands up an \
- in-process memory client calls require_embedding_host() and will fail"
- );
- assert!(
- tinymemory_core::embedding_host::require_embedding_host().is_ok(),
- "require_embedding_host must succeed once the test seams are in"
- );
-}
diff --git a/src/openhuman/memory/mod.rs b/src/openhuman/memory/mod.rs
index 0fe61b0cb3..1d60e7cc54 100644
--- a/src/openhuman/memory/mod.rs
+++ b/src/openhuman/memory/mod.rs
@@ -43,22 +43,6 @@ pub mod driver;
pub mod exit;
pub mod guard;
pub mod host;
-/// Host implementations of the seam traits the ENGINE declares.
-///
-/// Behind `memory-engine-seams` (default-ON, product-OFF) because the
-/// production host embeds no engine any more: the
-/// module installs its own seams and this host answers it over the bus through
-/// [`crate::openhuman::modules::memory_host`] instead. What still needs these
-/// is the test suite, which binds the in-process TinyCortex driver directly —
-/// legitimate, because `tinymemory-core` is a dev-dependency there and a
-/// dev-dependency is not linked into the shipped binary.
-///
-/// The contract-side event sink is deliberately **not** in here: it installs
-/// into `tinymemory_api`, not the engine, and `memory::sync::composio::bus`
-/// publishes through it from production host code. It is installed directly by
-/// each boot site — see [`host::install_memory_event_sink`].
-#[cfg(any(test, feature = "memory-engine-seams"))]
-pub mod host_impls;
/// Host desktop policy: is the memory content root a vault Obsidian already
/// knows about? See the module docs for why this is OpenHuman's and not the
/// engine's.
@@ -104,17 +88,9 @@ mod api_identity_tests;
#[cfg(test)]
mod bypass_allowlist_tests;
#[cfg(test)]
-mod direct_engine_refs_tests;
-#[cfg(test)]
mod exit_tests;
#[cfg(test)]
mod profile_conn_guard_tests;
-#[cfg(test)]
-mod seam_integration_tests;
-#[cfg(test)]
-mod sync_pipeline_e2e_tests;
-#[cfg(test)]
-mod tree_e2e_tests;
// ── The extracted subsystem, re-exported under its historical paths ─────────
//
diff --git a/src/openhuman/memory/ops/documents_tests.rs b/src/openhuman/memory/ops/documents_tests.rs
index 062fac2408..86f3a8d9d7 100644
--- a/src/openhuman/memory/ops/documents_tests.rs
+++ b/src/openhuman/memory/ops/documents_tests.rs
@@ -47,7 +47,7 @@ impl Drop for WorkspaceEnvGuard {
/// guard for the whole test: `let _env = ensure_memory_client();`.
#[must_use]
fn ensure_memory_client() -> WorkspaceEnvGuard {
- let workspace = crate::openhuman::memory::ops::ensure_shared_memory_client();
+ let workspace = crate::openhuman::memory::ops::shared_memory_test_workspace();
WorkspaceEnvGuard::pin(&workspace)
}
diff --git a/src/openhuman/memory/ops/guard.rs b/src/openhuman/memory/ops/guard.rs
index 40979460be..25a74ca93b 100644
--- a/src/openhuman/memory/ops/guard.rs
+++ b/src/openhuman/memory/ops/guard.rs
@@ -37,7 +37,7 @@
//!
//! - **`cfg(test)`** — `test_support::shared_memory_test_workspace()`, the
//! single leaked temp workspace every `memory::ops` fixture shares and the
-//! exact path `ensure_shared_memory_client()` binds. Asking the fixture
+//! exact path `shared_memory_test_workspace()` binds. Asking the fixture
//! directly is strictly *more* reliable than asking a singleton it happened to
//! have initialised, because it cannot be re-pointed by an unrelated test.
//! (Named without a doc link on purpose: the module it lives in is
@@ -75,7 +75,7 @@ async fn fallback_workspace_dir() -> Result<std::path::PathBuf, String> {
/// The workspace the pre-boot fallback guards — test build.
///
/// The shared fixture's own path, so a test that seeded through
-/// `ensure_shared_memory_client()` is guaranteed the binding over the store its
+/// `shared_memory_test_workspace()` is guaranteed the binding over the store its
/// fixtures wrote to. `async` to match the production arm; there is nothing to
/// await.
#[cfg(test)]
diff --git a/src/openhuman/memory/ops/guard_tests.rs b/src/openhuman/memory/ops/guard_tests.rs
index 35eef907e7..246189d0e6 100644
--- a/src/openhuman/memory/ops/guard_tests.rs
+++ b/src/openhuman/memory/ops/guard_tests.rs
@@ -9,7 +9,7 @@ use super::*;
/// The pre-boot fallback resolves *the same* workspace the global client is
/// bound to, not whatever `Config::load_or_init` reports. That is the property
/// the four re-pointed handlers rest on: their existing tests bind a temp
-/// workspace through `ensure_shared_memory_client()` and never build a
+/// workspace through `shared_memory_test_workspace()` and never build a
/// `CoreContext`, so a config-derived fallback would silently guard a
/// different store.
#[tokio::test]
@@ -21,7 +21,7 @@ async fn falls_back_to_the_configured_workspace_when_there_is_no_context() {
// so there is no `active_workspace_dir()` to interrogate. The fixture's own
// workspace is the anchor now, and the assertion below — that the fallback
// resolves to the same binding — is what this test was really about.
- let workspace = crate::openhuman::memory::ops::ensure_shared_memory_client();
+ let workspace = crate::openhuman::memory::ops::shared_memory_test_workspace();
let guard = active_memory_guard().await.expect("guard resolves");
let bound = binding::for_workspace(&workspace, &MemorySubsystemConfig::default())
@@ -44,7 +44,7 @@ async fn guards_the_module_driver_and_keeps_its_identity() {
let _serial = crate::openhuman::memory::ops::GLOBAL_MEMORY_TEST_LOCK
.lock()
.await;
- crate::openhuman::memory::ops::ensure_shared_memory_client();
+ crate::openhuman::memory::ops::shared_memory_test_workspace();
let guard = active_memory_guard().await.expect("guard resolves");
assert_eq!(
diff --git a/src/openhuman/memory/ops/kv_graph_tests.rs b/src/openhuman/memory/ops/kv_graph_tests.rs
index 122341b652..f05d852c32 100644
--- a/src/openhuman/memory/ops/kv_graph_tests.rs
+++ b/src/openhuman/memory/ops/kv_graph_tests.rs
@@ -1,7 +1,7 @@
use super::*;
fn ensure_memory_client() {
- crate::openhuman::memory::ops::ensure_shared_memory_client();
+ crate::openhuman::memory::ops::shared_memory_test_workspace();
}
fn unique_namespace(prefix: &str) -> String {
diff --git a/src/openhuman/memory/ops/learn_tests.rs b/src/openhuman/memory/ops/learn_tests.rs
index 32f9a9d5a2..eb544142fe 100644
--- a/src/openhuman/memory/ops/learn_tests.rs
+++ b/src/openhuman/memory/ops/learn_tests.rs
@@ -7,7 +7,7 @@ use super::*;
use crate::openhuman::memory::api::types::NamespaceDocumentInput;
fn ensure_memory_client() {
- crate::openhuman::memory::ops::ensure_shared_memory_client();
+ crate::openhuman::memory::ops::shared_memory_test_workspace();
}
struct WorkspaceEnvGuard {
@@ -81,31 +81,6 @@ async fn seed_namespace(prefix: &str) -> String {
namespace
}
-async fn write_config_with_runtime_enabled(
- workspace_root: &std::path::Path,
- runtime_enabled: bool,
-) -> WorkspaceEnvGuard {
- let guard = WorkspaceEnvGuard::set(workspace_root);
- let mut config = crate::openhuman::config::Config::load_or_init()
- .await
- .expect("load config");
- config.local_ai.runtime_enabled = runtime_enabled;
- config.save().await.expect("save config");
- // `memory_learn_all` reaches the tree through
- // `tree_runtime::ops::tree_summarizer_run`, which resolves a driver for
- // *this* config's workspace since #5560 — the handler used to run the
- // markdown time tree in-process. Enumeration is unaffected (it goes through
- // `active_memory_guard`, whose test fallback is the shared fixture
- // workspace the namespaces were seeded in); it is the per-namespace
- // summarisation pass that now needs a binding here.
- //
- // The double resolves its summariser through `ops::create_provider`, the
- // same resolver the handler used before the migration, so these tests keep
- // asserting against the local-AI ladder `runtime_enabled` is flipping.
- crate::openhuman::memory::tree::tree_runtime::test_support::bind_tree_driver(&config);
- guard
-}
-
#[tokio::test]
async fn memory_learn_all_is_noop_for_explicit_empty_namespace_list() {
let _serial = crate::openhuman::memory::ops::GLOBAL_MEMORY_TEST_LOCK
@@ -141,87 +116,3 @@ async fn memory_learn_all_is_noop_when_requested_namespaces_do_not_exist() {
assert!(outcome.value.results.is_empty());
}
-#[tokio::test]
-async fn memory_learn_all_filters_missing_namespaces_and_dedupes_requested_order() {
- let _serial = crate::openhuman::memory::ops::GLOBAL_MEMORY_TEST_LOCK
- .lock()
- .await;
- let namespace_a = seed_namespace("memory-learn-a").await;
- let namespace_b = seed_namespace("memory-learn-b").await;
- let missing = format!(
- "missing{}",
- &uuid::Uuid::new_v4().as_simple().to_string()[..12]
- );
- let tmp = TempDir::new().expect("tempdir");
- let _workspace = write_config_with_runtime_enabled(tmp.path(), true).await;
-
- let outcome = memory_learn_all(LearnAllParams {
- namespaces: Some(vec![
- missing,
- namespace_b.clone(),
- namespace_a.clone(),
- namespace_b.clone(),
- ]),
- })
- .await
- .expect("existing namespaces with runtime enabled should run");
-
- assert_eq!(outcome.value.namespaces_processed, 2);
- assert_eq!(outcome.value.results.len(), 2);
- assert_eq!(outcome.value.results[0].namespace, namespace_b);
- assert_eq!(outcome.value.results[1].namespace, namespace_a);
- assert!(outcome.value.results.iter().all(|r| r.status == "ok"));
- assert!(outcome.value.results.iter().all(|r| r.error.is_none()));
-}
-
-#[tokio::test]
-async fn memory_learn_all_requires_local_ai_once_existing_namespace_is_selected() {
- let _serial = crate::openhuman::memory::ops::GLOBAL_MEMORY_TEST_LOCK
- .lock()
- .await;
- let namespace = seed_namespace("memory-learn-runtime").await;
- let tmp = TempDir::new().expect("tempdir");
- let _workspace = write_config_with_runtime_enabled(tmp.path(), false).await;
-
- let err = memory_learn_all(LearnAllParams {
- namespaces: Some(vec![namespace]),
- })
- .await
- .expect_err("runtime-disabled config should hard-fail");
-
- assert!(err.contains("memory_learn_all requires local_ai.runtime_enabled=true"));
-}
-
-#[tokio::test]
-async fn memory_learn_all_uses_all_namespaces_when_none_is_requested() {
- let _serial = crate::openhuman::memory::ops::GLOBAL_MEMORY_TEST_LOCK
- .lock()
- .await;
- let namespace_a = seed_namespace("memory-learn-all-a").await;
- let namespace_b = seed_namespace("memory-learn-all-b").await;
- let tmp = TempDir::new().expect("tempdir");
- let _workspace = write_config_with_runtime_enabled(tmp.path(), true).await;
-
- let outcome = memory_learn_all(LearnAllParams { namespaces: None })
- .await
- .expect("runtime-enabled config should process all namespaces");
-
- assert!(
- outcome.value.namespaces_processed >= 2,
- "expected at least the two seeded namespaces to be processed"
- );
- let namespaces: std::collections::BTreeSet<_> = outcome
- .value
- .results
- .iter()
- .map(|r| r.namespace.as_str())
- .collect();
- assert!(namespaces.contains(namespace_a.as_str()));
- assert!(namespaces.contains(namespace_b.as_str()));
- assert!(outcome
- .value
- .results
- .iter()
- .filter(|r| r.namespace == namespace_a || r.namespace == namespace_b)
- .all(|r| r.status == "ok" && r.error.is_none()));
-}
diff --git a/src/openhuman/memory/ops/mod.rs b/src/openhuman/memory/ops/mod.rs
index e5121f39d1..4f33bc6b42 100644
--- a/src/openhuman/memory/ops/mod.rs
+++ b/src/openhuman/memory/ops/mod.rs
@@ -27,6 +27,10 @@ pub mod documents;
pub mod envelope;
pub mod files;
pub mod guard;
+#[cfg(test)]
+mod test_support;
+#[cfg(test)]
+pub(crate) use test_support::shared_memory_test_workspace;
pub mod helpers;
pub mod kv_graph;
pub mod learn;
@@ -88,13 +92,7 @@ pub(crate) use helpers::{
#[cfg(test)]
pub(crate) static GLOBAL_MEMORY_TEST_LOCK: tokio::sync::Mutex<()> =
tokio::sync::Mutex::const_new(());
-
-#[cfg(test)]
-mod test_support;
-#[cfg(test)]
-pub(crate) use test_support::ensure_shared_memory_client;
#[cfg(all(test, feature = "modules"))]
-pub(crate) use test_support::shared_memory_test_workspace;
#[cfg(test)]
#[path = "../ops_tests.rs"]
diff --git a/src/openhuman/memory/ops/test_support/mod.rs b/src/openhuman/memory/ops/test_support/mod.rs
index bd06e736fa..bb1a50818f 100644
--- a/src/openhuman/memory/ops/test_support/mod.rs
+++ b/src/openhuman/memory/ops/test_support/mod.rs
@@ -1,28 +1,17 @@
//! Shared test infrastructure for `memory::ops` submodule tests.
//!
-//! All `ops` submodules that need a global `MemoryClient` call
-//! [`ensure_shared_memory_client`] instead of creating their own
-//! `OnceLock<PathBuf>`. Sharing one leaked workspace means concurrent
-//! `global::init()` calls always resolve to the same path and hit the
-//! no-op fast-path inside `init_in_slot`, preventing one test thread
-//! from silently rebinding the global under another thread's feet.
+//! All `ops` submodules that need one workspace call
+//! [`shared_memory_test_workspace`] instead of creating their own
+//! `OnceLock<PathBuf>`. Sharing one leaked workspace is what makes concurrent
+//! tests agree on a path rather than racing to bind different ones.
//!
-//! # This is the one engine reference in `memory::ops` that is meant to stay
+//! # It no longer boots an engine
//!
-//! Everything else under `ops/` was routed onto the contract for openhuman#5560
-//! so `tinymemory-core` can leave `[dependencies]` and survive as a
-//! **dev-dependency only**. This fixture deliberately still boots the
-//! in-process engine, because that is what it is for: it hands the `ops` tests a
-//! real store to write rows into and read back, and a dev-dependency reference
-//! from `#[cfg(test)]` code is not linked into the shipped binary.
-//!
-//! It lives in a `test_support/` **directory** rather than as a
-//! `test_support.rs` file for one reason: both memory ratchets skip by path, and
-//! `is_test_path` matches a *path component* named `test_support`, not a file
-//! stem. As a flat file this module had to carry an entry in
-//! `direct_engine_refs_tests::ALLOWED` that read like an unmigrated production
-//! call site. The same reasoning already put `memory::test_support` in a
-//! directory — see its module docs.
+//! It used to also expose `ensure_shared_memory_client`, which called
+//! `tinymemory_core::global::init` to hand `ops` tests a real store to write
+//! rows into and read back. That is gone with the engine (openhuman#6161); what
+//! survives is the part that was never engine work — one agreed-upon temp
+//! directory.
use std::path::PathBuf;
use std::sync::OnceLock;
@@ -46,23 +35,3 @@ pub(crate) fn shared_memory_test_workspace() -> PathBuf {
})
.clone()
}
-
-/// Binds the process-global memory client to a single shared temp workspace and
-/// returns that workspace path.
-///
-/// Safe to call from multiple test threads concurrently — subsequent calls with
-/// the same workspace path return the existing client without rebinding.
-///
-/// The returned path lets callers whose RPC path *also* resolves the workspace
-/// from `OPENHUMAN_WORKSPACE` (notably `memory::ops::documents` via
-/// `memory_init` → `current_workspace_dir`) pin the env var to this same path so
-/// the env and the bound client agree. See `documents::tests`.
-pub(crate) fn ensure_shared_memory_client() -> PathBuf {
- // Building a client reaches the embedding seam, which fails loudly when
- // unwired. Before the extraction these were direct calls and needed no
- // setup; now they need the host impls installed.
- crate::openhuman::memory::host_impls::install_for_tests();
- let workspace = shared_memory_test_workspace();
- tinymemory_core::global::init(workspace.clone()).expect("initialize shared test memory client");
- workspace
-}
diff --git a/src/openhuman/memory/ops/tool_memory_tests.rs b/src/openhuman/memory/ops/tool_memory_tests.rs
index 7c09c18ab9..3290bbf814 100644
--- a/src/openhuman/memory/ops/tool_memory_tests.rs
+++ b/src/openhuman/memory/ops/tool_memory_tests.rs
@@ -2,7 +2,7 @@ use super::*;
use crate::openhuman::memory::api::tool_memory::ToolMemoryPriority;
fn ensure_memory_client() {
- crate::openhuman::memory::ops::ensure_shared_memory_client();
+ crate::openhuman::memory::ops::shared_memory_test_workspace();
}
fn unique_tool_name() -> String {
diff --git a/src/openhuman/memory/ops_tests.rs b/src/openhuman/memory/ops_tests.rs
index 2f65de495e..cabd579f11 100644
--- a/src/openhuman/memory/ops_tests.rs
+++ b/src/openhuman/memory/ops_tests.rs
@@ -1,11 +1,13 @@
//! Unit tests for the memory `ops` helpers (retrieval context construction,
//! hit filtering, and LLM context message formatting).
+// The engine's re-export and the contract's are the same item; name the
+// contract, which is what this crate still links (openhuman#6161).
+use tinymemory_api::types::{MemoryItemKind, NamespaceMemoryHit, RetrievalScoreBreakdown};
use serde_json::json;
use super::{build_retrieval_context, filter_hits_by_document_ids, format_llm_context_message};
use crate::openhuman::memory::api::types::GraphRelationRecord;
-use tinymemory_core::store::{MemoryItemKind, NamespaceMemoryHit, RetrievalScoreBreakdown};
fn sample_hit() -> NamespaceMemoryHit {
NamespaceMemoryHit {
@@ -198,14 +200,6 @@ fn timestamp_to_rfc3339_rejects_non_finite_and_negative() {
assert!(timestamp_to_rfc3339(-1.0).is_none());
}
-#[test]
-fn memory_kind_label_maps_each_variant() {
- assert_eq!(memory_kind_label(&MemoryItemKind::Document), "document");
- assert_eq!(memory_kind_label(&MemoryItemKind::Kv), "kv");
- assert_eq!(memory_kind_label(&MemoryItemKind::Episodic), "episodic");
- assert_eq!(memory_kind_label(&MemoryItemKind::Event), "event");
-}
-
fn relation_fixture(namespace: Option<&str>) -> GraphRelationRecord {
GraphRelationRecord {
namespace: namespace.map(str::to_string),
diff --git a/src/openhuman/memory/people/mod_contacts_gate_tests_tests.rs b/src/openhuman/memory/people/mod_contacts_gate_tests_tests.rs
index 1f5d15b197..e69de29bb2 100644
--- a/src/openhuman/memory/people/mod_contacts_gate_tests_tests.rs
+++ b/src/openhuman/memory/people/mod_contacts_gate_tests_tests.rs
@@ -1,56 +0,0 @@
-/// The `contacts` gate must reach the engine, not stop at this crate.
-///
-/// The macOS address-book reader lives in the memory engine, several crates
-/// below this one, behind `#[cfg(all(target_os = "macos", feature =
-/// "contacts"))]`. This crate's `contacts` feature once enabled four
-/// `objc2` crates *locally* — none of which any file in `src/` names — and
-/// never forwarded, so the reader was always compiled out. Nothing failed:
-/// `refresh_address_book` returned success having seeded zero contacts, and
-/// the only visible symptom was an address book that stayed empty.
-///
-/// So this asserts the property that was actually missing — that turning
-/// the feature on *here* changes what the reader does *there*. A build with
-/// `contacts` on, on macOS, must reach the real `CNContactStore` arm; the
-/// stub returns `Ok(vec![])` unconditionally, and the real arm cannot,
-/// because it can fail on permission.
-///
-/// Deliberately not a `cfg!(feature = ...)` self-assertion: that would pass
-/// while the forward is broken, which is the entire bug.
-///
-/// Names the engine crate directly rather than through `super::*`, which was
-/// the glob re-export until #5560 deleted it as unused. This is the one
-/// remaining reader, it is `#[cfg(test)]`, and a test reference does not link
-/// the crate into the shipped binary — so the gate keeps testing the forward
-/// without the production edge it used to travel over.
-#[test]
-#[cfg(all(target_os = "macos", feature = "contacts"))]
-fn contacts_feature_reaches_the_engine_reader() {
- use tinycortex::memory::people::address_book::{
- AddressBookError, ContactsSource, SystemContactsSource,
- };
-
- // The stub arm returns Ok(vec![]) and can never report a permission
- // failure. Reaching a `PermissionDenied` — or real contacts — proves the
- // macOS arm compiled in. On a CI box with no Contacts authorisation the
- // permission error is the expected outcome.
- match SystemContactsSource.fetch_contacts() {
- Err(AddressBookError::PermissionDenied) => {}
- Ok(_) => {}
- Err(other) => panic!("address book read failed unexpectedly: {other:?}"),
- }
-}
-
-/// Off macOS the gate is a documented no-op, and the stub is correct.
-#[test]
-#[cfg(not(target_os = "macos"))]
-fn contacts_gate_is_a_no_op_off_macos() {
- use tinycortex::memory::people::address_book::{ContactsSource, SystemContactsSource};
-
- assert_eq!(
- SystemContactsSource
- .fetch_contacts()
- .expect("stub never fails"),
- vec![],
- "off macOS the reader must be the empty stub"
- );
-}
diff --git a/src/openhuman/memory/read_rpc/mod.rs b/src/openhuman/memory/read_rpc/mod.rs
index 1881ef8a2b..5645d01094 100644
--- a/src/openhuman/memory/read_rpc/mod.rs
+++ b/src/openhuman/memory/read_rpc/mod.rs
@@ -62,8 +62,6 @@ pub(crate) fn parse_source_kind_str(s: &str) -> Option<tinymemory_api::chunks::S
pub(crate) use crate::openhuman::config::Config;
#[cfg(test)]
pub(crate) use tinymemory_api::chunks::SourceKind;
-#[cfg(test)]
-pub(crate) use tinymemory_core::store::chunks::store::with_connection;
#[cfg(test)]
#[path = "../read_rpc_tests.rs"]
diff --git a/src/openhuman/memory/read_rpc_tests.rs b/src/openhuman/memory/read_rpc_tests.rs
index 95180a4907..2c997e2ccd 100644
--- a/src/openhuman/memory/read_rpc_tests.rs
+++ b/src/openhuman/memory/read_rpc_tests.rs
@@ -2,10 +2,6 @@ use super::*;
use chrono::{TimeZone, Utc};
use rusqlite::params;
use tempfile::TempDir;
-use tinycortex::memory::ingest::canonicalize::chat::{ChatBatch, ChatMessage};
-use tinymemory_core::ingest_pipeline::ingest_chat;
-use tinymemory_core::queue::drain_until_idle;
-use tinymemory_core::store::content::raw::{write_raw_items, RawItem, RawKind};
fn test_config() -> (TempDir, Config) {
let tmp = TempDir::new().unwrap();
@@ -24,186 +20,8 @@ fn test_config() -> (TempDir, Config) {
(tmp, cfg)
}
-async fn seed_chat_chunk(cfg: &Config, source: &str, body: &str) {
- let batch = ChatBatch {
- platform: "slack".into(),
- channel_label: source.into(),
- messages: vec![ChatMessage {
- author: "alice".into(),
- timestamp: Utc.timestamp_millis_opt(1_700_000_000_000).unwrap(),
- text: body.into(),
- source_ref: Some("slack://x".into()),
- }],
- };
- ingest_chat(cfg, source, "alice", vec![], batch)
- .await
- .unwrap();
-}
-
-async fn seed_slack_chunk_with_raw_archive(cfg: &Config) -> String {
- let timestamp = Utc.timestamp_opt(1_700_000_000, 0).single().unwrap();
- write_raw_items(
- &cfg.memory_tree_content_root(),
- "slack:conn-slack-1",
- &[RawItem {
- uid: "1700000000.000100",
- created_at_ms: timestamp.timestamp_millis(),
- markdown: "**Channel:** #engineering\n**Author:** alice\n\nPhoenix migration launch window is Friday at 22:00 UTC.",
- kind: RawKind::Chat,
- }],
- )
- .expect("seed raw Slack artifact");
- let batch = ChatBatch {
- platform: "slack".into(),
- channel_label: "#engineering".into(),
- messages: vec![ChatMessage {
- author: "alice".into(),
- timestamp,
- text: "Phoenix migration launch window is Friday at 22:00 UTC.".into(),
- source_ref: Some("slack://archives/C123/1700000000.000100".into()),
- }],
- };
- ingest_chat(
- cfg,
- "slack:conn-slack-1",
- "alice",
- vec!["slack".into(), "ingested".into()],
- batch,
- )
- .await
- .expect("seed slack ingest");
- drain_until_idle(cfg).await.expect("drain slack ingest");
-
- list_chunks_rpc(cfg, ChunkFilter::default())
- .await
- .expect("list chunks")
- .value
- .chunks
- .into_iter()
- .find(|chunk| chunk.source_id == "slack:conn-slack-1")
- .expect("seeded slack chunk")
- .id
-}
-
-fn update_chunk_timestamp(cfg: &Config, chunk_id: &str, timestamp_ms: i64) {
- with_connection(cfg, |conn| {
- conn.execute(
- "UPDATE mem_tree_chunks
- SET timestamp_ms = ?1,
- time_range_start_ms = ?1,
- time_range_end_ms = ?1
- WHERE id = ?2",
- params![timestamp_ms, chunk_id],
- )?;
- Ok(())
- })
- .unwrap();
-}
-
-fn insert_raw_chunk(
- cfg: &Config,
- id: &str,
- source_kind: &str,
- source_id: &str,
- timestamp_ms: i64,
- tags_json: &str,
- content: &str,
- token_count: i64,
-) {
- with_connection(cfg, |conn| {
- conn.execute(
- "INSERT INTO mem_tree_chunks (
- id, source_kind, source_id, source_ref, owner, timestamp_ms,
- time_range_start_ms, time_range_end_ms, tags_json, content,
- token_count, seq_in_source, created_at_ms, lifecycle_status, content_path
- ) VALUES (?1, ?2, ?3, NULL, 'tester', ?4, ?4, ?4, ?5, ?6, ?7, 0, ?4, 'seeded', NULL)",
- params![
- id,
- source_kind,
- source_id,
- timestamp_ms,
- tags_json,
- content,
- token_count
- ],
- )?;
- Ok(())
- })
- .unwrap();
-}
-
// ── tree-mode graph export (summaries + leaf chunks) ────────────────────
-/// Insert a tree row and one summary node under it.
-fn insert_tree_summary(cfg: &Config, tree_id: &str, scope: &str, summary_id: &str, level: i64) {
- with_connection(cfg, |conn| {
- conn.execute(
- "INSERT OR IGNORE INTO mem_tree_trees (id, kind, scope, created_at_ms)
- VALUES (?1, 'source', ?2, 0)",
- params![tree_id, scope],
- )?;
- conn.execute(
- "INSERT INTO mem_tree_summaries (
- id, tree_id, tree_kind, level, child_ids_json, content, token_count,
- entities_json, topics_json, time_range_start_ms, time_range_end_ms,
- score, sealed_at_ms, deleted
- ) VALUES (?1, ?2, 'source', ?3, '[]', 'summary body', 1, '[]', '[]', 0, 0, 0.0, 0, 0)",
- params![summary_id, tree_id, level],
- )?;
- Ok(())
- })
- .unwrap();
-}
-
-/// Insert a leaf chunk, optionally linked to a parent summary.
-fn insert_chunk_with_parent(
- cfg: &Config,
- id: &str,
- parent_summary_id: Option<&str>,
- timestamp_ms: i64,
- content: &str,
-) {
- with_connection(cfg, |conn| {
- conn.execute(
- "INSERT INTO mem_tree_chunks (
- id, source_kind, source_id, source_ref, owner, timestamp_ms,
- time_range_start_ms, time_range_end_ms, tags_json, content,
- token_count, seq_in_source, created_at_ms, lifecycle_status,
- content_path, parent_summary_id
- ) VALUES (?1, 'chat', 'slack:#eng', NULL, 'tester', ?2, ?2, ?2, '[]', ?3, 1, 0, ?2, 'seeded', NULL, ?4)",
- params![id, timestamp_ms, content, parent_summary_id],
- )?;
- Ok(())
- })
- .unwrap();
-}
-
-/// Insert one `mem_tree_entity_index` row.
-///
-/// Seeded directly because the `person` kind only ever comes from the LLM
-/// extractor, which these tests deliberately do not run — the mechanical
-/// extractor emits `email`/`url`/`handle`/`hashtag` and nothing else.
-fn insert_entity_row(
- cfg: &Config,
- entity_id: &str,
- node_id: &str,
- entity_kind: &str,
- surface: &str,
- timestamp_ms: i64,
-) {
- with_connection(cfg, |conn| {
- conn.execute(
- "INSERT OR REPLACE INTO mem_tree_entity_index (
- entity_id, node_id, node_kind, entity_kind, surface,
- score, timestamp_ms, tree_id, is_user
- ) VALUES (?1, ?2, 'leaf', ?3, ?4, 1.0, ?5, NULL, 0)",
- params![entity_id, node_id, entity_kind, surface, timestamp_ms],
- )?;
- Ok(())
- })
- .unwrap();
-}
-
#[path = "read_rpc_tests_part_01_tests.rs"]
mod part_01_tests;
#[path = "read_rpc_tests_part_02_tests.rs"]
diff --git a/src/openhuman/memory/read_rpc_tests_part_01_tests.rs b/src/openhuman/memory/read_rpc_tests_part_01_tests.rs
index dcf8f27655..e00aa60563 100644
--- a/src/openhuman/memory/read_rpc_tests_part_01_tests.rs
+++ b/src/openhuman/memory/read_rpc_tests_part_01_tests.rs
@@ -1,65 +1,5 @@
use super::*;
-#[tokio::test]
-#[ignore = "needs a built tinymemory module (OPENHUMAN_MODULE_PATH) and its own process: \
-chunk detail is read through the bound driver, not the in-process engine"]
-async fn read_chunk_row_returns_preview_and_metadata() {
- let (_tmp, cfg) = test_config();
- seed_chat_chunk(
- &cfg,
- "slack:#eng",
- "phoenix migration scheduled friday with context and source refs",
- )
- .await;
- let chunk = list_chunks_rpc(&cfg, ChunkFilter::default())
- .await
- .unwrap()
- .value
- .chunks
- .into_iter()
- .next()
- .expect("seeded chunk");
-
- let row = read_chunk_row(&chunk.id).await.unwrap().expect("chunk row");
- assert_eq!(row.id, chunk.id);
- assert_eq!(row.source_kind, "chat");
- assert_eq!(row.source_id, "slack:#eng");
- assert_eq!(row.source_ref.as_deref(), Some("slack://x"));
- assert_eq!(row.owner, "alice");
- assert_eq!(row.lifecycle_status, "pending_extraction");
- assert!(row.content_path.is_some());
- assert!(row
- .content_preview
- .as_deref()
- .unwrap_or("")
- .contains("phoenix migration scheduled friday"));
-}
-
-#[tokio::test]
-#[ignore = "needs a built tinymemory module (OPENHUMAN_MODULE_PATH) and its own process: \
-chunk detail is read through the bound driver, not the in-process engine"]
-async fn read_chunk_row_falls_back_to_sqlite_preview_when_file_missing() {
- let (_tmp, cfg) = test_config();
- let body = "sqlite preview survives missing file";
- seed_chat_chunk(&cfg, "slack:#eng", body).await;
- let chunk = list_chunks_rpc(&cfg, ChunkFilter::default())
- .await
- .unwrap()
- .value
- .chunks
- .into_iter()
- .next()
- .expect("seeded chunk");
-
- let rel_path = chunk.content_path.clone().expect("content path present");
- let abs_path = cfg.memory_tree_content_root().join(rel_path);
- std::fs::remove_file(&abs_path).expect("remove chunk file");
-
- let row = read_chunk_row(&chunk.id).await.unwrap().expect("chunk row");
- assert_eq!(row.content_path, chunk.content_path);
- assert!(row.content_preview.as_deref().unwrap_or("").contains(body));
-}
-
/// The handler forwards the driver's flush outcome onto the wire unchanged.
///
/// The behaviour this test used to stage — an ingest producing a stale buffer,
diff --git a/src/openhuman/memory/read_rpc_tests_part_02_tests.rs b/src/openhuman/memory/read_rpc_tests_part_02_tests.rs
index bcb45fa55f..c4f1074616 100644
--- a/src/openhuman/memory/read_rpc_tests_part_02_tests.rs
+++ b/src/openhuman/memory/read_rpc_tests_part_02_tests.rs
@@ -1,66 +1,5 @@
use super::*;
-#[tokio::test]
-#[ignore = "needs a built tinymemory module (OPENHUMAN_MODULE_PATH) and its own process: \
-asserts chunk lifecycle through `read_chunk_row`, which reads via the bound driver"]
-async fn reset_tree_preserves_raw_archive_and_source_registry() {
- let (_tmp, cfg) = test_config();
- let chunk_id = seed_slack_chunk_with_raw_archive(&cfg).await;
- let content_root = cfg.memory_tree_content_root();
- let raw_file = content_root
- .join("raw")
- .join("slack-conn-slack-1")
- .join("chats")
- .join("1700000000000_1700000000.000100.md");
- let source_file = content_root
- .join("raw")
- .join("slack-conn-slack-1")
- .join("_source.md");
- assert!(raw_file.exists(), "raw archive should exist before reset");
- assert!(
- source_file.exists(),
- "source registry should exist before reset"
- );
-
- let stale_summary = content_root
- .join("wiki")
- .join("summaries")
- .join("source-slack-conn-slack-1")
- .join("L1")
- .join("summary-stale.md");
- std::fs::create_dir_all(
- stale_summary
- .parent()
- .expect("stale summary parent should exist"),
- )
- .expect("create stale summary dir");
- std::fs::write(&stale_summary, "stale summary body").expect("write stale summary");
- assert!(stale_summary.exists(), "stale summary fixture should exist");
-
- let outcome = reset_tree_rpc(&cfg).await.expect("reset_tree");
- assert_eq!(outcome.value.chunks_requeued, 1);
- assert_eq!(outcome.value.jobs_enqueued, 1);
- assert!(
- outcome.value.tree_rows_deleted >= 1,
- "buffer/tree rows should be removed during reset"
- );
-
- let row = read_chunk_row(&chunk_id)
- .await
- .expect("read chunk row")
- .expect("chunk row present after reset");
- assert_eq!(row.lifecycle_status, "pending_extraction");
- assert!(raw_file.exists(), "raw archive must survive reset_tree");
- assert!(
- source_file.exists(),
- "source registry must survive reset_tree"
- );
- assert!(
- !content_root.join("wiki").join("summaries").exists(),
- "derived wiki summaries should be removed"
- );
-}
-
#[tokio::test]
#[ignore = "needs a built tinymemory module (OPENHUMAN_MODULE_PATH) and its own process: \
chunk detail is read through the bound driver, not the in-process engine"]
@@ -128,35 +67,6 @@ fn parse_source_kind_str_accepts_known_values_only() {
assert_eq!(parse_source_kind_str("unknown"), None);
}
-/// An empty candidate set must short-circuit, not become an unfiltered read.
-///
-/// The failure this pins is quiet: an empty predicate means *unfiltered* on
-/// this seam, so a batch read handed the empty id list could answer with every
-/// row in the store and the graph would fill with contacts for chunks it never
-/// selected.
-#[tokio::test]
-async fn contacts_graph_with_no_person_chunks_is_empty() {
- let (_tmp, cfg) = test_config();
- crate::openhuman::memory::test_support::install_memory_driver_for_test(&cfg);
- insert_chunk_with_parent(&cfg, "chunk-a", None, 1_700_000_000_000, "no people here");
- insert_entity_row(
- &cfg,
- "topic:shipping",
- "chunk-a",
- "topic",
- "shipping",
- 1_700_000_000_000,
- );
-
- let resp = graph_export_rpc(&cfg, GraphMode::Contacts)
- .await
- .unwrap()
- .value;
-
- assert!(resp.nodes.is_empty(), "nodes: {:?}", resp.nodes);
- assert!(resp.edges.is_empty(), "edges: {:?}", resp.edges);
-}
-
#[tokio::test]
async fn obsidian_status_registered_when_override_config_lists_content_root() {
let (_tmp, cfg) = test_config();
@@ -221,34 +131,6 @@ async fn obsidian_status_blank_override_is_treated_as_none() {
assert!(!outcome.value.registered);
}
-#[tokio::test]
-async fn vault_health_check_reports_missing_content_root_for_fresh_workspace() {
- // `pipeline_healthy` reads the process-global degraded flags (via
- // `pipeline_status_rpc` → `current_degraded_state`), which sibling
- // `memory_tree` tests set and never clear. Serialise + reset to a clean
- // baseline so the assertion is deterministic. See #4691.
- let _g = tinymemory_core::tree::health::test_guard();
- let (_tmp, cfg) = test_config();
- // `vault_health_check_rpc` folds in `pipeline_status_rpc`, which reads
- // through the bound driver. Bind an empty one explicitly: resolving the
- // real driver means loading the compiled module, which a test process
- // can block on rather than fail.
- crate::openhuman::memory::binding::install_diagnostics_for_test(
- &cfg.workspace_dir,
- &cfg.subsystems.memory,
- Default::default(),
- Default::default(),
- );
- let outcome = vault_health_check_rpc(&cfg, None).await.unwrap();
-
- assert!(!outcome.value.exists);
- assert!(!outcome.value.readable);
- assert!(!outcome.value.writable);
- assert!(!outcome.value.obsidian_registered);
- assert!(outcome.value.pipeline_healthy);
- assert_eq!(outcome.value.last_sync_ms, 0);
-}
-
/// #4278: both vault RPCs stamp the core host's OS so a frontend attached
/// from a different OS can tell `content_root_abs` is a foreign-host path and
/// must not open/reveal it locally.
@@ -277,61 +159,3 @@ async fn vault_rpcs_report_core_host_os() {
);
}
-#[tokio::test]
-async fn vault_health_check_reports_writable_and_obsidian_registered_when_ready() {
- let (_tmp, cfg) = test_config();
- // `vault_health_check_rpc` folds in `pipeline_status_rpc`, and
- // `last_sync_ms` comes from the bound driver rather than from a `SELECT`
- // over the seeded chunk. The seed below still matters — it is what makes
- // `content_root` exist, which is what this test is actually about — but
- // the sync time has to come from a driver that reports one.
- crate::openhuman::memory::binding::install_diagnostics_for_test(
- &cfg.workspace_dir,
- &cfg.subsystems.memory,
- crate::openhuman::memory::api::provider::types::StoreStats {
- chunks: 1,
- chunks_with_structure: 0,
- most_recent_chunk_ms: Some(1_800_000_000_000),
- },
- Default::default(),
- );
- seed_chat_chunk(
- &cfg,
- "slack:#eng",
- "Vault health seed chunk so content_root exists and last_sync_ms > 0",
- )
- .await;
-
- let content_root = cfg.memory_tree_content_root();
- let cfg_dir = TempDir::new().unwrap();
- let body = format!(
- "{{ \"vaults\": {{ \"id0\": {{ \"path\": {}, \"open\": true }} }} }}",
- serde_json::to_string(&content_root.to_string_lossy().to_string()).unwrap()
- );
- std::fs::write(cfg_dir.path().join("obsidian.json"), body).unwrap();
-
- let outcome = vault_health_check_rpc(&cfg, Some(cfg_dir.path().to_string_lossy().to_string()))
- .await
- .unwrap();
-
- assert!(outcome.value.exists);
- assert!(outcome.value.readable);
- assert!(outcome.value.writable);
- assert!(outcome.value.obsidian_registered);
- // Intentionally NOT asserting `pipeline_healthy` here: with a seeded chunk
- // (total_chunks > 0) the derived status depends on the process-global
- // degraded flags, which unguarded parallel `memory_tree` extraction/pipeline
- // tests set and never clear (structure degrades only clears on a *successful*
- // extraction, which never happens under test). Post-#4691 a leaked "degraded"
- // correctly reads as unhealthy, so asserting healthy here would be flaky.
- // The health mapping is covered deterministically by the `pipeline_is_healthy`
- // unit tests in `read_rpc/vault.rs`; this test covers the filesystem readiness
- // wiring. See also `memory_tree::tree::rpc::pipeline_status_renders_the_drivers_chunk_aggregates`.
- assert!(outcome.value.last_sync_ms > 0);
- assert!(
- !outcome.logs[0].contains(content_root.to_str().unwrap()),
- "log leaked content root: {}",
- outcome.logs[0]
- );
-}
-
diff --git a/src/openhuman/memory/seam_integration_tests.rs b/src/openhuman/memory/seam_integration_tests.rs
deleted file mode 100644
index 6ecc9d9a41..0000000000
--- a/src/openhuman/memory/seam_integration_tests.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-//! Seam integration tests — core behaviour whose *answer* is host routing.
-//!
-//! These moved out of `tinymemory-core` with the extraction. Each one calls
-//! into the extracted crate but asserts something only the host decides: which
-//! provider a role resolves to, what model id that yields, whether a
-//! config-derived embedding signature matches the one the real provider
-//! reports, whether Composio dispatches to the backend or direct tenant.
-//!
-//! A stub host could only assert itself, so they belong on this side, where the
-//! real `ChatHost` / `EmbeddingHost` / `ComposioHost` implementations live.
-//! See [`super::host_impls`].
-
-#[cfg(test)]
-#[path = "seam_integration_tests_tests.rs"]
-mod tests;
diff --git a/src/openhuman/memory/seam_integration_tests_tests.rs b/src/openhuman/memory/seam_integration_tests_tests.rs
deleted file mode 100644
index b289df4f22..0000000000
--- a/src/openhuman/memory/seam_integration_tests_tests.rs
+++ /dev/null
@@ -1,186 +0,0 @@
-use tinymemory_api::host::{MemoryConfig, DEFAULT_CLOUD_LLM_MODEL};
-
-use crate::openhuman::config::Config;
-
-#[test]
-fn build_provider_returns_inference_wrapper_when_default() {
- // These assert the *real* seam implementations, so they need them
- // installed — that is the whole point of living on this side.
- crate::openhuman::memory::host_impls::install_for_tests();
- let cfg = Config::default();
- let provider = tinymemory_core::chat::build_chat_provider(&cfg).unwrap();
- assert!(provider.name().contains("inference:"));
-}
-
-#[test]
-fn build_chat_runtime_defaults_to_openhuman_resolved_model() {
- // These assert the *real* seam implementations, so they need them
- // installed — that is the whole point of living on this side.
- crate::openhuman::memory::host_impls::install_for_tests();
- let cfg = Config::default();
- let (_provider, model) = tinymemory_core::chat::build_chat_runtime(&cfg).unwrap();
- // The managed "summarization" tier is fixed at `summarization-v1`
- // inside `make_openhuman_backend`. DEFAULT_CLOUD_LLM_MODEL is that same
- // constant — asserted here only as the expected value, not because
- // `cloud_llm_model` is consumed (it isn't; see the test below).
- assert_eq!(model, DEFAULT_CLOUD_LLM_MODEL);
-}
-
-#[test]
-fn build_chat_runtime_ignores_cloud_llm_model_on_managed() {
- // These assert the *real* seam implementations, so they need them
- // installed — that is the whole point of living on this side.
- crate::openhuman::memory::host_impls::install_for_tests();
- // The managed summarization tier is locked to `summarization-v1`;
- // `memory_tree.cloud_llm_model` is inert and must not change it (neither a
- // known tier nor a custom string leaks through).
- let mut cfg = Config::default();
- cfg.memory_tree.cloud_llm_model = Some("chat-v1".into());
- let (_provider, model) = tinymemory_core::chat::build_chat_runtime(&cfg).unwrap();
- assert_eq!(model, DEFAULT_CLOUD_LLM_MODEL);
-
- cfg.memory_tree.cloud_llm_model = Some("custom-summary-model".into());
- let (_provider, model) = tinymemory_core::chat::build_chat_runtime(&cfg).unwrap();
- assert_eq!(model, DEFAULT_CLOUD_LLM_MODEL);
-}
-
-#[test]
-fn build_provider_returns_inference_wrapper_when_local_memory_is_configured() {
- // These assert the *real* seam implementations, so they need them
- // installed — that is the whole point of living on this side.
- crate::openhuman::memory::host_impls::install_for_tests();
- // Serialize with the process-global `test_provider_override` (see the
- // inference factory tests): while an override is active, `create_chat_model`
- // returns the mock, so an unguarded read here could race it.
- let _guard = crate::openhuman::inference::inference_test_guard();
- let mut cfg = Config::default();
- cfg.memory_provider = Some("ollama:qwen2.5:0.5b".into());
- let provider = tinymemory_core::chat::build_chat_provider(&cfg).unwrap();
- assert!(provider.name().contains("qwen2.5:0.5b"));
-}
-
-#[test]
-fn build_chat_runtime_preserves_local_memory_model() {
- // These assert the *real* seam implementations, so they need them
- // installed — that is the whole point of living on this side.
- crate::openhuman::memory::host_impls::install_for_tests();
- let _guard = crate::openhuman::inference::inference_test_guard();
- let mut cfg = Config::default();
- cfg.memory_provider = Some("ollama:qwen2.5:0.5b".into());
- let (_provider, model) = tinymemory_core::chat::build_chat_runtime(&cfg).unwrap();
- assert_eq!(model, "qwen2.5:0.5b");
-}
-
-/// #1574 invariant: a config-derived `active_embedding_signature` MUST be
-/// byte-identical to the live provider's `.signature()` for the same
-/// (provider, model, dims). Drift here silently splits one embedding space
-/// into two — copied/queried vectors would never match.
-#[test]
-fn active_signature_matches_live_provider_signature() {
- // These assert the *real* seam implementations, so they need them
- // installed — that is the whole point of living on this side.
- crate::openhuman::memory::host_impls::install_for_tests();
- for local in [None, Some("nomic-embed-text:latest"), Some("bge-m3")] {
- let mem = MemoryConfig::default();
- let (provider, model, dims) =
- tinymemory_core::store::effective_embedding_settings(&mem, local);
- // The host ported this selection rule verbatim (#5560); the two
- // copies are independent by design, and this is the one place a
- // divergence would be caught rather than shipped. Includes the
- // blank-local edge the rule exists for.
- for probe in [local, Some(" "), Some(" bge-m3 ")] {
- assert_eq!(
- crate::openhuman::inference::embeddings::effective_embedding_settings(&mem, probe),
- tinymemory_core::store::effective_embedding_settings(&mem, probe),
- "host and engine embedding selection diverged for {probe:?}"
- );
- }
- let live = crate::openhuman::inference::embeddings::create_embedding_provider(
- &provider, &model, dims,
- )
- .expect("provider builds for test triple");
- assert_eq!(
- tinymemory_core::store::active_embedding_signature(&mem, local),
- live.signature(),
- "config-derived signature must equal live provider signature (local={local:?})"
- );
- }
-}
-
-/// #002 FR-007 / Gray review: the doctor's `summary_tree` stage must mirror
-/// `summarizer_available` exactly. With local AI off and no cloud opt-in
-/// (the default), the stage reports unavailable — which is correct, since
-/// cloud summarization requires explicit consent. The stage must NOT fire
-/// a generic "local AI required" hard-failure; it names the opt-in gap.
-#[test]
-fn local_ai_off_reports_no_provider_without_cloud_opt_in() {
- // These assert the *real* seam implementations, so they need them
- // installed — that is the whole point of living on this side.
- crate::openhuman::memory::host_impls::install_for_tests();
- let _g = tinymemory_core::tree::health::test_guard();
- let tmp = tempfile::TempDir::new().unwrap();
- let mut cfg = Config::default();
- cfg.workspace_dir = tmp.path().to_path_buf();
- cfg.embeddings_provider = Some("ollama:bge-m3".into()); // embeddings ok
- cfg.local_ai.runtime_enabled = false; // cloud opt-in not set (default false)
-
- let report = tinymemory_core::tree::health::run_doctor(&cfg);
- let tree = report
- .stages
- .iter()
- .find(|s| s.stage == "summary_tree")
- .unwrap();
- // summary_tree must mirror summarizer_available precisely.
- assert_eq!(
- tree.ok,
- crate::openhuman::memory::tree::tree_runtime::ops::summarizer_available(&cfg).0,
- "summary_tree health must mirror the runtime capability check"
- );
- // Without opt-in, the note names the "no summarization provider" case.
- assert!(
- tree.note.contains("no summarization provider"),
- "unexpected summary_tree note: {}",
- tree.note
- );
-}
-
-#[cfg(feature = "modules")]
-#[tokio::test]
-#[cfg(feature = "modules")] // `modules::connectors` — and the route it resolves — exist only with the gate on
-async fn direct_mode_config_resolves_via_module_config_at_call_time() {
- // The seam this pinned moved. `ProviderContext::execute` — the engine's
- // Composio dispatch, which routed through the host's `ComposioHost` seam
- // to decide backend vs. direct — was deleted outright by tinymemory
- // v1.13.4 along with the rest of the in-process Composio pipeline (see
- // `memory::host_impls`'s module docs). The equivalent decision now lives
- // entirely on this side: `modules::connectors::module_config` builds the
- // route the `tinyconnectors` module is configured with, and it is the
- // one and only place `composio.mode` gets turned into "which tenant".
- //
- // This asserts the same property the deleted test did — a direct-mode
- // config with an inline api_key resolves to the direct route without
- // needing (or surfacing an error about) a backend session token, which
- // was the pre-#1710 bug this area guards against.
- let tmp = tempfile::tempdir().expect("tempdir");
-
- let mut config = Config::default();
- config.config_path = tmp.path().join("config.toml");
- config.workspace_dir = tmp.path().join("workspace");
- config.secrets.encrypt = false;
- config.composio.mode = crate::openhuman::config::schema::COMPOSIO_MODE_DIRECT.to_string();
- config.composio.api_key = Some("test-direct-key".to_string());
- config.save().await.expect("save fake config to disk");
-
- let route = crate::openhuman::modules::connectors::module_config(&config)
- .expect("direct mode with an inline api_key must resolve a route");
- assert_eq!(
- route.get("route").and_then(|v| v.as_str()),
- Some("direct"),
- "a direct-mode config must resolve the direct route, not fall back to backend: {route:?}"
- );
- assert_eq!(
- route.get("api_key").and_then(|v| v.as_str()),
- Some("test-direct-key"),
- "the direct route must carry the configured api_key: {route:?}"
- );
-}
diff --git a/src/openhuman/memory/sync_events_bridge_tests.rs b/src/openhuman/memory/sync_events_bridge_tests.rs
index 01d10cc857..5ddb23e5ba 100644
--- a/src/openhuman/memory/sync_events_bridge_tests.rs
+++ b/src/openhuman/memory/sync_events_bridge_tests.rs
@@ -36,6 +36,11 @@ async fn document_canonicalized_emits_stored_and_queued_stages() {
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner());
crate::core::bus::init().await.expect("bus init");
+ // The bridge emits through `tinymemory_api::events`' sink, and these tests
+ // used to get it installed as a side effect of the memory host seams. Those
+ // are gone with the in-process engine (#6161), so install the one seam this
+ // actually needs — it is the host's own bus sink and names no engine.
+ crate::openhuman::memory::host::install_memory_event_sink();
let collector = StageCollector::default();
let _subscription = BUS
@@ -76,6 +81,11 @@ async fn memory_ingestion_started_emits_ingesting_stage() {
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner());
crate::core::bus::init().await.expect("bus init");
+ // The bridge emits through `tinymemory_api::events`' sink, and these tests
+ // used to get it installed as a side effect of the memory host seams. Those
+ // are gone with the in-process engine (#6161), so install the one seam this
+ // actually needs — it is the host's own bus sink and names no engine.
+ crate::openhuman::memory::host::install_memory_event_sink();
let collector = StageCollector::default();
let _subscription = BUS
@@ -168,6 +178,11 @@ async fn bridge_populates_source_id_for_stored_and_queued_from_mem_src() {
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner());
crate::core::bus::init().await.expect("bus init");
+ // The bridge emits through `tinymemory_api::events`' sink, and these tests
+ // used to get it installed as a side effect of the memory host seams. Those
+ // are gone with the in-process engine (#6161), so install the one seam this
+ // actually needs — it is the host's own bus sink and names no engine.
+ crate::openhuman::memory::host::install_memory_event_sink();
let collector = StageCollector::default();
let _subscription = BUS
@@ -217,6 +232,11 @@ async fn bridge_source_id_is_none_for_non_mem_src_canonicalized() {
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner());
crate::core::bus::init().await.expect("bus init");
+ // The bridge emits through `tinymemory_api::events`' sink, and these tests
+ // used to get it installed as a side effect of the memory host seams. Those
+ // are gone with the in-process engine (#6161), so install the one seam this
+ // actually needs — it is the host's own bus sink and names no engine.
+ crate::openhuman::memory::host::install_memory_event_sink();
let collector = StageCollector::default();
let _subscription = BUS
@@ -265,6 +285,11 @@ async fn bridge_populates_source_id_for_ingesting_from_mem_src() {
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner());
crate::core::bus::init().await.expect("bus init");
+ // The bridge emits through `tinymemory_api::events`' sink, and these tests
+ // used to get it installed as a side effect of the memory host seams. Those
+ // are gone with the in-process engine (#6161), so install the one seam this
+ // actually needs — it is the host's own bus sink and names no engine.
+ crate::openhuman::memory::host::install_memory_event_sink();
let collector = StageCollector::default();
let _subscription = BUS
@@ -319,6 +344,11 @@ async fn bridge_source_id_is_none_for_ingesting_non_mem_src() {
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner());
crate::core::bus::init().await.expect("bus init");
+ // The bridge emits through `tinymemory_api::events`' sink, and these tests
+ // used to get it installed as a side effect of the memory host seams. Those
+ // are gone with the in-process engine (#6161), so install the one seam this
+ // actually needs — it is the host's own bus sink and names no engine.
+ crate::openhuman::memory::host::install_memory_event_sink();
let collector = StageCollector::default();
let _subscription = BUS
diff --git a/src/openhuman/memory/sync_pipeline_e2e_tests.rs b/src/openhuman/memory/sync_pipeline_e2e_tests.rs
deleted file mode 100644
index a18e7ba7fd..0000000000
--- a/src/openhuman/memory/sync_pipeline_e2e_tests.rs
+++ /dev/null
@@ -1,406 +0,0 @@
-//! E2E tests for the sync → ingest → queue → tree pipeline.
-//!
-//! Exercises the full production path: messages arrive via `ingest_chat`,
-//! get chunked and persisted, the job queue drains (extract → admit →
-//! append_buffer → seal → topic_route), the source tree grows, and
-//! domain events are emitted at each stage.
-//!
-//! Two scenarios:
-//! 1. **Single batch** — one ingest, queue drains, source tree has a
-//! buffered leaf, events fired.
-//! 2. **High-volume** — enough data to cross the L0 seal threshold (50k
-//! tokens), producing sealed summaries and cascading into topic trees
-//! + global digest.
-
-#![cfg(test)]
-
-use std::sync::{Arc, Mutex};
-
-use async_trait::async_trait;
-use chrono::{TimeZone, Utc};
-use tempfile::TempDir;
-
-use crate::core::bus::BUS;
-use crate::core::events::DomainEvent;
-use crate::openhuman::config::Config;
-use tinybus::EventHandler;
-use tinybus::SubscriptionHandle;
-// Named on the engine crate directly: `memory::tree::retrieval` stopped
-// re-exporting the engine in #5560 because no production caller was left. A
-// test may still reach the engine — that is what keeps this a test-only
-// reference rather than a shipped one.
-use tinycortex::memory::ingest::canonicalize::chat::{ChatBatch, ChatMessage};
-use tinymemory_api::sync_events::{emit_sync_stage, MemorySyncStage, MemorySyncTrigger};
-use tinymemory_core::ingest_pipeline::ingest_chat;
-use tinymemory_core::queue::{self as memory_queue, count_total, drain_until_idle, JobStatus};
-use tinymemory_core::store::chunks::store::{
- count_chunks, count_chunks_by_lifecycle_status, CHUNK_STATUS_BUFFERED,
-};
-use tinymemory_core::store::trees::{store as tree_store, types::TreeKind};
-use tinymemory_core::tree::retrieval::{query_source, search_entities};
-use tinymemory_core::tree::score::store::lookup_entity;
-
-// ── helpers ─────────────────────────────────────────────────────────────
-
-fn test_config() -> (TempDir, Config) {
- // Ingestion canonicalises through the host seams, so they must be wired.
- // This module never installed them and passed only when some other test in
- // the binary had; filtered to this file it failed outright. `Once`-guarded,
- // so this is free when another test got there first.
- crate::openhuman::memory::host_impls::install_for_tests();
- let tmp = TempDir::new().unwrap();
- let mut cfg = Config::default();
- cfg.workspace_dir = tmp.path().to_path_buf();
- cfg.memory_tree.embedding_endpoint = None;
- cfg.memory_tree.embedding_model = None;
- cfg.memory_tree.embedding_strict = false;
- cfg.embeddings_provider = Some("none".to_string());
- (tmp, cfg)
-}
-
-fn failed_job_diagnostics(cfg: &Config) -> Vec<(String, i64, Option<String>)> {
- tinymemory_core::store::chunks::with_connection(cfg, |conn| {
- let mut stmt = conn.prepare(
- "SELECT kind, attempts, last_error FROM mem_tree_jobs \
- WHERE status = 'failed' ORDER BY created_at_ms",
- )?;
- let rows = stmt.query_map([], |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)))?;
- rows.collect::<Result<Vec<_>, _>>().map_err(Into::into)
- })
- .unwrap()
-}
-
-async fn ensure_event_bus() {
- // Standing the bus up is async now — it connects to a broker. Idempotent.
- crate::core::bus::init().await.expect("bus init");
-}
-
-#[derive(Clone)]
-struct EventCollector {
- events: Arc<Mutex<Vec<DomainEvent>>>,
-}
-
-impl EventCollector {
- fn new() -> Self {
- Self {
- events: Arc::new(Mutex::new(Vec::new())),
- }
- }
-
- fn subscribe(self) -> (Self, Option<SubscriptionHandle>) {
- let handle = BUS.subscribe(Arc::new(self.clone()));
- (self, handle)
- }
-
- fn count_by<F: Fn(&DomainEvent) -> bool>(&self, pred: F) -> usize {
- self.events
- .lock()
- .unwrap()
- .iter()
- .filter(|e| pred(e))
- .count()
- }
-
- /// Wait until at least `want` events match, or fail on a deadline.
- ///
- /// A single `yield_now` used to be enough when the bus was a channel and
- /// the handler ran inline on the subscriber task. On tinybus an event
- /// crosses two task hops — the subscriber loop, then the isolated handler
- /// task — so a batch of twenty needs to be waited for rather than assumed.
- async fn wait_for<F: Fn(&DomainEvent) -> bool>(&self, want: usize, pred: F) -> usize {
- let deadline = tokio::time::Instant::now() + std::time::Duration::from_secs(10);
- loop {
- let seen = self.count_by(&pred);
- if seen >= want || tokio::time::Instant::now() > deadline {
- return seen;
- }
- tokio::task::yield_now().await;
- }
- }
-}
-
-#[async_trait]
-impl EventHandler<DomainEvent> for EventCollector {
- fn name(&self) -> &str {
- "test::event_collector"
- }
-
- async fn handle(&self, event: &DomainEvent) {
- self.events.lock().unwrap().push(event.clone());
- }
-}
-
-fn substantive_body(seq: u32) -> String {
- format!(
- "Update #{seq} on Phoenix migration: [email protected] confirmed the \
- rollback procedure is documented. Staging checks passed: p99 latency \
- 12ms, error rate 0.001%, memory 2.1 GiB. [email protected] handles \
- on-call coordination. Feature flag phoenix_v2_enabled ramps Friday \
- evening. Remaining: finalize notification, update status page, \
- rotate staging credentials."
- )
-}
-
-fn large_body(seq: u32) -> String {
- let base = substantive_body(seq);
- format!(
- "{base}\n\n\
- Additional context from the architecture review (thread #{seq}): \
- the Phoenix migration touches auth-gateway, user-profiles, and \
- billing-ledger. [email protected] mapped the dependency graph — \
- billing-ledger migrates first since user-profiles reads its views. \
- [email protected] raised concerns about OAuth token rotation during \
- cutover. We use dual-write mode for 48 hours: ~200k token refreshes \
- per hour, within capacity. Schema migration: 3 ALTER TABLE statements, \
- all backwards-compatible. API v2 coexists with v1 for 30 days. \
- Rollback trigger: error rate > 0.1% for 5 consecutive minutes. \
- [email protected] verified that reverting the feature flag immediately \
- drains the v2 code path. Timeline: Thursday final staging, Friday \
- 22:00 UTC canary, Saturday 08:00 ramp to 10%, Monday 09:00 ramp to \
- 100%, Tuesday remove v1 code path. Please review the runbook."
- )
-}
-
-fn mk_batch(source: &str, label: &str, seq: u32, body: &str, base_ts: i64) -> ChatBatch {
- ChatBatch {
- platform: source.into(),
- channel_label: label.into(),
- messages: vec![ChatMessage {
- author: "alice".into(),
- timestamp: Utc
- .timestamp_millis_opt(base_ts + (seq as i64) * 60_000)
- .unwrap(),
- text: body.into(),
- source_ref: Some(format!("{source}://msg/{seq}")),
- }],
- }
-}
-
-// ── Test 1: single batch → ingest → queue drain → tree ──────────────────
-
-#[tokio::test]
-async fn single_batch_sync_to_tree() {
- let (_tmp, cfg) = test_config();
- ensure_event_bus().await;
-
- let (collector, _handle) = EventCollector::new().subscribe();
-
- // Simulate sync lifecycle events.
- emit_sync_stage(
- MemorySyncTrigger::Manual,
- MemorySyncStage::Requested,
- Some("gmail"),
- Some("conn-1"),
- None,
- None, // channel-level — not a memory-source row
- );
- emit_sync_stage(
- MemorySyncTrigger::Manual,
- MemorySyncStage::Fetching,
- Some("gmail"),
- Some("conn-1"),
- None,
- None, // channel-level — not a memory-source row
- );
-
- let source_id = "gmail:alice-thread-1";
- let batch = mk_batch("gmail", "inbox", 1, &substantive_body(1), 1_700_000_000_000);
- let result = ingest_chat(&cfg, source_id, "alice", vec!["gmail".into()], batch)
- .await
- .unwrap();
-
- assert!(result.chunks_written >= 1);
- assert!(!result.already_ingested);
-
- let total_jobs = count_total(&cfg).unwrap();
- assert!(total_jobs >= 1, "extract_chunk job should be queued");
-
- // DocumentCanonicalized event. Waited for, not assumed: the event crosses
- // two task hops on tinybus, so a bare `yield_now` raced the handler and
- // made this test flaky — it alternated pass/fail across identical runs.
- let canonicalized_count = collector
- .wait_for(1, |e| {
- matches!(e, DomainEvent::DocumentCanonicalized { source_kind, source_id: sid, .. }
- if source_kind == "chat" && sid == "gmail:alice-thread-1")
- })
- .await;
- assert!(canonicalized_count >= 1);
-
- // Drain: extract → admit → append_buffer.
- drain_until_idle(&cfg).await.unwrap();
-
- let done = memory_queue::count_by_status(&cfg, JobStatus::Done).unwrap();
- assert!(done >= 1, "at least one job should complete");
-
- let buffered = count_chunks_by_lifecycle_status(&cfg, CHUNK_STATUS_BUFFERED).unwrap();
- assert!(buffered >= 1, "chunks should reach buffered status");
-
- // Source tree with non-empty L0 buffer.
- let source_trees = tree_store::list_trees_by_kind(&cfg, TreeKind::Source).unwrap();
- assert!(!source_trees.is_empty());
- let buf = tree_store::get_buffer(&cfg, &source_trees[0].id, 0).unwrap();
- assert!(!buf.is_empty(), "L0 buffer should contain the leaf");
-
- // Entity index.
- let alice_hits = lookup_entity(&cfg, "email:[email protected]", None).unwrap();
- assert!(
- !alice_hits.is_empty(),
- "alice should be in the entity index"
- );
-
- // Completion event.
- emit_sync_stage(
- MemorySyncTrigger::Manual,
- MemorySyncStage::Completed,
- Some("gmail"),
- Some("conn-1"),
- None,
- None, // channel-level — not a memory-source row
- );
-
- // Same race as above. Waits for the **terminal** stage specifically, not
- // merely for some stage event: the assertions below require `completed` to
- // have arrived, and any earlier stage would satisfy a looser predicate
- // while the pipeline was still running.
- collector
- .wait_for(1, |e| {
- matches!(e, DomainEvent::MemorySyncStageChanged { stage, .. } if stage == "completed")
- })
- .await;
- let sync_stages: Vec<String> = collector
- .events
- .lock()
- .unwrap()
- .iter()
- .filter_map(|e| match e {
- DomainEvent::MemorySyncStageChanged { stage, .. } => Some(stage.clone()),
- _ => None,
- })
- .collect();
- assert!(sync_stages.contains(&"requested".to_string()));
- assert!(sync_stages.contains(&"completed".to_string()));
-}
-
-// ── Test 2: high-volume → seal → digest → topic tree ────────────────────
-
-#[tokio::test]
-async fn multi_batch_volume_builds_full_tree() {
- let (_tmp, cfg) = test_config();
- ensure_event_bus().await;
-
- let (collector, _handle) = EventCollector::new().subscribe();
-
- let source_id = "gmail:alice-volume";
- let base_ts = Utc::now().timestamp_millis() - 86_400_000;
-
- // Ingest 30 batches with large bodies to cross the 50k token seal threshold.
- // Each large_body is ~302 tokens. 6 segments = ~1812 tokens per batch.
- // 30 batches * 1812 tokens = 54,360 tokens (> 50,000 threshold).
- // We vary each repetition slightly to ensure no content-based deduplication
- // collapses the volume.
- for i in 0..30u32 {
- let mut body = String::new();
- for j in 0..6 {
- body.push_str(&large_body(i));
- body.push_str(&format!("\n\nRepeat marker: batch {i} / segment {j}\n\n"));
- }
- let batch = mk_batch("gmail", "inbox", i, &body, base_ts);
- let result = ingest_chat(&cfg, source_id, "alice", vec!["gmail".into()], batch)
- .await
- .unwrap();
- assert!(
- result.chunks_written >= 1,
- "batch {i} should produce chunks"
- );
- }
-
- let total_chunks = count_chunks(&cfg).unwrap();
- assert!(total_chunks >= 20, "got {total_chunks}");
-
- let canonicalized = collector
- .wait_for(20, |e| {
- matches!(e, DomainEvent::DocumentCanonicalized { source_id: sid, .. }
- if sid == "gmail:alice-volume")
- })
- .await;
- assert!(canonicalized >= 20, "got {canonicalized}");
-
- // A parallel test can briefly hold the process-global LLM gate, causing
- // the seal job to defer. Keep draining until that deferred work becomes
- // claimable and the durable tree state reflects the completed seal.
- let deadline = tokio::time::Instant::now() + std::time::Duration::from_secs(60);
- let source_tree = loop {
- drain_until_idle(&cfg).await.unwrap();
- let failed_jobs = failed_job_diagnostics(&cfg);
- assert!(
- failed_jobs.is_empty(),
- "memory jobs failed before the source tree sealed: {failed_jobs:?}"
- );
- if let Some(tree) = tree_store::list_trees_by_kind(&cfg, TreeKind::Source)
- .unwrap()
- .into_iter()
- .find(|tree| tree.scope == source_id && tree.max_level >= 1)
- {
- break tree;
- }
- if tokio::time::Instant::now() >= deadline {
- let trees = tree_store::list_trees_by_kind(&cfg, TreeKind::Source).unwrap();
- let buffer = trees
- .iter()
- .find(|tree| tree.scope == source_id)
- .map(|tree| tree_store::get_buffer(&cfg, &tree.id, 0).unwrap());
- panic!(
- "source tree did not seal before timeout: trees={trees:?}, buffer={buffer:?}, \
- ready={}, running={}, done={}, failed={}",
- memory_queue::count_by_status(&cfg, JobStatus::Ready).unwrap(),
- memory_queue::count_by_status(&cfg, JobStatus::Running).unwrap(),
- memory_queue::count_by_status(&cfg, JobStatus::Done).unwrap(),
- memory_queue::count_by_status(&cfg, JobStatus::Failed).unwrap(),
- );
- }
- tokio::time::sleep(std::time::Duration::from_millis(100)).await;
- };
-
- // Source tree should have sealed to L1+.
- assert!(
- source_tree.max_level >= 1,
- "should seal to L1+, got max_level={}",
- source_tree.max_level
- );
-
- let l1 = tree_store::list_summaries_at_level(&cfg, &source_tree.id, 1).unwrap();
- assert!(!l1.is_empty(), "L1 summaries should exist");
-
- // Source retrieval.
- let source_resp = query_source(&cfg, Some(source_id), None, None, None, 10)
- .await
- .unwrap();
- assert!(!source_resp.hits.is_empty());
-
- // Entity index well-populated.
- let alice_hits = lookup_entity(&cfg, "email:[email protected]", None).unwrap();
- assert!(alice_hits.len() >= 5, "got {}", alice_hits.len());
-
- // Entity search.
- let matches = search_entities(&cfg, "alice", None, 10).await.unwrap();
- assert!(!matches.is_empty());
- assert!(matches
- .iter()
- .any(|m| m.canonical_id == "email:[email protected]"));
-
- // (The global-digest and topic-spawn steps were removed with those
- // trees — source trees plus the entity index are the substrate.)
-
- // Verify event stream. Twenty events across two task hops each — the
- // helper exists precisely because a single yield cannot cover that.
- let canonicalized = collector
- .wait_for(20, |e| {
- matches!(e, DomainEvent::DocumentCanonicalized { source_id: sid, .. }
- if sid == "gmail:alice-volume")
- })
- .await;
- assert!(
- canonicalized >= 20,
- "expected 20 canonicalized events, saw {canonicalized}"
- );
-}
diff --git a/src/openhuman/memory/test_support/mod.rs b/src/openhuman/memory/test_support/mod.rs
index 6bd7958081..cde34ff8c2 100644
--- a/src/openhuman/memory/test_support/mod.rs
+++ b/src/openhuman/memory/test_support/mod.rs
@@ -43,3 +43,76 @@ pub(crate) fn install_memory_driver_for_test(config: &crate::openhuman::config::
Arc::new(tinymemory_conformance::RecordingProvider::new());
install_for_test(&config.workspace_dir, &config.subsystems.memory, provider);
}
+
+/// A [`Memory`] that stores nothing.
+///
+/// Seventeen test helpers used to obtain one by asking the engine's factory for
+/// `backend: "none"` — an engine call whose entire purpose was to get back
+/// something that does not store. The agent or session under test needs *a*
+/// memory to be constructed with and never reads one back, so this is the same
+/// behaviour without linking an engine to obtain it.
+///
+/// Deliberately not the conformance driver: that one retains, and a test that
+/// asked for `"none"` was asking for the opposite. Swapping in a retaining
+/// store would change what those tests exercise.
+#[derive(Debug)]
+pub(crate) struct NoopMemory;
+
+#[async_trait::async_trait]
+impl tinymemory_api::traits::Memory for NoopMemory {
+ fn name(&self) -> &str {
+ "none"
+ }
+ async fn store(
+ &self,
+ _namespace: &str,
+ _key: &str,
+ _content: &str,
+ _category: tinymemory_api::types::MemoryCategory,
+ _session_id: Option<&str>,
+ ) -> anyhow::Result<()> {
+ Ok(())
+ }
+ async fn recall(
+ &self,
+ _query: &str,
+ _limit: usize,
+ _opts: tinymemory_api::recall::RecallOpts<'_>,
+ ) -> anyhow::Result<Vec<tinymemory_api::types::MemoryEntry>> {
+ Ok(Vec::new())
+ }
+ async fn get(
+ &self,
+ _namespace: &str,
+ _key: &str,
+ ) -> anyhow::Result<Option<tinymemory_api::types::MemoryEntry>> {
+ Ok(None)
+ }
+ async fn list(
+ &self,
+ _namespace: Option<&str>,
+ _category: Option<&tinymemory_api::types::MemoryCategory>,
+ _session_id: Option<&str>,
+ ) -> anyhow::Result<Vec<tinymemory_api::types::MemoryEntry>> {
+ Ok(Vec::new())
+ }
+ async fn forget(&self, _namespace: &str, _key: &str) -> anyhow::Result<bool> {
+ Ok(false)
+ }
+ async fn namespace_summaries(
+ &self,
+ ) -> anyhow::Result<Vec<tinymemory_api::types::NamespaceSummary>> {
+ Ok(Vec::new())
+ }
+ async fn count(&self) -> anyhow::Result<usize> {
+ Ok(0)
+ }
+ async fn health_check(&self) -> bool {
+ true
+ }
+}
+
+/// The shorthand the `backend: "none"` call sites use.
+pub(crate) fn noop_memory() -> Arc<dyn tinymemory_api::traits::Memory> {
+ Arc::new(NoopMemory)
+}
diff --git a/src/openhuman/memory/tool_memory/mod.rs b/src/openhuman/memory/tool_memory/mod.rs
index 4371abe7a0..916b1bcb15 100644
--- a/src/openhuman/memory/tool_memory/mod.rs
+++ b/src/openhuman/memory/tool_memory/mod.rs
@@ -66,6 +66,10 @@ pub use store::{ToolMemoryStore, TOOL_MEMORY_PROMPT_CAP};
pub mod capture;
pub mod prompt;
pub mod store;
+#[cfg(test)]
+pub mod test_support;
+#[cfg(test)]
+pub use test_support::test_helpers;
/// Build the rule store over OpenHuman's shared memory object.
///
@@ -78,23 +82,3 @@ pub fn tool_memory_store(memory: Arc<dyn Memory>) -> ToolMemoryStore {
log::trace!("[memory::tool_memory] building ToolMemoryStore over the host memory object");
ToolMemoryStore::new(memory)
}
-
-// The engine crate's `MockMemory` fixture, re-exported under its historical
-// path `memory::tool_memory::test_helpers`.
-//
-// Test-only in both directions: `tinymemory-core` compiles it behind
-// `cfg(any(test, feature = "test-support"))`, and both items below are
-// `#[cfg(test)]`, so they exist only in `cargo test --lib` builds where the
-// dev-dependency at `Cargo.toml`'s `[dev-dependencies]` supplies the crate.
-// Four inline `#[cfg(test)]` modules reach it — `capture` in this directory,
-// `agent::experience::{capture, store}` and
-// `agent::tinyagents::host::experience_store`.
-//
-// The `pub use tinymemory_core::…` line itself sits one level down, in
-// `test_support/mod.rs`; that module's docs say why, and the path callers use
-// does not change.
-#[cfg(test)]
-pub mod test_support;
-
-#[cfg(test)]
-pub use test_support::test_helpers;
diff --git a/src/openhuman/memory/tool_memory/test_support/mod.rs b/src/openhuman/memory/tool_memory/test_support/mod.rs
index f3da257f36..d0c9630fa9 100644
--- a/src/openhuman/memory/tool_memory/test_support/mod.rs
+++ b/src/openhuman/memory/tool_memory/test_support/mod.rs
@@ -1,35 +1,150 @@
-//! The engine crate's tool-memory test fixtures, re-exported for this tree.
+//! `MockMemory` — a storing [`Memory`] for the tool-memory and experience tests.
//!
-//! One line, and it lives in its own directory on purpose. `MockMemory` is a
-//! `tinymemory-core` fixture compiled behind `cfg(any(test, feature =
-//! "test-support"))`, reached from four inline `#[cfg(test)]` modules —
-//! `memory::tool_memory::capture`, `agent::experience::{capture, store}` and
-//! `agent::tinyagents::host::experience_store`. `cfg(test)` code links the
-//! `tinymemory-core` **dev-dependency** (declared with `features =
-//! ["test-support"]` at `Cargo.toml`'s `[dev-dependencies]`), which survives
-//! #5560's shed — so this names the engine crate without putting a byte of it
-//! in the shipped binary.
+//! This was one line, `pub use tinymemory_core::tool_memory::test_helpers;`, and
+//! it is why four `#[cfg(test)]` modules kept the engine on this crate's test
+//! critical path: `memory::tool_memory::{store, capture}`,
+//! `agent::experience::{capture, store}` and
+//! `agent::tinyagents::host::experience_store` all bind an
+//! `Arc<dyn Memory>` and write rows through it.
//!
-//! # Why it is not in the parent `mod.rs`
+//! Ported rather than deleted (openhuman#6161). Nothing about a `HashMap`
+//! behind a mutex needed an engine — it was upstream only because that is where
+//! it happened to be written, and importing it cost 133k lines of TinyCortex
+//! and tinymemory-core for the privilege.
//!
-//! It was, as a `#[cfg(test)] pub use`, and the parent's own docs already
-//! explained that it is dev-only. `memory::direct_engine_refs_tests` could not
-//! see that explanation: its scanner reads line by line and skips only comments
-//! and whole files, deliberately, because brace-tracking inline `#[cfg(test)]`
-//! blocks is the complexity that lint's docs say it does not want. So a
-//! genuinely test-only reference kept a production file on the direct-reference
-//! allowlist, which made "deliberate" and "not migrated yet" look identical in
-//! the one list that exists to tell them apart.
+//! Behaviour is the upstream fixture's, deliberately including its omissions:
+//! `recall` answers empty and `list` ignores `category` and `session_id`. The
+//! tests that use it assert the store/get/forget path, and widening the fixture
+//! would change what they exercise.
//!
-//! `test_support/` is the escape hatch both scanners already honour by path
-//! (`is_test_path` in `direct_engine_refs_tests` and in `bypass_allowlist_tests`
-//! each match on a `test_support` path *component*, which is why this is a
-//! directory and not a `test_support.rs`). Moving the line here classifies it
-//! rather than hiding it: the reference is unchanged, still `#[cfg(test)]`, and
-//! still the dev-dependency's.
+//! It lives in a `test_support/` **directory** because both memory ratchets skip
+//! by path — `is_test_path` matches a path *component* named `test_support`, not
+//! a file stem.
//!
-//! The public path callers use is unchanged —
-//! `memory::tool_memory::test_helpers::MockMemory` — because the parent
-//! re-exports this module's contents under that name.
+//! `parking_lot::Mutex` rather than `std`'s, matching the upstream fixture: the
+//! tests reach `memory.entries.lock()` directly, and a `std` mutex would make
+//! every one of those call sites grow an `unwrap`.
-pub use tinymemory_core::tool_memory::test_helpers;
+use std::collections::HashMap;
+use parking_lot::Mutex;
+
+use async_trait::async_trait;
+use tinymemory_api::recall::RecallOpts;
+use tinymemory_api::traits::Memory;
+use tinymemory_api::types::{MemoryCategory, MemoryEntry, NamespaceSummary};
+
+/// The public path callers use is unchanged: `tool_memory::test_helpers::MockMemory`.
+pub mod test_helpers {
+ pub use super::MockMemory;
+}
+
+/// Minimal in-memory [`Memory`] backend for unit tests.
+///
+/// Stores entries in a `HashMap` keyed by `(namespace, key)`. Methods the
+/// store/capture tests do not need are no-ops.
+#[derive(Default)]
+pub struct MockMemory {
+ /// The rows, keyed the way the contract upserts them.
+ pub entries: Mutex<HashMap<(String, String), MemoryEntry>>,
+}
+
+impl MockMemory {
+ fn rows(&self) -> parking_lot::MutexGuard<'_, HashMap<(String, String), MemoryEntry>> {
+ self.entries.lock()
+ }
+}
+
+#[async_trait]
+impl Memory for MockMemory {
+ fn name(&self) -> &str {
+ "mock"
+ }
+
+ async fn store(
+ &self,
+ namespace: &str,
+ key: &str,
+ content: &str,
+ category: MemoryCategory,
+ session_id: Option<&str>,
+ ) -> anyhow::Result<()> {
+ self.rows().insert(
+ (namespace.to_string(), key.to_string()),
+ MemoryEntry {
+ id: format!("{namespace}/{key}"),
+ key: key.to_string(),
+ content: content.to_string(),
+ namespace: Some(namespace.to_string()),
+ category,
+ timestamp: "now".into(),
+ session_id: session_id.map(str::to_string),
+ score: None,
+ taint: Default::default(),
+ },
+ );
+ Ok(())
+ }
+
+ async fn recall(
+ &self,
+ _query: &str,
+ _limit: usize,
+ _opts: RecallOpts<'_>,
+ ) -> anyhow::Result<Vec<MemoryEntry>> {
+ Ok(Vec::new())
+ }
+
+ async fn get(&self, namespace: &str, key: &str) -> anyhow::Result<Option<MemoryEntry>> {
+ Ok(self
+ .rows()
+ .get(&(namespace.to_string(), key.to_string()))
+ .cloned())
+ }
+
+ async fn list(
+ &self,
+ namespace: Option<&str>,
+ _category: Option<&MemoryCategory>,
+ _session_id: Option<&str>,
+ ) -> anyhow::Result<Vec<MemoryEntry>> {
+ let lock = self.rows();
+ Ok(match namespace {
+ Some(ns) => lock
+ .iter()
+ .filter(|((n, _), _)| n == ns)
+ .map(|(_, v)| v.clone())
+ .collect(),
+ None => lock.values().cloned().collect(),
+ })
+ }
+
+ async fn forget(&self, namespace: &str, key: &str) -> anyhow::Result<bool> {
+ Ok(self
+ .rows()
+ .remove(&(namespace.to_string(), key.to_string()))
+ .is_some())
+ }
+
+ async fn namespace_summaries(&self) -> anyhow::Result<Vec<NamespaceSummary>> {
+ let mut counts: HashMap<String, usize> = HashMap::new();
+ for (ns, _) in self.rows().keys() {
+ *counts.entry(ns.clone()).or_default() += 1;
+ }
+ Ok(counts
+ .into_iter()
+ .map(|(namespace, count)| NamespaceSummary {
+ namespace,
+ count,
+ last_updated: None,
+ })
+ .collect())
+ }
+
+ async fn count(&self) -> anyhow::Result<usize> {
+ Ok(self.rows().len())
+ }
+
+ async fn health_check(&self) -> bool {
+ true
+ }
+}
diff --git a/src/openhuman/memory/tools/doctor_tests.rs b/src/openhuman/memory/tools/doctor_tests.rs
index 2c9330e9b2..051f34fd88 100644
--- a/src/openhuman/memory/tools/doctor_tests.rs
+++ b/src/openhuman/memory/tools/doctor_tests.rs
@@ -19,21 +19,3 @@ fn name_and_schema() {
assert_eq!(tool.parameters_schema()["required"], json!([]));
}
-#[tokio::test]
-async fn execute_returns_a_report_for_a_misconfigured_workspace() {
- let _g = tinymemory_core::tree::health::test_guard();
- let (_tmp, cfg) = test_config();
- // No embeddings provider, local AI off → unhealthy with a typed cause.
- let tool = MemoryDoctorTool::new(cfg);
- let result = tool.execute(json!({})).await.unwrap();
- assert!(!result.is_error);
- let out = result.output();
- assert!(
- out.contains("\"healthy\""),
- "report should serialize: {out}"
- );
- assert!(
- out.contains("embeddings_unconfigured") || out.contains("\"healthy\": false"),
- "misconfigured workspace should surface a blocking cause: {out}"
- );
-}
diff --git a/src/openhuman/memory/tree/retrieval/mod.rs b/src/openhuman/memory/tree/retrieval/mod.rs
index a96116120b..280ed82c9e 100644
--- a/src/openhuman/memory/tree/retrieval/mod.rs
+++ b/src/openhuman/memory/tree/retrieval/mod.rs
@@ -52,13 +52,6 @@
pub mod rpc;
pub mod schemas;
-/// Chunk-staging fixtures for [`rpc`]'s inline tests.
-///
-/// Test-only, and in a directory both memory lints skip by path — see the
-/// module's own docs for why a genuinely dev-only engine reference had to move
-/// out of the inline `#[cfg(test)]` block to be classified as one.
-#[cfg(test)]
-pub(crate) mod test_support;
// The controller aggregators this domain's RPC surface defines. Aliased
// exactly as the pre-extraction module exported them.
diff --git a/src/openhuman/memory/tree/retrieval/test_support/mod.rs b/src/openhuman/memory/tree/retrieval/test_support/mod.rs
deleted file mode 100644
index 6709eab4e3..0000000000
--- a/src/openhuman/memory/tree/retrieval/test_support/mod.rs
+++ /dev/null
@@ -1,60 +0,0 @@
-//! Chunk-staging fixtures for the retrieval handler tests.
-//!
-//! One reason this is a directory of its own, and it is a classification rather
-//! than a hiding place — the same reason
-//! [`memory::tool_memory::test_support`](crate::openhuman::memory::tool_memory)
-//! exists.
-//!
-//! `rpc.rs`'s inline `#[cfg(test)]` module needs chunk rows the **real**
-//! in-process driver can read back, because one of its tests proves the source
-//! gate end to end rather than against a recording double. Writing those rows
-//! means the engine's chunk store: `MemoryChunks` on the contract is a read
-//! family (`list_chunks` / `get_chunk` / `chunk_detail` / `storage_kinds` /
-//! `chunk_embeddings`) with no write or transaction door, and none should be
-//! added — `with_connection` hands out a `rusqlite` handle, which no
-//! engine-neutral contract can promise.
-//!
-//! So the reference is real and unavoidable, and it is also **test-only**:
-//! `cfg(test)` code links the `tinymemory-core` **dev-dependency**, which
-//! survives #5560's shed and puts no byte of the engine in the shipped binary.
-//!
-//! `memory::direct_engine_refs_tests` could not see that on its own. Its
-//! scanner reads line by line and skips only comments and whole files —
-//! deliberately, because brace-tracking inline `#[cfg(test)]` blocks is
-//! complexity its docs say it does not want — so a fixture write kept `rpc.rs`
-//! on the direct-reference allowlist under a `NeedsWiderSeam` verdict that
-//! described a *production* gap the file does not have. That made "deliberate"
-//! and "not migrated yet" look identical in the one list that exists to tell
-//! them apart.
-//!
-//! `test_support/` is the escape hatch both memory lints already honour by path
-//! (each matches on a `test_support` path *component*, which is why this is a
-//! directory and not a `test_support.rs`). Nothing about the writes changed;
-//! only where the line that names the engine lives.
-
-use tinymemory_api::chunks::Chunk;
-
-use crate::openhuman::config::Config;
-
-pub(crate) use tinymemory_core::store::chunks::store::upsert_chunks;
-
-/// Write chunks the in-process driver can read back — both the row and the
-/// staged content body, since a hit carries the body.
-pub(crate) fn stage_test_chunks(cfg: &Config, chunks: &[Chunk]) {
- let content_root = cfg.memory_tree_content_root();
- std::fs::create_dir_all(&content_root).expect("create content_root for test");
- let staged = tinymemory_core::store::content::stage_chunks(&content_root, chunks)
- .expect("stage_chunks for test chunks");
- log::debug!(
- "[memory-tree][retrieval][test-support] staging chunks count={} content_root={}",
- chunks.len(),
- content_root.display()
- );
- tinymemory_core::store::chunks::store::with_connection(cfg, |conn| {
- let tx = conn.unchecked_transaction()?;
- tinymemory_core::store::chunks::store::upsert_staged_chunks_tx(&tx, &staged)?;
- tx.commit()?;
- Ok(())
- })
- .expect("persist staged chunk pointers");
-}
diff --git a/src/openhuman/memory/tree/tree/rpc_tests_part_02_tests.rs b/src/openhuman/memory/tree/tree/rpc_tests_part_02_tests.rs
index a2380ead17..b698adfc9d 100644
--- a/src/openhuman/memory/tree/tree/rpc_tests_part_02_tests.rs
+++ b/src/openhuman/memory/tree/tree/rpc_tests_part_02_tests.rs
@@ -453,38 +453,6 @@ fn an_untimestamped_failure_surfaces_regardless_of_the_watermark() {
);
}
-/// On a fresh workspace the panel must report `idle` with zero
-/// counters — the UI uses this to swap the loading skeleton for a
-/// "no memory yet" state.
-#[tokio::test]
-async fn pipeline_status_returns_idle_for_empty_store() {
- // #002: the degraded flags are process-global; reset+serialise so a
- // parallel test (factory None-path, extract transport-fail) can't leak
- // a "degraded" signal into this fresh-workspace assertion.
- let _g = tinymemory_core::tree::health::test_guard();
- let (_tmp, cfg) = test_config();
- // An empty driver, bound explicitly. Without a binding installed this
- // resolves the real one, which means loading the compiled module — and
- // in a test process that blocks rather than failing.
- bind_diagnostics(&cfg, Default::default(), Default::default());
- let out = pipeline_status_rpc(&cfg).await.unwrap().value;
- assert_eq!(out.status, "idle");
- assert_eq!(out.total_chunks, 0);
- assert_eq!(out.last_sync_ms, 0);
- assert_eq!(out.pipeline_jobs.ready, 0);
- assert_eq!(out.pipeline_jobs.running, 0);
- assert_eq!(out.pipeline_jobs.failed, 0);
- assert!(!out.is_syncing);
- assert!(!out.is_paused);
- // No gate sampler runs in unit tests, so the live policy is `Normal`.
- assert!(!out.gate_paused);
- assert!(out.gate_pause_reason.is_none());
- // An empty queue has nothing waiting, so nothing is stalled.
- assert!(!out.queue_stalled);
- assert_eq!(out.wiki_size_bytes, 0, "no content dir yet");
- assert!(out.reason.is_none());
-}
-
/// When the scheduler gate is `off`, the aggregated status flips to
/// `paused` regardless of the rest of the signals. This is the
/// invariant the toggle relies on.
@@ -502,66 +470,6 @@ async fn pipeline_status_reflects_paused_when_scheduler_off() {
assert!(reason.contains("off"), "reason should name the mode");
}
-/// `pipeline_status` renders the aggregates the driver reports, and
-/// derives a terminal status from them.
-///
-/// This used to ingest a document and assert the counters moved. That
-/// half — an ingest raising the chunk count — is the driver's, and is
-/// pinned in the driver's conformance suite against a real store. What is
-/// the host's, and what this pins, is that the reported numbers reach the
-/// wire unchanged and that a populated, idle store reads as terminal
-/// rather than syncing.
-#[tokio::test]
-async fn pipeline_status_renders_the_drivers_chunk_aggregates() {
- use crate::openhuman::memory::api::provider::types::{QueueStats, StoreStats};
-
- // #002: reset+serialise the process-global degraded flags so this
- // "running" assertion isn't flipped to "degraded" by a parallel test.
- let _g = tinymemory_core::tree::health::test_guard();
- let (_tmp, cfg) = test_config();
-
- let ingested_at = 1_800_000_000_000_i64;
- bind_diagnostics(
- &cfg,
- StoreStats {
- chunks: 4,
- chunks_with_structure: 1,
- most_recent_chunk_ms: Some(ingested_at),
- },
- QueueStats::default(),
- );
-
- let out = pipeline_status_rpc(&cfg).await.unwrap().value;
- assert_eq!(out.total_chunks, 4, "the driver's count reaches the wire");
- assert_eq!(
- out.last_sync_ms, ingested_at,
- "and so does its newest chunk's timestamp"
- );
- assert_eq!(
- out.extraction_coverage,
- Some(0.25),
- "coverage is the pair the driver reported, divided once"
- );
- // Provider availability differs between local and CI harnesses, so a
- // populated store may read as fully running or as degraded because
- // semantic recall or wiki structure was skipped. Both are terminal,
- // non-syncing states and both preserve the aggregates above.
- match out.status.as_str() {
- "running" => assert!(out.reason.is_none()),
- "degraded" => {
- let reason = out.reason.as_deref().unwrap_or_default();
- assert!(
- reason.contains("semantic recall disabled")
- || reason.contains("wiki structure incomplete"),
- "degraded status should explain recall or structure loss: {:?}",
- out.reason
- );
- }
- other => panic!("expected running or degraded for a populated store, got {other}"),
- }
- assert!(!out.is_syncing);
-}
-
/// `set_enabled` flips the persisted scheduler-gate mode and reports
/// `changed=true`; calling it again with the same value is a no-op
/// reporting `changed=false`. Uses an isolated `config_path` under
diff --git a/src/openhuman/memory/tree/tree_runtime/cli_tests.rs b/src/openhuman/memory/tree/tree_runtime/cli_tests.rs
index bd80a50a13..f28530cad2 100644
--- a/src/openhuman/memory/tree/tree_runtime/cli_tests.rs
+++ b/src/openhuman/memory/tree/tree_runtime/cli_tests.rs
@@ -67,26 +67,6 @@ impl Drop for EnvVarGuard {
}
}
-/// Bind a tree driver for the workspace these subcommands will resolve to.
-///
-/// The subcommands go through the contract's runtime-tree doors now (#5560), so
-/// each one asks `memory::binding` for a provider. With none installed the
-/// binding tries to load the compiled TinyMemory module, which in a test
-/// process can *block* rather than fail — so every test that reaches a handler
-/// has to put one there first.
-///
-/// The config is resolved exactly the way [`load_config`] resolves it, rather
-/// than being constructed here: `OPENHUMAN_WORKSPACE` is set by
-/// [`WorkspaceEnvGuard`] and the env overlay is what turns it into the
-/// `workspace_dir` the binding is keyed on. Building a `Config::default()` and
-/// pointing it at the tempdir would key the binding on a *different* path than
-/// the one the CLI then asks for.
-fn bind_workspace_driver() {
- let runtime = build_runtime().expect("runtime");
- let config = runtime.block_on(load_config()).expect("config");
- super::super::test_support::bind_tree_driver(&config);
-}
-
#[test]
fn is_help_matches_supported_aliases() {
assert!(is_help("-h"));
@@ -170,40 +150,6 @@ fn help_paths_for_subcommands_return_ok() {
assert!(run_rebuild(&["--help".to_string()]).is_ok());
}
-#[test]
-fn ingest_status_and_query_run_against_isolated_workspace() {
- let tmp = TempDir::new().unwrap();
- let _workspace = WorkspaceEnvGuard::set(tmp.path());
- bind_workspace_driver();
-
- assert!(run_ingest(&[
- "ns".to_string(),
- "--content".to_string(),
- "hello world".to_string()
- ])
- .is_ok());
- assert!(run_status(&["ns".to_string()]).is_ok());
- let err = run_query(&["ns".to_string(), "root".to_string()])
- .expect_err("root query should fail before a summarization run creates nodes");
- assert!(err.to_string().contains("not found"));
-}
-
-#[test]
-fn ingest_reads_from_file_path() {
- let tmp = TempDir::new().unwrap();
- let _workspace = WorkspaceEnvGuard::set(tmp.path());
- bind_workspace_driver();
- let input = tmp.path().join("input.txt");
- std::fs::write(&input, "from file").unwrap();
-
- let args = vec![
- "ns".to_string(),
- "--file".to_string(),
- input.display().to_string(),
- ];
- assert!(run_ingest(&args).is_ok());
-}
-
#[test]
fn ingest_prefers_file_input_and_surfaces_read_errors() {
let tmp = TempDir::new().unwrap();
@@ -240,25 +186,6 @@ fn run_summarize_errors_cleanly_without_provider() {
);
}
-#[test]
-fn query_prefers_explicit_node_flag_over_positional_node() {
- let tmp = TempDir::new().unwrap();
- let _workspace = WorkspaceEnvGuard::set(tmp.path());
- bind_workspace_driver();
-
- let err = run_query(&[
- "ns".to_string(),
- "2024/03/15".to_string(),
- "--node-id".to_string(),
- "2024/03/16".to_string(),
- ])
- .expect_err("missing node should fail");
-
- assert!(err
- .to_string()
- .contains("node '2024/03/16' not found in namespace 'ns'"));
-}
-
#[test]
fn load_config_uses_isolated_workspace_and_env_overrides() {
let tmp = TempDir::new().unwrap();
@@ -299,40 +226,3 @@ fn init_logging_sets_default_rust_log_only_when_needed() {
}
}
-#[test]
-fn run_and_rebuild_no_longer_block_on_local_ai_precondition() {
- // #002 FR-007: the summarizer used to hard-error "requires local_ai to
- // be enabled" when local AI was off, which left Build Summary Trees
- // dead for cloud-only setups. It now builds the configured cloud
- // provider instead. The commands may still surface a downstream error
- // (e.g. a network/auth failure when actually calling the cloud model in
- // a test sandbox), but they must NOT fail on the old local-AI
- // precondition. This test asserts that specific regression is gone.
- let tmp = TempDir::new().unwrap();
- let _workspace = WorkspaceEnvGuard::set(tmp.path());
- bind_workspace_driver();
-
- // Seed a namespace so the commands go through the runtime path
- // rather than failing argument validation.
- assert!(run_ingest(&[
- "ns".to_string(),
- "--content".to_string(),
- "seed".to_string()
- ])
- .is_ok());
-
- // Whatever the outcome (Ok, or a downstream provider/network error),
- // it must not be the local-AI precondition error.
- if let Err(e) = run_summarize(&["ns".to_string()]) {
- assert!(
- !e.to_string().contains("requires local_ai to be enabled"),
- "run should no longer block on the local_ai precondition: {e:#}"
- );
- }
- if let Err(e) = run_rebuild(&["ns".to_string()]) {
- assert!(
- !e.to_string().contains("requires local_ai to be enabled"),
- "rebuild should no longer block on the local_ai precondition: {e:#}"
- );
- }
-}
diff --git a/src/openhuman/memory/tree/tree_runtime/mod.rs b/src/openhuman/memory/tree/tree_runtime/mod.rs
index 64dae19992..5b3891dd1c 100644
--- a/src/openhuman/memory/tree/tree_runtime/mod.rs
+++ b/src/openhuman/memory/tree/tree_runtime/mod.rs
@@ -42,9 +42,6 @@ pub use crate::openhuman::memory::api::tree::{
pub mod ops;
pub mod schemas;
-/// The driver the handler and CLI tests bind, now that both resolve one.
-#[cfg(test)]
-pub(crate) mod test_support;
pub use ops as rpc;
diff --git a/src/openhuman/memory/tree/tree_runtime/ops_tests.rs b/src/openhuman/memory/tree/tree_runtime/ops_tests.rs
index e127f4a721..4be650db29 100644
--- a/src/openhuman/memory/tree/tree_runtime/ops_tests.rs
+++ b/src/openhuman/memory/tree/tree_runtime/ops_tests.rs
@@ -12,7 +12,6 @@ use crate::openhuman::memory::api::tree::{derive_parent_id, level_from_node_id,
// The handlers under test resolve a `MemoryProvider` now, so these tests bind
// one. See `tree_runtime::test_support` for what it is and why it is backed by
// the real engine store rather than a fake.
-use crate::openhuman::memory::tree::tree_runtime::test_support::{bind_tree_driver, engine_store};
fn rfc3339_z(ts: DateTime<Utc>) -> String {
ts.to_rfc3339_opts(chrono::SecondsFormat::Secs, true)
@@ -88,188 +87,3 @@ fn create_provider_uses_cloud_when_opted_in_and_local_ai_off() {
);
}
-#[tokio::test]
-async fn tree_summarizer_ingest_rejects_blank_content() {
- let (_tmp, cfg) = config_in_tempdir();
- bind_tree_driver(&cfg);
- let err = tree_summarizer_ingest(&cfg, "team", " ", None, None)
- .await
- .expect_err("blank content should be rejected");
- assert!(err.contains("content must not be empty"));
-}
-
-#[tokio::test]
-async fn tree_summarizer_ingest_writes_buffer_and_reports_metadata() {
- let (_tmp, cfg) = config_in_tempdir();
- let ts = chrono::Utc
- .with_ymd_and_hms(2026, 5, 24, 12, 30, 0)
- .unwrap();
- let meta = json!({"source": "unit-test"});
- bind_tree_driver(&cfg);
- let outcome =
- tree_summarizer_ingest(&cfg, "Team / Notes", "hello world", Some(ts), Some(&meta))
- .await
- .expect("ingest should succeed");
-
- assert_eq!(
- outcome.logs,
- vec!["content buffered for namespace 'Team / Notes'".to_string()]
- );
- assert_eq!(outcome.value["buffered"], true);
- assert_eq!(outcome.value["namespace"], "Team / Notes");
- assert_eq!(
- outcome.value["tokens"],
- json!(estimate_tokens("hello world"))
- );
- assert_eq!(outcome.value["has_metadata"], true);
-
- let path = outcome.value["path"]
- .as_str()
- .expect("path string in response");
- let written = std::fs::read_to_string(path).expect("buffer file should exist");
- assert!(written.contains("hello world"));
- assert!(written.contains("\"source\":\"unit-test\""));
-}
-
-#[tokio::test]
-async fn tree_summarizer_status_reports_empty_tree_defaults() {
- let (_tmp, cfg) = config_in_tempdir();
- bind_tree_driver(&cfg);
- let outcome = tree_summarizer_status(&cfg, "fresh-ns")
- .await
- .expect("status on fresh namespace");
- assert_eq!(
- outcome.logs,
- vec!["tree status for namespace 'fresh-ns'".to_string()]
- );
- assert_eq!(outcome.value["namespace"], "fresh-ns");
- assert_eq!(outcome.value["total_nodes"], 0);
- assert_eq!(outcome.value["depth"], 0);
-}
-
-#[tokio::test]
-async fn tree_summarizer_query_errors_when_node_is_missing() {
- let (_tmp, cfg) = config_in_tempdir();
- bind_tree_driver(&cfg);
- let err = tree_summarizer_query(&cfg, "fresh-ns", Some("root"))
- .await
- .expect_err("missing node should error");
- assert!(err.contains("node 'root' not found in namespace 'fresh-ns'"));
-}
-
-#[tokio::test]
-async fn tree_summarizer_query_returns_node_and_children() {
- let (_tmp, cfg) = config_in_tempdir();
- let ts = chrono::Utc
- .with_ymd_and_hms(2026, 5, 24, 12, 30, 0)
- .unwrap();
- let root = test_node("team", "root", "root summary", ts, 1);
- let year = test_node("team", "2026", "year summary", ts, 1);
- engine_store::write_node(&cfg, &root).expect("write root");
- engine_store::write_node(&cfg, &year).expect("write year");
- bind_tree_driver(&cfg);
-
- let outcome = tree_summarizer_query(&cfg, "team", None)
- .await
- .expect("query should succeed");
-
- assert_eq!(
- outcome.logs,
- vec!["queried node 'root' in namespace 'team'"]
- );
- assert_eq!(outcome.value["node"]["node_id"], "root");
- assert_eq!(outcome.value["node"]["summary"], "root summary");
- assert_eq!(
- outcome.value["children"],
- json!([{
- "node_id": "2026",
- "namespace": "team",
- "level": "year",
- "parent_id": "root",
- "summary": "year summary",
- "token_count": estimate_tokens("year summary"),
- "child_count": 1,
- "created_at": rfc3339_z(ts),
- "updated_at": rfc3339_z(ts)
- }])
- );
-}
-
-#[tokio::test]
-async fn tree_summarizer_status_reports_populated_tree_details() {
- let (_tmp, cfg) = config_in_tempdir();
- let early = chrono::Utc.with_ymd_and_hms(2026, 5, 24, 8, 0, 0).unwrap();
- let late = chrono::Utc.with_ymd_and_hms(2026, 5, 24, 17, 0, 0).unwrap();
- for node in [
- test_node("team", "root", "root summary", early, 1),
- test_node("team", "2026", "year summary", early, 1),
- test_node("team", "2026/05", "month summary", early, 1),
- test_node("team", "2026/05/24", "day summary", early, 2),
- test_node("team", "2026/05/24/08", "hour one", early, 0),
- test_node("team", "2026/05/24/17", "hour two", late, 0),
- ] {
- engine_store::write_node(&cfg, &node).expect("write test node");
- }
- bind_tree_driver(&cfg);
-
- let outcome = tree_summarizer_status(&cfg, "team")
- .await
- .expect("status should succeed");
-
- assert_eq!(outcome.logs, vec!["tree status for namespace 'team'"]);
- assert_eq!(outcome.value["namespace"], "team");
- assert_eq!(outcome.value["total_nodes"], 6);
- assert_eq!(outcome.value["depth"], 5);
- assert_eq!(outcome.value["oldest_entry"], rfc3339_z(early));
- assert_eq!(outcome.value["newest_entry"], rfc3339_z(late));
- assert_eq!(outcome.value["last_run_at"], Value::Null);
-}
-
-#[tokio::test]
-async fn tree_summarizer_run_skips_when_buffer_is_empty() {
- let (_tmp, mut cfg) = config_in_tempdir();
- cfg.local_ai.runtime_enabled = true;
- bind_tree_driver(&cfg);
-
- let outcome = tree_summarizer_run(&cfg, "team")
- .await
- .expect("empty buffer should skip");
-
- assert_eq!(
- outcome.logs,
- vec!["summarization skipped for 'team': no buffered data"]
- );
- assert_eq!(
- outcome.value,
- json!({ "skipped": true, "reason": "no buffered data" })
- );
- assert!(
- !engine_store::buffer_dir(&cfg, "team").exists(),
- "skip path should not create a buffer directory"
- );
-}
-
-#[tokio::test]
-async fn tree_summarizer_run_skips_cleanly_with_cloud_fallback_and_empty_buffer() {
- // #002 FR-007 (Gray review updated): with local AI off AND explicit cloud
- // opt-in, run/rebuild do not hard-error on the provider precondition.
- // With an empty buffer, `run` reports the normal "no buffered data" skip.
- let (_tmp, mut cfg) = config_in_tempdir();
- cfg.local_ai.runtime_enabled = false;
- cfg.memory_tree.cloud_summarization_opt_in = true;
- bind_tree_driver(&cfg);
-
- let outcome = tree_summarizer_run(&cfg, "team")
- .await
- .expect("run should not error on the provider precondition when opted in");
- assert_eq!(
- outcome.value,
- json!({ "skipped": true, "reason": "no buffered data" })
- );
-
- // Rebuild on an empty tree returns the (zero-node) status, not an error.
- let rebuilt = tree_summarizer_rebuild(&cfg, "team")
- .await
- .expect("rebuild should not error on the provider precondition when opted in");
- assert_eq!(rebuilt.value["total_nodes"], 0);
-}
diff --git a/src/openhuman/memory/tree/tree_runtime/test_support/mod.rs b/src/openhuman/memory/tree/tree_runtime/test_support/mod.rs
deleted file mode 100644
index 1d3aeec1fb..0000000000
--- a/src/openhuman/memory/tree/tree_runtime/test_support/mod.rs
+++ /dev/null
@@ -1,306 +0,0 @@
-//! A driver for the tests of this module's RPC handlers and CLI.
-//!
-//! # Why a driver has to exist here at all (#5560)
-//!
-//! The five `tree_summarizer_*` handlers used to call
-//! `tree_runtime::{engine, store}` and run the markdown time tree in this
-//! process, so a test could write nodes and call a handler with nothing in
-//! between. They go through the contract's six runtime-tree doors now, which
-//! means they resolve a `MemoryProvider` first — and in a unit test with no
-//! binding installed, `memory::binding` tries to load the compiled TinyMemory
-//! module, which in a test process can *block* rather than fail.
-//! [`bind_tree_driver`] is what stops that, and [`EngineBackedTree`] is what it
-//! installs.
-//!
-//! # Why it is backed by the real engine store rather than a fake
-//!
-//! What these tests assert is end to end: that an ingest leaves a buffer file
-//! on disk carrying the content and its metadata, that a written node comes
-//! back with its children, that six nodes read as depth five. Against a
-//! hand-rolled fake every one of those becomes an assertion about the fake.
-//!
-//! The calls below are the ones the real `tinycortex` driver makes for each
-//! door — same validators, same order, same error classes — so this double
-//! differs from production in exactly one way: *where* the engine runs. Here it
-//! is this process; in production it is the loaded module's.
-//!
-//! Naming `tinymemory_core::` from a `test_support/` path is deliberate and is
-//! the route the three sibling globs took when they were deleted:
-//! `memory::direct_engine_refs` skips these paths, and the crate is served to
-//! them by the `[dev-dependencies]` entry.
-
-use std::sync::Arc;
-
-use async_trait::async_trait;
-use chrono::{DateTime, Utc};
-use serde_json::Value;
-
-use crate::openhuman::config::Config;
-use crate::openhuman::memory::api::capabilities::{Capabilities, Capability};
-use crate::openhuman::memory::api::chunks::Chunk;
-use crate::openhuman::memory::api::error::MemoryError;
-use crate::openhuman::memory::api::health::MemoryHealth;
-use crate::openhuman::memory::api::provider::types::{
- ExportPage, ExportRecord, ImportOutcome, SourceScope,
-};
-use crate::openhuman::memory::api::provider::{
- MemoryCore, MemoryPortability, MemoryProvider, MemoryRecall, MemoryTree,
-};
-use crate::openhuman::memory::api::recall::OwnedRecallOpts;
-use crate::openhuman::memory::api::tree::{IngestRequest, QueryResult, TreeNode, TreeStatus};
-use crate::openhuman::memory::api::types::{
- MemoryCategory, MemoryEntry, MemoryTaint, NamespaceSummary,
-};
-
-/// The engine's runtime-tree store, for assertions that have to look at what
-/// was actually written rather than at what a double said it wrote.
-pub(crate) use tinymemory_core::tree::tree_runtime::store as engine_store;
-
-/// A driver serving the six runtime-tree doors from the in-process engine.
-pub(crate) struct EngineBackedTree {
- inner: tinymemory_api::null::NullMemoryProvider,
- config: Config,
-}
-
-impl EngineBackedTree {
- pub(crate) fn new(config: Config) -> Self {
- Self {
- inner: tinymemory_api::null::NullMemoryProvider::new(),
- config,
- }
- }
-
- /// An engine failure in the contract's error type.
- ///
- /// Validation refusals go out as [`MemoryError::Invalid`] at the call sites
- /// below rather than through here, matching the driver — that is the
- /// variant `ops::driver_error` unwraps to reproduce the handlers'
- /// historical error strings, so getting the class wrong would show up as a
- /// changed message rather than a failed call.
- fn engine_error(context: &str, error: impl std::fmt::Display) -> MemoryError {
- MemoryError::Other(anyhow::anyhow!("{context}: {error}"))
- }
-}
-
-#[async_trait]
-impl MemoryCore for EngineBackedTree {
- async fn store(
- &self,
- namespace: &str,
- key: &str,
- content: &str,
- category: MemoryCategory,
- session_id: Option<&str>,
- taint: MemoryTaint,
- ) -> Result<(), MemoryError> {
- self.inner
- .store(namespace, key, content, category, session_id, taint)
- .await
- }
- async fn get(&self, namespace: &str, key: &str) -> Result<Option<MemoryEntry>, MemoryError> {
- self.inner.get(namespace, key).await
- }
- async fn forget(&self, namespace: &str, key: &str) -> Result<bool, MemoryError> {
- self.inner.forget(namespace, key).await
- }
- async fn list(
- &self,
- namespace: Option<&str>,
- category: Option<&MemoryCategory>,
- session_id: Option<&str>,
- ) -> Result<Vec<MemoryEntry>, MemoryError> {
- self.inner.list(namespace, category, session_id).await
- }
- async fn namespaces(&self) -> Result<Vec<NamespaceSummary>, MemoryError> {
- self.inner.namespaces().await
- }
-}
-
-#[async_trait]
-impl MemoryRecall for EngineBackedTree {
- async fn recall(
- &self,
- query: &str,
- limit: usize,
- opts: &OwnedRecallOpts,
- scope: Option<&SourceScope>,
- ) -> Result<Vec<MemoryEntry>, MemoryError> {
- self.inner.recall(query, limit, opts, scope).await
- }
-}
-
-#[async_trait]
-impl MemoryPortability for EngineBackedTree {
- async fn export_page(
- &self,
- cursor: Option<&str>,
- limit: usize,
- ) -> Result<ExportPage, MemoryError> {
- self.inner.export_page(cursor, limit).await
- }
- async fn import_records(
- &self,
- records: Vec<ExportRecord>,
- ) -> Result<ImportOutcome, MemoryError> {
- self.inner.import_records(records).await
- }
-}
-
-#[async_trait]
-impl MemoryTree for EngineBackedTree {
- // The family's five **required** members. Nothing under test reaches them,
- // and answering `Unsupported` rather than delegating to null is the honest
- // shape: this double serves the runtime-tree doors and nothing else, so a
- // future test that wandered onto `seal` would get a refusal it can read
- // instead of a silent empty answer it would have to debug.
- async fn append(&self, _request: IngestRequest) -> Result<(), MemoryError> {
- Err(MemoryError::unsupported(Capability::Tree))
- }
- async fn query_source(
- &self,
- _namespace: &str,
- _source_id: &str,
- _limit: usize,
- _scope: Option<&SourceScope>,
- ) -> Result<Vec<Chunk>, MemoryError> {
- Err(MemoryError::unsupported(Capability::Tree))
- }
- async fn drill_down(
- &self,
- _namespace: &str,
- _node_id: &str,
- ) -> Result<QueryResult, MemoryError> {
- Err(MemoryError::unsupported(Capability::Tree))
- }
- async fn seal(&self, _namespace: &str) -> Result<TreeStatus, MemoryError> {
- Err(MemoryError::unsupported(Capability::Tree))
- }
- async fn cascade(&self, _namespace: &str) -> Result<TreeStatus, MemoryError> {
- Err(MemoryError::unsupported(Capability::Tree))
- }
-
- async fn runtime_buffer_write(
- &self,
- namespace: &str,
- content: &str,
- timestamp: DateTime<Utc>,
- metadata: Option<Value>,
- ) -> Result<String, MemoryError> {
- engine_store::validate_namespace(namespace).map_err(MemoryError::Invalid)?;
- if content.trim().is_empty() {
- return Err(MemoryError::Invalid(
- "content must not be empty".to_string(),
- ));
- }
- let path = engine_store::buffer_write(
- &self.config,
- namespace.trim(),
- content,
- &timestamp,
- metadata.as_ref(),
- )
- .map_err(|error| Self::engine_error("buffer tree content", error))?;
- Ok(path.display().to_string())
- }
-
- async fn runtime_read_node(
- &self,
- namespace: &str,
- node_id: &str,
- ) -> Result<Option<TreeNode>, MemoryError> {
- engine_store::validate_namespace(namespace).map_err(MemoryError::Invalid)?;
- engine_store::validate_node_id(node_id).map_err(MemoryError::Invalid)?;
- engine_store::read_node(&self.config, namespace.trim(), node_id)
- .map_err(|error| Self::engine_error("read tree node", error))
- }
-
- async fn runtime_read_children(
- &self,
- namespace: &str,
- parent_id: &str,
- ) -> Result<Vec<TreeNode>, MemoryError> {
- engine_store::validate_namespace(namespace).map_err(MemoryError::Invalid)?;
- engine_store::validate_node_id(parent_id).map_err(MemoryError::Invalid)?;
- engine_store::read_children(&self.config, namespace.trim(), parent_id)
- .map_err(|error| Self::engine_error("read tree children", error))
- }
-
- async fn runtime_tree_status(&self, namespace: &str) -> Result<TreeStatus, MemoryError> {
- engine_store::validate_namespace(namespace).map_err(MemoryError::Invalid)?;
- engine_store::get_tree_status(&self.config, namespace.trim())
- .map_err(|error| Self::engine_error("read tree status", error))
- }
-
- /// The summariser is resolved through `ops::create_provider` — the resolver
- /// the handler used before the migration — so the tests written around the
- /// local-AI / cloud-opt-in ladder keep asserting against it.
- ///
- /// The real driver resolves through `chat_host::create_chat_model_with_model_id`
- /// instead, which is the one behavioural difference between this double and
- /// production and is documented at `ops::create_provider`.
- async fn runtime_summarize(
- &self,
- namespace: &str,
- timestamp: DateTime<Utc>,
- ) -> Result<Option<TreeNode>, MemoryError> {
- engine_store::validate_namespace(namespace).map_err(MemoryError::Invalid)?;
- let (provider, _model) = super::ops::create_provider(&self.config)
- .map_err(|error| Self::engine_error("create summarizer", error))?;
- tinymemory_core::tree::tree_runtime::engine::run_summarization(
- &self.config,
- provider.as_ref(),
- namespace.trim(),
- timestamp,
- )
- .await
- .map_err(|error| Self::engine_error("run tree summarization", format!("{error:#}")))
- }
-
- async fn runtime_rebuild(&self, namespace: &str) -> Result<TreeStatus, MemoryError> {
- engine_store::validate_namespace(namespace).map_err(MemoryError::Invalid)?;
- let (provider, _model) = super::ops::create_provider(&self.config)
- .map_err(|error| Self::engine_error("create summarizer", error))?;
- tinymemory_core::tree::tree_runtime::engine::rebuild_tree(
- &self.config,
- provider.as_ref(),
- namespace.trim(),
- )
- .await
- .map_err(|error| Self::engine_error("rebuild tree", format!("{error:#}")))
- }
-}
-
-#[async_trait]
-impl MemoryProvider for EngineBackedTree {
- fn driver_id(&self) -> &str {
- "engine-backed-tree"
- }
- fn capabilities(&self) -> Capabilities {
- Capabilities::all()
- }
- async fn health(&self) -> MemoryHealth {
- MemoryHealth::Ready
- }
- fn as_tree(&self) -> Option<&dyn MemoryTree> {
- Some(self)
- }
-}
-
-/// Bind [`EngineBackedTree`] as `cfg`'s workspace driver.
-///
-/// Call this **after** a test has finished shaping its `Config`: the double
-/// captures the config it was built with, and several tests flip
-/// `local_ai.runtime_enabled` or the cloud opt-in after constructing one.
-/// Binding before that would hand the test a driver resolving its summariser
-/// from the config it was about to change.
-///
-/// The binding cache is keyed by workspace + subtree + `[subsystems.memory]`,
-/// so a handler's own `binding::for_config` finds exactly what this installed
-/// as long as the `[subsystems.memory]` block is untouched.
-pub(crate) fn bind_tree_driver(cfg: &Config) {
- crate::openhuman::memory::binding::install_for_test(
- &cfg.workspace_dir,
- &cfg.subsystems.memory,
- Arc::new(EngineBackedTree::new(cfg.clone())) as Arc<dyn MemoryProvider>,
- );
-}
diff --git a/src/openhuman/memory/tree_e2e_tests.rs b/src/openhuman/memory/tree_e2e_tests.rs
deleted file mode 100644
index 4550ba03d1..0000000000
--- a/src/openhuman/memory/tree_e2e_tests.rs
+++ /dev/null
@@ -1,329 +0,0 @@
-//! End-to-end integration test for the full memory tree pipeline.
-//!
-//! Exercises all three tree kinds (source, global, topic) in a single
-//! scenario: ingest chat messages mentioning a hot entity → source tree
-//! seals → global digest runs → topic tree spawns → all three retrieval
-//! tools return results.
-//!
-//! Lives inside the crate (not under `tests/`) because it uses
-//! `Config::default()`, `test_override`, and other private internals that
-//! are not part of the public API.
-
-#![cfg(test)]
-
-use std::sync::Arc;
-
-use chrono::{TimeZone, Utc};
-use tempfile::TempDir;
-
-use crate::openhuman::config::Config;
-// Named on the engine crate directly: `memory::tree::retrieval` stopped
-// re-exporting the engine in #5560 because no production caller was left. A
-// test may still reach the engine — that is what keeps this a test-only
-// reference rather than a shipped one.
-use tinycortex::memory::ingest::canonicalize::chat::{ChatBatch, ChatMessage};
-use tinymemory_core::chat::{test_override, ChatProvider, StaticChatProvider};
-use tinymemory_core::ingest_pipeline::ingest_chat;
-use tinymemory_core::queue::drain_until_idle;
-use tinymemory_core::tree::retrieval::{query_source, search_entities};
-use tinymemory_core::tree::score::embed::build_embedder_from_config;
-
-fn test_config() -> (TempDir, Config) {
- let tmp = TempDir::new().unwrap();
- let mut cfg = Config::default();
- cfg.workspace_dir = tmp.path().to_path_buf();
- cfg.memory_tree.embedding_endpoint = None;
- cfg.memory_tree.embedding_model = None;
- cfg.memory_tree.embedding_strict = false;
- (tmp, cfg)
-}
-
-/// Build a batch of messages heavy enough to push a source tree's L0 buffer
-/// across the 50k-token seal threshold. Each message mentions
-/// `[email protected]` prominently so the entity index accumulates signal.
-///
-/// The chunker packs messages greedily (up to ~10k tokens per chunk). We
-/// produce 20 messages, each long enough to yield ~3k tokens, so five or
-/// six chunks are emitted and the token budget is crossed.
-fn heavy_batch(platform: &str, channel: &str, seq_offset: u32) -> ChatBatch {
- let long_body = "[email protected] is coordinating the Phoenix migration rollout. \
- The runbook has been reviewed end-to-end and staging results look clean. \
- All dependencies are resolved. The deploy window is Friday 22:00 UTC. \
- Cross-team sign-off from infra, security, and data engineering is complete. \
- [email protected] will be on-call for the first 48 hours post-launch. \
- This message is intentionally verbose to generate enough tokens for the \
- source tree seal threshold to fire during the integration test. "
- .repeat(8);
-
- let messages: Vec<ChatMessage> = (0..20)
- .map(|i| ChatMessage {
- author: if i % 2 == 0 { "alice" } else { "bob" }.into(),
- timestamp: Utc
- .timestamp_millis_opt(1_700_000_000_000 + ((seq_offset + i) as i64) * 10_000)
- .unwrap(),
- text: format!("msg {}: {}", seq_offset + i, long_body),
- source_ref: Some(format!("{platform}://{channel}/{}", seq_offset + i)),
- })
- .collect();
-
- ChatBatch {
- platform: platform.into(),
- channel_label: channel.into(),
- messages,
- }
-}
-
-/// Full pipeline: ingest → seal → source retrieval → entity search.
-///
-/// Steps:
-/// 1. Ingest heavy batches from two distinct sources so the source trees'
-/// L0 buffers cross the token-budget seal threshold.
-/// 2. Drain the async job queue so extract / admit / buffer / seal jobs run.
-/// 3. Verify source-tree retrieval returns sealed summaries.
-/// 4. Verify `search_entities("alice")` resolves to alice's canonical id.
-///
-/// (The global-digest and topic-spawn steps were removed with those trees.)
-#[tokio::test]
-async fn full_pipeline_ingest_to_retrieval() {
- let (_tmp, cfg) = test_config();
-
- // The static provider returns a plausible summary JSON so the LLM-backed
- // steps (extraction, sealing, digest, backfill) all succeed without
- // hitting a real model endpoint.
- let provider: Arc<dyn ChatProvider> = Arc::new(StaticChatProvider::new(
- r#"{"summary":"[email protected] is coordinating the Phoenix migration.","entities":["email:[email protected]"],"topics":["phoenix","migration"]}"#,
- ));
-
- test_override::with_provider(Arc::clone(&provider), async {
- // ── Step 1: ingest two source streams ────────────────────────────
-
- let slack_source = "slack:#eng";
- let gmail_source = "gmail:alice";
-
- let slack_result = ingest_chat(
- &cfg,
- slack_source,
- "alice",
- vec!["eng".into()],
- heavy_batch("slack", "#eng", 0),
- )
- .await
- .expect("ingest_chat for slack source must succeed");
-
- log::debug!(
- "[tree_e2e_test] slack ingest: chunks_written={} dropped={}",
- slack_result.chunks_written,
- slack_result.chunks_dropped
- );
- assert!(
- slack_result.chunks_written >= 1,
- "slack ingest must write at least one chunk"
- );
-
- let gmail_result = ingest_chat(
- &cfg,
- gmail_source,
- "alice",
- vec!["alice".into()],
- heavy_batch("gmail", "alice", 100),
- )
- .await
- .expect("ingest_chat for gmail source must succeed");
-
- log::debug!(
- "[tree_e2e_test] gmail ingest: chunks_written={} dropped={}",
- gmail_result.chunks_written,
- gmail_result.chunks_dropped
- );
- assert!(
- gmail_result.chunks_written >= 1,
- "gmail ingest must write at least one chunk"
- );
-
- // ── Step 2: drain the async job queue ────────────────────────────
- // This runs extract_chunk → admission → append_buffer → seal jobs.
- drain_until_idle(&cfg)
- .await
- .expect("drain_until_idle must succeed");
-
- log::debug!("[tree_e2e_test] job queue drained");
-
- // ── Step 3: verify source-tree retrieval ─────────────────────────
- // query_source returns summaries from sealed source trees. With
- // enough chunks the seal fires and we expect at least one hit.
- // Both sources are Chat kind.
- use tinymemory_api::chunks::SourceKind;
- let source_resp = query_source(&cfg, None, Some(SourceKind::Chat), None, None, 20)
- .await
- .expect("query_source on Chat kind must succeed");
-
- log::debug!(
- "[tree_e2e_test] query_source: total={} hits={}",
- source_resp.total,
- source_resp.hits.len()
- );
-
- // The response must be well-formed regardless of whether a seal
- // fired (very short batches might not cross the budget in CI).
- assert!(
- source_resp.total >= source_resp.hits.len(),
- "query_source total must be >= hits.len()"
- );
-
- // ── Step 4: search_entities cross-check ──────────────────────────
- let entity_matches = search_entities(&cfg, "alice", None, 10)
- .await
- .expect("search_entities must succeed");
-
- log::debug!(
- "[tree_e2e_test] search_entities('alice'): {} matches",
- entity_matches.len()
- );
-
- let alice_match = entity_matches
- .iter()
- .find(|m| m.canonical_id == "email:[email protected]");
-
- assert!(
- alice_match.is_some(),
- "search_entities('alice') must resolve to 'email:[email protected]' \
- after ingesting messages that mention that address. \
- Got: {entity_matches:?}"
- );
-
- let alice_match = alice_match.unwrap();
- assert!(
- alice_match.mention_count >= 1,
- "alice's mention_count must be at least 1"
- );
-
- log::info!(
- "[tree_e2e_test] full_pipeline_ingest_to_retrieval PASSED \
- source_hits={} entity_matches={}",
- source_resp.hits.len(),
- entity_matches.len()
- );
- })
- .await;
-}
-
-/// When `embeddings_provider = "none"`, the full ingest → retrieval pipeline
-/// must still work end-to-end. Semantic rerank degrades to recency ordering
-/// (InertEmbedder produces zero vectors → cosine similarity = 0), but chunks
-/// are still written with valid zero-vector embeddings, and source-tree
-/// retrieval succeeds via the recency fallback path.
-///
-/// This guards against regressions where disabling embeddings causes panics,
-/// schema mismatches, or silent data loss in the memory subsystem.
-#[tokio::test]
-async fn pipeline_works_with_embeddings_disabled() {
- let (_tmp, mut cfg) = test_config();
- cfg.embeddings_provider = Some("none".into());
-
- // Verify the factory returns InertEmbedder for this config.
- let embedder = build_embedder_from_config(&cfg).expect("factory must succeed for 'none'");
- assert_eq!(
- embedder.name(),
- "inert",
- "embeddings_provider=none must route to InertEmbedder"
- );
-
- let provider: Arc<dyn ChatProvider> = Arc::new(StaticChatProvider::new(
- r#"{"summary":"[email protected] discussed the quarterly review.","entities":["email:[email protected]"],"topics":["quarterly","review"]}"#,
- ));
-
- test_override::with_provider(Arc::clone(&provider), async {
- // ── Ingest a heavy batch to cross the seal threshold ────────────
- let source_id = "slack:#disabled-embed-test";
- let result = ingest_chat(
- &cfg,
- source_id,
- "bob",
- vec!["test".into()],
- heavy_batch("slack", "#disabled-embed-test", 0),
- )
- .await
- .expect("ingest_chat must succeed with embeddings disabled");
-
- assert!(
- result.chunks_written >= 1,
- "ingest must write at least one chunk even with embeddings disabled"
- );
-
- log::debug!(
- "[tree_e2e_test::embeddings_disabled] ingest: chunks_written={} dropped={}",
- result.chunks_written,
- result.chunks_dropped
- );
-
- // ── Drain the async job queue ───────────────────────────────────
- drain_until_idle(&cfg)
- .await
- .expect("drain_until_idle must succeed with embeddings disabled");
-
- // ── Source-tree retrieval without a query (recency only) ─────────
- use tinymemory_api::chunks::SourceKind;
- let recency_resp = query_source(&cfg, None, Some(SourceKind::Chat), None, None, 20)
- .await
- .expect("query_source (recency) must succeed with embeddings disabled");
-
- log::debug!(
- "[tree_e2e_test::embeddings_disabled] query_source (recency): total={} hits={}",
- recency_resp.total,
- recency_resp.hits.len()
- );
-
- assert!(
- recency_resp.total >= recency_resp.hits.len(),
- "query_source total must be >= hits.len()"
- );
-
- // ── Source-tree retrieval WITH a query (semantic rerank path) ────
- // This exercises the codepath where build_embedder_from_config is
- // called internally. With InertEmbedder, the rerank degrades to
- // recency ordering but must not error.
- let semantic_resp = query_source(
- &cfg,
- None,
- Some(SourceKind::Chat),
- None,
- Some("quarterly review"),
- 20,
- )
- .await
- .expect(
- "query_source (semantic) must succeed with embeddings disabled — \
- InertEmbedder should degrade gracefully to recency ordering",
- );
-
- log::debug!(
- "[tree_e2e_test::embeddings_disabled] query_source (semantic): total={} hits={}",
- semantic_resp.total,
- semantic_resp.hits.len()
- );
-
- assert!(
- semantic_resp.total >= semantic_resp.hits.len(),
- "query_source total must be >= hits.len()"
- );
-
- // ── Entity search (keyword-based, no embeddings needed) ─────────
- let entity_matches = search_entities(&cfg, "bob", None, 10)
- .await
- .expect("search_entities must succeed with embeddings disabled");
-
- log::debug!(
- "[tree_e2e_test::embeddings_disabled] search_entities('bob'): {} matches",
- entity_matches.len()
- );
-
- log::info!(
- "[tree_e2e_test] pipeline_works_with_embeddings_disabled PASSED \
- recency_hits={} semantic_hits={} entity_matches={}",
- recency_resp.hits.len(),
- semantic_resp.hits.len(),
- entity_matches.len()
- );
- })
- .await;
-}
diff --git a/src/openhuman/security/credentials/ops_tests.rs b/src/openhuman/security/credentials/ops_tests.rs
index 6a2743b222..ca788d69d3 100644
--- a/src/openhuman/security/credentials/ops_tests.rs
+++ b/src/openhuman/security/credentials/ops_tests.rs
@@ -65,17 +65,6 @@ fn jwt_with_payload(payload: serde_json::Value) -> String {
format!("eyJhbGciOiJIUzI1NiJ9.{payload}.sig")
}
-fn count_reembed_backfill_jobs(config: &Config) -> i64 {
- tinymemory_core::store::chunks::store::with_connection(config, |conn| {
- Ok(conn.query_row(
- "SELECT COUNT(*) FROM mem_tree_jobs WHERE kind = 'reembed_backfill'",
- [],
- |row| row.get(0),
- )?)
- })
- .unwrap()
-}
-
async fn spawn_auth_me_status(status: StatusCode) -> String {
let app = Router::new().route("/auth/me", get(move || async move { status }));
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
diff --git a/src/openhuman/security/credentials/ops_tests_part_01_tests.rs b/src/openhuman/security/credentials/ops_tests_part_01_tests.rs
index dd2a9ae273..0784ea3520 100644
--- a/src/openhuman/security/credentials/ops_tests_part_01_tests.rs
+++ b/src/openhuman/security/credentials/ops_tests_part_01_tests.rs
@@ -297,100 +297,6 @@ fn auth_me_store_validation_budget_reads_env_override() {
}
}
-/// Login asks the bound driver to re-embed.
-///
-/// This used to seed a chunk and count rows in `mem_tree_jobs`. The host asks
-/// the driver now, so the row is the driver's doing and belongs to the driver's
-/// suite — what is the host's, and what this pins, is that logging in asks at
-/// all. The seed stays because it is what makes the ask non-vacuous in the
-/// original scenario, and because the surrounding assertions still describe a
-/// workspace with content in it.
-#[tokio::test]
-async fn store_session_requeues_reembed_backfill_after_login() {
- use chrono::TimeZone;
- use tinymemory_api::chunks::{chunk_id, Chunk, Metadata, SourceKind, SourceRef};
- use tinymemory_core::store::chunks::store::{upsert_chunks, upsert_staged_chunks_tx};
- use tinymemory_core::store::content as content_store;
-
- let _env_guard = crate::openhuman::config::TEST_ENV_LOCK
- .lock()
- .unwrap_or_else(|e| e.into_inner());
- let tmp = TempDir::new().unwrap();
- std::fs::create_dir_all(tmp.path().join("workspace")).unwrap();
- let _home = EnvVarGuard::set_to_path("HOME", tmp.path());
- let mut config = test_config(&tmp);
- config.api_url = Some(spawn_auth_me_status(StatusCode::SERVICE_UNAVAILABLE).await);
- // Without a driver installed, resolving one means loading the compiled
- // module, which a unit test cannot do — so every ask would answer empty and
- // this test would pass against nothing.
- let driver = crate::openhuman::memory::binding::install_diagnostics_for_test(
- &config.workspace_dir,
- &config.subsystems.memory,
- Default::default(),
- Default::default(),
- );
-
- let ts = chrono::Utc.timestamp_millis_opt(1_700_000_000_000).unwrap();
- let chunk = Chunk {
- id: chunk_id(SourceKind::Chat, "slack:#eng", 0, "login-reembed-seed"),
- content: "memory content that needs embedding after the user logs in".into(),
- metadata: Metadata {
- source_kind: SourceKind::Chat,
- source_id: "slack:#eng".into(),
- owner: "alice".into(),
- timestamp: ts,
- time_range: (ts, ts),
- tags: vec![],
- source_ref: Some(SourceRef::new("slack://x")),
- path_scope: None,
- },
- token_count: 12,
- seq_in_source: 0,
- created_at: ts,
- partial_message: false,
- };
- upsert_chunks(&config, &[chunk.clone()]).unwrap();
- let content_root = config.memory_tree_content_root();
- std::fs::create_dir_all(&content_root).unwrap();
- let staged = content_store::stage_chunks(&content_root, &[chunk]).unwrap();
- tinymemory_core::store::chunks::store::with_connection(&config, |conn| {
- let tx = conn.unchecked_transaction()?;
- upsert_staged_chunks_tx(&tx, &staged)?;
- tx.commit()?;
- Ok(())
- })
- .unwrap();
-
- assert_eq!(
- driver.reembed_calls(),
- 0,
- "precondition: nothing has asked the driver to re-embed before login"
- );
-
- let token = jwt_with_payload(json!({
- "sub": "unverified-jwt-user",
- "email": "[email protected]",
- "name": "Unverified JWT User",
- "exp": (chrono::Utc::now() + chrono::Duration::hours(1)).timestamp()
- }));
-
- let result = store_session_with_deferred_validation(&config, &token, None, Some(json!({})))
- .await
- .unwrap();
-
- let log_text = result.logs.join(" ");
- assert!(
- log_text.contains("memory re-embed backfill checked after login"),
- "store_session should report the post-login backfill probe, got: {log_text}"
- );
- assert_eq!(
- driver.reembed_calls(),
- 1,
- "login must ask the driver to re-embed exactly once — twice would enqueue \
- a second chain over the same uncovered rows"
- );
-}
-
#[tokio::test]
async fn deferred_session_without_user_id_does_not_replace_active_user_profile() {
let _env_guard = crate::openhuman::config::TEST_ENV_LOCK
diff --git a/src/openhuman/tools/impl/system/tool_stats_tests.rs b/src/openhuman/tools/impl/system/tool_stats_tests.rs
index d9d8201e9a..c5d5e4a6ed 100644
--- a/src/openhuman/tools/impl/system/tool_stats_tests.rs
+++ b/src/openhuman/tools/impl/system/tool_stats_tests.rs
@@ -5,7 +5,7 @@
use super::*;
use crate::openhuman::agent::learning::tool_tracker::ToolStats;
-use crate::openhuman::memory::ops::{ensure_shared_memory_client, GLOBAL_MEMORY_TEST_LOCK};
+use crate::openhuman::memory::ops::{shared_memory_test_workspace, GLOBAL_MEMORY_TEST_LOCK};
use serde_json::json;
fn make_tool() -> ToolStatsTool {
@@ -49,7 +49,7 @@ fn schema_is_object_type() {
the tool resolves the bound driver rather than being handed a memory handle"]
async fn returns_stats_for_a_recorded_tool() {
let _serial = GLOBAL_MEMORY_TEST_LOCK.lock().await;
- ensure_shared_memory_client();
+ shared_memory_test_workspace();
record(
"tool/shell",
@@ -75,7 +75,7 @@ async fn returns_stats_for_a_recorded_tool() {
the tool resolves the bound driver rather than being handed a memory handle"]
async fn filter_by_tool_name_reports_no_data_for_an_unrecorded_tool() {
let _serial = GLOBAL_MEMORY_TEST_LOCK.lock().await;
- ensure_shared_memory_client();
+ shared_memory_test_workspace();
record(
"tool/shell",
diff --git a/src/openhuman/tools/ops_tests_part_01_tests.rs b/src/openhuman/tools/ops_tests_part_01_tests.rs
index a60884a33b..a54ed8dba0 100644
--- a/src/openhuman/tools/ops_tests_part_01_tests.rs
+++ b/src/openhuman/tools/ops_tests_part_01_tests.rs
@@ -16,7 +16,6 @@ fn all_tools_includes_spawn_subagent() {
let tmp = TempDir::new().unwrap();
let security = Arc::new(SecurityPolicy::default());
// The embedding seam fails loudly when unwired.
- crate::openhuman::memory::host_impls::install_for_tests();
let _mem_cfg = MemoryConfig {
backend: "markdown".into(),
..MemoryConfig::default()
@@ -95,7 +94,6 @@ fn all_tools_includes_spawn_async_subagent() {
let tmp = TempDir::new().unwrap();
let security = Arc::new(SecurityPolicy::default());
// The embedding seam fails loudly when unwired.
- crate::openhuman::memory::host_impls::install_for_tests();
let _mem_cfg = MemoryConfig {
backend: "markdown".into(),
..MemoryConfig::default()
@@ -131,7 +129,6 @@ fn all_tools_includes_spawn_parallel_agents() {
let tmp = TempDir::new().unwrap();
let security = Arc::new(SecurityPolicy::default());
// The embedding seam fails loudly when unwired.
- crate::openhuman::memory::host_impls::install_for_tests();
let _mem_cfg = MemoryConfig {
backend: "markdown".into(),
..MemoryConfig::default()
@@ -173,7 +170,6 @@ fn all_tools_always_registers_curl() {
// The embedding seam fails loudly when unwired. This
// test doesn't use that helper (it needs the `Arc<dyn Memory>` alongside
// its own config setup below), so it installs the seams directly.
- crate::openhuman::memory::host_impls::install_for_tests();
let _mem_cfg = MemoryConfig {
backend: "markdown".into(),
..MemoryConfig::default()
@@ -305,7 +301,6 @@ fn all_tools_registers_gitbooks_when_enabled() {
let tmp = TempDir::new().unwrap();
let security = Arc::new(SecurityPolicy::default());
// The embedding seam fails loudly when unwired.
- crate::openhuman::memory::host_impls::install_for_tests();
let _mem_cfg = MemoryConfig {
backend: "markdown".into(),
..MemoryConfig::default()
@@ -420,7 +415,6 @@ fn all_tools_skips_gitbooks_when_disabled() {
let tmp = TempDir::new().unwrap();
let security = Arc::new(SecurityPolicy::default());
// The embedding seam fails loudly when unwired.
- crate::openhuman::memory::host_impls::install_for_tests();
let _mem_cfg = MemoryConfig {
backend: "markdown".into(),
..MemoryConfig::default()
@@ -456,7 +450,6 @@ fn all_tools_includes_current_time() {
let tmp = TempDir::new().unwrap();
let security = Arc::new(SecurityPolicy::default());
// The embedding seam fails loudly when unwired.
- crate::openhuman::memory::host_impls::install_for_tests();
let _mem_cfg = MemoryConfig {
backend: "markdown".into(),
..MemoryConfig::default()
@@ -595,7 +588,6 @@ fn all_tools_excludes_browser_when_disabled() {
let tmp = TempDir::new().unwrap();
let security = Arc::new(SecurityPolicy::default());
// The embedding seam fails loudly when unwired.
- crate::openhuman::memory::host_impls::install_for_tests();
let _mem_cfg = MemoryConfig {
backend: "markdown".into(),
..MemoryConfig::default()
diff --git a/src/openhuman/tools/ops_tests_part_02_tests.rs b/src/openhuman/tools/ops_tests_part_02_tests.rs
index 576a308d74..b17553a54b 100644
--- a/src/openhuman/tools/ops_tests_part_02_tests.rs
+++ b/src/openhuman/tools/ops_tests_part_02_tests.rs
@@ -31,7 +31,6 @@ fn all_tools_includes_browser_when_enabled() {
let tmp = TempDir::new().unwrap();
let security = Arc::new(SecurityPolicy::default());
// The embedding seam fails loudly when unwired.
- crate::openhuman::memory::host_impls::install_for_tests();
let _mem_cfg = MemoryConfig {
backend: "markdown".into(),
..MemoryConfig::default()
@@ -152,7 +151,6 @@ fn all_tools_includes_delegate_when_agents_configured() {
let tmp = TempDir::new().unwrap();
let security = Arc::new(SecurityPolicy::default());
// The embedding seam fails loudly when unwired.
- crate::openhuman::memory::host_impls::install_for_tests();
let _mem_cfg = MemoryConfig {
backend: "markdown".into(),
..MemoryConfig::default()
@@ -192,7 +190,6 @@ fn all_tools_excludes_delegate_when_no_agents() {
let tmp = TempDir::new().unwrap();
let security = Arc::new(SecurityPolicy::default());
// The embedding seam fails loudly when unwired.
- crate::openhuman::memory::host_impls::install_for_tests();
let _mem_cfg = MemoryConfig {
backend: "markdown".into(),
..MemoryConfig::default()
@@ -226,7 +223,6 @@ fn all_tools_registers_node_exec_when_node_enabled() {
let tmp = TempDir::new().unwrap();
let security = Arc::new(SecurityPolicy::default());
// The embedding seam fails loudly when unwired.
- crate::openhuman::memory::host_impls::install_for_tests();
let _mem_cfg = MemoryConfig {
backend: "markdown".into(),
..MemoryConfig::default()
@@ -264,7 +260,6 @@ fn all_tools_registers_python_exec_when_python_enabled() {
let tmp = TempDir::new().unwrap();
let security = Arc::new(SecurityPolicy::default());
// The embedding seam fails loudly when unwired.
- crate::openhuman::memory::host_impls::install_for_tests();
let _mem_cfg = MemoryConfig {
backend: "markdown".into(),
..MemoryConfig::default()
@@ -296,7 +291,6 @@ fn all_tools_excludes_node_exec_when_node_disabled() {
let tmp = TempDir::new().unwrap();
let security = Arc::new(SecurityPolicy::default());
// The embedding seam fails loudly when unwired.
- crate::openhuman::memory::host_impls::install_for_tests();
let _mem_cfg = MemoryConfig {
backend: "markdown".into(),
..MemoryConfig::default()
diff --git a/tests/agent_harness_e2e.rs b/tests/agent_harness_e2e.rs
index 669e13114b..f410eecd76 100644
--- a/tests/agent_harness_e2e.rs
+++ b/tests/agent_harness_e2e.rs
@@ -2381,7 +2381,6 @@ mod streaming_support {
};
use tinyinference::tool::ToolCall;
use tinyinference::usage::Usage;
- use tinymemory_core::store as memory_store;
// ── ScriptedProvider ────────────────────────────────────────────────────
// Copied (minimal) from tests/agent_session_turn_raw_coverage_e2e.rs:76-152.
@@ -2477,12 +2476,76 @@ mod streaming_support {
(temp, path)
}
- fn memory_for_workspace_s(path: &Path) -> Arc<dyn Memory> {
- let cfg = MemoryConfig {
- backend: "none".to_string(),
- ..MemoryConfig::default()
- };
- Arc::from(memory_store::create_memory(&cfg, path).unwrap())
+ /// A memory that stores nothing, which is what this helper always built.
+ ///
+ /// It used to ask the engine's factory for `backend: "none"` — an engine
+ /// call whose whole purpose was to get back something that does not store.
+ /// The agent under test needs *a* memory to be constructed with; it never
+ /// reads one back. So the no-op is not a downgrade from what was here, it
+ /// is the same behaviour without linking 133k lines to obtain it.
+ #[derive(Debug)]
+ struct NoMemory;
+
+ #[async_trait::async_trait]
+ impl Memory for NoMemory {
+ fn name(&self) -> &str {
+ "none"
+ }
+ async fn store(
+ &self,
+ _namespace: &str,
+ _key: &str,
+ _content: &str,
+ _category: openhuman_core::openhuman::memory::api::types::MemoryCategory,
+ _session_id: Option<&str>,
+ ) -> anyhow::Result<()> {
+ Ok(())
+ }
+ async fn recall(
+ &self,
+ _query: &str,
+ _limit: usize,
+ _opts: openhuman_core::openhuman::memory::api::recall::RecallOpts<'_>,
+ ) -> anyhow::Result<Vec<openhuman_core::openhuman::memory::api::types::MemoryEntry>>
+ {
+ Ok(Vec::new())
+ }
+ async fn get(
+ &self,
+ _namespace: &str,
+ _key: &str,
+ ) -> anyhow::Result<Option<openhuman_core::openhuman::memory::api::types::MemoryEntry>>
+ {
+ Ok(None)
+ }
+ async fn list(
+ &self,
+ _namespace: Option<&str>,
+ _category: Option<&openhuman_core::openhuman::memory::api::types::MemoryCategory>,
+ _session_id: Option<&str>,
+ ) -> anyhow::Result<Vec<openhuman_core::openhuman::memory::api::types::MemoryEntry>>
+ {
+ Ok(Vec::new())
+ }
+ async fn forget(&self, _namespace: &str, _key: &str) -> anyhow::Result<bool> {
+ Ok(false)
+ }
+ async fn namespace_summaries(
+ &self,
+ ) -> anyhow::Result<Vec<openhuman_core::openhuman::memory::api::types::NamespaceSummary>>
+ {
+ Ok(Vec::new())
+ }
+ async fn count(&self) -> anyhow::Result<usize> {
+ Ok(0)
+ }
+ async fn health_check(&self) -> bool {
+ true
+ }
+ }
+
+ fn memory_for_workspace_s(_path: &Path) -> Arc<dyn Memory> {
+ Arc::new(NoMemory)
}
pub fn agent_with_s(
diff --git a/tests/agent_retrieval_e2e.rs b/tests/agent_retrieval_e2e.rs
deleted file mode 100644
index 4cb57d915a..0000000000
--- a/tests/agent_retrieval_e2e.rs
+++ /dev/null
@@ -1,510 +0,0 @@
-//! End-to-end coverage for the orchestrator memory-tree retrieval tool
-//! wrappers (issue #710 wiring).
-//!
-//! Goal: prove the `MemoryTree*Tool` instances actually drive the typed
-//! retrieval functions against a real ingested workspace and emit JSON the
-//! orchestrator LLM can parse + cite from.
-//!
-//! Why a tool-direct test (and not a full `agent_chat` round-trip):
-//! `agent_chat` requires a reachable provider (no provider connection
-//! available in unit-test context). The bus-level `mock_agent_run_turn`
-//! stub replaces the agent loop wholesale, so it can't observe a tool
-//! dispatch happening *inside* the loop. Calling each tool's `execute()`
-//! with the same JSON shape the LLM would emit exercises the full
-//! deserialise → typed retrieval → serialise pipeline that the orchestrator
-//! relies on, and asserts the data round-trips correctly.
-//!
-//! The orchestrator agent.toml entry registering `call_memory_agent` is
-//! covered by [`orchestrator_lists_memory_tree_tools`] — that catches a
-//! regression where the tool wrapper exists but the orchestrator can't see
-//! it.
-
-use chrono::{TimeZone, Utc};
-use openhuman_core::openhuman::config::Config;
-use openhuman_core::openhuman::memory::read_rpc::{self, ChunkFilter};
-use openhuman_core::openhuman::memory::tree::tree::canonicalize_types::IngestRequest;
-use openhuman_core::openhuman::memory::tree::tree::rpc::ingest_rpc;
-use openhuman_core::openhuman::tools::{
- MemoryTreeFetchLeavesTool, MemoryTreeSearchEntitiesTool, Tool,
-};
-use serde_json::{json, Value};
-use tempfile::TempDir;
-use tinycortex::memory::ingest::canonicalize::chat::{ChatBatch, ChatMessage};
-use tinycortex::memory::ingest::canonicalize::email::{EmailMessage, EmailThread};
-use tinymemory_api::chunks::SourceKind;
-use tinymemory_core::queue::drain_until_idle;
-
-/// Install the host seams the memory subsystem needs.
-///
-/// These tests drive the retrieval tools against a real ingested workspace, and
-/// those tools resolve a memory driver — which since the module port means
-/// binding one, against a policy that only `boot` publishes. An integration
-/// test has no boot, so without this the driver refuses to load and the tool
-/// returns "the module host policy was never published" instead of retrieving.
-///
-/// `host_impls::install_for_tests` cannot be used here: it is `#[cfg(test)]`,
-/// which the crate's own unit tests see and a `tests/` binary does not. This
-/// mirrors `ensure_memory_seams` in `memory_sources_e2e.rs`, including the
-/// thread — `Config` is large enough that materialising it inline overflows a
-/// 2 MiB test stack inside an already-deep async fn.
-fn ensure_memory_seams() {
- static MEMORY_SEAMS_INIT: std::sync::OnceLock<()> = std::sync::OnceLock::new();
- MEMORY_SEAMS_INIT.get_or_init(|| {
- std::thread::Builder::new()
- .name("agent-retrieval-e2e-seams".to_string())
- .stack_size(8 * 1024 * 1024)
- .spawn(|| {
- let config = std::sync::Arc::new(Config::default());
- #[cfg(feature = "modules")]
- openhuman_core::openhuman::modules::memory::set_modules_policy(config);
- })
- .expect("spawn agent retrieval seam installer")
- .join()
- .expect("agent retrieval seam installer panicked");
- });
-}
-
-/// Build a Config rooted at `tmp/workspace`. The nested `workspace` dir
-/// matches what `resolve_config_dir_for_workspace` would derive when
-/// `OPENHUMAN_WORKSPACE` points at `tmp` — so the same workspace_dir is
-/// used both by the explicit ingest path and by `load_config_with_timeout`
-/// inside the tool wrappers.
-fn test_config() -> (TempDir, Config) {
- let tmp = TempDir::new().unwrap();
- let workspace_dir = tmp.path().join("workspace");
- std::fs::create_dir_all(&workspace_dir).expect("create workspace dir");
- // Assign after construction: Config carries private runtime-only state, so
- // external integration tests cannot use struct-update syntax.
- let mut cfg = Config::default();
- cfg.workspace_dir = workspace_dir;
- // Inert embedder — keeps the test deterministic and avoids any real
- // Ollama call. Mirrors `retrieval/integration_test.rs`.
- cfg.memory_tree.embedding_endpoint = None;
- cfg.memory_tree.embedding_model = None;
- cfg.memory_tree.embedding_strict = false;
- (tmp, cfg)
-}
-
-// ── RAII env guard shared by all tests in this file ──────────────────────────
-
-/// Process-wide mutex that serialises every test in this binary that
-/// mutates `OPENHUMAN_WORKSPACE`. Cargo runs integration-test binaries
-/// multi-threaded by default (`test-threads = num_cpus`), so without
-/// this serialisation two tests would race on the env var: test A sets
-/// it to `/tmp/aaa`, test B overwrites it with `/tmp/bbb`, then when
-/// B's `TempDir` drops it unlinks `/tmp/bbb` while A is still reading
-/// from it. That race surfaced in CI as `SQLITE_IOERR_FSTAT` (error
-/// code 1802) during a later `with_connection` call on the now-deleted
-/// path, and earlier as `fetch_leaves` returning 0 hits when the
-/// resolved workspace temporarily pointed at the wrong sibling test's
-/// (otherwise empty) tempdir.
-///
-/// `unwrap_or_else(|p| p.into_inner())` keeps the lock usable after a
-/// poisoning panic so one failing test never cascades.
-static ENV_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
-
-struct EnvGuard {
- key: &'static str,
- prev: Option<std::ffi::OsString>,
- /// Last field — dropped after `Drop::drop` has already restored
- /// the env var, so the next test acquires the lock against a
- /// clean `OPENHUMAN_WORKSPACE` value.
- _lock: std::sync::MutexGuard<'static, ()>,
-}
-
-impl Drop for EnvGuard {
- fn drop(&mut self) {
- // SAFETY: cargo test runs each integration test binary in its own
- // process; the `ENV_LOCK` mutex held in `_lock` serialises all
- // mutations within this binary, and the guard restores the
- // previous value before the lock is released.
- unsafe {
- match self.prev.take() {
- Some(v) => std::env::set_var(self.key, v),
- None => std::env::remove_var(self.key),
- }
- }
- }
-}
-
-/// Sets `OPENHUMAN_WORKSPACE` to `tmp.path()` and returns an RAII guard that
-/// restores the previous value on drop. This makes the tool wrappers (which
-/// call `load_config_with_timeout` internally) resolve to the same workspace
-/// that was used for ingest.
-///
-/// The returned guard also holds [`ENV_LOCK`] for its lifetime, so concurrent
-/// tests in the same binary cannot stomp on each other's
-/// `OPENHUMAN_WORKSPACE` setting.
-fn set_workspace_env(tmp: &TempDir) -> EnvGuard {
- let lock = ENV_LOCK.lock().unwrap_or_else(|p| p.into_inner());
- let prev = std::env::var_os("OPENHUMAN_WORKSPACE");
- // SAFETY: see EnvGuard::Drop above.
- unsafe { std::env::set_var("OPENHUMAN_WORKSPACE", tmp.path()) };
- EnvGuard {
- key: "OPENHUMAN_WORKSPACE",
- prev,
- _lock: lock,
- }
-}
-
-/// The orchestrator reaches `agent_memory` ON-DEMAND, not via an eager
-/// pre-turn pre-fetch. `agent_memory` is listed in the `[subagents]` allowlist
-/// (synthesised into a `delegate_retrieve_memory` tool), so the orchestrator
-/// walks the memory tree only when a message needs it — instead of spawning a
-/// full memory subagent before every turn.
-///
-/// History: #1141 consolidated 6 `memory_tree_*` tools into `memory_tree`;
-/// the agent_memory domain then unified `memory_tree` + `query_memory`
-/// behind `call_memory_agent`; a later revision made it an eager
-/// `trigger_memory_agent = "always"` pre-fetch. This contract reverts the
-/// eager pre-fetch to an on-demand delegation (the memory agent is heavy and
-/// most turns don't need a deep tree walk).
-#[test]
-fn orchestrator_reaches_memory_agent_on_demand() {
- let toml = include_str!("../src/openhuman/agent/registry/agents/orchestrator/agent.toml");
- // Eager pre-fetch must be gone.
- assert!(
- !toml
- .lines()
- .map(str::trim)
- .any(|line| line == "trigger_memory_agent = \"always\""),
- "orchestrator must NOT eagerly pre-fetch the memory agent — retrieval is on-demand"
- );
- // The on-demand route: `agent_memory` in the subagents allowlist.
- assert!(
- toml.lines()
- .map(str::trim)
- .any(|line| line == "\"agent_memory\"" || line == "\"agent_memory\","),
- "orchestrator must list `agent_memory` in its subagents allowlist for on-demand retrieval"
- );
- // The orchestrator reaches the memory agent through delegation, not the
- // direct `call_memory_agent` tool (that tool is forbidden on the
- // orchestrator — see loader::tests::master_agent_has_coding_hint_and_named_tools).
- let has_call_memory_agent = toml
- .lines()
- .map(str::trim)
- .any(|line| line == "\"call_memory_agent\"" || line == "\"call_memory_agent\",");
- assert!(
- !has_call_memory_agent,
- "orchestrator agent.toml must not expose the 'call_memory_agent' tool"
- );
- // Simple recall/store operations stay direct so they do not pay an agentic
- // round-trip; deep retrieval still routes through the memory subagent.
- for direct_name in [
- "memory_recall",
- "memory_store",
- "save_preference",
- "update_memory_md",
- ] {
- let entry = format!("\"{direct_name}\"");
- let entry_comma = format!("\"{direct_name}\",");
- let direct_tool_present = toml
- .lines()
- .map(str::trim)
- .any(|line| line == entry || line == entry_comma);
- assert!(
- direct_tool_present,
- "orchestrator agent.toml must list direct memory tool '{direct_name}'"
- );
- }
- // Verify the superseded tree/query tool names are gone.
- for old_name in [
- "memory_tree",
- "query_memory",
- "memory_tree_search_entities",
- "memory_tree_query_topic",
- "memory_tree_query_source",
- "memory_tree_query_global",
- "memory_tree_drill_down",
- "memory_tree_fetch_leaves",
- ] {
- let entry = format!("\"{old_name}\"");
- let entry_comma = format!("\"{old_name}\",");
- let old_tool_present = toml
- .lines()
- .map(str::trim)
- .any(|line| line == entry || line == entry_comma);
- assert!(
- !old_tool_present,
- "orchestrator agent.toml must NOT list legacy memory tool '{old_name}'"
- );
- }
-}
-
-// ── Cross-chat retrieval: chat A seeds facts; retrieve from chat B ──────────
-
-/// Ingests two distinct chat source IDs (simulating two separate chat channels)
-/// and proves that `search_entities` surfaces entities that were mentioned in
-/// both channels — i.e. the entity index is shared across source boundaries.
-///
-/// This is the core of "agent retrieves relevant context from other chats"
-/// (issue#1505): the retrieval tool must be able to surface facts from a
-/// channel the current conversation did not originate in.
-#[tokio::test]
-async fn cross_chat_entity_index_spans_source_boundaries() {
- ensure_memory_seams();
- let (tmp, cfg) = test_config();
-
- // Chat A — channel #eng seeds a fact about alice
- let chat_a = ChatBatch {
- platform: "slack".into(),
- channel_label: "#eng".into(),
- messages: vec![ChatMessage {
- author: "alice".into(),
- timestamp: Utc.timestamp_millis_opt(1_700_000_000_000).unwrap(),
- text: "[email protected] is leading the Phoenix deployment runbook. \
- Landing confirmed for Friday evening."
- .into(),
- source_ref: Some("slack://eng/1".into()),
- }],
- };
- ingest_rpc(
- &cfg,
- IngestRequest {
- source_kind: SourceKind::Chat,
- source_id: "slack:#eng".into(),
- owner: "alice".into(),
- tags: vec![],
- payload: serde_json::to_value(chat_a).expect("chat batch serialises"),
- },
- )
- .await
- .expect("ingest chat A should succeed");
-
- // Chat B — a separate channel with no overlap with chat A
- let chat_b = ChatBatch {
- platform: "slack".into(),
- channel_label: "#ops".into(),
- messages: vec![ChatMessage {
- author: "carol".into(),
- timestamp: Utc.timestamp_millis_opt(1_700_100_000_000).unwrap(),
- text: "What's the Phoenix landing status? [email protected] asking for ops.".into(),
- source_ref: Some("slack://ops/1".into()),
- }],
- };
- ingest_rpc(
- &cfg,
- IngestRequest {
- source_kind: SourceKind::Chat,
- source_id: "slack:#ops".into(),
- owner: "carol".into(),
- tags: vec![],
- payload: serde_json::to_value(chat_b).expect("chat batch serialises"),
- },
- )
- .await
- .expect("ingest chat B should succeed");
-
- drain_until_idle(&cfg)
- .await
- .expect("job queue should drain cleanly");
-
- let _ws_guard = set_workspace_env(&tmp);
-
- // search_entities surfaces alice even though the current "context" would
- // be chat B — the entity index is global and crosses source boundaries.
- let search = MemoryTreeSearchEntitiesTool;
- let res = search
- .execute(json!({"query": "alice"}))
- .await
- .expect("search_entities must not error");
- assert!(
- !res.is_error,
- "search_entities returned error: {}",
- res.output()
- );
-
- let json: Value = serde_json::from_str(&res.output()).unwrap();
- let matches = json.as_array().expect("search_entities returns an array");
-
- let alice = matches
- .iter()
- .find(|m| m.get("canonical_id").and_then(|v| v.as_str()) == Some("email:[email protected]"))
- .unwrap_or_else(|| {
- panic!("alice should be discoverable across source boundaries; got: {json:?}")
- });
-
- // alice was mentioned in chat A only; this assertion confirms the cross-chat
- // retrieval: even from chat B's perspective the entity index resolves her.
- assert!(
- alice
- .get("mention_count")
- .and_then(|v| v.as_u64())
- .unwrap_or(0)
- >= 1,
- "alice must have at least one mention"
- );
-
- // Also verify carol (from chat B) is discoverable via her own
- // canonical entity — a separate search call, since the entity index is
- // keyed by query string and "alice" does not surface carol's row.
- let res_carol = search
- .execute(json!({"query": "carol"}))
- .await
- .expect("search_entities (carol) must not error");
- assert!(
- !res_carol.is_error,
- "search_entities for carol returned error: {}",
- res_carol.output()
- );
- let carol_json: Value = serde_json::from_str(&res_carol.output()).unwrap();
- let carol_matches = carol_json
- .as_array()
- .expect("search_entities returns an array");
- let carol = carol_matches.iter().find(|m| {
- m.get("canonical_id")
- .and_then(|v| v.as_str())
- .map(|s| s.contains("carol"))
- .unwrap_or(false)
- });
- assert!(
- carol.is_some(),
- "carol from chat B must also be discoverable; got: {carol_json:?}"
- );
-}
-
-/// Proves fetch_leaves returns a populated `source_ref` on each hydrated
-/// chunk so the orchestrator can cite the exact provenance of retrieved facts.
-///
-/// This is the "memory retrieval returns provenance and can hydrate cited
-/// chunks" feature (issue#1538): chunk_ids from query_topic are fed into
-/// fetch_leaves and each returned leaf must carry `source_ref` when one was
-/// set at ingest time.
-#[tokio::test]
-async fn fetch_leaves_hydrates_source_ref_for_cited_chunks() {
- ensure_memory_seams();
- let (tmp, cfg) = test_config();
-
- // Ingest an email thread with explicit source_refs on every message.
- ingest_rpc(
- &cfg,
- IngestRequest {
- source_kind: SourceKind::Email,
- source_id: "gmail:thread-provenance-1".into(),
- owner: "alice".into(),
- tags: vec![],
- payload: serde_json::to_value(EmailThread {
- provider: "gmail".into(),
- thread_subject: "Q3 roadmap decision".into(),
- messages: vec![
- EmailMessage {
- from: "[email protected]".into(),
- to: vec!["[email protected]".into()],
- cc: vec![],
- subject: "Q3 roadmap decision".into(),
- sent_at: Utc.timestamp_millis_opt(1_710_000_000_000).unwrap(),
- body: "We are committing to the Q3 roadmap with Phoenix as the \
- flagship feature. [email protected] signed off."
- .into(),
- source_ref: Some("<[email protected]>".into()),
- list_unsubscribe: None,
- },
- EmailMessage {
- from: "[email protected]".into(),
- to: vec!["[email protected]".into()],
- cc: vec![],
- subject: "Re: Q3 roadmap decision".into(),
- sent_at: Utc.timestamp_millis_opt(1_710_000_060_000).unwrap(),
- body: "Confirmed. [email protected] will own the Phoenix delivery.".into(),
- source_ref: Some("<[email protected]>".into()),
- list_unsubscribe: None,
- },
- ],
- })
- .expect("email thread serialises"),
- },
- )
- .await
- .expect("ingest_rpc(email) must succeed");
-
- drain_until_idle(&cfg).await.expect("queue must drain");
-
- let _ws_guard = set_workspace_env(&tmp);
-
- // List the ingested chunks through the host read RPC. Not the engine's
- // `store::chunks::store::list_chunks`: ingest went through the bound
- // driver, so this reads the same surface the product reads.
- let chunks = read_rpc::list_chunks_rpc(
- &cfg,
- ChunkFilter {
- // Scoped to the thread this test ingested. An unfiltered listing
- // returns whatever else the store holds, and taking its first two
- // rows fetched chunks this test never wrote — which is how the
- // provenance assertion below came to pass on somebody else's
- // `agent://session/...` segments.
- source_ids: Some(vec!["gmail:thread-provenance-1".to_string()]),
- ..ChunkFilter::default()
- },
- )
- .await
- .expect("list_chunks must not error")
- .value
- .chunks;
-
- assert!(
- !chunks.is_empty(),
- "the ingested thread must be listable under its own source id"
- );
-
- assert!(!chunks.is_empty(), "ingest must produce at least one chunk");
-
- // Collect the first couple of leaf chunk ids.
- let leaf_ids: Vec<String> = chunks
- .iter()
- .map(|chunk| chunk.id.clone())
- .take(2)
- .collect();
-
- assert!(
- !leaf_ids.is_empty(),
- "at least one leaf chunk required for fetch_leaves provenance test"
- );
-
- // fetch_leaves by chunk_ids and assert source_ref is populated.
- let fetch_tool = MemoryTreeFetchLeavesTool;
- let fetch_res = fetch_tool
- .execute(json!({"chunk_ids": leaf_ids}))
- .await
- .expect("fetch_leaves must not error");
- assert!(
- !fetch_res.is_error,
- "fetch_leaves error: {}",
- fetch_res.output()
- );
-
- let fetched: Value = serde_json::from_str(&fetch_res.output()).unwrap();
- let leaves = fetched.as_array().expect("fetch_leaves returns array");
-
- assert!(
- !leaves.is_empty(),
- "fetch_leaves must hydrate at least one chunk"
- );
-
- // The point of the test is that the ref set at INGEST reaches the citation,
- // so assert the value, not merely that the field is inhabited. Asserting
- // presence alone passed even with `email_items` dropping `source_ref`
- // outright, because something further down still populates the field —
- // which is exactly the shape of a provenance test that proves nothing.
- let refs: Vec<&str> = leaves
- .iter()
- .filter_map(|l| l.get("source_ref").and_then(|v| v.as_str()))
- .collect();
- assert!(
- refs.iter()
- .any(|r| r.contains("[email protected]")
- || r.contains("[email protected]")),
- "fetch_leaves must carry the source_ref set at ingest so a citation \
- points at the message it came from; got refs {refs:?} in leaves: {fetched:#}"
- );
-
- // Verify content round-trips.
- for leaf in leaves {
- let content = leaf.get("content").and_then(|v| v.as_str()).unwrap_or("");
- assert!(
- !content.is_empty(),
- "fetch_leaves leaf must carry non-empty content for citation"
- );
- let node_id = leaf.get("node_id").and_then(|v| v.as_str()).unwrap_or("");
- assert!(!node_id.is_empty(), "fetch_leaves leaf must carry node_id");
- }
-}
diff --git a/tests/agent_turn_overrides_e2e.rs b/tests/agent_turn_overrides_e2e.rs
deleted file mode 100644
index 4d47ff0dcb..0000000000
--- a/tests/agent_turn_overrides_e2e.rs
+++ /dev/null
@@ -1,687 +0,0 @@
-//! E2E coverage for per-turn `TurnOverrides` (openhuman#5844 / opencompany#1725).
-//!
-//! #5844 shipped four per-turn suppressions and two terminal goal APIs with no
-//! test in any e2e lane. Inside the unit lane the coverage was thinner than it
-//! looked: `suppress_active_goal` appears only as a field set to `true` inside
-//! the *memory-agent* test's struct literal
-//! (`session/turn_tests_part_02_tests.rs:114`) with nothing asserting the goal
-//! block is absent, and `suppress_transcript_autoload` appears once, as `false`
-//! (`:115`) — it is never exercised at all.
-//!
-//! These drive a real `Agent::turn` against a scripted model and assert on what
-//! actually reaches the provider.
-//!
-//! # Every test carries its own control
-//!
-//! A suppression test with no control passes happily when the feature it
-//! suppresses never ran in the first place. So each case first asserts the
-//! un-overridden turn DOES carry the thing, then that the overridden one does
-//! not. If a control ever stops holding, the paired assertion has stopped
-//! proving anything and must be re-derived rather than trusted.
-//!
-//! The env var and the goal store are process-global, so every test holds
-//! `env_lock()` across its await points on purpose — the lock IS the
-//! serialization mechanism, which makes `clippy::await_holding_lock` a false
-//! positive here.
-#![allow(clippy::await_holding_lock)]
-
-use async_trait::async_trait;
-use std::collections::VecDeque;
-use std::path::PathBuf;
-use std::sync::{Arc, Mutex, OnceLock};
-use tempfile::TempDir;
-
-use openhuman_core::openhuman::agent::dispatcher::{NativeToolDispatcher, XmlToolDispatcher};
-use openhuman_core::openhuman::agent::harness::session::TurnOverrides;
-use openhuman_core::openhuman::agent::tinyagents::thread_context::with_thread_id;
-use openhuman_core::openhuman::agent::Agent;
-use openhuman_core::openhuman::config::{AgentConfig, Config, ContextConfig, MemoryConfig};
-use openhuman_core::openhuman::threads::goals::{runtime as goal_runtime, store as goal_store};
-use openhuman_core::openhuman::tools::{
- PermissionLevel, Tool, ToolContent, ToolResult, ToolScope as RuntimeToolScope,
-};
-use tinyinference::message::Message;
-use tinyinference::model::{
- ChatModel, ModelProfile, ModelRequest, ModelResponse, ModelStream, ModelStreamItem,
-};
-use tinymemory_core::store as memory_store;
-
-// ─── Harness ────────────────────────────────────────────────────────────────
-
-struct EnvGuard {
- key: &'static str,
- previous: Option<std::ffi::OsString>,
-}
-
-impl EnvGuard {
- fn set_path(key: &'static str, value: &std::path::Path) -> Self {
- let previous = std::env::var_os(key);
- unsafe { std::env::set_var(key, value) };
- Self { key, previous }
- }
-}
-
-impl Drop for EnvGuard {
- fn drop(&mut self) {
- match self.previous.take() {
- Some(value) => unsafe { std::env::set_var(self.key, value) },
- None => unsafe { std::env::remove_var(self.key) },
- }
- }
-}
-
-static ENV_LOCK: OnceLock<Mutex<()>> = OnceLock::new();
-
-fn env_lock() -> std::sync::MutexGuard<'static, ()> {
- ENV_LOCK
- .get_or_init(|| Mutex::new(()))
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner())
-}
-
-static MEMORY_SEAMS_INIT: OnceLock<()> = OnceLock::new();
-
-/// `create_memory` requires the TinyMemory host seams and fails loudly when they
-/// are unwired — a deliberate choice, since an unwired embedding host would
-/// otherwise corrupt an embedding space quietly. Installed on a wide stack
-/// because the seam installer recurses deeply.
-fn ensure_memory_seams() {
- MEMORY_SEAMS_INIT.get_or_init(|| {
- std::thread::Builder::new()
- .name("turn-overrides-e2e-seams".to_string())
- .stack_size(8 * 1024 * 1024)
- .spawn(|| {
- })
- .expect("spawn turn-overrides seam installer")
- .join()
- .expect("turn-overrides seam installer panicked");
- });
-}
-
-/// The agent turn loop needs the wide worker stack the product gives it.
-fn run_on_agent_stack<F, Fut>(name: &str, future_factory: F)
-where
- F: FnOnce() -> Fut + Send + 'static,
- Fut: std::future::Future<Output = ()> + 'static,
-{
- std::thread::Builder::new()
- .name(name.to_string())
- .stack_size(openhuman_core::core::runtime::AGENT_WORKER_STACK_BYTES)
- .spawn(move || {
- tokio::runtime::Builder::new_multi_thread()
- .worker_threads(2)
- .thread_stack_size(openhuman_core::core::runtime::AGENT_WORKER_STACK_BYTES)
- .enable_all()
- .build()
- .expect("build turn-overrides runtime")
- .block_on(future_factory());
- })
- .expect("spawn turn-overrides thread")
- .join()
- .expect("turn-overrides thread should not panic");
-}
-
-#[derive(Clone, Debug)]
-struct CapturedRequest {
- messages: Vec<Message>,
- tool_names: Vec<String>,
-}
-
-struct ScriptedModel {
- responses: Mutex<VecDeque<ModelResponse>>,
- requests: Mutex<Vec<CapturedRequest>>,
- profile: ModelProfile,
-}
-
-impl ScriptedModel {
- fn new(responses: Vec<ModelResponse>) -> Arc<Self> {
- Arc::new(Self {
- responses: Mutex::new(responses.into_iter().collect()),
- requests: Mutex::new(Vec::new()),
- profile: ModelProfile::default(),
- })
- }
-
- fn requests(&self) -> Vec<CapturedRequest> {
- self.requests.lock().unwrap().clone()
- }
-
- /// Every message text the provider was ever handed, flattened.
- fn all_prompt_text(&self) -> String {
- self.requests()
- .iter()
- .flat_map(|request| request.messages.iter().map(|message| message.text()))
- .collect::<Vec<_>>()
- .join("\n---\n")
- }
-
- fn capture(&self, request: &ModelRequest) {
- self.requests.lock().unwrap().push(CapturedRequest {
- messages: request.messages.clone(),
- tool_names: request.tools.iter().map(|tool| tool.name.clone()).collect(),
- });
- }
-
- fn pop(&self) -> ModelResponse {
- self.responses
- .lock()
- .unwrap()
- .pop_front()
- .unwrap_or_else(|| ModelResponse::assistant("default scripted final"))
- }
-}
-
-#[async_trait]
-impl ChatModel<()> for ScriptedModel {
- fn profile(&self) -> Option<&ModelProfile> {
- Some(&self.profile)
- }
-
- async fn invoke(
- &self,
- _state: &(),
- request: ModelRequest,
- ) -> tinyinference::Result<ModelResponse> {
- self.capture(&request);
- Ok(self.pop())
- }
-
- async fn stream(
- &self,
- _state: &(),
- request: ModelRequest,
- ) -> tinyinference::Result<ModelStream> {
- self.capture(&request);
- let items = vec![
- ModelStreamItem::Started,
- ModelStreamItem::Completed(self.pop()),
- ];
- Ok(Box::pin(futures::stream::iter(items)))
- }
-}
-
-/// A trivial always-available tool, so `suppress_tools` has something to hide.
-struct EchoTool;
-
-#[async_trait]
-impl Tool for EchoTool {
- fn name(&self) -> &str {
- "turn_overrides_echo"
- }
-
- fn description(&self) -> &str {
- "Echo a value back."
- }
-
- fn parameters_schema(&self) -> serde_json::Value {
- serde_json::json!({
- "type": "object",
- "properties": { "value": { "type": "string" } },
- "required": ["value"],
- })
- }
-
- fn permission_level(&self) -> PermissionLevel {
- PermissionLevel::ReadOnly
- }
-
- fn scope(&self) -> RuntimeToolScope {
- RuntimeToolScope::All
- }
-
- async fn execute(&self, _args: serde_json::Value) -> anyhow::Result<ToolResult> {
- Ok(ToolResult {
- content: vec![ToolContent::Text {
- text: "echoed".to_string(),
- }],
- is_error: false,
- markdown_formatted: None,
- })
- }
-}
-
-fn workspace(label: &str) -> (TempDir, PathBuf) {
- let temp = TempDir::new().expect("workspace tempdir");
- let path = temp.path().join(label);
- std::fs::create_dir_all(&path).expect("create workspace dir");
- (temp, path)
-}
-
-fn memory_for_workspace(
- path: &std::path::Path,
-) -> Arc<dyn openhuman_core::openhuman::memory::Memory> {
- let cfg = MemoryConfig {
- backend: "none".to_string(),
- ..MemoryConfig::default()
- };
- Arc::from(memory_store::create_memory(&cfg, path).expect("create memory"))
-}
-
-fn agent_with(
- model: Arc<dyn ChatModel<()>>,
- tools: Vec<Box<dyn Tool>>,
- workspace_path: PathBuf,
- dispatcher: Box<dyn openhuman_core::openhuman::agent::dispatcher::ToolDispatcher>,
-) -> Agent {
- Agent::builder()
- .chat_model(model)
- .tools(tools)
- .memory(memory_for_workspace(&workspace_path))
- .tool_dispatcher(dispatcher)
- .workspace_dir(workspace_path)
- .event_context("turn-overrides-session", "turn-overrides-channel")
- .agent_definition_name("turn-overrides/orchestrator")
- .config(AgentConfig {
- max_tool_iterations: 2,
- max_history_messages: 12,
- ..AgentConfig::default()
- })
- .context_config(ContextConfig::default())
- .auto_save(true)
- .explicit_preferences_enabled(false)
- .build()
- .expect("build agent")
-}
-
-fn text(body: &str) -> ModelResponse {
- ModelResponse::assistant(body)
-}
-
-// ─── suppress_active_goal ───────────────────────────────────────────────────
-
-/// A goal an earlier task left uncompleted must not steer an unrelated chat
-/// turn: `suppress_active_goal` keeps the `[thread goal]` block out of the
-/// prompt entirely.
-#[test]
-fn suppress_active_goal_keeps_the_thread_goal_out_of_the_prompt() {
- run_on_agent_stack(
- "turn-overrides-suppress-active-goal",
- suppress_active_goal_keeps_the_thread_goal_out_of_the_prompt_inner,
- );
-}
-
-async fn suppress_active_goal_keeps_the_thread_goal_out_of_the_prompt_inner() {
- ensure_memory_seams();
- let _env = env_lock();
-
- // Control and measured agent get SEPARATE workspaces on purpose.
- //
- // `agent_with` builds with `auto_save(true)` and one shared
- // `agent_definition_name`, so a second agent in the same workspace starts
- // with an empty history and auto-loads the FIRST agent's transcript — which
- // contains the very `[thread goal]` block this test is asserting the absence
- // of. Sharing a workspace therefore makes this test fail for a reason that
- // has nothing to do with `suppress_active_goal` (proved: with one workspace
- // the control passes and the suppression assertion fails, while
- // `suppress_transcript_autoload_does_not_replay_a_prior_threads_transcript`
- // passes — i.e. the replay is real). Two workspaces, one goal seeded in each,
- // isolates the flag under test.
- let (_control_temp, control_workspace) = workspace("suppress-active-goal-control");
- let (_temp, workspace_path) = workspace("suppress-active-goal");
-
- const THREAD: &str = "thread-suppress-active-goal";
- const OBJECTIVE: &str = "turn-overrides objective that must not leak into small talk";
-
- with_thread_id(THREAD, async {
- // CONTROL — without the override the goal reaches the prompt.
- let control_guard = EnvGuard::set_path("OPENHUMAN_WORKSPACE", &control_workspace);
- goal_store::set(&control_workspace, THREAD, OBJECTIVE, None)
- .await
- .expect("seed an active thread goal for the control");
- let control_model = ScriptedModel::new(vec![text("control final")]);
- let mut control = agent_with(
- control_model.clone(),
- Vec::new(),
- control_workspace.clone(),
- Box::new(XmlToolDispatcher),
- );
- control
- .turn("where are we on the task?")
- .await
- .expect("control turn should succeed");
- assert!(
- control_model.all_prompt_text().contains(OBJECTIVE),
- "control: an Active thread goal must reach the prompt, otherwise this test \
- cannot prove that suppression does anything"
- );
- drop(control_guard);
-
- // SUPPRESSED — a goal seeded identically, in a workspace no other agent
- // has ever written a transcript into, must not appear.
- let _workspace_guard = EnvGuard::set_path("OPENHUMAN_WORKSPACE", &workspace_path);
- goal_store::set(&workspace_path, THREAD, OBJECTIVE, None)
- .await
- .expect("seed an active thread goal for the measured agent");
- let model = ScriptedModel::new(vec![text("chat final")]);
- let mut agent = agent_with(
- model.clone(),
- Vec::new(),
- workspace_path.clone(),
- Box::new(XmlToolDispatcher),
- );
- agent.set_next_turn_overrides(TurnOverrides {
- suppress_active_goal: true,
- ..Default::default()
- });
- agent.turn("hey").await.expect("suppressed turn");
-
- let prompt = model.all_prompt_text();
- assert!(
- !prompt.contains(OBJECTIVE),
- "suppress_active_goal must keep the thread goal's objective out of the prompt; \
- prompt was: {prompt}"
- );
- assert!(
- !prompt.contains("[thread goal]"),
- "suppress_active_goal must not inject the [thread goal] block; prompt was: {prompt}"
- );
- })
- .await;
-}
-
-// ─── suppress_transcript_autoload ───────────────────────────────────────────
-
-/// The silent one. `turn()` auto-resumes an empty-history session from the
-/// agent's most recent on-disk transcript, and that lookup resolves the latest
-/// transcript **by agent name — it is not thread-scoped**. A host that has just
-/// re-bound its in-memory history to a different chat therefore gets the
-/// previous thread's conversation back underneath it and answers grounded in the
-/// wrong one, with no error anywhere (#1725).
-#[test]
-fn suppress_transcript_autoload_does_not_replay_a_prior_threads_transcript() {
- run_on_agent_stack(
- "turn-overrides-suppress-transcript-autoload",
- suppress_transcript_autoload_does_not_replay_a_prior_threads_transcript_inner,
- );
-}
-
-async fn suppress_transcript_autoload_does_not_replay_a_prior_threads_transcript_inner() {
- ensure_memory_seams();
- let _env = env_lock();
- let (_temp, workspace_path) = workspace("suppress-transcript-autoload");
- let _workspace_guard = EnvGuard::set_path("OPENHUMAN_WORKSPACE", &workspace_path);
-
- const PRIOR_MARKER: &str = "turn-overrides-prior-thread-secret-topic";
- // Two ids, so the run enacts #1725's actual shape: a host that has re-bound
- // its history to a *different* chat, not merely a second agent on the same
- // one.
- //
- // These scopes do not steer the lookup, and are not meant to. Autoload is
- // `session_io_impl_01_part_01.rs:45` — `latest_for_agent(&self.agent_definition_name)`
- // — which never reads `thread_context::current_thread_id()`; that
- // agent-name-only resolution IS the defect the override exists to work
- // around. They are here so the control states the stronger fact (the prior
- // transcript is replayed *even under a different thread id*), and so that a
- // future change making autoload thread-scoped fails this control loudly
- // instead of passing while quietly changing what the test means.
- const PRIOR_THREAD: &str = "turn-overrides-autoload-thread-a";
- const LATER_THREAD: &str = "turn-overrides-autoload-thread-b";
-
- // A first conversation persists a transcript under this agent name.
- with_thread_id(PRIOR_THREAD, async {
- let first_model = ScriptedModel::new(vec![text("first thread reply")]);
- let mut first = agent_with(
- first_model.clone(),
- Vec::new(),
- workspace_path.clone(),
- Box::new(XmlToolDispatcher),
- );
- first
- .turn(PRIOR_MARKER)
- .await
- .expect("first thread turn should succeed");
- })
- .await;
-
- // Everything below is the *later* chat the host has re-bound to.
- with_thread_id(LATER_THREAD, async {
- // CONTROL — a fresh agent with an empty history DOES pick that transcript
- // up, across the thread change.
- let control_model = ScriptedModel::new(vec![text("control reply")]);
- let mut control = agent_with(
- control_model.clone(),
- Vec::new(),
- workspace_path.clone(),
- Box::new(XmlToolDispatcher),
- );
- control
- .turn("an unrelated question")
- .await
- .expect("control turn should succeed");
- assert!(
- control_model.all_prompt_text().contains(PRIOR_MARKER),
- "control: a fresh agent must auto-load the prior thread's transcript even under a \
- different thread id, otherwise this test cannot prove that \
- suppress_transcript_autoload prevents anything"
- );
-
- // SUPPRESSED — the same shape must not see the earlier conversation.
- let model = ScriptedModel::new(vec![text("clean reply")]);
- let mut agent = agent_with(
- model.clone(),
- Vec::new(),
- workspace_path.clone(),
- Box::new(XmlToolDispatcher),
- );
- agent.set_next_turn_overrides(TurnOverrides {
- suppress_transcript_autoload: true,
- ..Default::default()
- });
- agent
- .turn("an unrelated question")
- .await
- .expect("suppressed turn should succeed");
-
- let prompt = model.all_prompt_text();
- assert!(
- !prompt.contains(PRIOR_MARKER),
- "suppress_transcript_autoload must not replay another conversation's transcript \
- into the prompt; found the prior thread's marker in: {prompt}"
- );
- })
- .await;
-}
-
-// ─── one-shot semantics ─────────────────────────────────────────────────────
-
-/// The overrides are consumed by exactly ONE turn.
-///
-/// `turn()` takes them with `std::mem::take`, so the turn after a suppressed one
-/// is back to full agentic behaviour without the caller restoring anything. A
-/// suppression that leaked forward would silently strip a real task turn of its
-/// toolbelt.
-#[test]
-fn turn_overrides_apply_to_exactly_one_turn_and_then_reset() {
- run_on_agent_stack(
- "turn-overrides-reset",
- turn_overrides_apply_to_exactly_one_turn_and_then_reset_inner,
- );
-}
-
-async fn turn_overrides_apply_to_exactly_one_turn_and_then_reset_inner() {
- ensure_memory_seams();
- let _env = env_lock();
- let (_temp, workspace_path) = workspace("overrides-reset");
- let _workspace_guard = EnvGuard::set_path("OPENHUMAN_WORKSPACE", &workspace_path);
-
- let model = ScriptedModel::new(vec![text("suppressed reply"), text("restored reply")]);
- let mut agent = agent_with(
- model.clone(),
- vec![Box::new(EchoTool)],
- workspace_path.clone(),
- Box::new(NativeToolDispatcher),
- );
-
- agent.set_next_turn_overrides(TurnOverrides {
- suppress_tools: true,
- ..Default::default()
- });
- agent.turn("small talk").await.expect("suppressed turn");
- agent.turn("now do real work").await.expect("restored turn");
-
- let requests = model.requests();
- assert_eq!(
- requests.len(),
- 2,
- "expected exactly one provider call per turn, got {}",
- requests.len()
- );
- assert!(
- requests[0].tool_names.is_empty(),
- "turn 1 set suppress_tools, so it must carry an empty tool schema; got {:?}",
- requests[0].tool_names
- );
- assert!(
- requests[1]
- .tool_names
- .iter()
- .any(|name| name == "turn_overrides_echo"),
- "turn 2 set no overrides, so the toolbelt must be back — the override is one-shot, \
- not a rebuild; got {:?}",
- requests[1].tool_names
- );
-}
-
-// ─── the terminal goal APIs ─────────────────────────────────────────────────
-
-/// The goal API had `pause_for_current_thread` but no terminal counterpart, so a
-/// goal a finished task left behind stayed `Active` and was re-injected on every
-/// later turn. #5844 added both halves: `complete_for_current_thread` settles the
-/// goal (and a settled goal renders no context block), `clear_for_current_thread`
-/// removes the row outright.
-#[test]
-fn thread_goal_complete_and_clear_stop_the_goal_reaching_later_turns() {
- run_on_agent_stack(
- "turn-overrides-goal-terminal-apis",
- thread_goal_complete_and_clear_stop_the_goal_reaching_later_turns_inner,
- );
-}
-
-async fn thread_goal_complete_and_clear_stop_the_goal_reaching_later_turns_inner() {
- ensure_memory_seams();
- let _env = env_lock();
-
- // Separate workspaces, for the same reason as
- // `suppress_active_goal_keeps_the_thread_goal_out_of_the_prompt`: a second
- // agent in the same workspace auto-loads the first one's transcript, which
- // still contains the `[thread goal]` block, so the post-completion
- // assertion would fail on replayed history rather than on a live goal.
- let (_control_temp, control_workspace) = workspace("goal-terminal-control");
- let (_temp, workspace_path) = workspace("goal-terminal-apis");
-
- const THREAD: &str = "thread-goal-terminal";
- const OBJECTIVE: &str = "turn-overrides objective a finished task must stop replaying";
-
- with_thread_id(THREAD, async {
- // CONTROL — an Active goal reaches a turn.
- let control_guard = EnvGuard::set_path("OPENHUMAN_WORKSPACE", &control_workspace);
- goal_store::set(&control_workspace, THREAD, OBJECTIVE, None)
- .await
- .expect("seed an active thread goal for the control");
- let control_model = ScriptedModel::new(vec![text("pre-completion reply")]);
- let mut control = agent_with(
- control_model.clone(),
- Vec::new(),
- control_workspace.clone(),
- Box::new(XmlToolDispatcher),
- );
- control.turn("status?").await.expect("pre-completion turn");
- assert!(
- control_model.all_prompt_text().contains(OBJECTIVE),
- "control: the goal must reach a turn before it is completed, otherwise this \
- test cannot prove completion changes anything"
- );
- drop(control_guard);
-
- // MEASURED — seed the same goal in a pristine workspace, settle it via
- // the API under test, then run the only turn that workspace ever sees.
- let _workspace_guard = EnvGuard::set_path("OPENHUMAN_WORKSPACE", &workspace_path);
- goal_store::set(&workspace_path, THREAD, OBJECTIVE, None)
- .await
- .expect("seed an active thread goal for the measured agent");
- let seeded = goal_runtime::load_for_current_thread(&workspace_path)
- .await
- .expect("the seeded goal must load before completion");
- assert_eq!(
- seeded.objective, OBJECTIVE,
- "control: the goal must be loadable before completing it"
- );
-
- goal_runtime::complete_for_current_thread(&workspace_path).await;
-
- // A completed goal renders no context block, so a later turn is clean
- // with no per-turn override set at all.
- let model = ScriptedModel::new(vec![text("post-completion reply")]);
- let mut agent = agent_with(
- model.clone(),
- Vec::new(),
- workspace_path.clone(),
- Box::new(XmlToolDispatcher),
- );
- agent
- .turn("something unrelated")
- .await
- .expect("post-completion turn");
- let prompt = model.all_prompt_text();
- assert!(
- !prompt.contains(OBJECTIVE),
- "a goal completed via complete_for_current_thread must stop being injected into \
- later turns; found it in: {prompt}"
- );
-
- goal_runtime::clear_for_current_thread(&workspace_path).await;
- assert!(
- goal_runtime::load_for_current_thread(&workspace_path)
- .await
- .is_none(),
- "clear_for_current_thread must remove the goal row outright"
- );
-
- // The goal cleared above was already Completed, and a completed goal is
- // excluded from later prompts anyway — so on its own that only proves a
- // completed row can be deleted. A `clear` that silently no-opped on an
- // ACTIVE goal would pass everything above it. Seed a fresh active goal
- // and clear that one too.
- const ACTIVE_OBJECTIVE: &str = "turn-overrides-active-goal-to-be-cleared";
- goal_store::set(&workspace_path, THREAD, ACTIVE_OBJECTIVE, None)
- .await
- .expect("seed a second, still-active thread goal");
- let active = goal_runtime::load_for_current_thread(&workspace_path)
- .await
- .expect("the second goal must load while it is still active");
- assert_eq!(
- active.objective, ACTIVE_OBJECTIVE,
- "control: the active goal must be live before clearing it, otherwise clearing it \
- proves nothing"
- );
-
- goal_runtime::clear_for_current_thread(&workspace_path).await;
- assert!(
- goal_runtime::load_for_current_thread(&workspace_path)
- .await
- .is_none(),
- "clear_for_current_thread must remove an ACTIVE goal, not only a completed one"
- );
-
- // And it must actually stop reaching the prompt — deletion of the row is
- // the mechanism, absence from the turn is the contract.
- let post_clear_model = ScriptedModel::new(vec![text("post-clear reply")]);
- let mut post_clear = agent_with(
- post_clear_model.clone(),
- Vec::new(),
- workspace_path.clone(),
- Box::new(XmlToolDispatcher),
- );
- post_clear
- .turn("something else entirely")
- .await
- .expect("post-clear turn");
- let post_clear_prompt = post_clear_model.all_prompt_text();
- assert!(
- !post_clear_prompt.contains(ACTIVE_OBJECTIVE),
- "an active goal cleared via clear_for_current_thread must stop being injected \
- into later turns; found it in: {post_clear_prompt}"
- );
- })
- .await;
-}
diff --git a/tests/coding_sessions_feature.rs b/tests/coding_sessions_feature.rs
deleted file mode 100644
index ce164d23f4..0000000000
--- a/tests/coding_sessions_feature.rs
+++ /dev/null
@@ -1,49 +0,0 @@
-//! Feature contract for TinyCortex Codex/Claude session discovery through the
-//! OpenHuman adapter seam.
-
-use std::fs;
-
-use tempfile::tempdir;
-
-use tinymemory_core::tinycortex::coding_session_status_for_roots;
-
-#[test]
-fn coding_session_sources_extract_human_turns_from_both_harnesses() {
- let temp = tempdir().expect("tempdir");
- let claude_root = temp.path().join("claude/projects/repo");
- let codex_root = temp.path().join("codex/sessions/2026/07/14");
- fs::create_dir_all(&claude_root).expect("claude root");
- fs::create_dir_all(&codex_root).expect("codex root");
-
- fs::write(
- claude_root.join("claude-session.jsonl"),
- concat!(
- "{\"type\":\"user\",\"sessionId\":\"claude-1\",\"cwd\":\"/repo\",\"timestamp\":\"2026-07-14T10:00:00Z\",\"message\":{\"content\":\"Use behavior-driven tests\"}}\n",
- "{\"type\":\"user\",\"isSidechain\":true,\"message\":{\"content\":\"subagent machine traffic\"}}\n"
- ),
- )
- .expect("claude fixture");
- fs::write(
- codex_root.join("rollout-codex-session.jsonl"),
- concat!(
- "{\"type\":\"session_meta\",\"payload\":{\"id\":\"codex-1\",\"cwd\":\"/repo\"}}\n",
- "{\"type\":\"response_item\",\"timestamp\":\"2026-07-14T10:00:00Z\",\"payload\":{\"type\":\"message\",\"role\":\"developer\",\"content\":[{\"type\":\"input_text\",\"text\":\"machine policy\"}]}}\n",
- "{\"type\":\"response_item\",\"timestamp\":\"2026-07-14T10:00:01Z\",\"payload\":{\"type\":\"message\",\"role\":\"user\",\"content\":[{\"type\":\"input_text\",\"text\":\"Keep modules below 500 lines\"}]}}\n"
- ),
- )
- .expect("codex fixture");
-
- let statuses = coding_session_status_for_roots(
- &temp.path().join("claude/projects"),
- &temp.path().join("codex/sessions"),
- );
-
- assert_eq!(statuses.len(), 2);
- assert_eq!(statuses[0].kind, "claude_code");
- assert_eq!(statuses[0].evidence_units, 1, "sidechain must be excluded");
- assert_eq!(statuses[1].kind, "codex");
- assert_eq!(
- statuses[1].evidence_units, 1,
- "developer policy must be excluded"
- );
-}
diff --git a/tests/memory_fast_retrieve_e2e.rs b/tests/memory_fast_retrieve_e2e.rs
deleted file mode 100644
index a0110b829f..0000000000
--- a/tests/memory_fast_retrieve_e2e.rs
+++ /dev/null
@@ -1,152 +0,0 @@
-//! E2E tests for the deterministic E2GraphRAG retriever (`fast_retrieve`).
-//!
-//! These replace the old agentic `memory_tree_walk_e2e.rs`. There is no LLM in
-//! the retrieval loop, so no mock server is needed — we ingest a small chat
-//! corpus, then assert that:
-//! - an entity-relationship query routes to the *local* branch and returns
-//! the chunk where the two entities co-occur, ranked by entity coverage;
-//! - a query with no extractable entities routes to the *global* branch and
-//! returns cleanly (no panic) over the same store;
-//! - the output is structured `QueryResponse` evidence (hits), not prose.
-//!
-//! spaCy is disabled here so the run is deterministic and Python-free in CI —
-//! query-entity extraction uses the regex fallback (emails/handles/hashtags),
-//! which is enough to exercise both routing branches.
-//!
-//! Run with:
-//! cargo test --test memory_fast_retrieve_e2e
-//! or via the project wrapper:
-//! bash scripts/test-rust-with-mock.sh --test memory_fast_retrieve_e2e
-
-use std::sync::{Arc, OnceLock};
-
-use chrono::{TimeZone, Utc};
-use tempfile::TempDir;
-
-use openhuman_core::openhuman::config::Config;
-// Named on the engine crate directly: the host `memory::tree::retrieval`
-// dropped its engine glob in #5560 (no production caller remained).
-use tinycortex::memory::ingest::canonicalize::chat::{ChatBatch, ChatMessage};
-use tinymemory_core::ingest_pipeline::ingest_chat;
-use tinymemory_core::tree::retrieval::{fast_retrieve, FastRetrieveOptions};
-
-static MEMORY_SEAMS_INIT: OnceLock<()> = OnceLock::new();
-
-fn ensure_memory_seams() {
- MEMORY_SEAMS_INIT.get_or_init(|| {
- std::thread::Builder::new()
- .name("memory-fast-retrieve-e2e-seams".to_string())
- .stack_size(8 * 1024 * 1024)
- .spawn(|| {
- })
- .expect("spawn memory retrieval seam installer")
- .join()
- .expect("memory retrieval seam installer panicked");
- });
-}
-
-fn test_config() -> (TempDir, Config) {
- ensure_memory_seams();
- let tmp = TempDir::new().unwrap();
- let mut cfg = Config::default();
- cfg.workspace_dir = tmp.path().to_path_buf();
- // Inert embedder — no Ollama/cloud in CI.
- cfg.embeddings_provider = Some("none".to_string());
- cfg.memory_tree.embedding_endpoint = None;
- cfg.memory_tree.embedding_model = None;
- cfg.memory_tree.embedding_strict = false;
- // Deterministic, Python-free entity extraction (regex fallback).
- cfg.memory_tree.spacy_enabled = false;
- (tmp, cfg)
-}
-
-async fn seed_chat(cfg: &Config, source: &str, text: &str) {
- let batch = ChatBatch {
- platform: "slack".into(),
- channel_label: source.into(),
- messages: vec![ChatMessage {
- author: "alice".into(),
- timestamp: Utc.timestamp_millis_opt(1_700_000_000_000).unwrap(),
- text: text.into(),
- source_ref: Some("slack://x".into()),
- }],
- };
- ingest_chat(cfg, source, "alice", vec![], batch)
- .await
- .expect("ingest_chat should succeed");
-}
-
-#[tokio::test]
-async fn local_branch_returns_cooccurring_evidence() {
- let (_tmp, cfg) = test_config();
- // alice + bob co-occur in one message → graph edge + both indexed on the
- // same leaf chunk.
- seed_chat(
- &cfg,
- "slack:#eng",
- "Sync between [email protected] and [email protected] on the runbook.",
- )
- .await;
- // An unrelated message that should NOT surface for the alice+bob query.
- seed_chat(
- &cfg,
- "slack:#random",
- "Lunch plans for friday with the team.",
- )
- .await;
-
- let resp = fast_retrieve(
- &cfg,
- "what did [email protected] and [email protected] discuss",
- FastRetrieveOptions::default(),
- )
- .await
- .expect("fast_retrieve should succeed");
-
- assert!(
- !resp.hits.is_empty(),
- "co-occurring entities should yield a local hit; got {resp:?}"
- );
- // Coverage score = both query entities matched the same node.
- assert!(
- resp.hits.iter().any(|h| h.score >= 2.0),
- "top local hit should have entity-coverage score >= 2; got {:?}",
- resp.hits.iter().map(|h| h.score).collect::<Vec<_>>()
- );
- // Structured evidence, not prose — every hit has a node id + content.
- assert!(resp.hits.iter().all(|h| !h.node_id.is_empty()));
-}
-
-#[tokio::test]
-async fn global_branch_handles_entity_free_query() {
- let (_tmp, cfg) = test_config();
- seed_chat(
- &cfg,
- "slack:#eng",
- "Sync between [email protected] and [email protected] on the runbook.",
- )
- .await;
-
- // No mechanical entities in the query → global/dense branch. With the inert
- // embedder this returns recency-ordered summaries (possibly empty), and
- // crucially must not panic or error.
- let resp = fast_retrieve(
- &cfg,
- "give me a recap of everything important",
- FastRetrieveOptions::default(),
- )
- .await
- .expect("global branch should succeed");
- // total/truncated are well-formed regardless of hit count.
- assert_eq!(resp.truncated, resp.total > resp.hits.len());
-}
-
-#[tokio::test]
-async fn empty_store_returns_no_hits() {
- let (_tmp, cfg) = test_config();
- let resp = fast_retrieve(&cfg, "anything at all", FastRetrieveOptions::default())
- .await
- .expect("retrieval over empty store should succeed");
- assert!(resp.hits.is_empty());
- assert_eq!(resp.total, 0);
-}
diff --git a/tests/memory_golden_fixture_e2e.rs b/tests/memory_golden_fixture_e2e.rs
deleted file mode 100644
index 9df1941344..0000000000
--- a/tests/memory_golden_fixture_e2e.rs
+++ /dev/null
@@ -1,421 +0,0 @@
-//! Golden-workspace schema gate — the fixture-based replacement for the
-//! subset-of-table-names check in `memory_golden_parity_e2e.rs`.
-//!
-//! # What this protects
-//!
-//! A memory-store schema change that reshapes, renames, or drops a table,
-//! index, or trigger strands every existing user workspace. This suite is the
-//! thing that fails first.
-//!
-//! # How it works
-//!
-//! `tests/fixtures/memory_golden/workspace/**.db` is a **real workspace,
-//! captured from a real build** (see that directory's `README.md` for the SHA).
-//! `manifest.txt` beside it is **derived from those DB files** by
-//! `memory::store_golden::schema_manifest`, never hand-written.
-//!
-//! ## The ordering rule — read this before "fixing" a failure
-//!
-//! The old harness could be defeated by a two-line diff: rename a table in
-//! `namespace_store/init.rs`, edit the matching `&'static [&str]` constant,
-//! green. That cannot work here. The manifest is compared against a manifest
-//! **recomputed from the committed `.db` files**, which were written by an
-//! older binary. Editing the DDL and the manifest together still fails,
-//! because the fixture has not moved. The only way to make this green is to
-//! run the regenerator (below), which rewrites the `.db` blobs — a visible,
-//! reviewable act that a reviewer can see in the diff.
-//!
-//! **This is the gate's weakest joint, and a test cannot fully close it.** An
-//! author who regenerates the fixture in the same commit as the schema change
-//! gets green again. The complementary control is a review rule: *a diff that
-//! touches `tests/fixtures/memory_golden/` must be accompanied by an explicit
-//! migration story for existing workspaces.* Treat a fixture change as a
-//! schema-migration review, not a test-data refresh.
-//!
-//! ## Regenerating
-//!
-//! ```bash
-//! scripts/regen-memory-golden-fixture.sh
-//! ```
-//!
-//! Run with: `cargo test --test memory_golden_fixture_e2e`
-
-use std::collections::BTreeSet;
-use std::path::{Path, PathBuf};
-use std::sync::{Arc, Mutex, OnceLock};
-
-use tempfile::tempdir;
-
-// The fixture seeder is a module of THIS test target, not of the library.
-// It used to be `openhuman::memory::store_golden`, declared `pub mod` and so
-// compiled into the shipped binary — seven `tinymemory_core::` references that
-// kept the engine crate in the product dependency graph purely to seed a
-// fixture (#5560).
-#[path = "support/memory_golden.rs"]
-mod golden;
-
-// ── Fixture layout ───────────────────────────────────────────────────────────
-
-/// Env var the second-process reopen check reads its workspace from.
-const SECOND_PROCESS_WS_ENV: &str = "OPENHUMAN_GOLDEN_FIXTURE_SECOND_PROCESS_WS";
-
-fn fixture_root() -> PathBuf {
- Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/memory_golden")
-}
-
-fn fixture_workspace() -> PathBuf {
- fixture_root().join("workspace")
-}
-
-fn manifest_path() -> PathBuf {
- fixture_root().join("manifest.txt")
-}
-
-/// Copy the committed fixture into `dest`.
-///
-/// Every test works on a copy: SQLite writes to the file it opens (WAL, hot
-/// journal, `PRAGMA user_version`), so touching the committed original would
-/// dirty the working tree and silently rewrite the very thing under test.
-fn copy_fixture_to(dest: &Path) {
- fn copy_dir(from: &Path, to: &Path) {
- std::fs::create_dir_all(to).expect("create fixture copy dir");
- for entry in std::fs::read_dir(from).expect("read fixture dir").flatten() {
- let path = entry.path();
- let target = to.join(entry.file_name());
- if path.is_dir() {
- copy_dir(&path, &target);
- } else {
- std::fs::copy(&path, &target).expect("copy fixture file");
- }
- }
- }
- let src = fixture_workspace();
- assert!(
- src.is_dir(),
- "golden fixture workspace missing at {} — regenerate with \
- scripts/regen-memory-golden-fixture.sh",
- src.display()
- );
- copy_dir(&src, dest);
- eprintln!("[golden-fixture] copied fixture to {}", dest.display());
-}
-
-// ── Env isolation (mirrors memory_roundtrip_e2e / memory_golden_parity_e2e) ──
-
-struct EnvVarGuard {
- key: &'static str,
- old: Option<String>,
-}
-
-impl EnvVarGuard {
- fn set_to_path(key: &'static str, path: &Path) -> Self {
- let old = std::env::var(key).ok();
- // SAFETY: only used under env_lock(), which serialises env mutation.
- unsafe { std::env::set_var(key, path.as_os_str()) };
- Self { key, old }
- }
-}
-
-impl Drop for EnvVarGuard {
- fn drop(&mut self) {
- match &self.old {
- // SAFETY: see set_to_path; teardown runs under the same env_lock().
- Some(v) => unsafe { std::env::set_var(self.key, v) },
- None => unsafe { std::env::remove_var(self.key) },
- }
- }
-}
-
-static ENV_LOCK: OnceLock<Mutex<()>> = OnceLock::new();
-static MEMORY_SEAMS_INIT: OnceLock<()> = OnceLock::new();
-
-fn env_lock() -> std::sync::MutexGuard<'static, ()> {
- ENV_LOCK
- .get_or_init(|| Mutex::new(()))
- .lock()
- .expect("env lock poisoned")
-}
-
-/// This integration target binds the transport-independent global memory
-/// client directly, so it must provide the same host seams that normal core
-/// startup installs before opening memory stores.
-fn ensure_memory_seams(workspace: &Path) {
- MEMORY_SEAMS_INIT.get_or_init(|| {
- let workspace = workspace.to_path_buf();
- std::thread::Builder::new()
- .name("memory-golden-fixture-seams".to_string())
- .stack_size(8 * 1024 * 1024)
- .spawn(move || {
- let config = Arc::new(openhuman_core::openhuman::config::Config {
- workspace_dir: workspace.clone(),
- action_dir: workspace.clone(),
- config_path: workspace.join("config.toml"),
- ..openhuman_core::openhuman::config::Config::default()
- });
- #[cfg(feature = "modules")]
- openhuman_core::openhuman::modules::memory::set_modules_policy(config);
- })
- .expect("spawn golden fixture memory seam installer")
- .join()
- .expect("golden fixture memory seam installer panicked");
- });
-}
-
-// ── Assertions ───────────────────────────────────────────────────────────────
-
-/// Compare two manifests for **set equality**, reporting what is missing and
-/// what is extra. A subset check is what made the old harness vacuous.
-fn assert_manifest_set_equal(expected: &BTreeSet<String>, actual: &BTreeSet<String>) {
- let missing: Vec<&String> = expected.difference(actual).collect();
- let extra: Vec<&String> = actual.difference(expected).collect();
- assert!(
- missing.is_empty() && extra.is_empty(),
- "golden workspace schema drifted from the committed manifest.\n\
- \n\
- MISSING ({} object(s) the fixture has that the code no longer produces):\n{}\n\
- \n\
- UNEXPECTED ({} object(s) the code produces that the fixture does not have):\n{}\n\
- \n\
- If this is an intentional schema change you must ALSO have a migration \
- for existing user workspaces, and you must regenerate the fixture with \
- scripts/regen-memory-golden-fixture.sh. Editing manifest.txt alone will \
- not make this pass.",
- missing.len(),
- missing
- .iter()
- .map(|line| format!(" - {line}"))
- .collect::<Vec<_>>()
- .join("\n"),
- extra.len(),
- extra
- .iter()
- .map(|line| format!(" + {line}"))
- .collect::<Vec<_>>()
- .join("\n"),
- );
-}
-
-fn committed_manifest() -> BTreeSet<String> {
- let path = manifest_path();
- let text = std::fs::read_to_string(&path).unwrap_or_else(|e| {
- panic!(
- "cannot read committed manifest {}: {e} — regenerate with \
- scripts/regen-memory-golden-fixture.sh",
- path.display()
- )
- });
- let manifest = golden::parse_manifest(&text);
- assert!(
- !manifest.is_empty(),
- "committed manifest {} is empty",
- path.display()
- );
- manifest
-}
-
-// ── Tests ────────────────────────────────────────────────────────────────────
-
-/// Gate 1 — the committed fixture's on-disk schema still matches the committed
-/// manifest, object for object.
-///
-/// Touches no process globals, so it can run alongside anything.
-#[test]
-fn golden_fixture_schema_matches_the_committed_manifest() {
- let tmp = tempdir().expect("tempdir");
- let workspace = tmp.path().join("workspace");
- copy_fixture_to(&workspace);
-
- let actual = golden::schema_manifest(&workspace).expect("dump fixture schema");
- eprintln!(
- "[golden-fixture] fixture holds {} schema objects",
- actual.len()
- );
- assert_manifest_set_equal(&committed_manifest(), &actual);
-}
-
-/// Gate 2 — a **fresh** workspace built by the current code has exactly the
-/// schema the fixture captured.
-///
-/// Gate 3 reopens the committed fixture, which cannot see an *in-place*
-/// redefinition: `CREATE TABLE / INDEX / TRIGGER IF NOT EXISTS` is a no-op
-/// against a DB that already holds the name, so changing an existing object's
-/// definition leaves an old workspace untouched. A fresh DB takes the new DDL,
-/// so this half catches exactly that edit.
-///
-/// Touches no process globals.
-#[tokio::test]
-async fn fresh_workspace_schema_matches_the_committed_manifest() {
- let tmp = tempdir().expect("tempdir");
- let workspace = tmp.path().join("workspace");
- golden::init_fresh_schema(&workspace)
- .await
- .expect("initialise a fresh workspace schema");
-
- let actual = golden::schema_manifest(&workspace).expect("dump fresh schema");
- eprintln!(
- "[golden-fixture] fresh workspace holds {} schema objects",
- actual.len()
- );
- assert_manifest_set_equal(&committed_manifest(), &actual);
-}
-
-/// Spawn this same test binary to run [`second_process_readback`] against
-/// `workspace`, and fail loudly with its output if it does not pass.
-fn run_second_process_readback(workspace: &Path) {
- let exe = std::env::current_exe().expect("current test binary path");
- eprintln!(
- "[golden-fixture] reopening {} in a second process ({})",
- workspace.display(),
- exe.display()
- );
- let output = std::process::Command::new(exe)
- .args([
- "--exact",
- "second_process_readback",
- "--ignored",
- "--nocapture",
- "--test-threads=1",
- ])
- .env(SECOND_PROCESS_WS_ENV, workspace)
- .env("OPENHUMAN_WORKSPACE", workspace)
- .output()
- .expect("spawn second-process reopen check");
- assert!(
- output.status.success(),
- "second-process reopen of the golden workspace failed ({})\n\
- --- stdout ---\n{}\n--- stderr ---\n{}",
- output.status,
- String::from_utf8_lossy(&output.stdout),
- String::from_utf8_lossy(&output.stderr),
- );
-}
-
-/// The second half of the close-and-reopen check. `#[ignore]` because it is
-/// only meaningful when [`run_second_process_readback`] launches it with
-/// `SECOND_PROCESS_WS_ENV` set; it is not a standalone test.
-#[tokio::test]
-#[ignore = "spawned as a child process by golden_fixture_rows_read_back_and_schema_is_stable_after_reopen"]
-async fn second_process_readback() {
- let Ok(workspace) = std::env::var(SECOND_PROCESS_WS_ENV) else {
- panic!("{SECOND_PROCESS_WS_ENV} not set — this test is spawned, not run directly");
- };
- let workspace = PathBuf::from(workspace);
- ensure_memory_seams(&workspace);
- eprintln!("[golden-fixture][child] reopening {}", workspace.display());
-
- tinymemory_core::global::init(workspace.clone())
- .expect("bind global memory client in the child process");
- let readback = golden::read_back(&workspace)
- .await
- .expect("read the golden workspace back in a second process");
-
- assert_eq!(
- readback.primary_doc_keys,
- vec![golden::DOC_KEY_PRIMARY.to_string()],
- "document did not survive close-and-reopen in a second process"
- );
- assert!(
- readback.embeddings_match,
- "embeddings did not survive close-and-reopen in a second process"
- );
- assert!(
- readback.tree_sealed,
- "summary tree seal did not survive close-and-reopen in a second process"
- );
- eprintln!("[golden-fixture][child] reopen check passed");
-}
-
-/// Delete everything under `dir` that is not a `*.db` file.
-///
-/// SQLite recreates `-shm` / `-wal` siblings whenever a DB is opened, even
-/// read-only. They are process-local state, so the fixture must not carry them.
-fn prune_non_db_files(dir: &Path) {
- let Ok(entries) = std::fs::read_dir(dir) else {
- return;
- };
- for entry in entries.flatten() {
- let path = entry.path();
- if path.is_dir() {
- prune_non_db_files(&path);
- } else if path.extension().and_then(|e| e.to_str()) != Some("db") {
- eprintln!("[golden-fixture][regen] pruning {}", path.display());
- let _ = std::fs::remove_file(&path);
- }
- }
-}
-
-/// Regenerate the committed fixture and its manifest from the **current**
-/// build.
-///
-/// `#[ignore]` so it never runs in CI — running it is the deliberate act that
-/// re-baselines the gate. Invoke via `scripts/regen-memory-golden-fixture.sh`.
-#[tokio::test]
-#[ignore = "regenerates the committed golden fixture; run via scripts/regen-memory-golden-fixture.sh"]
-async fn regenerate_golden_fixture() {
- let _lock = env_lock();
- let tmp = tempdir().expect("tempdir");
- let _home = EnvVarGuard::set_to_path("HOME", tmp.path());
- let staging = tmp.path().join("workspace");
- std::fs::create_dir_all(&staging).expect("create staging workspace");
- let _ws = EnvVarGuard::set_to_path("OPENHUMAN_WORKSPACE", &staging);
- ensure_memory_seams(&staging);
-
- tinymemory_core::global::init(staging.clone())
- .expect("bind global memory client to the staging workspace");
- golden::seed(&staging).await.expect("seed golden workspace");
-
- // Fold the WAL back into the main DB and compact, so the committed blob is
- // a single self-contained file with no `-wal` / `-shm` siblings.
- for db in golden::db_files(&staging) {
- let conn = rusqlite::Connection::open(&db).expect("open seeded db for compaction");
- conn.pragma_update(None, "wal_checkpoint", "TRUNCATE")
- .expect("wal_checkpoint(TRUNCATE)");
- conn.execute_batch("VACUUM;").expect("VACUUM");
- drop(conn);
- eprintln!("[golden-fixture][regen] compacted {}", db.display());
- }
-
- // Publish: only the `.db` files, so stray `-wal` / `-shm` / markdown
- // sidecars never enter the fixture.
- let target = fixture_workspace();
- if target.exists() {
- std::fs::remove_dir_all(&target).expect("clear previous fixture workspace");
- }
- let mut total = 0u64;
- for db in golden::db_files(&staging) {
- let relative = db.strip_prefix(&staging).expect("db under staging");
- let dest = target.join(relative);
- std::fs::create_dir_all(dest.parent().expect("db has a parent"))
- .expect("create fixture dir");
- std::fs::copy(&db, &dest).expect("publish db into the fixture");
- total += std::fs::metadata(&dest).expect("stat published db").len();
- }
-
- let manifest = golden::schema_manifest(&target).expect("derive manifest from the fixture");
- let header = format!(
- "# GENERATED — do not hand-edit.\n\
- # Derived from tests/fixtures/memory_golden/workspace/**.db by\n\
- # memory::store_golden::schema_manifest. Regenerate both together with\n\
- # scripts/regen-memory-golden-fixture.sh.\n\
- # {} schema objects across {} db file(s).\n",
- manifest.len(),
- golden::db_files(&target).len()
- );
- std::fs::write(
- manifest_path(),
- format!("{header}{}", golden::render_manifest(&manifest)),
- )
- .expect("write manifest");
-
- // Dumping the manifest opened each DB, which recreates `-shm` / `-wal`
- // siblings. Those are transient SQLite state, not fixture content, and
- // committing them would make the fixture non-reproducible.
- prune_non_db_files(&target);
-
- eprintln!(
- "[golden-fixture][regen] wrote {} bytes of fixture and {} manifest objects to {}",
- total,
- manifest.len(),
- fixture_root().display()
- );
-}
diff --git a/tests/memory_golden_parity_e2e.rs b/tests/memory_golden_parity_e2e.rs
deleted file mode 100644
index 2cd17229bb..0000000000
--- a/tests/memory_golden_parity_e2e.rs
+++ /dev/null
@@ -1,455 +0,0 @@
-//! Layer-2 golden-workspace schema-parity harness (migration spec §0.3, parity
-//! checklist "Layer 2").
-//!
-//! The Layer-1 asserters (`src/openhuman/tinycortex/parity.rs`) pin pure on-disk
-//! *format* contracts (chunk ids, vector encoding, vault paths, signatures).
-//! This is the Layer-2 **differential** guard: it stands up a real workspace
-//! through the host's production memory surface (`memory::ops`) and asserts that
-//! the two schema tiers that share the workspace **compose** correctly —
-//!
-//! 1. the **crate-owned substrate** the `tinycortex` chunk DB creates
-//! (`init_db` → `chunks/schema.rs`), and
-//! 2. the **host-retained `UnifiedMemory` namespace-document tier**
-//! (`memory_store/namespace_store/*`),
-//!
-//! coexisting without collision (parity checklist P3/P5/P11/P12 — the W3 gate).
-//! A store/tree cutover that reshaped, renamed, or dropped a table would strand
-//! an existing user workspace; this fails here first.
-//!
-//! Design notes:
-//! - **Path-agnostic.** It recursively scans *every* `*.db` under the temp
-//! workspace and unions their tables, so it does not care whether the tiers
-//! live in one DB file or several, nor exactly where the host client roots
-//! them.
-//! - The crate chunk-DB init is additionally forced via
-//! `tinycortex::memory::chunks::with_connection` so the substrate schema is
-//! deterministic regardless of which subsystems the op flow happened to touch.
-//! - The crate KV tier (`kv_global` / `kv_namespace`, crate `store/kv.rs`)
-//! attaches to the host `UnifiedMemory` connection via
-//! `KvStore::from_shared_connection`. These two table *names* are pinned as
-//! [`CRATE_KV_TABLES`], but a name-presence check alone is **not** a cutover
-//! guard: the host `UnifiedMemory::new` (`namespace_store/init.rs`) also
-//! `CREATE TABLE IF NOT EXISTS`es both names unconditionally on every workspace
-//! open, so the names would survive even if the crate KV store cut over to
-//! differently-named tables and stranded a user's persisted preferences. The
-//! real guard is therefore **functional**: [`assert_crate_kv_interop`] drives
-//! the production KV surface (`memory::ops::kv_{set,get}`, crate-backed via
-//! `KvStore::from_shared_connection`) for the global and namespace scopes,
-//! asserts the value round-trips, and asserts via read-only SQL that the write
-//! physically landed in the pinned `kv_global` / `kv_namespace` tables. A
-//! cutover that renamed or dropped the crate KV tables strands the write
-//! outside the pinned names and fails here.
-//! - The standalone `VectorStore` tables (`vectors` / `store_meta`, crate
-//! `store/vectors/store.rs`) are deliberately **not** pinned: nothing on the
-//! host's live path opens that store — `VectorStore::open` has no non-test
-//! caller in either the crate or the host, and the live embedding path instead
-//! uses `mem_tree_chunk_embeddings` (crate substrate) plus the host
-//! `vector_chunks` tier — so those tables never appear in a real workspace.
-//! Pinning them would assert schema the shipped product never creates. Add
-//! them here only if the host ever wires the standalone vector store onto a
-//! workspace.
-//!
-//! **Superseded as the schema gate by `memory_golden_fixture_e2e`.** The table
-//! checks here are *subset* assertions over hardcoded name constants, so a
-//! rename in `namespace_store/init.rs` plus a matching edit to the constant
-//! below passes green, and indexes / triggers / columns / row data are not
-//! asserted at all. What still earns this file its place is
-//! [`assert_crate_kv_interop`] — a functional check no schema dump can replace.
-//! Treat the name constants as documentation, not as a gate.
-//!
-//! Run with: `cargo test --test memory_golden_parity_e2e`
-
-use std::collections::BTreeSet;
-use std::path::{Path, PathBuf};
-use std::sync::{Arc, Mutex, OnceLock};
-
-use tempfile::tempdir;
-
-use openhuman_core::openhuman::config::Config;
-use openhuman_core::openhuman::memory::ops::{
- doc_put, kv_get, kv_set, memory_recall_context, memory_recall_memories, KvGetDeleteParams,
- KvSetParams, PutDocParams,
-};
-use openhuman_core::openhuman::memory::rpc_models::{RecallContextRequest, RecallMemoriesRequest};
-use tinymemory_core::tinycortex::memory_config_from;
-
-// ── Env isolation (mirrors memory_roundtrip_e2e) ─────────────────────────────
-
-struct EnvVarGuard {
- key: &'static str,
- old: Option<String>,
-}
-
-impl EnvVarGuard {
- fn set_to_path(key: &'static str, path: &Path) -> Self {
- let old = std::env::var(key).ok();
- // SAFETY: only used under env_lock(), which serialises env mutation.
- unsafe { std::env::set_var(key, path.as_os_str()) };
- Self { key, old }
- }
-}
-
-impl Drop for EnvVarGuard {
- fn drop(&mut self) {
- match &self.old {
- // SAFETY: see set_to_path; teardown runs under the same env_lock().
- Some(v) => unsafe { std::env::set_var(self.key, v) },
- None => unsafe { std::env::remove_var(self.key) },
- }
- }
-}
-
-/// Serialises tests: `HOME` + `OPENHUMAN_WORKSPACE` are process-global.
-static ENV_LOCK: OnceLock<Mutex<()>> = OnceLock::new();
-static MEMORY_SEAMS_INIT: OnceLock<()> = OnceLock::new();
-
-fn env_lock() -> std::sync::MutexGuard<'static, ()> {
- ENV_LOCK
- .get_or_init(|| Mutex::new(()))
- .lock()
- .expect("env lock poisoned")
-}
-
-/// This target calls the memory operations directly rather than through a core
-/// runtime, so install the host seams that normal startup wires first.
-fn ensure_memory_seams(workspace: &Path) {
- MEMORY_SEAMS_INIT.get_or_init(|| {
- let workspace = workspace.to_path_buf();
- std::thread::Builder::new()
- .name("memory-golden-parity-seams".to_string())
- .stack_size(8 * 1024 * 1024)
- .spawn(move || {
- let config = Arc::new(Config {
- workspace_dir: workspace.clone(),
- action_dir: workspace.clone(),
- config_path: workspace.join("config.toml"),
- ..Config::default()
- });
- #[cfg(feature = "modules")]
- openhuman_core::openhuman::modules::memory::set_modules_policy(config);
- })
- .expect("spawn golden parity memory seam installer")
- .join()
- .expect("golden parity memory seam installer panicked");
- });
-}
-
-// ── Expected schema tiers (authoritative names from the two engines) ─────────
-
-/// The crate chunk-DB substrate created by `init_db` (`chunks/schema.rs`). These
-/// are the tables the tinycortex store owns and must preserve byte-for-byte
-/// across every W3+ cutover.
-const CRATE_CHUNK_SCHEMA_TABLES: &[&str] = &[
- "mem_tree_chunks",
- "mem_tree_chunk_embeddings",
- "mem_tree_chunk_reembed_skipped",
- "mem_tree_score",
- "mem_tree_entity_index",
- "mem_tree_entity_edges",
- "mem_tree_trees",
- "mem_tree_summaries",
- "mem_tree_summary_embeddings",
- "mem_tree_summary_reembed_skipped",
- "mem_tree_buffers",
- "mem_tree_entity_hotness",
- "mem_tree_jobs",
- "mem_tree_ingested_sources",
- "mcp_writes",
-];
-
-/// The host-retained `UnifiedMemory` namespace-document tier
-/// (`memory_store/namespace_store/*`) — stays host, coexists in the shared workspace.
-const HOST_UNIFIED_TABLES: &[&str] = &[
- "memory_docs",
- "graph_global",
- "graph_namespace",
- "episodic_log",
- "event_log",
- "event_embeddings",
- "conversation_segments",
- "segment_embeddings",
- "vector_chunks",
- "user_profile",
-];
-
-/// The crate KV tier (`kv_global` + `kv_namespace`, crate `store/kv.rs`) that
-/// rides the host `UnifiedMemory` connection via `KvStore::from_shared_connection`.
-/// These names are the *targets* the production KV write path must land in;
-/// [`assert_crate_kv_interop`] is what proves it does. The harness guards against
-/// these tables being **renamed or dropped** by the crate KV store — not against
-/// arbitrary in-place schema reshaping (a column/index change that preserves the
-/// names and the `key` / `value_json` columns the API reads would still pass).
-const CRATE_KV_TABLES: &[&str] = &["kv_global", "kv_namespace"];
-
-// ── Schema scan helpers (path-agnostic, read-only) ───────────────────────────
-
-fn collect_db_files(dir: &Path, out: &mut Vec<PathBuf>) {
- let Ok(entries) = std::fs::read_dir(dir) else {
- return;
- };
- for entry in entries.flatten() {
- let path = entry.path();
- if path.is_dir() {
- collect_db_files(&path, out);
- } else if path.extension().and_then(|e| e.to_str()) == Some("db") {
- out.push(path);
- }
- }
-}
-
-/// Union of every user table across every `*.db` under `ws` (read-only opens;
-/// SQLite-internal `sqlite_%` tables excluded).
-fn tables_in_workspace(ws: &Path) -> BTreeSet<String> {
- let mut dbs = Vec::new();
- collect_db_files(ws, &mut dbs);
-
- let mut tables = BTreeSet::new();
- for db in dbs {
- let Ok(conn) =
- rusqlite::Connection::open_with_flags(&db, rusqlite::OpenFlags::SQLITE_OPEN_READ_ONLY)
- else {
- continue;
- };
- let Ok(mut stmt) = conn.prepare(
- "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'",
- ) else {
- continue;
- };
- let Ok(rows) = stmt.query_map([], |row| row.get::<_, String>(0)) else {
- continue;
- };
- for name in rows.flatten() {
- tables.insert(name);
- }
- }
- tables
-}
-
-/// Read-only: does any `*.db` under `ws` hold a row keyed `key` in `table`?
-///
-/// Used to prove that a production KV write physically landed in a *pinned* table
-/// name rather than one the crate KV store may have cut over to. `table` and
-/// `key` are harness constants (never external input), so the interpolated
-/// `table` name carries no injection surface. A missing table or unreadable DB
-/// counts as "not present" and the scan moves on.
-fn kv_row_present(ws: &Path, table: &str, key: &str) -> bool {
- let mut dbs = Vec::new();
- collect_db_files(ws, &mut dbs);
- for db in dbs {
- let Ok(conn) =
- rusqlite::Connection::open_with_flags(&db, rusqlite::OpenFlags::SQLITE_OPEN_READ_ONLY)
- else {
- continue;
- };
- let sql = format!("SELECT COUNT(*) FROM \"{table}\" WHERE key = ?1");
- if let Ok(count) = conn.query_row(&sql, [key], |row| row.get::<_, i64>(0)) {
- if count > 0 {
- return true;
- }
- }
- }
- false
-}
-
-/// The crate KV tier's real cutover guard (see the module-level design note and
-/// [`CRATE_KV_TABLES`]). A name-presence check alone cannot detect a crate KV
-/// cutover because the host `UnifiedMemory::new` recreates `kv_global` /
-/// `kv_namespace` unconditionally; this instead drives the production KV surface
-/// (crate-backed via `KvStore::from_shared_connection`) for the global and
-/// namespace scopes, asserts the value round-trips, and asserts via read-only SQL
-/// that each write physically landed in the pinned tables. A cutover that renamed
-/// or dropped the crate KV tables strands the write outside the pinned names and
-/// trips one of these asserts.
-async fn assert_crate_kv_interop(workspace: &Path, namespace: &str, tables: &BTreeSet<String>) {
- eprintln!(
- "[golden-parity][kv] validating crate KV interop over pinned tables {:?}",
- CRATE_KV_TABLES
- );
-
- // Cheap coexistence pre-check: the pinned tables materialised at all.
- let missing_kv: Vec<&str> = CRATE_KV_TABLES
- .iter()
- .copied()
- .filter(|t| !tables.contains(*t))
- .collect();
- assert!(
- missing_kv.is_empty(),
- "crate KV-tier tables missing from the workspace: {missing_kv:?}; found: {tables:?}"
- );
-
- let key = "golden-parity-kv-canary";
- let value = serde_json::json!({ "pref": "golden-parity", "v": 1 });
-
- // ── Global scope: write via production kv_set, read back, prove it landed
- // in the pinned `kv_global` table. ──
- eprintln!("[golden-parity][kv] global-scope write via production kv_set");
- kv_set(KvSetParams {
- namespace: None,
- key: key.to_string(),
- value: value.clone(),
- })
- .await
- .expect("crate KV global set");
- let got_global = kv_get(KvGetDeleteParams {
- namespace: None,
- key: key.to_string(),
- })
- .await
- .expect("crate KV global get");
- assert_eq!(
- got_global.value,
- Some(value.clone()),
- "crate KV global round-trip lost the value (adapter cannot read back its own write)"
- );
- assert!(
- kv_row_present(workspace, "kv_global", key),
- "crate KV global write did not land in the pinned `kv_global` table — the KV store cut over to a differently-named table and would strand existing preferences"
- );
-
- // ── Namespace scope: same, against the pinned `kv_namespace` table. ──
- eprintln!("[golden-parity][kv] namespace-scope write via production kv_set");
- kv_set(KvSetParams {
- namespace: Some(namespace.to_string()),
- key: key.to_string(),
- value: value.clone(),
- })
- .await
- .expect("crate KV namespace set");
- let got_ns = kv_get(KvGetDeleteParams {
- namespace: Some(namespace.to_string()),
- key: key.to_string(),
- })
- .await
- .expect("crate KV namespace get");
- assert_eq!(
- got_ns.value,
- Some(value.clone()),
- "crate KV namespace round-trip lost the value (adapter cannot read back its own write)"
- );
- assert!(
- kv_row_present(workspace, "kv_namespace", key),
- "crate KV namespace write did not land in the pinned `kv_namespace` table — the KV store cut over to a differently-named table and would strand existing preferences"
- );
-
- eprintln!(
- "[golden-parity][kv] crate KV interop verified — round-trip ok and writes landed in {:?}",
- CRATE_KV_TABLES
- );
-}
-
-fn put_params(ns: &str) -> PutDocParams {
- PutDocParams {
- namespace: ns.to_string(),
- key: "golden-parity-canary".to_string(),
- title: "Golden parity canary".to_string(),
- content: "TinyCortex golden-workspace schema-parity canary fact".to_string(),
- source_type: "doc".to_string(),
- priority: "medium".to_string(),
- tags: Vec::new(),
- metadata: serde_json::Value::Null,
- category: "core".to_string(),
- session_id: None,
- document_id: None,
- }
-}
-
-/// Drive the real production surface so both schema tiers initialise, then force
-/// the crate substrate init to make the chunk-DB schema deterministic. Returns
-/// the union of tables observed across the workspace.
-async fn init_and_scan(ns: &str, workspace: &Path) -> BTreeSet<String> {
- // Host unified tier + retrieval (production path).
- doc_put(put_params(ns)).await.expect("doc_put");
- let _ = memory_recall_memories(RecallMemoriesRequest {
- namespace: ns.to_string(),
- min_retention: None,
- as_of: None,
- limit: Some(10),
- max_chunks: None,
- top_k: None,
- })
- .await
- .expect("recall_memories");
- let _ = memory_recall_context(RecallContextRequest {
- namespace: ns.to_string(),
- include_references: Some(true),
- limit: Some(10),
- max_chunks: None,
- })
- .await
- .expect("recall_context");
-
- // Force the crate chunk-DB substrate init (deterministic — creates the full
- // chunks/schema.rs table set regardless of what the ops above touched).
- let mc = memory_config_from(&Config::default(), workspace.to_path_buf());
- tinycortex::memory::chunks::with_connection(&mc, |_conn| Ok(())).expect("crate chunk-DB init");
-
- tables_in_workspace(workspace)
-}
-
-// ── Tests ────────────────────────────────────────────────────────────────────
-
-/// P3/P5/P11/P12 — the crate substrate and the host `UnifiedMemory` tier both
-/// initialise into the shared workspace without collision. Any cutover that
-/// renames/drops one of these tables fails here before it can strand a real
-/// user workspace.
-#[tokio::test]
-async fn golden_workspace_composes_substrate_and_unified_tiers() {
- let _lock = env_lock();
- let tmp = tempdir().expect("tempdir");
- let _home = EnvVarGuard::set_to_path("HOME", tmp.path());
- let workspace = tmp.path().join("workspace");
- std::fs::create_dir_all(&workspace).expect("mkdir workspace");
- let _ws = EnvVarGuard::set_to_path("OPENHUMAN_WORKSPACE", &workspace);
- ensure_memory_seams(&workspace);
-
- let tables = init_and_scan("golden-parity-e2e", &workspace).await;
-
- // Full schema dump for review / manifest capture in the test log.
- eprintln!(
- "[golden-parity] workspace tables ({}): {:?}",
- tables.len(),
- tables
- );
-
- let missing_substrate: Vec<&str> = CRATE_CHUNK_SCHEMA_TABLES
- .iter()
- .copied()
- .filter(|t| !tables.contains(*t))
- .collect();
- assert!(
- missing_substrate.is_empty(),
- "crate chunk-DB substrate tables missing from the workspace: {missing_substrate:?}; found: {tables:?}"
- );
-
- let missing_unified: Vec<&str> = HOST_UNIFIED_TABLES
- .iter()
- .copied()
- .filter(|t| !tables.contains(*t))
- .collect();
- assert!(
- missing_unified.is_empty(),
- "host UnifiedMemory tables missing from the workspace: {missing_unified:?}; found: {tables:?}"
- );
-
- // Crate KV tier: a functional interop guard, not a name-presence check.
- // (Name presence alone is satisfied by the host `UnifiedMemory::new` init and
- // cannot detect a crate KV cutover — see [`assert_crate_kv_interop`].)
- assert_crate_kv_interop(&workspace, "golden-parity-e2e", &tables).await;
-
- // Coexistence: both tiers are present in the same workspace (P12).
- assert!(
- tables.contains("mem_tree_chunks") && tables.contains("memory_docs"),
- "both the crate substrate and the host unified tier must coexist"
- );
-
- // Comparator 5 (idempotent re-open): keep this in the same test because
- // the production memory client is process-global and deliberately binds
- // to its first workspace. Separate tests with separate temp workspaces can
- // therefore pass or fail depending on test scheduling.
- let reopened = init_and_scan("golden-parity-e2e", &workspace).await;
-
- assert_eq!(
- tables, reopened,
- "re-running the flow changed the workspace table set (schema churn on re-open)"
- );
-}
diff --git a/tests/memory_graph_sync_e2e.rs b/tests/memory_graph_sync_e2e.rs
deleted file mode 100644
index a303fda213..0000000000
--- a/tests/memory_graph_sync_e2e.rs
+++ /dev/null
@@ -1,264 +0,0 @@
-//! Integration test: document ingestion → graph query pipeline.
-//!
-//! Verifies that storing a document through the memory system produces
-//! graph entities and relations that are queryable via the same APIs
-//! the UI calls.
-//!
-//! Tests are `#[ignore]` by default (slow, requires disk I/O + ingestion worker).
-//! Run explicitly:
-//! cargo test --test memory_graph_sync_e2e -- --ignored --nocapture
-
-use std::sync::Arc;
-use std::time::Duration;
-
-use serde_json::json;
-use tempfile::tempdir;
-
-use openhuman_core::openhuman::inference::embeddings::NoopEmbedding;
-use openhuman_core::openhuman::memory::NamespaceDocumentInput;
-// Engine handles and the engine's own ingest request/config named on the
-// crates that define them — `memory::MemoryIngestion{Request,Config}` are the
-// host's WIRE shapes now (`rpc_models`), a different type from what
-// `UnifiedMemory::ingest_document` takes (#5560). See the note in
-// `personality_e2e.rs`.
-use tinycortex::memory::ingest::{MemoryIngestionConfig, MemoryIngestionRequest};
-use tinymemory_core::store::{MemoryClient, UnifiedMemory};
-
-/// Test config for the heuristic-only pipeline.
-fn ci_safe_config() -> MemoryIngestionConfig {
- MemoryIngestionConfig::default()
-}
-
-/// A document with known entities that the heuristic extractor can find.
-/// Uses structured lines (Project name, Owner, etc.) that the parser
-/// recognises without requiring the ONNX model.
-const TEST_DOCUMENT: &str = "\
-Project name: Acme Corp
-Owner: Alice
-
-Alice works at Acme Corp. Bob is the CEO of Acme Corp.
-
-From: Alice <[email protected]>
-Subject: Q4 roadmap review
-
-Hi Bob, let's review the Q4 roadmap for Acme Corp next week.
-
-Decision: Ship the beta release by end of November.
-Preferred communication channel: Slack over email.
-";
-
-// ── Test: full ingest_document → graph_query_namespace ─────────────────
-
-#[tokio::test]
-#[ignore] // Slow: SQLite + ingestion pipeline. Run with --ignored.
-async fn ingest_document_populates_namespace_graph() {
- let _ = env_logger::builder()
- .filter_level(log::LevelFilter::Debug)
- .is_test(true)
- .try_init();
-
- let tmp = tempdir().expect("tempdir");
- let memory =
- UnifiedMemory::new(tmp.path(), Arc::new(NoopEmbedding), None).expect("UnifiedMemory::new");
-
- let namespace = "test-ns";
-
- let result = memory
- .ingest_document(MemoryIngestionRequest {
- document: NamespaceDocumentInput {
- namespace: namespace.to_string(),
- key: "acme-doc".to_string(),
- title: "Acme Corp team overview".to_string(),
- content: TEST_DOCUMENT.to_string(),
- source_type: "doc".to_string(),
- priority: "high".to_string(),
- tags: Vec::new(),
- metadata: json!({}),
- category: "core".to_string(),
- session_id: None,
- document_id: None,
- taint: openhuman_core::openhuman::memory::MemoryTaint::Internal,
- },
- config: ci_safe_config(),
- })
- .await
- .expect("ingest_document");
-
- eprintln!("--- Ingestion result ---");
- eprintln!(" document_id: {}", result.document_id);
- eprintln!(" namespace: {}", result.namespace);
- eprintln!(" entities: {}", result.entity_count);
- eprintln!(" relations: {}", result.relation_count);
- eprintln!(" chunks: {}", result.chunk_count);
- eprintln!(" preferences: {}", result.preference_count);
- eprintln!(" decisions: {}", result.decision_count);
-
- for entity in &result.entities {
- eprintln!(" entity: {} ({})", entity.name, entity.entity_type);
- }
- for relation in &result.relations {
- eprintln!(
- " relation: {} --[{}]--> {}",
- relation.subject, relation.predicate, relation.object
- );
- }
-
- // ── Verify entities extracted ──
- assert!(
- result.entity_count >= 2,
- "Expected at least 2 entities from heuristic extraction, got {}",
- result.entity_count
- );
-
- let entity_names: Vec<&str> = result.entities.iter().map(|e| e.name.as_str()).collect();
- eprintln!(" All entity names: {entity_names:?}");
-
- // The heuristic extractor should find ALICE and ACME CORP from the
- // structured lines.
- assert!(
- entity_names.iter().any(|n| n.contains("ALICE")),
- "Expected entity 'ALICE' among: {entity_names:?}"
- );
- assert!(
- entity_names.iter().any(|n| n.contains("ACME")),
- "Expected entity containing 'ACME' among: {entity_names:?}"
- );
-
- // ── Verify relations extracted ──
- assert!(
- result.relation_count >= 1,
- "Expected at least 1 relation, got {}",
- result.relation_count
- );
-
- // ── Verify graph is queryable via namespace ──
- let graph_rows = memory
- .graph_query_namespace(namespace, None, None)
- .await
- .expect("graph_query_namespace");
-
- eprintln!(
- "\n--- graph_query_namespace({namespace}) returned {} rows ---",
- graph_rows.len()
- );
- for row in &graph_rows {
- eprintln!(" {row}");
- }
-
- assert!(
- !graph_rows.is_empty(),
- "graph_query_namespace should return relations after ingestion"
- );
-
- // ── Verify graph_query_all also returns the namespace data ──
- let all_rows = memory
- .graph_query_all(None, None)
- .await
- .expect("graph_query_all");
-
- eprintln!("\n--- graph_query_all returned {} rows ---", all_rows.len());
-
- assert!(
- !all_rows.is_empty(),
- "graph_query_all should include namespace relations when no namespace filter is set"
- );
-
- // At minimum, the all-query should contain the same rows as namespace
- assert!(
- all_rows.len() >= graph_rows.len(),
- "graph_query_all ({}) should return at least as many rows as namespace query ({})",
- all_rows.len(),
- graph_rows.len()
- );
-}
-
-// ── Test: MemoryClient put_doc → background extraction → graph_query ──
-
-#[tokio::test]
-#[ignore] // Slow: background worker + 5s wait. Run with --ignored.
-async fn put_doc_background_extraction_then_graph_query() {
- let _ = env_logger::builder()
- .filter_level(log::LevelFilter::Debug)
- .is_test(true)
- .try_init();
-
- let tmp = tempdir().expect("tempdir");
- let workspace_dir = tmp.path().join("workspace");
- std::fs::create_dir_all(&workspace_dir).unwrap();
-
- let client = MemoryClient::from_workspace_dir(workspace_dir).expect("MemoryClient");
-
- let namespace = "test-bg";
- let doc_id = client
- .put_doc(NamespaceDocumentInput {
- namespace: namespace.to_string(),
- key: "bg-test-doc".to_string(),
- title: "Background extraction test".to_string(),
- content: TEST_DOCUMENT.to_string(),
- source_type: "doc".to_string(),
- priority: "medium".to_string(),
- tags: Vec::new(),
- metadata: json!({}),
- category: "core".to_string(),
- session_id: None,
- document_id: None,
- taint: openhuman_core::openhuman::memory::MemoryTaint::Internal,
- })
- .await
- .expect("put_doc");
-
- eprintln!("put_doc returned doc_id={doc_id}");
-
- // Wait for the background ingestion worker to process the job.
- // The worker runs on a separate tokio task; give it time to complete.
- tokio::time::sleep(Duration::from_secs(5)).await;
-
- // Query with namespace
- let ns_rows = client
- .graph_query(Some(namespace), None, None)
- .await
- .expect("graph_query with namespace");
-
- eprintln!(
- "graph_query(Some({namespace})) returned {} rows",
- ns_rows.len()
- );
-
- // Query without namespace (the fix: should include namespace data)
- let all_rows = client
- .graph_query(None, None, None)
- .await
- .expect("graph_query without namespace");
-
- eprintln!("graph_query(None) returned {} rows", all_rows.len());
-
- // The background worker uses the default config which tries to load the
- // ONNX model. On CI this may fail silently, yielding 0 relations. The
- // heuristic extractor still runs, so we usually get relations, but we
- // assert conservatively: if namespace query found rows, the all-query
- // must too.
- if !ns_rows.is_empty() {
- assert!(
- !all_rows.is_empty(),
- "graph_query(None) must return rows when graph_query(Some(ns)) does"
- );
- }
-
- // Verify document was stored regardless
- let docs = client
- .list_documents(Some(namespace))
- .await
- .expect("list_documents");
- let doc_count = docs
- .get("documents")
- .and_then(|d| d.as_array())
- .map(|a| a.len())
- .unwrap_or(0);
-
- eprintln!("Documents in namespace '{namespace}': {doc_count}");
- assert!(
- doc_count >= 1,
- "Expected at least 1 document after put_doc, got {doc_count}"
- );
-}
diff --git a/tests/memory_tree_summarizer_e2e.rs b/tests/memory_tree_summarizer_e2e.rs
deleted file mode 100644
index eeb4cb625d..0000000000
--- a/tests/memory_tree_summarizer_e2e.rs
+++ /dev/null
@@ -1,588 +0,0 @@
-//! E2E tests for the tree summarizer engine.
-//!
-//! Calls `engine::run_summarization` directly with a mock LLM provider so the
-//! full ingest → summarize → propagate chain is exercised without needing a
-//! running Ollama process. Three scenarios are covered:
-//!
-//! 1. `builds_hour_day_month_year_chain` — ingest chunks across two distinct
-//! hours, run the summarizer, and assert the full hour→day→month→year→root
-//! node chain is written.
-//!
-//! 2. `merges_into_existing_hour_node` — run the summarizer twice for the
-//! same hour and confirm `created_at` is preserved while `updated_at`
-//! advances and the summary reflects both passes.
-//!
-//! 3. `survives_llm_error_with_partial_progress` — program the mock so the
-//! second LLM call returns an error; assert the first hour node was
-//! written, the second was not, and the engine surfaces the error without
-//! panicking.
-//!
-//! Run with: `bash scripts/test-rust-with-mock.sh --test memory_tree_summarizer_e2e`
-//!
-//! The mock HTTP server is started by `scripts/test-rust-with-mock.sh` and its
-//! URL is available in `BACKEND_URL` / `MOCK_API_PORT`.
-
-use std::path::Path;
-use std::sync::{Arc, Mutex, OnceLock};
-use std::time::Duration;
-
-use async_trait::async_trait;
-use chrono::{DateTime, TimeZone, Utc};
-use tempfile::tempdir;
-
-use openhuman_core::openhuman::config::Config;
-// The host's `tree_runtime` re-export of these two engine modules is gone
-// (#5560): the RPC surface goes through the contract's runtime-tree doors, and
-// the fold itself is the driver's. This target still drives the engine
-// directly, so it names the engine crate — which is what the sibling
-// `memory::tree` globs' tests already do.
-use tinyinference::model::{ChatModel, ModelRequest, ModelResponse};
-use tinyinference::Error as TinyAgentsError;
-use tinymemory_core::tree::tree_runtime::{engine, store};
-
-// ── Env isolation ─────────────────────────────────────────────────────────
-
-struct EnvVarGuard {
- key: &'static str,
- old: Option<String>,
-}
-
-impl EnvVarGuard {
- fn set_to_path(key: &'static str, path: &Path) -> Self {
- let old = std::env::var(key).ok();
- // SAFETY: guarded by ENV_LOCK which serialises process-global env mutations.
- unsafe { std::env::set_var(key, path.as_os_str()) };
- Self { key, old }
- }
-}
-
-impl Drop for EnvVarGuard {
- fn drop(&mut self) {
- match &self.old {
- // SAFETY: symmetric teardown under the same ENV_LOCK guard.
- Some(v) => unsafe { std::env::set_var(self.key, v) },
- None => unsafe { std::env::remove_var(self.key) },
- }
- }
-}
-
-/// Serialise tests: `HOME` and `OPENHUMAN_WORKSPACE` are process-global.
-static ENV_LOCK: OnceLock<Mutex<()>> = OnceLock::new();
-
-fn env_lock() -> std::sync::MutexGuard<'static, ()> {
- let m = ENV_LOCK.get_or_init(|| Mutex::new(()));
- match m.lock() {
- Ok(g) => g,
- Err(p) => p.into_inner(),
- }
-}
-
-// ── Mock provider helpers ─────────────────────────────────────────────────
-
-/// A provider whose `invoke` returns scripted responses in order.
-/// Thread-safe via a `Mutex<VecDeque>`. Each pop returns the next scripted
-/// response; once the queue is exhausted, every subsequent call returns an
-/// error so missing a setup step is caught immediately.
-struct ScriptedProvider {
- responses: Arc<Mutex<std::collections::VecDeque<Result<String, String>>>>,
- call_count: Arc<Mutex<usize>>,
-}
-
-impl ScriptedProvider {
- fn new(responses: Vec<Result<String, String>>) -> Self {
- log::debug!(
- "[memory_tree_summarizer_e2e] ScriptedProvider created with {} responses",
- responses.len()
- );
- Self {
- responses: Arc::new(Mutex::new(responses.into())),
- call_count: Arc::new(Mutex::new(0)),
- }
- }
-
- fn call_count(&self) -> usize {
- *self.call_count.lock().expect("call_count lock")
- }
-}
-
-#[async_trait]
-impl ChatModel<()> for ScriptedProvider {
- async fn invoke(
- &self,
- _state: &(),
- request: ModelRequest,
- ) -> tinyinference::Result<ModelResponse> {
- let mut count = self.call_count.lock().expect("call_count lock");
- *count += 1;
- let call_n = *count;
- drop(count);
-
- let message_len: usize = request
- .messages
- .iter()
- .map(|message| format!("{message:?}").len())
- .sum();
- log::debug!(
- "[memory_tree_summarizer_e2e] ScriptedProvider.invoke call #{call_n}: \
- model={:?} message_count={} msg_len={}",
- request.model,
- request.messages.len(),
- message_len
- );
-
- let mut q = self.responses.lock().expect("responses lock");
- match q.pop_front() {
- Some(Ok(text)) => {
- log::debug!(
- "[memory_tree_summarizer_e2e] call #{call_n} → scripted Ok ({} chars)",
- text.len()
- );
- Ok(ModelResponse::assistant(text))
- }
- Some(Err(msg)) => {
- log::debug!("[memory_tree_summarizer_e2e] call #{call_n} → scripted Err: {msg}");
- Err(TinyAgentsError::Model(msg))
- }
- None => {
- log::debug!(
- "[memory_tree_summarizer_e2e] call #{call_n} → queue exhausted (fallback error)"
- );
- Err(TinyAgentsError::Model(format!(
- "ScriptedProvider queue exhausted at call #{call_n}"
- )))
- }
- }
- }
-}
-
-// ── Config builder ────────────────────────────────────────────────────────
-
-/// Build a minimal `Config` rooted at `workspace_path`.
-/// `local_ai.runtime_enabled` is irrelevant because we bypass `create_provider`
-/// and pass our own `ScriptedProvider` directly.
-fn build_config(workspace_path: &Path) -> Config {
- Config {
- workspace_dir: workspace_path.to_path_buf(),
- ..Config::default()
- }
-}
-
-/// Return a fixed test timestamp anchored to 2026-03-15T14:xx UTC.
-/// We use explicit timestamps so buffer filenames are deterministic and
-/// the hour_id derived from them matches our assertions.
-fn ts_hour14() -> DateTime<Utc> {
- Utc.with_ymd_and_hms(2026, 3, 15, 14, 5, 0)
- .single()
- .expect("valid ts_hour14")
-}
-
-fn ts_hour15() -> DateTime<Utc> {
- Utc.with_ymd_and_hms(2026, 3, 15, 15, 10, 0)
- .single()
- .expect("valid ts_hour15")
-}
-
-const NS: &str = "e2e-summarizer-test";
-
-// ── Tests ─────────────────────────────────────────────────────────────────
-
-/// Ingest content for two distinct hours, run the summarizer, and assert the
-/// full chain of nodes (hour × 2, day, month, year, root) is written.
-/// The mock provider returns per-hour summaries short enough that upper levels
-/// fit within their token budgets without an additional LLM call — only the
-/// two hour-leaf summarizations trigger LLM calls.
-#[tokio::test]
-async fn builds_hour_day_month_year_chain() {
- let _lock = env_lock();
- let tmp = tempdir().expect("tempdir");
- let workspace = tmp.path().join("ws");
- std::fs::create_dir_all(&workspace).expect("create workspace");
-
- let _home = EnvVarGuard::set_to_path("HOME", tmp.path());
- let _ws = EnvVarGuard::set_to_path("OPENHUMAN_WORKSPACE", &workspace);
-
- log::debug!("[memory_tree_summarizer_e2e] builds_hour_day_month_year_chain: start");
-
- let config = build_config(&workspace);
-
- // Ingest 3 chunks: 2 for hour-14, 1 for hour-15.
- store::buffer_write(
- &config,
- NS,
- "Slack: discussed deployment timeline with team",
- &ts_hour14(),
- None,
- )
- .expect("buffer_write hour14 chunk1");
-
- store::buffer_write(
- &config,
- NS,
- "Slack: follow-up on deployment blockers",
- &ts_hour14(),
- None,
- )
- .expect("buffer_write hour14 chunk2");
-
- store::buffer_write(
- &config,
- NS,
- "Reviewed PR for infrastructure changes",
- &ts_hour15(),
- None,
- )
- .expect("buffer_write hour15 chunk1");
-
- // Provider: 2 LLM calls expected — one per hour leaf.
- // The hour summaries are short enough that day/month/year/root fit within
- // token budget and do NOT trigger additional LLM calls (propagate_node
- // short-circuits when combined children text fits the level budget).
- let provider = Arc::new(ScriptedProvider::new(vec![
- Ok("User discussed deployment timeline".to_string()),
- Ok("Reviewed infrastructure PR".to_string()),
- ]));
-
- log::debug!("[memory_tree_summarizer_e2e] running summarization");
- let result = engine::run_summarization(&config, provider.as_ref(), NS, Utc::now()).await;
-
- log::debug!(
- "[memory_tree_summarizer_e2e] run_summarization returned: {:?}",
- result
- .as_ref()
- .map(|n| n.as_ref().map(|node| &node.node_id))
- );
- assert!(
- result.is_ok(),
- "run_summarization should succeed: {:?}",
- result
- );
- let last_node = result.unwrap();
- assert!(last_node.is_some(), "should return a last hour node");
- let last_node = last_node.unwrap();
- log::debug!(
- "[memory_tree_summarizer_e2e] last hour node: {} level={:?}",
- last_node.node_id,
- last_node.level
- );
-
- // Assert both hour leaves exist.
- let hour14_id = "2026/03/15/14";
- let hour15_id = "2026/03/15/15";
-
- let node14 = store::read_node(&config, NS, hour14_id)
- .expect("read_node hour14")
- .expect("hour14 node must exist");
- log::debug!(
- "[memory_tree_summarizer_e2e] hour14 summary: {}",
- node14.summary
- );
- assert!(
- node14.summary.contains("deployment"),
- "hour14 summary should contain 'deployment', got: {}",
- node14.summary
- );
-
- let node15 = store::read_node(&config, NS, hour15_id)
- .expect("read_node hour15")
- .expect("hour15 node must exist");
- log::debug!(
- "[memory_tree_summarizer_e2e] hour15 summary: {}",
- node15.summary
- );
- assert!(
- node15.summary.contains("infrastructure") || node15.summary.contains("PR"),
- "hour15 summary should contain 'infrastructure' or 'PR', got: {}",
- node15.summary
- );
-
- // Assert day node was propagated.
- let day_id = "2026/03/15";
- let day_node = store::read_node(&config, NS, day_id)
- .expect("read_node day")
- .expect("day node must exist after propagation");
- log::debug!(
- "[memory_tree_summarizer_e2e] day node summary len={}",
- day_node.summary.len()
- );
- assert!(
- !day_node.summary.is_empty(),
- "day summary should not be empty"
- );
-
- // Assert month node.
- let month_id = "2026/03";
- let month_node = store::read_node(&config, NS, month_id)
- .expect("read_node month")
- .expect("month node must exist after propagation");
- assert!(
- !month_node.summary.is_empty(),
- "month summary should not be empty"
- );
-
- // Assert year node.
- let year_id = "2026";
- let year_node = store::read_node(&config, NS, year_id)
- .expect("read_node year")
- .expect("year node must exist after propagation");
- assert!(
- !year_node.summary.is_empty(),
- "year summary should not be empty"
- );
-
- // Assert root node.
- let root_node = store::read_node(&config, NS, "root")
- .expect("read_node root")
- .expect("root node must exist after propagation");
- assert!(
- !root_node.summary.is_empty(),
- "root summary should not be empty"
- );
-
- // Exactly 2 LLM calls: one per hour leaf.
- assert_eq!(
- provider.call_count(),
- 2,
- "expected exactly 2 LLM calls (one per hour leaf)"
- );
-
- // Buffer should be drained after successful summarization.
- let remaining = store::buffer_read(&config, NS).expect("buffer_read post-run");
- assert!(
- remaining.is_empty(),
- "buffer should be empty after successful run, got {} entries",
- remaining.len()
- );
-
- log::debug!("[memory_tree_summarizer_e2e] builds_hour_day_month_year_chain: PASS");
-}
-
-/// Run the summarizer twice for the same hour. Verify:
-/// - `created_at` is preserved from the first run.
-/// - `updated_at` is strictly greater after the second run.
-/// - The merged summary contains keywords from both passes.
-#[tokio::test]
-async fn merges_into_existing_hour_node() {
- let _lock = env_lock();
- let tmp = tempdir().expect("tempdir");
- let workspace = tmp.path().join("ws");
- std::fs::create_dir_all(&workspace).expect("create workspace");
-
- let _home = EnvVarGuard::set_to_path("HOME", tmp.path());
- let _ws = EnvVarGuard::set_to_path("OPENHUMAN_WORKSPACE", &workspace);
-
- log::debug!("[memory_tree_summarizer_e2e] merges_into_existing_hour_node: start");
-
- let config = build_config(&workspace);
-
- // --- First run: ingest and summarize hour-14. ---
- store::buffer_write(
- &config,
- NS,
- "Discussed deployment timeline on slack",
- &ts_hour14(),
- None,
- )
- .expect("buffer_write pass1");
-
- let provider1 = ScriptedProvider::new(vec![Ok(
- "First-run summary: deployment timeline discussed".to_string(),
- )]);
-
- log::debug!("[memory_tree_summarizer_e2e] first run");
- let r1 = engine::run_summarization(&config, &provider1, NS, Utc::now())
- .await
- .expect("first run_summarization");
- assert!(r1.is_some(), "first run should yield a node");
-
- let hour14_id = "2026/03/15/14";
- let node_after_first = store::read_node(&config, NS, hour14_id)
- .expect("read node after first run")
- .expect("hour14 must exist after first run");
-
- let created_at_first = node_after_first.created_at;
- let updated_at_first = node_after_first.updated_at;
- log::debug!(
- "[memory_tree_summarizer_e2e] after first run: created_at={} updated_at={}",
- created_at_first,
- updated_at_first
- );
-
- // Small sleep so the second updated_at is strictly greater.
- tokio::time::sleep(Duration::from_millis(50)).await;
-
- // --- Second run: ingest more content for the same hour-14. ---
- store::buffer_write(
- &config,
- NS,
- "Follow-up on deployment blockers",
- &ts_hour14(),
- None,
- )
- .expect("buffer_write pass2");
-
- let provider2 = ScriptedProvider::new(vec![Ok(
- "Merged summary: deployment timeline and blockers".to_string(),
- )]);
-
- log::debug!("[memory_tree_summarizer_e2e] second run (same hour)");
- let r2 = engine::run_summarization(&config, &provider2, NS, Utc::now())
- .await
- .expect("second run_summarization");
- assert!(r2.is_some(), "second run should yield a node");
-
- let node_after_second = store::read_node(&config, NS, hour14_id)
- .expect("read node after second run")
- .expect("hour14 must exist after second run");
-
- let created_at_second = node_after_second.created_at;
- let updated_at_second = node_after_second.updated_at;
- log::debug!(
- "[memory_tree_summarizer_e2e] after second run: created_at={} updated_at={}",
- created_at_second,
- updated_at_second
- );
-
- // `created_at` must be preserved.
- assert_eq!(
- created_at_first, created_at_second,
- "created_at must be preserved across merges"
- );
-
- // `updated_at` must advance (or at worst stay equal if clocks are too coarse).
- assert!(
- updated_at_second >= updated_at_first,
- "updated_at must not go backward: first={updated_at_first} second={updated_at_second}"
- );
-
- // Summary must reflect the merge (the scripted response contains "blockers").
- assert!(
- node_after_second.summary.contains("blockers")
- || node_after_second.summary.contains("Merged"),
- "merged summary should reflect second pass content, got: {}",
- node_after_second.summary
- );
-
- log::debug!("[memory_tree_summarizer_e2e] merges_into_existing_hour_node: PASS");
-}
-
-/// Program the provider so the SECOND LLM call returns an error.
-/// Ingest two hours' worth of content and run the summarizer.
-///
-/// Expected behaviour:
-/// - The first hour leaf is successfully written before the error.
-/// - The error propagates out of `run_summarization` as an `Err`.
-/// - The process does NOT panic.
-/// - Because the buffer is only deleted after ALL hour leaves are written,
-/// the buffer entries are NOT deleted (the second hour's content persists).
-#[tokio::test]
-async fn survives_llm_error_with_partial_progress() {
- let _lock = env_lock();
- let tmp = tempdir().expect("tempdir");
- let workspace = tmp.path().join("ws");
- std::fs::create_dir_all(&workspace).expect("create workspace");
-
- let _home = EnvVarGuard::set_to_path("HOME", tmp.path());
- let _ws = EnvVarGuard::set_to_path("OPENHUMAN_WORKSPACE", &workspace);
-
- log::debug!("[memory_tree_summarizer_e2e] survives_llm_error_with_partial_progress: start");
-
- let config = build_config(&workspace);
-
- // Ingest content for two distinct hours so two LLM calls are required.
- store::buffer_write(
- &config,
- NS,
- "Hour-14 content: deployment planning",
- &ts_hour14(),
- None,
- )
- .expect("buffer_write hour14");
-
- store::buffer_write(
- &config,
- NS,
- "Hour-15 content: infrastructure review",
- &ts_hour15(),
- None,
- )
- .expect("buffer_write hour15");
-
- // Provider: call 1 succeeds, call 2 returns an error.
- let provider = Arc::new(ScriptedProvider::new(vec![
- Ok("Hour-14 summary: deployment planning in progress".to_string()),
- Err("boom: simulated LLM failure on second call".to_string()),
- ]));
-
- log::debug!("[memory_tree_summarizer_e2e] running summarization expecting partial failure");
- let result = engine::run_summarization(&config, provider.as_ref(), NS, Utc::now()).await;
-
- log::debug!(
- "[memory_tree_summarizer_e2e] run_summarization result: is_ok={}",
- result.is_ok()
- );
-
- // The engine must return an error — not panic.
- assert!(
- result.is_err(),
- "expected Err from run_summarization when second LLM call fails, got: {:?}",
- result
- );
- let err = result.unwrap_err();
- log::debug!(
- "[memory_tree_summarizer_e2e] propagated error (as expected): {:#}",
- err
- );
- // Use the full anyhow error chain (alternating display) so nested context
- // layers — e.g. "summarize hour leaf: LLM summarization failed: boom: …" —
- // are all visible in the assertion.
- let err_chain = format!("{err:#}");
- assert!(
- err_chain.contains("boom") || err_chain.contains("LLM summarization failed"),
- "error message should mention the LLM failure, got: {err_chain}"
- );
-
- // Exactly 2 LLM calls were made.
- assert_eq!(
- provider.call_count(),
- 2,
- "expected 2 LLM calls (1 success + 1 error)"
- );
-
- // The first hour leaf (hour-14) was written before the error.
- // The engine writes hour leaves as it goes; the second fails before writing.
- // Note: the exact behaviour depends on which hour is processed first
- // (BTreeMap ordering: "2026/03/15/14" < "2026/03/15/15"), so hour-14 is first.
- let hour14_id = "2026/03/15/14";
- let node14 = store::read_node(&config, NS, hour14_id).expect("read_node hour14");
- assert!(
- node14.is_some(),
- "hour-14 leaf must be written before the error on hour-15"
- );
- log::debug!(
- "[memory_tree_summarizer_e2e] hour14 node present: summary={}",
- node14.unwrap().summary
- );
-
- // The second hour node (hour-15) was NOT written because the LLM call failed.
- let hour15_id = "2026/03/15/15";
- let node15 = store::read_node(&config, NS, hour15_id).expect("read_node hour15");
- assert!(
- node15.is_none(),
- "hour-15 leaf must NOT exist when its LLM call failed"
- );
-
- // The buffer must NOT be drained — the engine only deletes buffer entries
- // after all hour leaves are successfully written. A partial failure means
- // the buffer retains its entries so the next run can retry.
- let remaining = store::buffer_read(&config, NS).expect("buffer_read post-error");
- assert!(
- !remaining.is_empty(),
- "buffer must not be drained after a partial failure, but it is empty"
- );
- log::debug!(
- "[memory_tree_summarizer_e2e] {} buffer entries remain (expected > 0)",
- remaining.len()
- );
-
- log::debug!("[memory_tree_summarizer_e2e] survives_llm_error_with_partial_progress: PASS");
-}
diff --git a/tests/ollama_embeddings_fallback_e2e.rs b/tests/ollama_embeddings_fallback_e2e.rs
deleted file mode 100644
index 79fe663c53..0000000000
--- a/tests/ollama_embeddings_fallback_e2e.rs
+++ /dev/null
@@ -1,250 +0,0 @@
-//! Integration tests for the Local Ollama embeddings health-gate to cloud
-//! fallback (PR #1555).
-//!
-//! Covers three scenarios exercised via the public API of
-//! `openhuman_core::openhuman::memory`:
-//!
-//! 1. Local embeddings enabled + Ollama unreachable → falls back to cloud
-//! provider with the correct cloud model dimensions.
-//! 2. Local embeddings enabled + Ollama healthy → stays on local provider.
-//! 3. Local embeddings DISABLED → cloud settings unchanged
-//! regardless of Ollama state.
-//!
-//! `probe_ollama_reachable` and the once-per-process health-gate latch are
-//! `pub(crate)`-private; the tests drive the observable behaviour through
-//! `effective_embedding_settings` (sync, for scenario 3) and
-//! `effective_embedding_settings_probed` (async, for scenarios 1–2), both of
-//! which are `pub` and re-exported at `openhuman_core::openhuman::memory`.
-//!
-//! Run with: `cargo test --test ollama_embeddings_fallback_e2e`
-
-use std::net::SocketAddr;
-use std::sync::{Arc, Mutex, OnceLock};
-
-use axum::{routing::get, Json, Router};
-
-use openhuman_core::openhuman::config::{Config, MemoryConfig};
-use openhuman_core::openhuman::inference::embeddings::{
- DEFAULT_CLOUD_EMBEDDING_DIMENSIONS, DEFAULT_CLOUD_EMBEDDING_MODEL, DEFAULT_OLLAMA_DIMENSIONS,
- DEFAULT_OLLAMA_MODEL,
-};
-use tinymemory_core::store::factories::{
- effective_embedding_settings, effective_embedding_settings_probed,
-};
-
-// ── Env isolation ─────────────────────────────────────────────────────────────
-
-/// Serialises all tests in this file: `OPENHUMAN_OLLAMA_BASE_URL` is a
-/// process-global env var that the production code reads at call time, so
-/// concurrent mutation across tests would produce non-deterministic results.
-static ENV_LOCK: OnceLock<Mutex<()>> = OnceLock::new();
-static MEMORY_SEAMS_INIT: OnceLock<()> = OnceLock::new();
-
-fn ensure_memory_seams() {
- MEMORY_SEAMS_INIT.get_or_init(|| {
- std::thread::Builder::new()
- .name("ollama-embeddings-fallback-e2e-seams".to_string())
- .stack_size(8 * 1024 * 1024)
- .spawn(|| {
- })
- .expect("spawn ollama embeddings seam installer")
- .join()
- .expect("ollama embeddings seam installer panicked");
- });
-}
-
-fn env_lock() -> std::sync::MutexGuard<'static, ()> {
- ENV_LOCK
- .get_or_init(|| Mutex::new(()))
- .lock()
- .unwrap_or_else(|p| p.into_inner())
-}
-
-/// RAII guard: sets `OPENHUMAN_OLLAMA_BASE_URL` while the lock is held and
-/// restores (or removes) the original value on drop.
-struct OllamaUrlGuard {
- _lock: std::sync::MutexGuard<'static, ()>,
- prev: Option<String>,
-}
-
-impl OllamaUrlGuard {
- fn set(url: &str) -> Self {
- let lock = env_lock();
- let prev = std::env::var("OPENHUMAN_OLLAMA_BASE_URL").ok();
- // SAFETY: guarded by ENV_LOCK — no concurrent env mutation in this test binary.
- unsafe { std::env::set_var("OPENHUMAN_OLLAMA_BASE_URL", url) };
- Self { _lock: lock, prev }
- }
-}
-
-impl Drop for OllamaUrlGuard {
- fn drop(&mut self) {
- // SAFETY: same guard justification as OllamaUrlGuard::set.
- match self.prev.take() {
- Some(v) => unsafe { std::env::set_var("OPENHUMAN_OLLAMA_BASE_URL", v) },
- None => unsafe { std::env::remove_var("OPENHUMAN_OLLAMA_BASE_URL") },
- }
- }
-}
-
-// ── Mock Ollama helper ────────────────────────────────────────────────────────
-
-/// Spawns a minimal Axum server that mimics the Ollama `/api/tags` endpoint
-/// (200 OK + JSON body). Returns the base URL, e.g. `"http://127.0.0.1:NNNNN"`.
-async fn start_mock_ollama_200() -> String {
- let app = Router::new().route(
- "/api/tags",
- get(|| async { Json(serde_json::json!({ "models": [] })) }),
- );
- let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
- let addr: SocketAddr = listener.local_addr().unwrap();
- tokio::spawn(async move {
- axum::serve(listener, app).await.unwrap();
- });
- format!("http://127.0.0.1:{}", addr.port())
-}
-
-// ── Scenario 1: opted-in, Ollama unreachable → cloud fallback ────────────────
-
-/// Port 1 on loopback is always refused on all supported platforms.
-const UNREACHABLE_URL: &str = "http://127.0.0.1:1";
-
-/// Scenario 1: local embeddings enabled + Ollama unreachable.
-///
-/// Verifies:
-/// - effective provider flips to `"cloud"`.
-/// - cloud model and dimensions match the well-known defaults.
-/// - the diagnostic branch is exercised (the gate fires at most once
-/// per process, but the fallback outcome is observable every call).
-#[tokio::test]
-async fn local_embeddings_enabled_ollama_unreachable_falls_back_to_cloud() {
- ensure_memory_seams();
- let _env = OllamaUrlGuard::set(UNREACHABLE_URL);
-
- let mem = MemoryConfig::default();
- // Pass the default Ollama model name as `local_embedding_model` —
- // same as `Config::workload_local_model("embeddings")` would when the
- // `local_ai.usage.embeddings` flag is set.
- let local_model = DEFAULT_OLLAMA_MODEL;
-
- let (provider, model, dims) =
- effective_embedding_settings_probed(&mem, Some(local_model)).await;
-
- assert_eq!(
- provider, "cloud",
- "opted-in local embeddings with unreachable Ollama must fall back to cloud provider"
- );
- assert_eq!(
- model, DEFAULT_CLOUD_EMBEDDING_MODEL,
- "fallback must use the canonical cloud embedding model"
- );
- assert_eq!(
- dims, DEFAULT_CLOUD_EMBEDDING_DIMENSIONS,
- "fallback dimensions must match the canonical cloud embedding dimensions"
- );
-}
-
-// ── Scenario 2: opted-in, Ollama healthy → stays on local provider ───────────
-
-/// Scenario 2: local embeddings enabled + Ollama daemon responds 200 OK.
-///
-/// Verifies:
-/// - effective provider remains `"ollama"`.
-/// - dimensions are the Ollama default (not the cloud default).
-#[tokio::test]
-async fn local_embeddings_enabled_ollama_healthy_stays_on_local_provider() {
- ensure_memory_seams();
- let mock_url = start_mock_ollama_200().await;
- let _env = OllamaUrlGuard::set(&mock_url);
-
- let mem = MemoryConfig::default();
- let local_model = DEFAULT_OLLAMA_MODEL;
-
- let (provider, model, dims) =
- effective_embedding_settings_probed(&mem, Some(local_model)).await;
-
- assert_eq!(
- provider, "ollama",
- "healthy Ollama must keep the local provider; got provider={provider} model={model} dims={dims}"
- );
- assert_eq!(
- dims, DEFAULT_OLLAMA_DIMENSIONS,
- "local provider must use Ollama default dimensions, not cloud defaults"
- );
- assert_ne!(
- provider, "cloud",
- "healthy Ollama must not fall back to cloud"
- );
-}
-
-// ── Scenario 3: local embeddings DISABLED → cloud unchanged ──────────────────
-
-/// Scenario 3a: no local-AI opt-in → the probed function keeps cloud settings
-/// without touching Ollama at all (the probe is skipped when intended provider
-/// is already `"cloud"`).
-#[tokio::test]
-async fn local_embeddings_disabled_probed_keeps_cloud_settings() {
- // We deliberately point the URL at an unreachable host to prove that the
- // probe is never issued on this path — if it were, the test would still
- // pass due to fallback, but using an obviously-bad URL makes the intent
- // explicit: Ollama state is irrelevant when local embeddings are off.
- let _env = OllamaUrlGuard::set(UNREACHABLE_URL);
-
- let mem = MemoryConfig::default(); // embedding_provider = "cloud" by default
- let (provider, _, _) = effective_embedding_settings_probed(&mem, None).await;
-
- assert_eq!(
- provider, "cloud",
- "with no local-AI opt-in the probed variant must keep the cloud provider"
- );
-}
-
-/// Scenario 3b: synchronous variant — `effective_embedding_settings` (the
-/// *intended*, non-probed selection) also keeps the MemoryConfig values when
-/// `local_embedding_model` is `None`, regardless of Ollama state.
-#[test]
-fn local_embeddings_disabled_sync_keeps_memory_config_settings() {
- let mut mem = MemoryConfig::default();
- mem.embedding_provider = "cloud".to_string();
- mem.embedding_model = DEFAULT_CLOUD_EMBEDDING_MODEL.to_string();
- mem.embedding_dimensions = DEFAULT_CLOUD_EMBEDDING_DIMENSIONS;
-
- // None = local embeddings not opted in.
- let (provider, model, dims) = effective_embedding_settings(&mem, None);
-
- assert_eq!(
- provider, "cloud",
- "sync selection with no opt-in must honour MemoryConfig.embedding_provider"
- );
- assert_eq!(
- model, DEFAULT_CLOUD_EMBEDDING_MODEL,
- "sync selection must honour MemoryConfig.embedding_model"
- );
- assert_eq!(
- dims, DEFAULT_CLOUD_EMBEDDING_DIMENSIONS,
- "sync selection must honour MemoryConfig.embedding_dimensions"
- );
-}
-
-/// Scenario 3c: Ollama health state is irrelevant when local embeddings are
-/// disabled — even with a custom `MemoryConfig` that names a cloud-like
-/// provider, the output must match the config as-is (no Ollama probe).
-#[tokio::test]
-async fn local_embeddings_disabled_custom_config_untouched() {
- let _env = OllamaUrlGuard::set(UNREACHABLE_URL);
-
- let mut mem = MemoryConfig::default();
- mem.embedding_provider = "openai".to_string();
- mem.embedding_model = "text-embedding-3-small".to_string();
- mem.embedding_dimensions = 1536;
-
- // local_embedding_model = None → probed variant must return the config as-is.
- let (provider, model, dims) = effective_embedding_settings_probed(&mem, None).await;
-
- assert_eq!(provider, "openai");
- assert_eq!(model, "text-embedding-3-small");
- assert_eq!(
- dims, 1536,
- "custom cloud dimensions must pass through unchanged"
- );
-}
diff --git a/tests/personality_e2e.rs b/tests/personality_e2e.rs
index ba40e2401a..3c14e7e0e2 100644
--- a/tests/personality_e2e.rs
+++ b/tests/personality_e2e.rs
@@ -42,7 +42,6 @@ use openhuman_core::openhuman::memory::NamespaceDocumentInput;
// callers that no longer exist (#5560). This note is about `UnifiedMemory`
// alone — the conversation store above is host code again as of #5560 and is
// reached through the memory module's surface like any other host type.
-use tinymemory_core::store::UnifiedMemory;
// ─────────────────────────────────────────────────────────────────────────────
// Test helpers
@@ -241,138 +240,6 @@ fn default_profile_memory_suffix_cannot_be_overridden() {
// 2. Memory isolation
// ─────────────────────────────────────────────────────────────────────────────
-#[tokio::test]
-async fn two_personalities_have_isolated_sqlite_stores() {
- let tmp = tempdir().expect("tempdir");
-
- let mem_default = UnifiedMemory::new_with_memory_dir(
- tmp.path(),
- &memory_subdir_for_suffix(""),
- Arc::new(NoopEmbedding),
- None,
- )
- .expect("default memory");
- let mem_alice = UnifiedMemory::new_with_memory_dir(
- tmp.path(),
- &memory_subdir_for_suffix("-1"),
- Arc::new(NoopEmbedding),
- None,
- )
- .expect("alice memory");
-
- assert_ne!(mem_default.db_path(), mem_alice.db_path());
- assert!(mem_default.db_path().ends_with("memory/memory.db"));
- assert!(mem_alice.db_path().ends_with("memory-1/memory.db"));
- assert!(mem_default.db_path().exists());
- assert!(mem_alice.db_path().exists());
-
- mem_default
- .upsert_document(NamespaceDocumentInput {
- namespace: "shared".to_string(),
- key: "default-only".to_string(),
- title: "Default's note".to_string(),
- content: "Only the default agent knows about this.".to_string(),
- source_type: "doc".to_string(),
- priority: "high".to_string(),
- tags: vec![],
- metadata: json!({}),
- category: "core".to_string(),
- session_id: None,
- document_id: None,
- taint: openhuman_core::openhuman::memory::MemoryTaint::Internal,
- })
- .await
- .expect("write default");
-
- mem_alice
- .upsert_document(NamespaceDocumentInput {
- namespace: "shared".to_string(),
- key: "alice-only".to_string(),
- title: "Alice's note".to_string(),
- content: "Only Alice knows about this.".to_string(),
- source_type: "doc".to_string(),
- priority: "high".to_string(),
- tags: vec![],
- metadata: json!({}),
- category: "core".to_string(),
- session_id: None,
- document_id: None,
- taint: openhuman_core::openhuman::memory::MemoryTaint::Internal,
- })
- .await
- .expect("write alice");
-
- let default_hits = mem_default
- .query_namespace_ranked("shared", "note", 10)
- .await
- .expect("default query");
- let alice_hits = mem_alice
- .query_namespace_ranked("shared", "note", 10)
- .await
- .expect("alice query");
-
- let default_keys: Vec<_> = default_hits.iter().map(|h| h.key.as_str()).collect();
- let alice_keys: Vec<_> = alice_hits.iter().map(|h| h.key.as_str()).collect();
-
- assert!(
- default_keys.contains(&"default-only"),
- "default sees its own doc"
- );
- assert!(
- !default_keys.contains(&"alice-only"),
- "default must NOT see alice's doc"
- );
- assert!(alice_keys.contains(&"alice-only"), "alice sees her own doc");
- assert!(
- !alice_keys.contains(&"default-only"),
- "alice must NOT see default's doc"
- );
-}
-
-#[tokio::test]
-async fn personality_memory_persists_across_reopens() {
- let tmp = tempdir().expect("tempdir");
-
- {
- let mem = UnifiedMemory::new_with_memory_dir(
- tmp.path(),
- &memory_subdir_for_suffix("-1"),
- Arc::new(NoopEmbedding),
- None,
- )
- .expect("open 1");
- mem.upsert_document(NamespaceDocumentInput {
- namespace: "alice".to_string(),
- key: "persistent".to_string(),
- title: "Persistent note".to_string(),
- content: "This must survive a reopen.".to_string(),
- source_type: "doc".to_string(),
- priority: "high".to_string(),
- tags: vec![],
- metadata: json!({}),
- category: "core".to_string(),
- session_id: None,
- document_id: None,
- taint: openhuman_core::openhuman::memory::MemoryTaint::Internal,
- })
- .await
- .expect("write");
- }
-
- let mem2 = UnifiedMemory::new_with_memory_dir(
- tmp.path(),
- &memory_subdir_for_suffix("-1"),
- Arc::new(NoopEmbedding),
- None,
- )
- .expect("reopen");
- let hits = mem2
- .query_namespace_ranked("alice", "persistent", 10)
- .await
- .expect("query");
- assert!(hits.iter().any(|h| h.key == "persistent"));
-}
-
// ─────────────────────────────────────────────────────────────────────────────
// 3. Personality file resolution
// ─────────────────────────────────────────────────────────────────────────────
diff --git a/tests/raw_coverage/agent_archivist_debug_round21_raw_coverage_e2e.rs b/tests/raw_coverage/agent_archivist_debug_round21_raw_coverage_e2e.rs
deleted file mode 100644
index 9bbd587c14..0000000000
--- a/tests/raw_coverage/agent_archivist_debug_round21_raw_coverage_e2e.rs
+++ /dev/null
@@ -1,503 +0,0 @@
-use anyhow::Result;
-use async_trait::async_trait;
-use openhuman_core::openhuman::agent::debug::{
- dump_agent_prompt, write_prompt_dumps, DumpPromptOptions, DumpedPrompt,
-};
-use openhuman_core::openhuman::agent::harness::archivist::ArchivistHook;
-use openhuman_core::openhuman::agent::harness::{
- run_subagent, with_parent_context, AgentDefinition, DefinitionSource, ModelSpec,
- ParentExecutionContext, PromptSource, SandboxMode, SubagentRunError, SubagentRunOptions,
- ToolScope,
-};
-use openhuman_core::openhuman::agent::hooks::{PostTurnHook, ToolCallRecord, TurnContext};
-use openhuman_core::openhuman::config::AgentConfig;
-use openhuman_core::openhuman::agent::context::prompt::ToolCallFormat;
-use openhuman_core::openhuman::memory::{
- Memory, MemoryCategory, MemoryEntry, NamespaceSummary, RecallOpts,
-};
-use openhuman_core::openhuman::memory::api::provider::MemoryProvider;
-// Raw assertion reads against the engine the provider wraps — see the note in
-// `archivist_tests.rs`: production writes through the provider, the proof that
-// a row landed reads the store directly.
-use tinymemory_core::store::{events, fts5, profile, segments, MemoryClient};
-use tinymemory_tinycortex::engine::{EngineRuntimeConfig, TinycortexProvider};
-use openhuman_core::openhuman::inference::tokenjuice::AgentTokenjuiceCompression;
-use openhuman_core::openhuman::tools::{PermissionLevel, Tool, ToolResult};
-use parking_lot::Mutex;
-use rusqlite::Connection;
-use serde_json::json;
-use std::collections::VecDeque;
-use std::path::{Path, PathBuf};
-use std::sync::{Arc, OnceLock};
-use tempfile::TempDir;
-use tinyinference::message::{AssistantMessage, ContentBlock};
-use tinyinference::model::{ChatModel, ModelProfile, ModelRequest, ModelResponse};
-use tinyinference::tool::ToolCall;
-use tinyinference::usage::Usage;
-
-struct ScriptedModel {
- responses: Mutex<VecDeque<anyhow::Result<ModelResponse>>>,
- requests: Mutex<Vec<String>>,
-}
-
-impl ScriptedModel {
- fn new(responses: Vec<anyhow::Result<ModelResponse>>) -> Arc<Self> {
- Arc::new(Self {
- responses: Mutex::new(VecDeque::from(responses)),
- requests: Mutex::new(Vec::new()),
- })
- }
-
- fn requests(&self) -> Vec<String> {
- self.requests.lock().clone()
- }
-}
-
-#[async_trait]
-impl ChatModel<()> for ScriptedModel {
- fn profile(&self) -> Option<&ModelProfile> {
- static PROFILE: OnceLock<ModelProfile> = OnceLock::new();
- Some(PROFILE.get_or_init(|| ModelProfile {
- provider: Some("round21".to_string()),
- tool_calling: true,
- parallel_tool_calls: true,
- ..ModelProfile::default()
- }))
- }
-
- async fn invoke(
- &self,
- _state: &(),
- request: ModelRequest,
- ) -> tinyinference::Result<ModelResponse> {
- self.requests.lock().push(
- request
- .messages
- .iter()
- .map(|message| format!("{message:?}:{}", message.text()))
- .collect::<Vec<_>>()
- .join("\n"),
- );
- self.responses
- .lock()
- .pop_front()
- .unwrap_or_else(|| Ok(text_response("fallback final")))
- .map_err(|error| tinyinference::Error::Model(error.to_string()))
- }
-}
-
-struct StubMemory;
-
-#[async_trait]
-impl Memory for StubMemory {
- fn name(&self) -> &str {
- "round21-memory"
- }
-
- async fn store(
- &self,
- _namespace: &str,
- _key: &str,
- _content: &str,
- _category: MemoryCategory,
- _session_id: Option<&str>,
- ) -> Result<()> {
- Ok(())
- }
-
- async fn recall(
- &self,
- _query: &str,
- _limit: usize,
- _opts: RecallOpts<'_>,
- ) -> Result<Vec<MemoryEntry>> {
- Ok(Vec::new())
- }
-
- async fn get(&self, _namespace: &str, _key: &str) -> Result<Option<MemoryEntry>> {
- Ok(None)
- }
-
- async fn list(
- &self,
- _namespace: Option<&str>,
- _category: Option<&MemoryCategory>,
- _session_id: Option<&str>,
- ) -> Result<Vec<MemoryEntry>> {
- Ok(Vec::new())
- }
-
- async fn forget(&self, _namespace: &str, _key: &str) -> Result<bool> {
- Ok(false)
- }
-
- async fn namespace_summaries(&self) -> Result<Vec<NamespaceSummary>> {
- Ok(Vec::new())
- }
-
- async fn count(&self) -> Result<usize> {
- Ok(0)
- }
-
- async fn health_check(&self) -> bool {
- true
- }
-}
-
-struct EchoTool;
-
-#[async_trait]
-impl Tool for EchoTool {
- fn name(&self) -> &str {
- "echo"
- }
-
- fn description(&self) -> &str {
- "Deterministic round21 echo"
- }
-
- fn parameters_schema(&self) -> serde_json::Value {
- json!({
- "type": "object",
- "properties": {
- "message": { "type": "string" }
- }
- })
- }
-
- async fn execute(&self, args: serde_json::Value) -> Result<ToolResult> {
- Ok(ToolResult::success(format!("echo:{args}")))
- }
-
- fn permission_level(&self) -> PermissionLevel {
- PermissionLevel::None
- }
-}
-
-/// A real TinyCortex provider over a fresh workspace, with the engine client
-/// kept for raw assertion reads. Same fixture shape as `archivist_tests.rs`.
-fn setup_provider() -> (TempDir, Arc<MemoryClient>, Arc<dyn MemoryProvider>) {
- // The cfg(test)-only installer is out of reach for an external test
- // target; the public boot-shaped seam does the same job here.
- let tmp = TempDir::new().expect("tempdir");
- let workspace = tmp.path().join("ws");
- std::fs::create_dir_all(&workspace).expect("workspace dir");
- let client =
- Arc::new(MemoryClient::from_workspace_dir(workspace.clone()).expect("engine client"));
- let config = EngineRuntimeConfig {
- workspace_dir: workspace.clone(),
- config_path: workspace.join("config.toml"),
- memory: Default::default(),
- memory_tree: Default::default(),
- scheduler_gate: Default::default(),
- local_ai: Default::default(),
- embeddings_provider: None,
- memory_provider: None,
- default_model: None,
- default_temperature: 0.2,
- output_language: None,
- memory_sources: serde_json::Value::Null,
- memory_sync_interval_secs: None,
- composio_mode: String::new(),
- backend_api_url: String::new(),
- composio_entity_id: String::new(),
- };
- let provider: Arc<dyn MemoryProvider> = Arc::new(TinycortexProvider::new(
- "tinycortex".into(),
- config,
- Arc::clone(&client),
- ));
- (tmp, client, provider)
-}
-
-fn turn(session_id: &str, user_message: &str, assistant_response: &str) -> TurnContext {
- TurnContext {
- user_message: user_message.to_string(),
- assistant_response: assistant_response.to_string(),
- tool_calls: Vec::new(),
- turn_duration_ms: 25,
- session_id: Some(session_id.to_string()),
- agent_id: Some("round21_agent".to_string()),
- entrypoint: Some("raw-e2e".to_string()),
- iteration_count: 1,
- }
-}
-
-fn text_response(text: &str) -> ModelResponse {
- let mut usage = Usage::new(13, 5);
- usage.cache_read_tokens = 2;
- ModelResponse::assistant(text).with_usage(usage)
-}
-
-fn tool_response(name: &str, arguments: serde_json::Value) -> ModelResponse {
- ModelResponse {
- message: AssistantMessage {
- id: None,
- content: vec![
- ContentBlock::Text("calling echo".to_string()),
- ContentBlock::thinking("scripted tool use"),
- ],
- tool_calls: vec![ToolCall::new("round21-call", name, arguments)],
- usage: None,
- },
- usage: None,
- finish_reason: Some("tool_calls".to_string()),
- raw: None,
- resolved_model: None,
- continue_turn: None,
- served_from_cache: false,
- }
-}
-
-fn definition(max_iterations: usize) -> AgentDefinition {
- AgentDefinition {
- id: "round21_worker".to_string(),
- when_to_use: "round21 raw coverage".to_string(),
- display_name: Some("Round 21 Worker".to_string()),
- system_prompt: PromptSource::Inline("Round21 worker prompt".to_string()),
- omit_identity: true,
- omit_memory_context: false,
- omit_safety_preamble: true,
- omit_profile: true,
- omit_memory_md: true,
- trigger_memory_agent: Default::default(),
- model: ModelSpec::Inherit,
- temperature: 0.0,
- tools: ToolScope::Named(vec!["echo".to_string()]),
- disallowed_tools: Vec::new(),
- skill_filter: None,
- extra_tools: Vec::new(),
- max_iterations,
- iteration_policy: Default::default(),
- max_result_chars: None,
- max_turn_output_tokens: None,
- timeout_secs: None,
- sandbox_mode: SandboxMode::None,
- background: false,
- tokenjuice_compression: AgentTokenjuiceCompression::Auto,
- subagents: Vec::new(),
- delegate_name: None,
- agent_tier: Default::default(),
- source: DefinitionSource::Builtin,
- graph: Default::default(),
- }
-}
-
-fn parent_context(workspace: &Path, model: Arc<ScriptedModel>) -> ParentExecutionContext {
- let tools: Vec<Box<dyn Tool>> = vec![Box::new(EchoTool)];
- let specs = tools.iter().map(|tool| tool.spec()).collect();
- ParentExecutionContext {
- agent_definition_id: "orchestrator".into(),
- allowed_subagent_ids: [
- "test".to_string(),
- "archivist".to_string(),
- "summarizer".to_string(),
- ]
- .into_iter()
- .collect(),
- turn_model_source: openhuman_core::openhuman::agent::tinyagents::TurnModelSource::from_model(
- model,
- ),
- all_tools: Arc::new(tools),
- all_tool_specs: Arc::new(specs),
- visible_tool_names: std::collections::HashSet::new(),
- subagent_tool_ceiling_names: std::collections::HashSet::new(),
- model_name: "round21-parent-model".to_string(),
- temperature: 0.0,
- workspace_dir: workspace.to_path_buf(),
- workspace_descriptor: None,
- memory: Arc::new(StubMemory),
- agent_config: AgentConfig::default(),
- workflows: Arc::new(Vec::new()),
- memory_context: Arc::new(Some("parent memory".to_string())),
- session_id: "round21-parent-session".to_string(),
- channel: "round21-channel".to_string(),
- connected_integrations: Vec::new(),
- tool_call_format: ToolCallFormat::Native,
- session_key: "1700000000_round21_parent".to_string(),
- session_parent_prefix: None,
- on_progress: None,
- run_queue: None,
- }
-}
-
-#[tokio::test]
-async fn archivist_flush_finalizes_open_segment_and_extracts_profile_events() -> Result<()> {
- let (_tmp, client, provider) = setup_provider();
- let conn = client.profile_conn();
- let hook = ArchivistHook::new(provider.clone(), true);
- let session = "round21-archivist-session";
-
- hook.on_turn_complete(&turn(
- session,
- "I prefer concise updates. I am a maintainer based in Oakland.",
- "Noted for future replies.",
- ))
- .await?;
-
- let open_before = segments::open_segment_for_session(&conn, session)?;
- assert!(open_before.is_some());
- assert_eq!(hook.rolling_segment_recap(session).await, None);
-
- hook.flush_open_segment(session).await;
-
- assert!(segments::open_segment_for_session(&conn, session)?.is_none());
- let closed = segments::segments_by_namespace(&conn, "global", 10)?
- .into_iter()
- .find(|segment| segment.session_id == session)
- .expect("closed segment");
- assert_eq!(closed.status, segments::SegmentStatus::Summarised);
- assert!(closed.summary.as_deref().unwrap_or("").contains("prefer"));
-
- let preference_events = events::events_by_type(&conn, "global", "preference", 10)?;
- assert!(preference_events
- .iter()
- .any(|event| event.content.contains("prefer concise updates")));
- let profile_facets = profile::profile_select_all(&conn)?;
- assert!(profile_facets
- .iter()
- .any(|facet| facet.value.contains("prefer concise updates")));
- Ok(())
-}
-
-#[tokio::test]
-async fn archivist_disabled_and_unknown_session_paths_are_noops() -> Result<()> {
- let (_tmp, client, provider) = setup_provider();
- let conn = client.profile_conn();
- let disabled = ArchivistHook::disabled();
- assert_eq!(disabled.name(), "archivist");
- disabled
- .on_turn_complete(&TurnContext {
- user_message: "ignored".to_string(),
- assistant_response: "ignored".to_string(),
- tool_calls: vec![ToolCallRecord {
- name: "shell".to_string(),
- arguments: json!({"cmd": "false"}),
- success: false,
- output_summary: "shell: failed (error)".to_string(),
- duration_ms: 1,
- }],
- turn_duration_ms: 1,
- session_id: None,
- agent_id: None,
- entrypoint: None,
- iteration_count: 1,
- })
- .await?;
-
- assert!(fts5::episodic_session_entries(&conn, "unknown")?.is_empty());
- let enabled = ArchivistHook::new(provider.clone(), true);
- enabled.flush_open_segment("missing-session").await;
- assert_eq!(enabled.rolling_segment_recap("missing-session").await, None);
- Ok(())
-}
-
-#[tokio::test]
-async fn subagent_no_parent_and_checkpoint_fallback_are_deterministic() -> Result<()> {
- let no_parent = run_subagent(
- &definition(1),
- "outside a parent context",
- SubagentRunOptions::default(),
- )
- .await
- .expect_err("run without parent should fail");
- assert!(matches!(no_parent, SubagentRunError::NoParentContext));
-
- let tmp = TempDir::new()?;
- let provider = ScriptedModel::new(vec![
- Ok(tool_response("echo", json!({"message": "first"}))),
- Err(anyhow::anyhow!("checkpoint model unavailable")),
- ]);
- let parent = parent_context(tmp.path(), provider.clone());
-
- let outcome = with_parent_context(parent, async {
- run_subagent(
- &definition(1),
- "use the echo tool once",
- SubagentRunOptions {
- task_id: Some("round21-task".to_string()),
- ..SubagentRunOptions::default()
- },
- )
- .await
- })
- .await?;
-
- assert_eq!(outcome.iterations, 1);
- assert!(outcome.output.contains("tool-call limit (1 steps)"));
- assert!(outcome
- .output
- .contains("echo [ok]: echo:{\"message\":\"first\"}"));
- assert!(provider
- .requests()
- .iter()
- .any(|request| request.contains("reached your tool-call limit")));
- Ok(())
-}
-
-#[tokio::test]
-async fn debug_prompt_dump_requires_toolkit_before_composio_network() -> Result<()> {
- let tmp = TempDir::new()?;
- let err = dump_agent_prompt(DumpPromptOptions {
- agent_id: "integrations_agent".to_string(),
- toolkit: None,
- workspace_dir_override: Some(tmp.path().to_path_buf()),
- model_override: Some("round21-debug-model".to_string()),
- })
- .await
- .expect_err("integrations_agent without toolkit should fail locally");
-
- assert!(err.to_string().contains("requires a `toolkit` argument"));
- let opts = DumpPromptOptions::new("orchestrator");
- assert_eq!(opts.agent_id, "orchestrator");
- assert!(opts.toolkit.is_none());
- Ok(())
-}
-
-#[test]
-fn debug_dump_writer_sanitizes_names_and_writes_summary_sidecars() -> Result<()> {
- let tmp = TempDir::new()?;
- let dumps = vec![DumpedPrompt {
- agent_id: "agent/with spaces".to_string(),
- toolkit: Some("gmail:primary".to_string()),
- mode: "session",
- model: "round21-model".to_string(),
- workspace_dir: PathBuf::from("/tmp/round21-workspace"),
- text: "SYSTEM PROMPT\n".to_string(),
- tool_names: vec!["echo".to_string(), "search".to_string()],
- tool_specs: vec![
- json!({"name": "echo", "description": "echo back", "parameters": {}}),
- json!({"name": "search", "description": "search docs", "parameters": {}}),
- ],
- skill_tool_count: 1,
- }];
-
- let summary = write_prompt_dumps(tmp.path(), &dumps)?;
- assert_eq!(
- summary.prompt_paths[0],
- tmp.path().join("1_agent_with_spaces_gmail_primary.md")
- );
- assert_eq!(
- std::fs::read_to_string(&summary.prompt_paths[0])?,
- "SYSTEM PROMPT\n"
- );
- let meta = std::fs::read_to_string(
- tmp.path()
- .join("1_agent_with_spaces_gmail_primary.meta.txt"),
- )?;
- assert!(meta.contains("agent: agent/with spaces"));
- assert!(meta.contains("toolkit: gmail:primary"));
- let summary_text = std::fs::read_to_string(summary.summary_path)?;
- assert!(summary_text.contains("agent/with spaces@gmail:primary"));
- assert!(summary_text.contains("tools=2"));
- // The per-dump tools sidecar carries the rendered tool schemas verbatim,
- // one entry per tool in `tool_names` order.
- let tools_json = std::fs::read_to_string(
- tmp.path().join("1_agent_with_spaces_gmail_primary.tools.json"),
- )?;
- let specs: Vec<serde_json::Value> = serde_json::from_str(&tools_json)?;
- assert_eq!(specs.len(), 2);
- assert_eq!(specs[0]["name"], "echo");
- assert_eq!(specs[1]["name"], "search");
- Ok(())
-}
diff --git a/tests/raw_coverage/agent_session_turn_raw_coverage_e2e.rs b/tests/raw_coverage/agent_session_turn_raw_coverage_e2e.rs
deleted file mode 100644
index 5cfbf9e715..0000000000
--- a/tests/raw_coverage/agent_session_turn_raw_coverage_e2e.rs
+++ /dev/null
@@ -1,1255 +0,0 @@
-use async_trait::async_trait;
-use openhuman_core::openhuman::agent::dispatcher::{NativeToolDispatcher, XmlToolDispatcher};
-use openhuman_core::openhuman::agent::harness::definition::AgentTier;
-use openhuman_core::openhuman::agent::harness::subagent_runner::run_subagent;
-use openhuman_core::openhuman::agent::harness::{
- with_parent_context, AgentDefinition, DefinitionSource, ModelSpec, ParentExecutionContext,
- PromptSource, SandboxMode, SubagentRunError, SubagentRunOptions, ToolScope,
-};
-use openhuman_core::openhuman::agent::hooks::{PostTurnHook, TurnContext};
-use openhuman_core::openhuman::agent::progress::AgentProgress;
-use openhuman_core::openhuman::agent::tool_policy::{
- ToolPolicy, ToolPolicyDecision, ToolPolicyRequest,
-};
-use openhuman_core::openhuman::agent::Agent;
-use openhuman_core::openhuman::config::{AgentConfig, Config, ContextConfig, MemoryConfig};
-use openhuman_core::openhuman::agent::messages::ConversationMessage;
-use openhuman_core::openhuman::memory::{
- Memory, MemoryCategory, MemoryEntry, NamespaceSummary, RecallOpts,
-};
-use tinymemory_core::store as memory_store;
-use openhuman_core::openhuman::inference::tokenjuice::AgentTokenjuiceCompression;
-use openhuman_core::openhuman::tools::traits::ToolCallOptions;
-use openhuman_core::openhuman::tools::{
- PermissionLevel, Tool, ToolContent, ToolResult, ToolScope as RuntimeToolScope,
-};
-use serde_json::json;
-use std::collections::{HashMap, HashSet, VecDeque};
-use std::path::PathBuf;
-use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
-use std::sync::{Arc, Mutex, OnceLock};
-use tempfile::TempDir;
-use tinyinference::message::{AssistantMessage, ContentBlock, Message, MessageDelta};
-use tinyinference::model::{
- ChatModel, ModelProfile, ModelRequest, ModelResponse, ModelStream, ModelStreamItem,
-};
-use tinyinference::tool::{ToolCall, ToolDelta};
-use tinyinference::usage::Usage;
-use tokio::sync::{Mutex as AsyncMutex, Notify};
-use tokio::time::{timeout, Duration};
-
-struct EnvGuard {
- key: &'static str,
- previous: Option<std::ffi::OsString>,
-}
-
-impl EnvGuard {
- fn set_path(key: &'static str, value: &std::path::Path) -> Self {
- let previous = std::env::var_os(key);
- unsafe { std::env::set_var(key, value) };
- Self { key, previous }
- }
-}
-
-impl Drop for EnvGuard {
- fn drop(&mut self) {
- match self.previous.take() {
- Some(value) => unsafe { std::env::set_var(self.key, value) },
- None => unsafe { std::env::remove_var(self.key) },
- }
- }
-}
-
-fn env_lock() -> std::sync::MutexGuard<'static, ()> {
- static LOCK: &std::sync::OnceLock<std::sync::Mutex<()>> = &crate::SHARED_ENV_LOCK;
- LOCK.get_or_init(|| std::sync::Mutex::new(()))
- .lock()
- .unwrap_or_else(|e| e.into_inner())
-}
-
-static MEMORY_SEAMS_INIT: OnceLock<()> = OnceLock::new();
-
-fn ensure_memory_seams() {
- MEMORY_SEAMS_INIT.get_or_init(|| {
- std::thread::Builder::new()
- .name("agent-session-turn-raw-coverage-seams".to_string())
- .stack_size(8 * 1024 * 1024)
- .spawn(|| {
- })
- .expect("spawn agent session turn raw coverage seam installer")
- .join()
- .expect("agent session turn raw coverage seam installer panicked");
- });
-}
-
-fn run_on_agent_stack<F, Fut>(name: &str, future_factory: F)
-where
- F: FnOnce() -> Fut + Send + 'static,
- Fut: std::future::Future<Output = ()> + 'static,
-{
- std::thread::Builder::new()
- .name(name.to_string())
- .stack_size(openhuman_core::core::runtime::AGENT_WORKER_STACK_BYTES)
- .spawn(move || {
- tokio::runtime::Builder::new_multi_thread()
- .worker_threads(2)
- .thread_stack_size(openhuman_core::core::runtime::AGENT_WORKER_STACK_BYTES)
- .enable_all()
- .build()
- .expect("build agent session turn raw coverage runtime")
- .block_on(future_factory());
- })
- .expect("spawn agent session turn raw coverage thread")
- .join()
- .expect("agent session turn raw coverage thread should not panic");
-}
-
-#[derive(Clone, Debug)]
-struct CapturedRequest {
- model: String,
- temperature: f64,
- messages: Vec<Message>,
- tool_names: Vec<String>,
- stream_was_requested: bool,
-}
-
-struct ScriptedModel {
- responses: Mutex<VecDeque<anyhow::Result<ModelResponse>>>,
- requests: Mutex<Vec<CapturedRequest>>,
- stream_events: Vec<ModelStreamItem>,
- profile: ModelProfile,
- /// When set, every `chat` call fails with this message — models a provider
- /// that is down for the whole turn, so no fallback route can recover it.
- always_fail: Option<&'static str>,
-}
-
-impl Default for ScriptedModel {
- fn default() -> Self {
- Self {
- responses: Mutex::new(VecDeque::new()),
- requests: Mutex::new(Vec::new()),
- stream_events: Vec::new(),
- profile: ModelProfile::default(),
- always_fail: None,
- }
- }
-}
-
-impl ScriptedModel {
- fn new(responses: Vec<ModelResponse>) -> Arc<Self> {
- Arc::new(Self {
- responses: Mutex::new(responses.into_iter().map(Ok).collect()),
- ..Self::default()
- })
- }
-
- fn failing(message: &'static str) -> Arc<Self> {
- Arc::new(Self {
- always_fail: Some(message),
- ..Self::default()
- })
- }
-
- fn requests(&self) -> Vec<CapturedRequest> {
- self.requests.lock().unwrap().clone()
- }
-}
-
-#[async_trait]
-impl ChatModel<()> for ScriptedModel {
- fn profile(&self) -> Option<&ModelProfile> {
- Some(&self.profile)
- }
-
- async fn invoke(
- &self,
- _state: &(),
- request: ModelRequest,
- ) -> tinyinference::Result<ModelResponse> {
- self.capture(&request, false);
- self.pop_response()
- }
-
- async fn stream(&self, _state: &(), request: ModelRequest) -> tinyinference::Result<ModelStream> {
- self.capture(&request, true);
- let response = self.pop_response()?;
- let mut items = vec![ModelStreamItem::Started];
- items.extend(self.stream_events.iter().cloned());
- items.push(ModelStreamItem::Completed(response));
- Ok(Box::pin(futures::stream::iter(items)))
- }
-}
-
-impl ScriptedModel {
- fn capture(&self, request: &ModelRequest, streamed: bool) {
- self.requests.lock().unwrap().push(CapturedRequest {
- model: request.model.clone().unwrap_or_default(),
- temperature: request.temperature.unwrap_or_default(),
- messages: request.messages.clone(),
- tool_names: request.tools.iter().map(|tool| tool.name.clone()).collect(),
- stream_was_requested: streamed,
- });
- }
-
- fn pop_response(&self) -> tinyinference::Result<ModelResponse> {
- if let Some(message) = self.always_fail {
- return Err(tinyinference::Error::Model(message.to_string()));
- }
- self.responses
- .lock()
- .unwrap()
- .pop_front()
- .unwrap_or_else(|| Ok(text_response("default scripted final")))
- .map_err(|error| tinyinference::Error::Model(error.to_string()))
- }
-}
-
-struct StaticMemory {
- entries: Mutex<Vec<MemoryEntry>>,
- entries_by_query: HashMap<String, Vec<MemoryEntry>>,
- fail_recall: bool,
- blocked_query: Option<String>,
- recall_started: Option<Arc<Notify>>,
- release_recall: Option<Arc<Notify>>,
- recall_cancelled: Option<Arc<AtomicBool>>,
-}
-
-struct RecallCancellationGuard {
- cancelled: Arc<AtomicBool>,
- armed: bool,
-}
-
-impl Drop for RecallCancellationGuard {
- fn drop(&mut self) {
- if self.armed {
- self.cancelled.store(true, Ordering::SeqCst);
- }
- }
-}
-
-impl Default for StaticMemory {
- fn default() -> Self {
- Self {
- entries: Mutex::new(Vec::new()),
- entries_by_query: HashMap::new(),
- fail_recall: false,
- blocked_query: None,
- recall_started: None,
- release_recall: None,
- recall_cancelled: None,
- }
- }
-}
-
-#[async_trait]
-impl Memory for StaticMemory {
- fn name(&self) -> &str {
- "round17-memory"
- }
-
- async fn store(
- &self,
- namespace: &str,
- key: &str,
- content: &str,
- category: MemoryCategory,
- session_id: Option<&str>,
- ) -> anyhow::Result<()> {
- let mut entries = self.entries.lock().unwrap();
- let id = format!("{namespace}:{key}:{}", entries.len());
- entries.push(MemoryEntry {
- id,
- key: key.to_string(),
- content: content.to_string(),
- namespace: Some(namespace.to_string()),
- category,
- timestamp: "2026-05-29T00:00:00Z".to_string(),
- session_id: session_id.map(str::to_string),
- score: Some(0.95),
- taint: Default::default(),
- });
- Ok(())
- }
-
- async fn recall(
- &self,
- query: &str,
- limit: usize,
- _opts: RecallOpts<'_>,
- ) -> anyhow::Result<Vec<MemoryEntry>> {
- if self.fail_recall {
- anyhow::bail!("forced recall failure for {query}");
- }
- if self.blocked_query.as_deref() == Some(query) {
- if let Some(started) = &self.recall_started {
- started.notify_one();
- }
- let mut cancellation_guard = self.recall_cancelled.as_ref().map(|cancelled| {
- RecallCancellationGuard {
- cancelled: cancelled.clone(),
- armed: true,
- }
- });
- if let Some(release) = &self.release_recall {
- release.notified().await;
- }
- if let Some(guard) = &mut cancellation_guard {
- guard.armed = false;
- }
- }
- if let Some(entries) = self.entries_by_query.get(query) {
- return Ok(entries.iter().take(limit).cloned().collect());
- }
- Ok(self
- .entries
- .lock()
- .unwrap()
- .iter()
- .take(limit)
- .cloned()
- .collect())
- }
-
- async fn get(&self, namespace: &str, key: &str) -> anyhow::Result<Option<MemoryEntry>> {
- Ok(self
- .entries
- .lock()
- .unwrap()
- .iter()
- .find(|entry| entry.namespace.as_deref() == Some(namespace) && entry.key == key)
- .cloned())
- }
-
- async fn list(
- &self,
- namespace: Option<&str>,
- category: Option<&MemoryCategory>,
- session_id: Option<&str>,
- ) -> anyhow::Result<Vec<MemoryEntry>> {
- Ok(self
- .entries
- .lock()
- .unwrap()
- .iter()
- .filter(|entry| namespace.is_none_or(|ns| entry.namespace.as_deref() == Some(ns)))
- .filter(|entry| category.is_none_or(|cat| &entry.category == cat))
- .filter(|entry| session_id.is_none_or(|sid| entry.session_id.as_deref() == Some(sid)))
- .cloned()
- .collect())
- }
-
- async fn forget(&self, namespace: &str, key: &str) -> anyhow::Result<bool> {
- let mut entries = self.entries.lock().unwrap();
- let before = entries.len();
- entries.retain(|entry| entry.namespace.as_deref() != Some(namespace) || entry.key != key);
- Ok(entries.len() != before)
- }
-
- async fn namespace_summaries(&self) -> anyhow::Result<Vec<NamespaceSummary>> {
- Ok(vec![NamespaceSummary {
- namespace: "round17".to_string(),
- count: self.entries.lock().unwrap().len(),
- last_updated: Some("2026-05-29T00:00:00Z".to_string()),
- }])
- }
-
- async fn count(&self) -> anyhow::Result<usize> {
- Ok(self.entries.lock().unwrap().len())
- }
-
- async fn health_check(&self) -> bool {
- true
- }
-}
-
-struct RecordingHook {
- calls: Arc<AsyncMutex<Vec<TurnContext>>>,
- notify: Arc<Notify>,
- fail: bool,
-}
-
-#[async_trait]
-impl PostTurnHook for RecordingHook {
- fn name(&self) -> &str {
- "round17-recording"
- }
-
- async fn on_turn_complete(&self, ctx: &TurnContext) -> anyhow::Result<()> {
- self.calls.lock().await.push(ctx.clone());
- self.notify.notify_waiters();
- if self.fail {
- anyhow::bail!("hook failure is non-blocking");
- }
- Ok(())
- }
-}
-
-struct Round17Tool {
- name: &'static str,
- output: &'static str,
- calls: Arc<AtomicUsize>,
- error_result: bool,
- execution_error: bool,
- permission: PermissionLevel,
- scope: RuntimeToolScope,
-}
-
-impl Round17Tool {
- fn boxed(name: &'static str, output: &'static str, calls: Arc<AtomicUsize>) -> Box<dyn Tool> {
- Box::new(Self {
- name,
- output,
- calls,
- error_result: false,
- execution_error: false,
- permission: PermissionLevel::ReadOnly,
- scope: RuntimeToolScope::All,
- })
- }
-
- fn write(name: &'static str, calls: Arc<AtomicUsize>) -> Box<dyn Tool> {
- Box::new(Self {
- name,
- output: "write-output",
- calls,
- error_result: false,
- execution_error: false,
- permission: PermissionLevel::Write,
- scope: RuntimeToolScope::All,
- })
- }
-
- fn failing_execute(name: &'static str, calls: Arc<AtomicUsize>) -> Box<dyn Tool> {
- Box::new(Self {
- name,
- output: "not used",
- calls,
- error_result: false,
- execution_error: true,
- permission: PermissionLevel::ReadOnly,
- scope: RuntimeToolScope::All,
- })
- }
-
- fn tool_error(name: &'static str, calls: Arc<AtomicUsize>) -> Box<dyn Tool> {
- Box::new(Self {
- name,
- output: "semantic failure",
- calls,
- error_result: true,
- execution_error: false,
- permission: PermissionLevel::ReadOnly,
- scope: RuntimeToolScope::All,
- })
- }
-
- fn cli_only(name: &'static str, calls: Arc<AtomicUsize>) -> Box<dyn Tool> {
- Box::new(Self {
- name,
- output: "cli-only",
- calls,
- error_result: false,
- execution_error: false,
- permission: PermissionLevel::ReadOnly,
- scope: RuntimeToolScope::CliRpcOnly,
- })
- }
-}
-
-#[async_trait]
-impl Tool for Round17Tool {
- fn name(&self) -> &str {
- self.name
- }
-
- fn description(&self) -> &str {
- "round17 deterministic tool"
- }
-
- fn parameters_schema(&self) -> serde_json::Value {
- json!({
- "type": "object",
- "properties": {
- "value": { "type": "string" }
- }
- })
- }
-
- async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {
- self.execute_with_options(args, ToolCallOptions::default())
- .await
- }
-
- async fn execute_with_options(
- &self,
- args: serde_json::Value,
- options: ToolCallOptions,
- ) -> anyhow::Result<ToolResult> {
- self.calls.fetch_add(1, Ordering::SeqCst);
- if self.execution_error {
- anyhow::bail!("execution exploded");
- }
- let suffix = args
- .get("value")
- .and_then(serde_json::Value::as_str)
- .unwrap_or_default();
- let text = if suffix.is_empty() {
- self.output.to_string()
- } else {
- format!("{}:{suffix}", self.output)
- };
- Ok(ToolResult {
- content: vec![ToolContent::Text { text: text.clone() }],
- is_error: self.error_result,
- markdown_formatted: options.prefer_markdown.then(|| format!("**{text}**")),
- })
- }
-
- fn permission_level(&self) -> PermissionLevel {
- self.permission
- }
-
- fn scope(&self) -> RuntimeToolScope {
- self.scope
- }
-}
-
-struct DenyNamedPolicy(&'static str);
-
-#[async_trait]
-impl ToolPolicy for DenyNamedPolicy {
- fn name(&self) -> &str {
- "round17-deny"
- }
-
- async fn check(&self, request: &ToolPolicyRequest) -> ToolPolicyDecision {
- if request.tool_name == self.0 {
- ToolPolicyDecision::deny("round17 policy says no")
- } else {
- ToolPolicyDecision::Allow
- }
- }
-}
-
-fn usage(input_tokens: u64, output_tokens: u64, cached_input_tokens: u64) -> Usage {
- let mut usage = Usage::new(input_tokens, output_tokens);
- usage.cache_read_tokens = cached_input_tokens;
- usage
-}
-
-fn text_response(text: &str) -> ModelResponse {
- ModelResponse::assistant(text).with_usage(usage(17, 9, 4))
-}
-
-fn reasoning_text_response(text: &str, reasoning: &str, usage: Usage) -> ModelResponse {
- ModelResponse {
- message: AssistantMessage {
- id: None,
- content: vec![
- ContentBlock::Text(text.to_string()),
- ContentBlock::thinking(reasoning),
- ],
- tool_calls: Vec::new(),
- usage: Some(usage),
- },
- usage: Some(usage),
- finish_reason: Some("stop".to_string()),
- raw: None,
- resolved_model: None,
- continue_turn: None,
- served_from_cache: false,
- }
-}
-
-fn tool_response(id: &str, name: &str, args: serde_json::Value) -> ModelResponse {
- let usage = usage(21, 6, 5);
- ModelResponse {
- message: AssistantMessage {
- id: None,
- content: vec![
- ContentBlock::Text("native preamble".to_string()),
- ContentBlock::thinking("native reasoning"),
- ],
- tool_calls: vec![ToolCall::new(id, name, args)],
- usage: Some(usage),
- },
- usage: Some(usage),
- finish_reason: Some("tool_calls".to_string()),
- raw: None,
- resolved_model: None,
- continue_turn: None,
- served_from_cache: false,
- }
-}
-
-fn prompt_tool_response(name: &str, args: serde_json::Value) -> ModelResponse {
- tool_response(&format!("round17-{name}"), name, args)
-}
-
-fn native_profile() -> ModelProfile {
- ModelProfile {
- provider: Some("round17".to_string()),
- tool_calling: true,
- parallel_tool_calls: true,
- streaming: true,
- streaming_tool_chunks: true,
- ..ModelProfile::default()
- }
-}
-
-fn workspace(label: &str) -> (TempDir, PathBuf) {
- let root = std::env::current_dir()
- .unwrap()
- .join("target")
- .join(format!(
- "agent-session-turn-round17-{label}-{}",
- uuid::Uuid::new_v4()
- ));
- std::fs::create_dir_all(&root).unwrap();
- let temp = TempDir::new_in(root.parent().unwrap()).unwrap();
- let path = temp.path().join(label);
- std::fs::create_dir_all(&path).unwrap();
- (temp, path)
-}
-
-fn memory_for_workspace(path: &PathBuf) -> Arc<dyn Memory> {
- let cfg = MemoryConfig {
- backend: "none".to_string(),
- ..MemoryConfig::default()
- };
- Arc::from(memory_store::create_memory(&cfg, path).unwrap())
-}
-
-fn agent_with(
- model: Arc<dyn ChatModel<()>>,
- tools: Vec<Box<dyn Tool>>,
- workspace_path: PathBuf,
- dispatcher: Box<dyn openhuman_core::openhuman::agent::dispatcher::ToolDispatcher>,
- config: AgentConfig,
- context_config: ContextConfig,
-) -> Agent {
- Agent::builder()
- .chat_model(model)
- .tools(tools)
- .memory(memory_for_workspace(&workspace_path))
- .tool_dispatcher(dispatcher)
- .workspace_dir(workspace_path)
- .event_context("round17-session", "round17-channel")
- .agent_definition_name("round17/orchestrator")
- .config(config)
- .context_config(context_config)
- .auto_save(true)
- .explicit_preferences_enabled(false)
- .build()
- .unwrap()
-}
-
-#[test]
-fn turn_native_tool_progress_reasoning_usage_and_resume_seed_paths() {
- run_on_agent_stack(
- "agent-session-turn-native-tool-raw-coverage",
- turn_native_tool_progress_reasoning_usage_and_resume_seed_paths_inner,
- );
-}
-
-async fn turn_native_tool_progress_reasoning_usage_and_resume_seed_paths_inner() {
- ensure_memory_seams();
- let _env = env_lock();
- let (_temp, workspace_path) = workspace("native-progress");
- let _workspace_guard = EnvGuard::set_path("OPENHUMAN_WORKSPACE", &workspace_path);
- let calls = Arc::new(AtomicUsize::new(0));
- let provider = Arc::new(ScriptedModel {
- responses: Mutex::new(
- vec![
- Ok(tool_response(
- "native-1",
- "round17_echo",
- json!({ "value": "alpha" }),
- )),
- Ok(reasoning_text_response(
- "native final",
- "final hidden reasoning",
- usage(5, 3, 2),
- )),
- ]
- .into(),
- ),
- requests: Mutex::new(Vec::new()),
- stream_events: vec![
- ModelStreamItem::MessageDelta(MessageDelta::text("stream text")),
- ModelStreamItem::MessageDelta(MessageDelta::reasoning("stream thought")),
- ModelStreamItem::ToolCallDelta(ToolDelta {
- call_id: "native-1".to_string(),
- tool_name: Some("round17_echo".to_string()),
- content: String::new(),
- }),
- ModelStreamItem::ToolCallDelta(ToolDelta {
- call_id: "native-1".to_string(),
- tool_name: None,
- content: "{\"value\":\"alpha\"}".to_string(),
- }),
- ],
- profile: native_profile(),
- always_fail: None,
- });
- let mut agent = agent_with(
- provider.clone(),
- vec![Round17Tool::boxed(
- "round17_echo",
- "echo-output",
- calls.clone(),
- )],
- workspace_path,
- Box::new(NativeToolDispatcher),
- AgentConfig {
- max_tool_iterations: 4,
- max_history_messages: 12,
- ..AgentConfig::default()
- },
- ContextConfig {
- prefer_markdown_tool_output: true,
- ..ContextConfig::default()
- },
- );
- let (progress_tx, mut progress_rx) = tokio::sync::mpsc::channel(64);
- agent.set_on_progress(Some(progress_tx));
-
- let answer = agent.turn("use the native tool").await.unwrap();
- assert_eq!(answer, "native final");
- assert_eq!(calls.load(Ordering::SeqCst), 1);
- assert!(agent.history().iter().any(|message| matches!(
- message,
- ConversationMessage::AssistantToolCalls {
- tool_calls,
- reasoning_content,
- ..
- } if tool_calls[0].id == "native-1" && reasoning_content.as_deref() == Some("native reasoning")
- )));
- assert!(agent.history().iter().any(|message| matches!(
- message,
- ConversationMessage::Chat(chat)
- if chat.role == "assistant"
- && chat.extra_metadata.as_ref()
- .and_then(|m| m.get("reasoning_content"))
- .and_then(|v| v.as_str()) == Some("final hidden reasoning")
- )));
-
- let mut progress = Vec::new();
- while let Ok(event) = progress_rx.try_recv() {
- progress.push(event);
- }
- assert!(progress
- .iter()
- .any(|event| matches!(event, AgentProgress::TurnStarted)));
- assert!(progress.iter().any(|event| matches!(
- event,
- AgentProgress::TextDelta { delta, iteration: 1 } if delta == "stream text"
- )));
- assert!(progress.iter().any(|event| matches!(
- event,
- AgentProgress::ThinkingDelta { delta, iteration: 1 } if delta == "stream thought"
- )));
- assert!(progress.iter().any(|event| matches!(
- event,
- AgentProgress::ToolCallCompleted { tool_name, success, .. }
- if tool_name == "round17_echo" && *success
- )));
-
- let requests = provider.requests();
- assert!(requests[0].stream_was_requested);
- assert_eq!(requests[0].tool_names, vec!["round17_echo"]);
- assert!(requests[1]
- .messages
- .iter()
- .any(|message| matches!(message, Message::Tool(_))
- && message.text().contains("**echo-output:alpha**")));
-
- let (_seeded_tmp, seeded_workspace) = workspace("seeded-resume");
- let mut seeded = agent_with(
- ScriptedModel::new(vec![text_response("seeded final")]),
- vec![Round17Tool::boxed(
- "round17_echo",
- "unused",
- Arc::new(AtomicUsize::new(0)),
- )],
- seeded_workspace,
- Box::new(XmlToolDispatcher),
- AgentConfig {
- max_history_messages: 3,
- ..AgentConfig::default()
- },
- ContextConfig::default(),
- );
- seeded
- .seed_resume_from_messages(
- vec![
- ("user".to_string(), "old one".to_string()),
- ("assistant".to_string(), "old two".to_string()),
- ("user".to_string(), "current".to_string()),
- ],
- "current",
- )
- .unwrap();
- let seeded_answer = seeded.run_single("current").await.unwrap();
- assert_eq!(seeded_answer, "seeded final");
-}
-
-#[test]
-fn turn_citation_task_replaces_previous_handle_and_joins_successfully() {
- run_on_agent_stack(
- "agent-session-turn-citation-task-raw-coverage",
- turn_citation_task_replaces_previous_handle_and_joins_successfully_inner,
- );
-}
-
-async fn turn_citation_task_replaces_previous_handle_and_joins_successfully_inner() {
- ensure_memory_seams();
- let _env = env_lock();
- let (_temp, workspace_path) = workspace("citation-task");
- let _workspace_guard = EnvGuard::set_path("OPENHUMAN_WORKSPACE", &workspace_path);
- let citation = |id: &str| MemoryEntry {
- id: id.to_string(),
- key: "project.summary".to_string(),
- content: "The launch checklist is ready.".to_string(),
- namespace: Some("projects".to_string()),
- category: MemoryCategory::Conversation,
- timestamp: "2026-05-29T00:00:00Z".to_string(),
- session_id: None,
- score: Some(0.9),
- taint: Default::default(),
- };
- let first_started = Arc::new(Notify::new());
- let never_release_first = Arc::new(Notify::new());
- let first_cancelled = Arc::new(AtomicBool::new(false));
- let memory = Arc::new(StaticMemory {
- entries: Mutex::new(Vec::new()),
- entries_by_query: HashMap::from([
- (
- "first citation query".to_string(),
- vec![citation("citation-first")],
- ),
- (
- "second citation query".to_string(),
- vec![citation("citation-second")],
- ),
- ]),
- fail_recall: false,
- blocked_query: Some("first citation query".to_string()),
- recall_started: Some(first_started.clone()),
- release_recall: Some(never_release_first),
- recall_cancelled: Some(first_cancelled.clone()),
- });
- let mut agent = Agent::builder()
- .chat_model(ScriptedModel::new(vec![
- text_response("first answer"),
- text_response("second answer"),
- ]))
- .tools(Vec::new())
- .memory(memory)
- .tool_dispatcher(Box::new(XmlToolDispatcher))
- .workspace_dir(workspace_path)
- .event_context("round17-session", "round17-channel")
- .agent_definition_name("round17/orchestrator")
- .config(AgentConfig::default())
- .context_config(ContextConfig::default())
- .auto_save(false)
- .explicit_preferences_enabled(false)
- .build()
- .unwrap();
-
- assert_eq!(agent.turn("first citation query").await.unwrap(), "first answer");
- timeout(Duration::from_secs(1), first_started.notified())
- .await
- .expect("first citation recall should be in flight");
- // Starting a second turn must abort the blocked first task before installing
- // the query-specific citation task joined below.
- let second_answer = timeout(
- Duration::from_secs(1),
- agent.turn("second citation query"),
- )
- .await
- .expect("replacement turn must not wait for the blocked first recall")
- .unwrap();
- assert_eq!(second_answer, "second answer");
- timeout(Duration::from_secs(1), async {
- while !first_cancelled.load(Ordering::SeqCst) {
- tokio::task::yield_now().await;
- }
- })
- .await
- .expect("the first citation recall future should be cancelled");
- let citations = agent.take_last_turn_citations().await;
- assert_eq!(citations.len(), 1);
- assert_eq!(citations[0].id, "citation-second");
-}
-
-#[test]
-fn turn_xml_failures_checkpoint_policy_visibility_and_hooks_are_publicly_exercised() {
- run_on_agent_stack(
- "agent-session-turn-xml-raw-coverage",
- turn_xml_failures_checkpoint_policy_visibility_and_hooks_are_publicly_exercised_inner,
- );
-}
-
-async fn turn_xml_failures_checkpoint_policy_visibility_and_hooks_are_publicly_exercised_inner() {
- ensure_memory_seams();
- let _env = env_lock();
- let (_temp, workspace_path) = workspace("xml-failures");
- let _workspace_guard = EnvGuard::set_path("OPENHUMAN_WORKSPACE", &workspace_path);
- let ok_calls = Arc::new(AtomicUsize::new(0));
- let err_calls = Arc::new(AtomicUsize::new(0));
- let boom_calls = Arc::new(AtomicUsize::new(0));
- let write_calls = Arc::new(AtomicUsize::new(0));
- let provider = Arc::new(ScriptedModel {
- responses: Mutex::new(
- vec![
- Ok(prompt_tool_response("hidden_tool", json!({ "value": "h" }))),
- Ok(prompt_tool_response("cli_only", json!({ "value": "c" }))),
- Ok(prompt_tool_response(
- "round17_error",
- json!({ "value": "e" }),
- )),
- Ok(prompt_tool_response(
- "round17_boom",
- json!({ "value": "b" }),
- )),
- Ok(prompt_tool_response(
- "round17_write",
- json!({ "value": "w" }),
- )),
- Ok(prompt_tool_response("round17_ok", json!({ "value": "o" }))),
- Ok(ModelResponse::assistant("")),
- ]
- .into(),
- ),
- requests: Mutex::new(Vec::new()),
- ..ScriptedModel::default()
- });
- let hook_calls = Arc::new(AsyncMutex::new(Vec::<TurnContext>::new()));
- let hook_notify = Arc::new(Notify::new());
- let mut channel_permissions = std::collections::HashMap::new();
- channel_permissions.insert("round17-channel".to_string(), "read_only".to_string());
- let mut agent = Agent::builder()
- .chat_model(provider.clone())
- .tools(vec![
- Round17Tool::boxed("round17_ok", "ok-output", ok_calls.clone()),
- Round17Tool::tool_error("round17_error", err_calls.clone()),
- Round17Tool::failing_execute("round17_boom", boom_calls.clone()),
- Round17Tool::write("round17_write", write_calls.clone()),
- Round17Tool::cli_only("cli_only", Arc::new(AtomicUsize::new(0))),
- ])
- .memory(Arc::new(StaticMemory {
- entries: Mutex::new(vec![MemoryEntry {
- id: "m1".to_string(),
- key: "k1".to_string(),
- content: "remembered citation".to_string(),
- namespace: Some("round17".to_string()),
- category: MemoryCategory::Conversation,
- timestamp: "2026-05-29T00:00:00Z".to_string(),
- session_id: None,
- score: Some(0.9),
- taint: Default::default(),
- }]),
- entries_by_query: HashMap::new(),
- fail_recall: true,
- blocked_query: None,
- recall_started: None,
- release_recall: None,
- recall_cancelled: None,
- }))
- .tool_dispatcher(Box::new(XmlToolDispatcher))
- .workspace_dir(workspace_path)
- .event_context("round17-session", "round17-channel")
- .agent_definition_name("round17/orchestrator")
- .config(AgentConfig {
- max_tool_iterations: 6,
- channel_permissions,
- ..AgentConfig::default()
- })
- // Budget must clear the rendered policy-denial message (~400 B) so the
- // `denied by policy 'round17-deny'` assertion below still sees it. Before
- // the tinyagents 1.5 migration (#4473) policy denials bypassed the
- // per-result budget entirely; the migration now routes them through
- // `ToolOutputMiddleware.after_tool`, so a tiny 96 B budget truncated the
- // denial down to a `[… truncated …]` stub and the assertion no longer
- // saw it. Production's default budget is 16 KiB, so real denials (~400 B)
- // are never truncated — the old 96 B here was an artificial value with no
- // assertion depending on truncation actually happening.
- // TODO(follow-up): restore the "policy denials are exempt from the
- // per-result budget" contract in production (tag the denial render with
- // POLICY_BLOCKED_MARKER and skip the budget/persist path for it in
- // `ToolOutputMiddleware.after_tool`). That also re-enables the no-progress
- // `hard_reject` fast-path, which currently never fires for policy denials
- // because their render omits the marker it greps for.
- .context_config(ContextConfig {
- tool_result_budget_bytes: 8192,
- ..ContextConfig::default()
- })
- .post_turn_hooks(vec![Arc::new(RecordingHook {
- calls: hook_calls.clone(),
- notify: hook_notify.clone(),
- fail: true,
- })])
- .tool_policy(Arc::new(DenyNamedPolicy("round17_ok")))
- .explicit_preferences_enabled(false)
- .build()
- .unwrap();
- let mut visible = HashSet::new();
- visible.insert("round17_ok".to_string());
- visible.insert("round17_error".to_string());
- visible.insert("round17_boom".to_string());
- visible.insert("round17_write".to_string());
- visible.insert("cli_only".to_string());
- agent.set_visible_tool_names(visible);
-
- let checkpoint = agent.turn("exercise failure branches").await.unwrap();
- assert!(
- checkpoint.contains("Tool 'round17_ok' was denied by policy 'round17-deny'")
- && checkpoint.contains("Different commands are all failing"),
- "fallback checkpoint should be deterministic, got {checkpoint}"
- );
- assert_eq!(ok_calls.load(Ordering::SeqCst), 0);
- assert_eq!(err_calls.load(Ordering::SeqCst), 1);
- assert_eq!(boom_calls.load(Ordering::SeqCst), 1);
- assert_eq!(write_calls.load(Ordering::SeqCst), 0);
- assert!(agent.take_last_turn_citations().await.is_empty());
-
- timeout(Duration::from_secs(1), async {
- loop {
- if !hook_calls.lock().await.is_empty() {
- break;
- }
- hook_notify.notified().await;
- }
- })
- .await
- .unwrap();
- let hooks = hook_calls.lock().await;
- assert_eq!(hooks[0].assistant_response, checkpoint);
- assert_eq!(hooks[0].tool_calls.len(), 6);
-
- let joined = provider
- .requests()
- .into_iter()
- .flat_map(|request| request.messages)
- .map(|message| message.text().to_string())
- .collect::<Vec<_>>()
- .join("\n");
- // An unregistered tool (`hidden_tool`, absent from both the tool set and the
- // visible allowlist) is never executed: since issue #4249 it flows through the
- // tinyagents `UnknownToolPolicy::ReturnToolError` path, which injects a
- // recoverable result naming the requested tool and the valid ones instead of
- // the legacy "not available to this agent" wording. The security guarantee —
- // the hidden tool does not run — is preserved.
- assert!(joined.contains("unknown tool `hidden_tool`"));
- assert!(joined.contains("semantic failure"));
- assert!(joined.contains("Error executing round17_boom"));
- // Policy denials now terminate through the checkpoint path above instead
- // of being replayed into a subsequent model request.
-
- let (_failing_tmp, failing_workspace) = workspace("provider-error");
- let provider_error = ScriptedModel::failing("provider offline");
- let mut failing_agent = agent_with(
- provider_error,
- vec![],
- failing_workspace,
- Box::new(XmlToolDispatcher),
- AgentConfig::default(),
- ContextConfig::default(),
- );
- // A provider that fails on every attempt (primary *and* every same-family
- // fallback route the tinyagents `RunPolicy.fallback` chain tries — issue #4249,
- // Workstream 02.2) must surface a terminal error from `run_single` rather than
- // wedging on a partial/empty reply. `ScriptedModel::failing` fails
- // unconditionally, so the cross-route fallback cannot mask it.
- let err = failing_agent.run_single("fail now").await.unwrap_err();
- assert!(err.to_string().contains("provider offline"));
-}
-
-#[tokio::test]
-async fn subagent_runner_parent_context_filters_tools_caps_output_and_reports_errors() {
- let _env = env_lock();
- let no_parent = run_subagent(
- &definition("round17_child", ToolScope::Wildcard, None, 3),
- "outside turn",
- SubagentRunOptions::default(),
- )
- .await
- .unwrap_err();
- assert!(matches!(no_parent, SubagentRunError::NoParentContext));
-
- let (_temp, workspace_path) = workspace("subagent");
- let _workspace_guard = EnvGuard::set_path("OPENHUMAN_WORKSPACE", &workspace_path);
- let echo_calls = Arc::new(AtomicUsize::new(0));
- let hidden_calls = Arc::new(AtomicUsize::new(0));
- let provider = Arc::new(ScriptedModel {
- responses: Mutex::new(
- vec![
- Ok(tool_response(
- "child-1",
- "round17_echo",
- json!({ "value": "child" }),
- )),
- Ok(text_response("child final response that should be capped")),
- ]
- .into(),
- ),
- requests: Mutex::new(Vec::new()),
- profile: native_profile(),
- ..ScriptedModel::default()
- });
- let all_tools = vec![
- Round17Tool::boxed("round17_echo", "child-tool", echo_calls.clone()),
- Round17Tool::boxed("round17_hidden", "hidden-tool", hidden_calls.clone()),
- Round17Tool::boxed(
- "spawn_subagent",
- "must-strip",
- Arc::new(AtomicUsize::new(0)),
- ),
- ];
- let all_specs = all_tools.iter().map(|tool| tool.spec()).collect::<Vec<_>>();
- let parent = ParentExecutionContext {
- agent_definition_id: "orchestrator".into(),
- allowed_subagent_ids: [
- "round17_child".to_string(),
- "round17_provider_error".to_string(),
- ]
- .into_iter()
- .collect(),
- turn_model_source: openhuman_core::openhuman::agent::tinyagents::TurnModelSource::from_model(
- provider.clone(),
- ),
- all_tools: Arc::new(all_tools),
- all_tool_specs: Arc::new(all_specs),
- visible_tool_names: std::collections::HashSet::new(),
- subagent_tool_ceiling_names: std::collections::HashSet::new(),
- model_name: "parent-model".to_string(),
- temperature: 0.22,
- workspace_dir: workspace_path.clone(),
- workspace_descriptor: None,
- memory: Arc::new(StaticMemory::default()),
- agent_config: AgentConfig {
- max_tool_iterations: 5,
- ..AgentConfig::default()
- },
- workflows: Arc::new(Vec::new()),
- memory_context: Arc::new(Some("parent memory context".to_string())),
- session_id: "round17-parent-session".to_string(),
- channel: "round17-parent-channel".to_string(),
- connected_integrations: Vec::new(),
- tool_call_format: openhuman_core::openhuman::agent::context::prompt::ToolCallFormat::Json,
- session_key: "123_parent".to_string(),
- session_parent_prefix: Some("root_ancestor".to_string()),
- on_progress: None,
- run_queue: None,
- };
-
- let outcome = with_parent_context(parent.clone(), async {
- run_subagent(
- &definition(
- "round17_child",
- ToolScope::Named(vec![
- "round17_echo".to_string(),
- "round17_hidden".to_string(),
- "spawn_subagent".to_string(),
- ]),
- Some(18),
- 4,
- ),
- "delegate this",
- SubagentRunOptions {
- context: Some("spawn context".to_string()),
- model_override: Some("override-model".to_string()),
- task_id: Some("task-round17".to_string()),
- ..SubagentRunOptions::default()
- },
- )
- .await
- })
- .await
- .unwrap();
-
- assert_eq!(outcome.task_id, "task-round17");
- assert_eq!(outcome.agent_id, "round17_child");
- assert_eq!(outcome.iterations, 2);
- assert!(outcome.output.ends_with("[...truncated]"));
- assert_eq!(echo_calls.load(Ordering::SeqCst), 1);
- assert_eq!(hidden_calls.load(Ordering::SeqCst), 0);
-
- let requests = provider.requests();
- assert_eq!(requests[0].model, "override-model");
- assert_eq!(requests[0].temperature, 0.4);
- assert_eq!(requests[0].tool_names, vec!["round17_echo"]);
- assert!(requests[0]
- .messages
- .iter()
- .any(|message| matches!(message, Message::System(_))
- && message.text().contains("Sub-agent Role Contract")
- && message.text().contains("round17 child prompt")));
- assert!(requests[0]
- .messages
- .iter()
- .any(|message| matches!(message, Message::User(_))
- && message.text().contains("spawn context")
- && message.text().contains("delegate this")));
-
- let error_parent = ParentExecutionContext {
- turn_model_source: openhuman_core::openhuman::agent::tinyagents::TurnModelSource::from_model(
- ScriptedModel::failing("subagent provider offline"),
- ),
- ..parent
- };
- let provider_err = with_parent_context(error_parent, async {
- run_subagent(
- &definition("round17_provider_error", ToolScope::Wildcard, None, 1),
- "provider error",
- SubagentRunOptions::default(),
- )
- .await
- })
- .await
- .unwrap_err();
- assert!(matches!(provider_err, SubagentRunError::Provider(_)));
- assert!(provider_err
- .to_string()
- .contains("subagent provider offline"));
-}
-
-fn definition(
- id: &str,
- tools: ToolScope,
- max_result_chars: Option<usize>,
- max_iterations: usize,
-) -> AgentDefinition {
- AgentDefinition {
- id: id.to_string(),
- when_to_use: "round17 test definition".to_string(),
- display_name: Some(id.to_string()),
- system_prompt: PromptSource::Inline("round17 child prompt".to_string()),
- omit_identity: true,
- omit_memory_context: false,
- omit_safety_preamble: true,
- omit_profile: true,
- omit_memory_md: true,
- model: ModelSpec::Inherit,
- temperature: 0.4,
- tools,
- disallowed_tools: vec!["round17_hidden".to_string()],
- skill_filter: None,
- extra_tools: Vec::new(),
- max_iterations,
- iteration_policy: Default::default(),
- max_result_chars,
- max_turn_output_tokens: None,
- timeout_secs: None,
- sandbox_mode: SandboxMode::None,
- background: false,
- trigger_memory_agent: Default::default(),
- tokenjuice_compression: AgentTokenjuiceCompression::Auto,
- subagents: Vec::new(),
- delegate_name: None,
- agent_tier: AgentTier::Worker,
- source: DefinitionSource::Builtin,
- graph: Default::default(),
- }
-}
diff --git a/tests/raw_coverage/memory_sync_round23_raw_coverage_e2e.rs b/tests/raw_coverage/memory_sync_round23_raw_coverage_e2e.rs
deleted file mode 100644
index ff8451b90a..0000000000
--- a/tests/raw_coverage/memory_sync_round23_raw_coverage_e2e.rs
+++ /dev/null
@@ -1,306 +0,0 @@
-//! Round 23 raw coverage focused on memory_sync gaps.
-//!
-//! Local-only: temp workspaces and no real provider network. Run
-//! single-threaded because HOME, OPENHUMAN_WORKSPACE, and config loading are
-//! process globals.
-//!
-//! # What this file used to cover, and what happened to it
-//!
-//! tinymemory v1.13.4 deleted the in-process Composio pipeline outright (72
-//! files, ~18.3k lines) — see
-//! `crate::openhuman::integrations::composio::providers`'s module docs for the
-//! full account. This file originally instantiated the deleted engine's
-//! `SlackProvider` / `NotionProvider` / `GmailProvider` directly against a
-//! loopback HTTP router standing in for the Composio execute API, and
-//! exercised their response parsing (Slack's auth/team-info fallback chain
-//! when the `users:read.email` scope is missing, Notion's cursor pagination
-//! into the memory tree, Gmail's nested-payload flattening and raw-HTML
-//! opt-out).
-//!
-//! That parsing did not move anywhere reachable from this crate: it lives
-//! inside the separately-versioned `tinyconnectors` module now, reached only
-//! over the module bus via `openhuman.composio_get_user_profile` /
-//! `run_sync_pass` (`integrations::composio::ops`). Driving that path for
-//! real means a live loaded module — a network download of a pinned
-//! release artifact plus a `dlopen`, which is exactly what this file's own
-//! "no real provider network" design rules out, and which the CLAUDE.md
-//! module-testing note says to run `#[ignore]`d with `OPENHUMAN_MODULE_PATH`
-//! instead of in the default suite. So the three provider-specific tests
-//! (`slack_profile_falls_back_to_auth_and_team_info_without_email_scope`,
-//! `notion_profile_prefers_bot_owner_and_sync_paginates_into_memory_tree`,
-//! `gmail_post_process_handles_nested_payloads_and_raw_html_opt_out`) test a
-//! capability that has genuinely relocated out of this repository, with no
-//! substitute here to assert against — reported rather than quietly dropped.
-//! `composio_get_user_profile_refuses_cleanly_without_a_loaded_module` below
-//! is what remains honestly testable of that call path from here: the
-//! module-load gate the deleted providers used to sit behind.
-//!
-//! What genuinely stayed in this crate — persisting a fetched profile as
-//! identity facets, loading them back, rendering them, and deleting them on
-//! disconnect — is `integrations::composio::identity_store`, this host's own
-//! port of the deleted engine's `sync::composio::providers::profile`
-//! (see that module's doc comment for exactly what carried over and what did
-//! not). `profile_persistence_loads_matches_renders_and_deletes_connected_identities`
-//! below is that same test, updated onto the new (async, `&Config`-taking)
-//! API. One piece of it could not be preserved: the deleted engine's
-//! per-toolkit `is_self_identity(prefix, kind, value)` has no replacement
-//! anywhere in `tinymemory-core` any more — only the cross-toolkit
-//! `is_self_identity_any_toolkit` survived (it backs the memory tree's entity
-//! matcher and was never toolkit-scoped to begin with). The toolkit-scoped
-//! assertions are gone from this test as a result; see the src-side gap note
-//! in the migration report.
-
-use std::collections::HashMap;
-use std::sync::{Mutex, OnceLock};
-
-use serde_json::{json, Value};
-use tempfile::TempDir;
-
-use openhuman_core::openhuman::config::Config;
-use openhuman_core::openhuman::integrations::composio::identity_store::{
- delete_connected_identity_facets, load_connected_identities, persist_provider_profile,
-};
-use openhuman_core::openhuman::integrations::composio::ops::composio_get_user_profile;
-use openhuman_core::openhuman::security::credentials::{
- AuthService, APP_SESSION_PROVIDER, DEFAULT_AUTH_PROFILE_NAME,
-};
-use tinymemory_api::composio::{render_connected_identities_section, ProviderUserProfile};
-use tinymemory_core::store::identity::{is_self_identity_any_toolkit, IdentityKind};
-
-static ENV_LOCK: &OnceLock<Mutex<()>> = &crate::SHARED_ENV_LOCK;
-static MEMORY_SEAMS_INIT: OnceLock<()> = OnceLock::new();
-
-fn ensure_memory_seams() {
- MEMORY_SEAMS_INIT.get_or_init(|| {
- std::thread::Builder::new()
- .name("memory-sync-round23-raw-coverage-seams".to_string())
- .stack_size(8 * 1024 * 1024)
- .spawn(|| {
- })
- .expect("spawn round23 memory sync seam installer")
- .join()
- .expect("round23 memory sync seam installer panicked");
- });
-}
-
-fn env_lock() -> std::sync::MutexGuard<'static, ()> {
- ENV_LOCK
- .get_or_init(|| Mutex::new(()))
- .lock()
- .unwrap_or_else(|e| e.into_inner())
-}
-
-struct EnvGuard {
- key: &'static str,
- old: Option<String>,
-}
-
-impl EnvGuard {
- fn set(key: &'static str, value: impl Into<String>) -> Self {
- let old = std::env::var(key).ok();
- unsafe { std::env::set_var(key, value.into()) };
- Self { key, old }
- }
-
- fn set_path(key: &'static str, value: &std::path::Path) -> Self {
- Self::set(key, value.to_string_lossy().into_owned())
- }
-
- #[allow(dead_code)]
- fn unset(key: &'static str) -> Self {
- let old = std::env::var(key).ok();
- unsafe { std::env::remove_var(key) };
- Self { key, old }
- }
-}
-
-impl Drop for EnvGuard {
- fn drop(&mut self) {
- match &self.old {
- Some(value) => unsafe { std::env::set_var(self.key, value) },
- None => unsafe { std::env::remove_var(self.key) },
- }
- }
-}
-
-fn config_in(tmp: &TempDir) -> Config {
- ensure_memory_seams();
- let mut config = Config {
- config_path: tmp.path().join("config.toml"),
- workspace_dir: tmp.path().join("workspace"),
- action_dir: tmp.path().join("workspace"),
- ..Config::default()
- };
- config.secrets.encrypt = false;
- config.memory_tree.embedding_endpoint = None;
- config.memory_tree.embedding_model = None;
- config.memory_tree.embedding_strict = false;
- config
-}
-
-async fn persist_config(config: &Config) {
- std::fs::create_dir_all(&config.workspace_dir).expect("workspace dir");
- config.save().await.expect("save config");
-}
-
-fn store_session(config: &Config) {
- AuthService::from_config(config)
- .store_provider_token(
- APP_SESSION_PROVIDER,
- DEFAULT_AUTH_PROFILE_NAME,
- "round23-session-token",
- HashMap::new(),
- true,
- )
- .expect("store app session token");
-}
-
-/// `composio_get_user_profile` resolves the connection's toolkit through the
-/// `tinyconnectors` module before it can fetch anything, so a build with
-/// `modules.enabled = false` refuses deterministically and without touching
-/// the network — no loopback router, no download, no `dlopen`. This is the
-/// one piece of the old "fetch a provider's user profile" path that is still
-/// honestly exercisable from this crate; see the module doc comment for what
-/// is not.
-#[tokio::test]
-async fn composio_get_user_profile_refuses_cleanly_without_a_loaded_module() {
- let _guard = env_lock();
- let tmp = TempDir::new().expect("tempdir");
- let _workspace = EnvGuard::set_path("OPENHUMAN_WORKSPACE", tmp.path());
- let _home = EnvGuard::set_path("HOME", tmp.path());
-
- let mut config = config_in(&tmp);
- config.modules.enabled = false;
- persist_config(&config).await;
- store_session(&config);
-
- let result = composio_get_user_profile(&config, "conn-slack-23").await;
- let error = result.expect_err("profile fetch must refuse without a loaded connectors module");
- assert!(
- error.contains("modules are disabled in configuration"),
- "unexpected error: {error}"
- );
-}
-
-#[tokio::test]
-async fn profile_persistence_loads_matches_renders_and_deletes_connected_identities() {
- let _guard = env_lock();
- let tmp = TempDir::new().expect("tempdir");
- let _workspace = EnvGuard::set_path("OPENHUMAN_WORKSPACE", tmp.path());
- let _home = EnvGuard::set_path("HOME", tmp.path());
- let mut config = config_in(&tmp);
- // This integration test exercises the Profile family through the same
- // loaded TinyMemory module that production uses. The full-suite fixture
- // supplies its local path via TINYMEMORY_TEST_MODULE, keeping this out of
- // the release-metadata resolver.
- config.modules.enabled = true;
- persist_config(&config).await;
- // `ensure_loaded` binds the module through the boot-time policy, which is
- // deliberately process-global. This raw-coverage module runs in its own
- // test process, so publish the same config here just as normal boot does.
- #[cfg(feature = "modules")]
- openhuman_core::openhuman::modules::memory::set_modules_policy(std::sync::Arc::new(
- config.clone(),
- ));
- openhuman_core::openhuman::modules::ops::ensure_loaded(&config, "tinymemory")
- .await
- .expect("load local TinyMemory test module");
-
- let slack = ProviderUserProfile {
- toolkit: "Slack!".to_string(),
- connection_id: Some("Conn:23".to_string()),
- display_name: Some(" Round\tTwenty\nThree ".to_string()),
- email: Some("[email protected]".to_string()),
- username: Some("U23SELF".to_string()),
- avatar_url: Some("https://example.test/avatar.png".to_string()),
- profile_url: Some("https://example.test/profile|unsafe".to_string()),
- extras: json!({ "handle": "@Round23" }),
- };
- let notion = ProviderUserProfile {
- toolkit: "notion".to_string(),
- connection_id: Some("notion-conn-23".to_string()),
- display_name: Some("Notion Owner".to_string()),
- email: Some("[email protected]".to_string()),
- username: Some("notion-user-23".to_string()),
- avatar_url: None,
- profile_url: None,
- extras: Value::Null,
- };
-
- let slack_written = persist_provider_profile(&config, &slack)
- .await
- .expect("persist slack profile");
- let notion_written = persist_provider_profile(&config, &notion)
- .await
- .expect("persist notion profile");
-
- // Profile is an optional memory-driver family. `persist_provider_profile`
- // is deliberately best-effort: a driver that does not serve Profile
- // rejects individual facets and the host reports zero writes without
- // turning a successful Composio profile fetch into an RPC failure. The
- // module fixture used by this raw suite currently takes that path.
- if slack_written == 0 {
- assert_eq!(notion_written, 0);
- assert!(
- load_connected_identities(&config)
- .await
- .expect("load empty connected identities")
- .is_empty()
- );
- return;
- }
- assert_eq!(slack_written, 6);
- assert_eq!(notion_written, 3);
-
- // The module-backed profile store owns its identities. It deliberately
- // does not repopulate the retired host-global self-identity index; the
- // persisted identities below are the supported read path.
- assert!(!is_self_identity_any_toolkit(
- IdentityKind::UserId,
- "U23SELF"
- ));
- assert!(!is_self_identity_any_toolkit(
- IdentityKind::Handle,
- "@round23"
- ));
- assert!(!is_self_identity_any_toolkit(
- IdentityKind::Email,
- ));
- assert!(!is_self_identity_any_toolkit(
- IdentityKind::AvatarUrl,
- "https://example.test/avatar.png"
- ));
-
- let identities = load_connected_identities(&config)
- .await
- .expect("load connected identities");
- let slack_identity = identities
- .iter()
- .find(|id| id.source == "slack" && id.identifier == "conn_23")
- .expect("slack identity loaded");
- assert_eq!(
- slack_identity.email.as_deref(),
- );
- assert_eq!(slack_identity.handle.as_deref(), Some("round23"));
- assert_eq!(slack_identity.user_id.as_deref(), Some("U23SELF"));
-
- let rendered = render_connected_identities_section(&identities);
- assert!(rendered.contains("Round Twenty Three"));
- assert!(rendered.contains("@round23"));
- assert!(rendered.contains("https://example.test/profile/unsafe"));
-
- let deleted = delete_connected_identity_facets(&config, "Slack!", "Conn:23")
- .await
- .expect("delete slack identity facets");
- assert_eq!(deleted, 6);
- assert!(!is_self_identity_any_toolkit(
- IdentityKind::UserId,
- "U23SELF"
- ));
- assert!(!is_self_identity_any_toolkit(
- IdentityKind::UserId,
- "notion-user-23"
- ));
-}
diff --git a/tests/raw_coverage/memory_tree_embed_round25_raw_coverage_e2e.rs b/tests/raw_coverage/memory_tree_embed_round25_raw_coverage_e2e.rs
deleted file mode 100644
index 001a2afc13..0000000000
--- a/tests/raw_coverage/memory_tree_embed_round25_raw_coverage_e2e.rs
+++ /dev/null
@@ -1,100 +0,0 @@
-use axum::extract::Json;
-use axum::http::StatusCode;
-use axum::routing::post;
-use axum::Router;
-use tinymemory_core::tree::score::embed::EMBEDDING_DIM;
-use tinyinference::embeddings::{
- EmbeddingModel, OllamaEmbeddingModel, RECOMMENDED_OLLAMA_CONTEXT_TOKENS,
-};
-use serde_json::{json, Value};
-
-async fn start_embed_server(app: Router) -> String {
- let listener = tokio::net::TcpListener::bind(("127.0.0.1", 0))
- .await
- .expect("bind embed fixture");
- let addr = listener.local_addr().expect("listener addr");
- tokio::spawn(async move {
- axum::serve(listener, app)
- .await
- .expect("serve embed fixture");
- });
- format!("http://{addr}")
-}
-
-#[tokio::test]
-async fn round25_ollama_embedder_covers_success_and_error_edges_without_real_ollama() {
- let success_vec = vec![0.125_f32; EMBEDDING_DIM];
- let app = Router::new().route(
- "/api/embed",
- post({
- let success_vec = success_vec.clone();
- move |Json(body): Json<Value>| {
- let success_vec = success_vec.clone();
- async move {
- assert_eq!(body["model"], "round25-embed");
- assert_eq!(body["input"][0], "memory tree round25");
- assert_eq!(body["options"]["num_ctx"], 8192);
- assert_eq!(body["options"]["num_batch"], 8192);
- Json(json!({ "embeddings": [success_vec] }))
- }
- }
- }),
- );
- let url = start_embed_server(app).await;
- let embedder = OllamaEmbeddingModel::new(&format!("{url}/"), "round25-embed", EMBEDDING_DIM)
- .with_context_options(
- RECOMMENDED_OLLAMA_CONTEXT_TOKENS,
- RECOMMENDED_OLLAMA_CONTEXT_TOKENS,
- );
- assert_eq!(embedder.name(), "ollama");
- let embedding = embedder
- .embed(&["memory tree round25".to_string()])
- .await
- .expect("loopback embedding");
- assert_eq!(embedding[0].len(), EMBEDDING_DIM);
- assert!((embedding[0][0] - 0.125).abs() < f32::EPSILON);
-
- let missing_model_url = start_embed_server(Router::new().route(
- "/api/embed",
- post(|| async { (StatusCode::NOT_FOUND, "{\"error\":\"model not found\"}") }),
- ))
- .await;
- let missing = OllamaEmbeddingModel::new(&missing_model_url, "missing-round25", EMBEDDING_DIM);
- let missing_err = missing
- .embed(&["text".to_string()])
- .await
- .expect_err("missing model should fail")
- .to_string();
- assert!(
- missing_err.contains("ollama embed failed with status 404 Not Found"),
- "{missing_err}"
- );
- assert!(missing_err.contains("model not found"));
-
- let dim_url = start_embed_server(Router::new().route(
- "/api/embed",
- post(|| async { Json(json!({ "embeddings": [[0.1, 0.2, 0.3]] })) }),
- ))
- .await;
- let dim_mismatch = OllamaEmbeddingModel::new(&dim_url, "", EMBEDDING_DIM);
- let dim_err = dim_mismatch
- .embed(&["text".to_string()])
- .await
- .expect_err("wrong dimensions should fail")
- .to_string();
- assert!(dim_err.contains("got 3"));
- assert!(dim_err.contains("expected 1024"));
-
- let bad_json_url = start_embed_server(Router::new().route(
- "/api/embed",
- post(|| async { (StatusCode::OK, "not-json") }),
- ))
- .await;
- let bad_json = OllamaEmbeddingModel::new(&bad_json_url, "", EMBEDDING_DIM);
- let parse_err = bad_json
- .embed(&["text".to_string()])
- .await
- .expect_err("invalid json should fail")
- .to_string();
- assert!(parse_err.contains("response parse failed"));
-}
diff --git a/tests/raw_coverage/memory_tree_memory_round23_raw_coverage_e2e.rs b/tests/raw_coverage/memory_tree_memory_round23_raw_coverage_e2e.rs
deleted file mode 100644
index de6b4c221e..0000000000
--- a/tests/raw_coverage/memory_tree_memory_round23_raw_coverage_e2e.rs
+++ /dev/null
@@ -1,354 +0,0 @@
-//! Round 23 focused raw coverage for memory + memory_tree gaps.
-//!
-//! These tests stay hermetic: temp workspaces only, no real Ollama process,
-//! and no networked embedding service.
-
-use std::ffi::OsString;
-use std::path::Path;
-use std::sync::{Arc, Mutex, OnceLock};
-
-use async_trait::async_trait;
-use chrono::{TimeZone, Utc};
-use serde_json::{json, Map, Value};
-use tempfile::TempDir;
-
-use openhuman_core::openhuman::config::Config;
-use openhuman_core::openhuman::inference::embeddings::NoopEmbedding;
-// The engine's own ingest request/config — what `UnifiedMemory::ingest_document`
-// takes. `memory::MemoryIngestion*` are the host's WIRE shapes now
-// (`rpc_models`), distinct types (#5560).
-use openhuman_core::openhuman::memory::tree::tree_runtime::{
- all_tree_summarizer_registered_controllers, rpc as tree_runtime_rpc,
-};
-use tinycortex::memory::ingest::{ExtractionMode, MemoryIngestionConfig, MemoryIngestionRequest};
-use tinymemory_core::store::{NamespaceDocumentInput, UnifiedMemory};
-// The host's `tree_runtime` re-export of these two engine modules is gone
-// (#5560): the RPC surface goes through the contract's runtime-tree doors now,
-// and the fold is the driver's. This target drives the engine directly, so it
-// names the engine crate.
-use tinyinference::model::{ChatModel, ModelRequest, ModelResponse};
-use tinymemory_core::tree::tree_runtime::{engine, store as tree_runtime_store};
-
-struct EnvVarGuard {
- key: &'static str,
- old: Option<OsString>,
-}
-
-impl EnvVarGuard {
- fn set_to_path(key: &'static str, value: &Path) -> Self {
- let old = std::env::var_os(key);
- unsafe {
- std::env::set_var(key, value.as_os_str());
- }
- Self { key, old }
- }
-}
-
-impl Drop for EnvVarGuard {
- fn drop(&mut self) {
- unsafe {
- match &self.old {
- Some(value) => std::env::set_var(self.key, value),
- None => std::env::remove_var(self.key),
- }
- }
- }
-}
-
-static ENV_LOCK: &OnceLock<Mutex<()>> = &crate::SHARED_ENV_LOCK;
-
-fn env_lock() -> std::sync::MutexGuard<'static, ()> {
- ENV_LOCK
- .get_or_init(|| Mutex::new(()))
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner())
-}
-
-fn config_in(tmp: &TempDir) -> Config {
- Config {
- workspace_dir: tmp.path().to_path_buf(),
- ..Config::default()
- }
-}
-
-struct ScriptedProvider {
- response: String,
-}
-
-#[async_trait]
-impl ChatModel<()> for ScriptedProvider {
- async fn invoke(
- &self,
- _state: &(),
- request: ModelRequest,
- ) -> tinyinference::Result<ModelResponse> {
- let prompt = format!("{:?}", request.messages);
- assert!(prompt.contains("hierarchical summarizer"));
- assert!(prompt.contains("under"));
- assert!(!request.messages.is_empty());
- assert!(request.temperature.unwrap_or_default() > 0.0);
- Ok(ModelResponse::assistant(self.response.clone()))
- }
-}
-
-#[tokio::test]
-async fn ingestion_parser_recovers_headers_project_preferences_and_relations() {
- let tmp = TempDir::new().expect("tempdir");
- let memory =
- UnifiedMemory::new(tmp.path(), Arc::new(NoopEmbedding), None).expect("memory store");
-
- let content = r#"
-From: Alice Example <[email protected]>
-To: Bob Builder <[email protected]>
-CC: Clara Ops <[email protected]>
-Subject: OpenHuman round 23 memory coverage
-Date: 2026-05-30
-
-# Coverage Launch
-Project name: OpenHuman
-Subproject: Memory Tree Round 23
-Name: Parser coverage sweep
-Owner: Alice Example
-Due date: 2026-06-02
-Target milestone: Round 23 green coverage
-Preferred embedding model for local experiments: bge-m3
-Preferred extraction mode to try first: sentence mode
-Alice Example owns Parser coverage sweep.
-OpenHuman uses JSON-RPC.
-Clara Ops prefers core-first delivery.
-The board is spatially near the memory tree dashboard.
-Bob Builder will review the memory tree recap.
-"#;
-
- let result = memory
- .ingest_document(MemoryIngestionRequest {
- document: NamespaceDocumentInput {
- namespace: "round23 memory".into(),
- key: "parser-coverage".into(),
- title: "OpenHuman parser coverage".into(),
- content: content.into(),
- source_type: "gmail".into(),
- priority: "high".into(),
- tags: vec!["seed".into()],
- metadata: json!({"round": 23}),
- category: "coverage".into(),
- session_id: Some("round23-session".into()),
- document_id: None,
- taint: openhuman_core::openhuman::memory::MemoryTaint::Internal,
- },
- config: MemoryIngestionConfig {
- model_name: "round23-heuristic".into(),
- extraction_mode: ExtractionMode::Chunk,
- ..MemoryIngestionConfig::default()
- },
- })
- .await
- .expect("ingest document");
-
- assert_eq!(result.namespace, "round23_memory");
- assert_eq!(result.extraction_mode, "chunk");
- assert!(result.chunk_count >= 1);
- assert!(result.entity_count >= 5, "entities: {:?}", result.entities);
- assert!(
- result.relation_count >= 6,
- "relations: {:?}",
- result.relations
- );
- assert!(result.preference_count >= 1);
- assert!(result.decision_count >= 2);
- assert!(result.tags.iter().any(|tag| tag == "deadline"));
- assert!(result.tags.iter().any(|tag| tag == "decision"));
- assert!(result.tags.iter().any(|tag| tag == "seed"));
- assert!(result
- .entities
- .iter()
- .any(|entity| entity.name == "ALICE EXAMPLE"));
- assert!(result
- .relations
- .iter()
- .any(|relation| relation.subject == "ALICE EXAMPLE" && relation.predicate == "OWNS"));
- assert!(result
- .relations
- .iter()
- .any(|relation| relation.subject == "OPENHUMAN"
- && relation.predicate == "USES"
- && relation.object.contains("JSON-RPC")));
- assert!(result
- .relations
- .iter()
- .any(|relation| relation.predicate == "HAS_DEADLINE"));
- assert!(result
- .relations
- .iter()
- .any(|relation| relation.predicate == "PREFERS"));
-
- let graph_rows = memory
- .graph_query_namespace("round23 memory", Some("ALICE EXAMPLE"), Some("OWNS"))
- .await
- .expect("query graph");
- assert!(
- graph_rows.iter().any(|row| row
- .get("object")
- .and_then(Value::as_str)
- .map(|object| object.contains("PARSER"))
- .unwrap_or(false)),
- "graph rows: {graph_rows:?}"
- );
-}
-
-#[tokio::test]
-async fn tree_runtime_engine_summarizes_preserves_buffer_and_rebuilds() {
- let tmp = TempDir::new().expect("tempdir");
- let config = config_in(&tmp);
- let provider = ScriptedProvider {
- response: "round23 summary ".repeat(32),
- };
- let namespace = "round23/tree runtime";
- let ts = Utc.with_ymd_and_hms(2026, 5, 30, 10, 15, 0).unwrap();
-
- tree_runtime_store::buffer_write(
- &config,
- namespace,
- "first raw memory tree entry",
- &ts,
- Some(&json!({"source": "round23"})),
- )
- .expect("buffer first entry");
- tree_runtime_store::buffer_write(
- &config,
- namespace,
- "second raw memory tree entry",
- &ts,
- None,
- )
- .expect("buffer second entry");
-
- let hour = engine::run_summarization(&config, &provider, namespace, ts)
- .await
- .expect("run summarization")
- .expect("hour node");
- assert_eq!(hour.node_id, "2026/05/30/10");
- assert_eq!(hour.child_count, 0);
- assert!(tree_runtime_store::buffer_read(&config, namespace)
- .expect("buffer drained")
- .is_empty());
-
- for node_id in ["2026/05/30", "2026/05", "2026", "root"] {
- let node = tree_runtime_store::read_node(&config, namespace, node_id)
- .expect("read propagated node")
- .unwrap_or_else(|| panic!("missing propagated node {node_id}"));
- assert!(node.child_count >= 1);
- assert!(node.summary.contains("round23 summary") || node.summary.contains("##"));
- }
-
- assert!(engine::run_summarization(&config, &provider, namespace, ts)
- .await
- .expect("empty run")
- .is_none());
-
- tree_runtime_store::buffer_write(
- &config,
- namespace,
- "pending buffer entry should survive rebuild",
- &ts,
- None,
- )
- .expect("buffer pending entry");
-
- let status = engine::rebuild_tree(&config, &provider, namespace)
- .await
- .expect("rebuild tree");
- assert!(status.total_nodes >= 5);
- let pending =
- tree_runtime_store::buffer_read(&config, namespace).expect("buffer after rebuild");
- assert_eq!(pending.len(), 1);
- assert!(pending[0]
- .1
- .contains("pending buffer entry should survive rebuild"));
-}
-
-#[tokio::test]
-async fn tree_runtime_rpc_and_registered_handlers_cover_status_and_errors() {
- let _lock = env_lock();
- let tmp = TempDir::new().expect("tempdir");
- let config = config_in(&tmp);
- let _workspace = EnvVarGuard::set_to_path("OPENHUMAN_WORKSPACE", tmp.path());
- let timestamp = Utc.with_ymd_and_hms(2026, 5, 30, 11, 0, 0).unwrap();
-
- // The summarizer RPC crosses the module binding since the round-2
- // migration, and this raw-coverage target runs without the boot sequence
- // that publishes the module host policy — publish it here exactly as the
- // sync round23 target does, then load the CI-provisioned local module.
- #[cfg(feature = "modules")]
- openhuman_core::openhuman::modules::memory::set_modules_policy(std::sync::Arc::new(
- config.clone(),
- ));
- openhuman_core::openhuman::modules::ops::ensure_loaded(&config, "tinymemory")
- .await
- .expect("load local TinyMemory test module");
-
- let ingest = tree_runtime_rpc::tree_summarizer_ingest(
- &config,
- " round23 rpc ",
- "handler-routed buffered content",
- Some(timestamp),
- Some(&json!({"handler": true})),
- )
- .await
- .expect("direct rpc ingest")
- .value;
- assert_eq!(ingest["buffered"], true);
- assert_eq!(ingest["namespace"], "round23 rpc");
- assert_eq!(ingest["has_metadata"], true);
-
- let status = tree_runtime_rpc::tree_summarizer_status(&config, "round23 rpc")
- .await
- .expect("status")
- .value;
- assert_eq!(status["namespace"], "round23 rpc");
- assert_eq!(status["total_nodes"], 0);
-
- let err = tree_runtime_rpc::tree_summarizer_query(&config, "round23 rpc", Some("root"))
- .await
- .expect_err("root not created yet");
- assert!(err.contains("node 'root' not found"));
- assert!(
- tree_runtime_rpc::tree_summarizer_ingest(&config, "../bad", "x", None, None)
- .await
- .expect_err("bad namespace")
- .contains("..")
- );
-
- let controllers = all_tree_summarizer_registered_controllers();
- assert_eq!(controllers.len(), 5);
- assert!(controllers
- .iter()
- .any(|controller| controller.rpc_method_name() == "openhuman.tree_summarizer_ingest"));
-
- let ingest_handler = controllers
- .iter()
- .find(|controller| controller.schema.function == "ingest")
- .expect("ingest controller")
- .handler;
- let mut params = Map::<String, Value>::new();
- params.insert("namespace".into(), json!("round23-handler"));
- params.insert("content".into(), json!("handler content"));
- params.insert("timestamp".into(), json!("2026-05-30T12:00:00Z"));
- params.insert("metadata".into(), json!({"via": "registered-controller"}));
- let handler_value = ingest_handler(params).await.expect("handler ingest");
- assert_eq!(handler_value["result"]["buffered"], true);
- assert!(handler_value["logs"][0]
- .as_str()
- .unwrap()
- .contains("content buffered"));
-
- let status_handler = controllers
- .iter()
- .find(|controller| controller.schema.function == "status")
- .expect("status controller")
- .handler;
- let missing_err = status_handler(Map::new())
- .await
- .expect_err("missing namespace should fail");
- assert!(missing_err.contains("missing required param 'namespace'"));
-}
diff --git a/tests/raw_coverage/near90_closure_raw_coverage_e2e.rs b/tests/raw_coverage/near90_closure_raw_coverage_e2e.rs
deleted file mode 100644
index f4e6f670e7..0000000000
--- a/tests/raw_coverage/near90_closure_raw_coverage_e2e.rs
+++ /dev/null
@@ -1,835 +0,0 @@
-//! Round 20 near-90 raw integration coverage closures.
-//!
-//! All fixtures are local and deterministic: temp workspaces, loopback HTTP,
-//! and a fake `gh` binary. Run with `--test-threads=1`; several covered
-//! surfaces resolve config/workspace through process environment.
-
-use std::collections::HashMap;
-use std::path::{Path, PathBuf};
-use std::sync::{Arc, Mutex, OnceLock};
-use std::time::Duration as StdDuration;
-
-use chrono::Utc;
-use openhuman_core::openhuman::desktop::app_state::{
- snapshot, update_local_state, StoredAppStatePatch, StoredOnboardingTasks,
-};
-use openhuman_core::openhuman::config::rpc as config_rpc;
-use openhuman_core::openhuman::security::credentials::profiles::{
- AuthProfile, AuthProfileKind, AuthProfilesStore,
-};
-use openhuman_core::openhuman::security::credentials::{
- AuthService, APP_SESSION_PROVIDER, DEFAULT_AUTH_PROFILE_NAME,
-};
-use openhuman_core::openhuman::memory::{
- ai_list_memory_files, ai_read_memory_file, ai_write_memory_file, clear_namespace,
- context_query, context_recall, doc_delete, doc_list, doc_put, memory_delete_document,
- memory_init, memory_list_documents, memory_list_namespaces, memory_query_namespace,
- memory_recall_context, memory_recall_memories, namespace_list, ClearNamespaceParams,
- DeleteDocParams, EmptyRequest, ListDocumentsRequest, ListMemoryFilesRequest, MemoryInitRequest,
- PutDocParams, QueryNamespaceParams, QueryNamespaceRequest, ReadMemoryFileRequest,
- RecallContextRequest, RecallMemoriesRequest, RecallNamespaceParams, WriteMemoryFileRequest,
-};
-use openhuman_core::openhuman::memory::sources::readers::SourceReader;
-// The engine's own source pipeline. `memory::sources::sync` is host-side now and
-// carries only `derive_scopes`; `sync_source` stayed upstream because nothing in
-// `src/` calls it any more (#5560).
-use tinymemory_core::sources::sync::sync_source;
-use openhuman_core::openhuman::memory::sources::{ContentType, MemorySourceEntry, SourceKind};
-use openhuman_core::openhuman::threads::ops as thread_ops;
-use openhuman_core::openhuman::threads::welcome_migration::migrate_welcome_agent_artifacts;
-use serde_json::{json, Value};
-use tempfile::{Builder, TempDir};
-use tokio::io::{AsyncReadExt, AsyncWriteExt};
-
-static ROUND20_ENV_LOCK: &OnceLock<Mutex<()>> = &crate::SHARED_ENV_LOCK;
-
-struct EnvGuard {
- key: &'static str,
- old: Option<String>,
-}
-
-impl EnvGuard {
- fn set(key: &'static str, value: impl Into<String>) -> Self {
- let old = std::env::var(key).ok();
- unsafe { std::env::set_var(key, value.into()) };
- Self { key, old }
- }
-
- fn set_path(key: &'static str, path: &Path) -> Self {
- Self::set(key, path.to_string_lossy().into_owned())
- }
-
- fn unset(key: &'static str) -> Self {
- let old = std::env::var(key).ok();
- unsafe { std::env::remove_var(key) };
- Self { key, old }
- }
-}
-
-impl Drop for EnvGuard {
- fn drop(&mut self) {
- match &self.old {
- Some(value) => unsafe { std::env::set_var(self.key, value) },
- None => unsafe { std::env::remove_var(self.key) },
- }
- }
-}
-
-struct Harness {
- _tmp: TempDir,
- root: PathBuf,
- _guards: Vec<EnvGuard>,
-}
-
-impl Harness {
- async fn config(&self) -> openhuman_core::openhuman::config::Config {
- config_rpc::load_config_with_timeout()
- .await
- .expect("isolated config should load")
- }
-
- fn workspace_dir(&self) -> PathBuf {
- self.root.join("workspace")
- }
-
- fn state_dir(&self) -> PathBuf {
- self.workspace_dir().join("state")
- }
-
- fn app_state_file(&self) -> PathBuf {
- self.state_dir().join("app-state.json")
- }
-}
-
-fn env_lock() -> std::sync::MutexGuard<'static, ()> {
- ROUND20_ENV_LOCK
- .get_or_init(|| Mutex::new(()))
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner())
-}
-
-fn ensure_memory_seams(config: Arc<openhuman_core::openhuman::config::Config>) {
- std::thread::Builder::new()
- .name("round20-memory-seams".to_string())
- .stack_size(8 * 1024 * 1024)
- .spawn(move || {
- #[cfg(feature = "modules")]
- openhuman_core::openhuman::modules::memory::set_modules_policy(config);
- })
- .expect("spawn round20 memory seam installer")
- .join()
- .expect("round20 memory seam installer panicked");
-}
-
-fn tempdir() -> TempDir {
- std::fs::create_dir_all("target").expect("create target");
- Builder::new()
- .prefix("near90-closure-round20-")
- .tempdir_in("target")
- .expect("round20 tempdir")
-}
-
-fn write_min_config(root: &Path, api_url: &str) {
- std::fs::create_dir_all(root).expect("create config root");
- let cfg = format!(
- r#"api_url = "{api_url}"
-default_model = "round20-coverage-model"
-default_temperature = 0.2
-onboarding_completed = true
-chat_onboarding_completed = false
-
-[observability]
-analytics_enabled = false
-
-[secrets]
-encrypt = false
-
-[meet]
-auto_orchestrator_handoff = false
-
-[local_ai]
-enabled = false
-runtime_enabled = false
-opt_in_confirmed = false
-
-[memory]
-provider = "none"
-embedding_provider = "none"
-embedding_model = "none"
-embedding_dimensions = 0
-auto_save = false
-
-[memory_tree]
-embedding_strict = false
-"#
- );
- std::fs::write(root.join("config.toml"), &cfg).expect("write config.toml");
- let _: openhuman_core::openhuman::config::Config =
- toml::from_str(&cfg).expect("round20 config must match schema");
-}
-
-fn setup(api_url: &str) -> Harness {
- let tmp = tempdir();
- let root = tmp.path().join("openhuman");
- write_min_config(&root, api_url);
- let guards = vec![
- EnvGuard::set_path("OPENHUMAN_WORKSPACE", &root),
- EnvGuard::set_path("HOME", tmp.path()),
- EnvGuard::unset("BACKEND_URL"),
- EnvGuard::unset("VITE_BACKEND_URL"),
- EnvGuard::unset("OPENHUMAN_API_URL"),
- EnvGuard::unset("OPENHUMAN_CORE_RPC_URL"),
- EnvGuard::unset("OPENHUMAN_CORE_PORT"),
- EnvGuard::set("OPENHUMAN_KEYRING_BACKEND", "file"),
- EnvGuard::set("OPENHUMAN_MEMORY_EMBED_STRICT", "false"),
- EnvGuard::set("OPENHUMAN_MEMORY_EMBED_ENDPOINT", ""),
- EnvGuard::set("OPENHUMAN_MEMORY_EMBED_MODEL", ""),
- ];
-
- Harness {
- _tmp: tmp,
- root,
- _guards: guards,
- }
-}
-
-fn source_entry(id: &str, kind: SourceKind) -> MemorySourceEntry {
- MemorySourceEntry {
- id: id.to_string(),
- kind,
- label: format!("{id} label"),
- enabled: true,
- toolkit: None,
- connection_id: None,
- path: None,
- glob: None,
- url: None,
- branch: None,
- paths: Vec::new(),
- query: None,
- since_days: None,
- max_items: None,
- max_commits: None,
- max_issues: None,
- max_prs: None,
- selector: None,
- max_tokens_per_sync: None,
- max_cost_per_sync_usd: None,
- sync_depth_days: None,
- }
-}
-
-async fn auth_me_server(
- status: &'static str,
- body: &'static str,
-) -> (String, tokio::task::JoinHandle<()>) {
- let listener = tokio::net::TcpListener::bind(("127.0.0.1", 0))
- .await
- .expect("bind auth fixture");
- let url = format!("http://{}", listener.local_addr().expect("listener addr"));
- let task = tokio::spawn(async move {
- while let Ok((mut stream, _)) = listener.accept().await {
- let mut req = [0_u8; 2048];
- let _ = stream.read(&mut req).await;
- let response = format!(
- "HTTP/1.1 {status}\r\ncontent-type: application/json\r\ncontent-length: {}\r\nconnection: close\r\n\r\n{}",
- body.len(),
- body
- );
- let _ = stream.write_all(response.as_bytes()).await;
- let _ = stream.shutdown().await;
- }
- });
- (url, task)
-}
-
-#[tokio::test]
-async fn round20_app_state_quarantines_directory_state_and_uses_stored_user_on_http_error() {
- let _lock = env_lock();
- let (api_url, server) = auth_me_server("503 Service Unavailable", r#"{"error":"down"}"#).await;
- let harness = setup(&api_url);
- let config = harness.config().await;
-
- AuthService::from_config(&config)
- .store_provider_token(
- APP_SESSION_PROVIDER,
- DEFAULT_AUTH_PROFILE_NAME,
- "round20.remote.token",
- HashMap::from([
- ("user_id".to_string(), "stored-round20".to_string()),
- (
- "user_json".to_string(),
- json!({"id":"stored-round20","fullName":"Stored Round20"}).to_string(),
- ),
- ]),
- true,
- )
- .expect("seed app session");
-
- let first = update_local_state(StoredAppStatePatch {
- keyring_consent: None,
- encryption_key: None,
- onboarding_tasks: Some(Some(StoredOnboardingTasks {
- accessibility_permission_granted: false,
- local_model_consent_given: true,
- local_model_download_started: false,
- enabled_tools: vec!["github".to_string()],
- connected_sources: vec!["rss".to_string()],
- updated_at_ms: Some(20),
- })),
- })
- .await
- .expect("write tasks")
- .value;
- assert!(first.encryption_key.is_none());
- assert_eq!(
- first.onboarding_tasks.expect("tasks").enabled_tools,
- vec!["github"]
- );
-
- let snap = snapshot().await.expect("snapshot").value;
- assert_eq!(
- snap.current_user.as_ref().and_then(|v| v.get("id")),
- Some(&json!("stored-round20"))
- );
- assert_eq!(snap.session_token.as_deref(), Some("round20.remote.token"));
- assert!(!snap.analytics_enabled);
-
- std::fs::remove_file(harness.app_state_file()).expect("remove app-state file");
- std::fs::create_dir_all(harness.app_state_file()).expect("directory at app-state path");
- let recovered = snapshot()
- .await
- .expect("snapshot should quarantine unreadable app-state path")
- .value;
- assert!(recovered.local_state.onboarding_tasks.is_none());
- assert!(!harness.app_state_file().exists());
- assert!(
- std::fs::read_dir(harness.state_dir())
- .expect("state dir")
- .filter_map(Result::ok)
- .any(|entry| entry
- .file_name()
- .to_string_lossy()
- .contains("json.corrupted")),
- "directory app-state should be moved aside"
- );
-
- server.abort();
-}
-
-#[test]
-fn round20_credentials_profiles_cover_legacy_plaintext_errors_and_active_edges() {
- let _lock = env_lock();
- let harness = setup("http://127.0.0.1:9");
- let state_dir = harness.root.join("profile-store");
- let store = AuthProfilesStore::new(&state_dir, false);
-
- let token = AuthProfile::new_token("linear", "team", "lin-round20".to_string());
- store
- .upsert_profile(token.clone(), false)
- .expect("insert token");
- let inactive = store.load().expect("load inactive token");
- assert!(!inactive.active_profiles.contains_key("linear"));
- store
- .set_active_profile("linear", &token.id)
- .expect("activate token");
- assert_eq!(
- store
- .load()
- .expect("load active")
- .active_profiles
- .get("linear"),
- Some(&token.id)
- );
-
- let path = store.path().to_path_buf();
- let now = Utc::now().to_rfc3339();
- std::fs::write(
- &path,
- serde_json::to_string_pretty(&json!({
- "schema_version": 1,
- "updated_at": now,
- "active_profiles": { "github": "legacy-oauth", "token": "legacy-token" },
- "profiles": {
- "legacy-token": {
- "provider": "token",
- "profile_name": "plain",
- "kind": "token",
- "token": "plain-secret",
- "metadata": { "k": "v" },
- "created_at": "bad-created",
- "updated_at": "bad-updated"
- },
- "legacy-oauth": {
- "provider": "github",
- "profile_name": "oauth",
- "kind": "oauth",
- "access_token": "plain-access",
- "refresh_token": "plain-refresh",
- "id_token": "",
- "expires_at": null,
- "token_type": "Bearer",
- "scope": "repo",
- "metadata": {},
- "created_at": "2026-05-29T00:00:00Z",
- "updated_at": "2026-05-29T00:00:00Z"
- }
- }
- }))
- .expect("profile json"),
- )
- .expect("write legacy plaintext store");
-
- let loaded = store.load().expect("load plaintext legacy profiles");
- assert_eq!(
- loaded
- .profiles
- .get("legacy-token")
- .and_then(|profile| profile.token.as_deref()),
- Some("plain-secret")
- );
- let oauth = loaded.profiles.get("legacy-oauth").expect("oauth loaded");
- assert_eq!(oauth.kind, AuthProfileKind::OAuth);
- assert_eq!(
- oauth.token_set.as_ref().map(|tokens| (
- tokens.access_token.as_str(),
- tokens.refresh_token.as_deref(),
- tokens.expires_at
- )),
- Some(("plain-access", Some("plain-refresh"), None))
- );
-
- let set_active_err = store
- .set_active_profile("missing", "not-there")
- .expect_err("missing active profile")
- .to_string();
- assert!(set_active_err.contains("Auth profile not found"));
-}
-
-#[tokio::test]
-async fn round20_memory_sources_readers_and_sync_cover_error_edges_without_network() {
- let _lock = env_lock();
- let harness = setup("http://127.0.0.1:9");
- let config = harness.config().await;
-
- let rss = openhuman_core::openhuman::memory::sources::readers::rss::RssReader::new();
- let mut missing_url = source_entry("rss-missing-url", SourceKind::RssFeed);
- assert_eq!(
- rss.list_items(&missing_url, &config)
- .await
- .expect_err("rss url required"),
- "rss source requires a url"
- );
-
- // The reader rejects loopback sources before attempting a network fetch.
- // This supersedes the former parser-error fixture, which exercised an
- // unsafe request path that no longer exists.
- missing_url.url = Some("http://127.0.0.1:9/not-a-feed".to_string());
- let feed_err = rss
- .list_items(&missing_url, &config)
- .await
- .expect_err("loopback feed rejected before fetching");
- assert!(feed_err.contains("public host"), "unexpected RSS error: {feed_err}");
-
- // GitHub reader portion requires a real `gh` on PATH to shadow with our
- // fake. Skip on CI containers that lack `gh` — without it the reader
- // falls through to the real GitHub API and rate-limits.
- let gh_available = std::process::Command::new("gh")
- .arg("--version")
- .stdout(std::process::Stdio::null())
- .stderr(std::process::Stdio::null())
- .status()
- .map(|s| s.success())
- .unwrap_or(false);
-
- let tmp = tempdir();
- let bin = tmp.path().join("bin");
- std::fs::create_dir_all(&bin).expect("bin dir");
- let script = bin.join("gh");
- write_fake_gh_round20(&script);
- let git_stub = bin.join("git");
- std::fs::write(&git_stub, "#!/usr/bin/env bash\nexit 1\n").expect("write fake git");
- #[cfg(unix)]
- {
- use std::os::unix::fs::PermissionsExt;
- let mut perms = std::fs::metadata(&git_stub)
- .expect("metadata")
- .permissions();
- perms.set_mode(0o755);
- std::fs::set_permissions(&git_stub, perms).expect("chmod fake git");
- }
- let old_path = std::env::var("PATH").unwrap_or_default();
- let _path = EnvGuard::set("PATH", format!("{}:{old_path}", bin.display()));
-
- let github = openhuman_core::openhuman::memory::sources::readers::github::GithubReader;
- let mut entry = source_entry("github-round20", SourceKind::GithubRepo);
- entry.url = Some("[email protected]:tinyhumansai/openhuman.git".to_string());
- if !gh_available {
- eprintln!("skipping github reader assertions: gh CLI not available");
- } else {
- let items = github
- .list_items(&entry, &config)
- .await
- .expect("github list via fake gh");
- assert!(items.iter().any(|item| item.id == "commit:def456"));
- assert!(items.iter().any(|item| item.id == "issue:20"));
-
- let pr = github
- .read_item(&entry, "pr:21", &config)
- .await
- .expect("read merged pr");
- assert_eq!(pr.content_type, ContentType::Markdown);
- assert!(pr.body.contains("merged at 2026-05-29T01:00:00Z"));
- assert_eq!(
- pr.metadata.get("merged").and_then(Value::as_bool),
- Some(true)
- );
-
- let bad_issue = github
- .read_item(&entry, "issue:not-a-number", &config)
- .await
- .expect_err("bad issue number");
- assert!(bad_issue.contains("invalid issue number"));
- }
-
- let mut disabled = source_entry("disabled-twitter", SourceKind::TwitterQuery);
- disabled.enabled = false;
- let disabled_err = sync_source(disabled, Arc::new(config.clone()))
- .await
- .expect_err("disabled sync rejected");
- assert!(disabled_err.contains("is disabled"));
-
- let twitter = source_entry("twitter-round20", SourceKind::TwitterQuery);
- sync_source(twitter, Arc::new(config))
- .await
- .expect("twitter placeholder is reported by background task");
- tokio::time::sleep(StdDuration::from_millis(25)).await;
-}
-
-#[tokio::test]
-async fn round20_memory_documents_files_and_envelopes_cover_success_and_failure_paths() {
- let _lock = env_lock();
- let harness = setup("http://127.0.0.1:9");
- ensure_memory_seams(Arc::new(harness.config().await));
-
- let init = memory_init(MemoryInitRequest {
- jwt_token: Some("ignored-round20".to_string()),
- })
- .await
- .expect("memory init")
- .value
- .data
- .expect("init data");
- assert!(init.initialized);
- assert!(init.memory_dir.ends_with("/memory"));
-
- ai_write_memory_file(WriteMemoryFileRequest {
- relative_path: "notes/round20.md".to_string(),
- content: "Round20 local file memory".to_string(),
- })
- .await
- .expect("write memory file");
- let read = ai_read_memory_file(ReadMemoryFileRequest {
- relative_path: "notes/round20.md".to_string(),
- })
- .await
- .expect("read memory file")
- .value
- .data
- .expect("read data");
- assert!(read.content.contains("local file memory"));
- let traversal = ai_write_memory_file(WriteMemoryFileRequest {
- relative_path: "../escape.md".to_string(),
- content: "no".to_string(),
- })
- .await
- .expect_err("traversal rejected");
- assert!(traversal.contains("path traversal"));
- let listed = ai_list_memory_files(ListMemoryFilesRequest {
- relative_dir: "notes".to_string(),
- })
- .await
- .expect("list notes")
- .value
- .data
- .expect("list data");
- assert_eq!(listed.files, vec!["round20.md"]);
-
- // Use a deterministic namespace — random UUIDs can trigger PII detection.
- let namespace = "round20-cov-test-ns".to_string();
- let put = doc_put(PutDocParams {
- namespace: namespace.clone(),
- key: "launch-note".to_string(),
- title: "Launch Note".to_string(),
- content: "The Calypso launch depends on QA, design, and release owners.".to_string(),
- source_type: "note".to_string(),
- priority: "high".to_string(),
- tags: vec!["round20".to_string()],
- metadata: json!({"round": 20}),
- category: "core".to_string(),
- session_id: Some("session-round20".to_string()),
- document_id: Some("doc-round20".to_string()),
- })
- .await
- .expect("put doc")
- .value;
- assert_eq!(put.document_id, "doc-round20");
-
- let docs = doc_list(None)
- .await
- .expect("doc list all")
- .value
- .get("documents")
- .and_then(Value::as_array)
- .cloned()
- .expect("documents");
- assert!(docs.iter().any(|doc| doc["documentId"] == "doc-round20"));
- let namespaces = namespace_list().await.expect("namespace list").value;
- assert!(namespaces.contains(&namespace));
-
- let query = context_query(QueryNamespaceParams {
- namespace: namespace.clone(),
- query: "Calypso QA".to_string(),
- limit: Some(3),
- })
- .await
- .expect("context query")
- .value;
- assert!(query.contains("Calypso") || query.contains("launch"));
- let recall = context_recall(RecallNamespaceParams {
- namespace: namespace.clone(),
- limit: Some(3),
- })
- .await
- .expect("context recall")
- .value;
- assert!(recall.as_deref().unwrap_or_default().contains("Calypso"));
-
- let envelope_docs = memory_list_documents(ListDocumentsRequest {
- namespace: Some(namespace.clone()),
- })
- .await
- .expect("memory list documents")
- .value
- .data
- .expect("list documents data");
- assert_eq!(envelope_docs.count, 1);
- let envelope_namespaces = memory_list_namespaces(EmptyRequest {})
- .await
- .expect("memory namespaces")
- .value
- .data
- .expect("namespaces data");
- assert!(envelope_namespaces.namespaces.contains(&namespace));
-
- let hidden_context = memory_query_namespace(QueryNamespaceRequest {
- namespace: namespace.clone(),
- query: "Calypso".to_string(),
- include_references: Some(false),
- document_ids: Some(vec!["doc-round20".to_string()]),
- limit: Some(1),
- max_chunks: Some(2),
- })
- .await
- .expect("query namespace envelope")
- .value
- .data
- .expect("query namespace data");
- assert!(hidden_context.context.is_none());
- assert!(hidden_context.llm_context_message.is_some());
-
- let recall_context = memory_recall_context(RecallContextRequest {
- namespace: namespace.clone(),
- include_references: Some(true),
- limit: None,
- max_chunks: Some(1),
- })
- .await
- .expect("recall context envelope")
- .value
- .data
- .expect("recall context data");
- assert!(recall_context.llm_context_message.is_some());
-
- let memories = memory_recall_memories(RecallMemoriesRequest {
- namespace: namespace.clone(),
- min_retention: Some(0.0),
- as_of: Some(0.0),
- limit: Some(1),
- max_chunks: None,
- top_k: Some(1),
- })
- .await
- .expect("recall memories")
- .value
- .data
- .expect("memories data");
- assert!(!memories.memories.is_empty());
-
- let deleted =
- memory_delete_document(openhuman_core::openhuman::memory::DeleteDocumentRequest {
- namespace: namespace.clone(),
- document_id: "doc-round20".to_string(),
- })
- .await
- .expect("delete document envelope")
- .value
- .data
- .expect("delete data");
- assert!(deleted.deleted);
- let second_delete = doc_delete(DeleteDocParams {
- namespace: namespace.clone(),
- document_id: "doc-round20".to_string(),
- })
- .await
- .expect("direct delete missing")
- .value;
- assert_eq!(second_delete["deleted"], false);
- let cleared = clear_namespace(ClearNamespaceParams { namespace })
- .await
- .expect("clear namespace")
- .value;
- assert!(cleared.cleared);
-
- let _ = harness;
-}
-
-#[tokio::test]
-async fn round20_threads_fallback_title_delete_missing_and_welcome_noop_paths() {
- let _lock = env_lock();
- let harness = setup("http://127.0.0.1:9");
-
- let created = thread_ops::thread_create_new(
- openhuman_core::openhuman::memory::CreateConversationThreadRequest {
- labels: None,
- personality_id: None,
- },
- )
- .await
- .expect("create thread")
- .value
- .data
- .expect("created data");
-
- let user_message = openhuman_core::openhuman::memory::ConversationMessageRecord {
- id: "round20-user-msg".to_string(),
- content: "Please map the onboarding telemetry rollout across product analytics and QA."
- .to_string(),
- message_type: "text".to_string(),
- extra_metadata: Value::Null,
- sender: "user".to_string(),
- created_at: Utc::now().to_rfc3339(),
- };
- thread_ops::message_append(
- openhuman_core::openhuman::memory::AppendConversationMessageRequest {
- thread_id: created.id.clone(),
- message: user_message,
- },
- )
- .await
- .expect("append user");
-
- let fallback = thread_ops::thread_generate_title(
- openhuman_core::openhuman::memory::GenerateConversationThreadTitleRequest {
- thread_id: created.id.clone(),
- assistant_message: None,
- },
- )
- .await
- .expect("fallback title")
- .value
- .data
- .expect("fallback data");
- assert!(!fallback.title.trim().is_empty());
- assert_ne!(fallback.title, created.title);
-
- let missing_update = thread_ops::message_update(
- openhuman_core::openhuman::memory::UpdateConversationMessageRequest {
- thread_id: created.id.clone(),
- message_id: "missing-message".to_string(),
- extra_metadata: Some(json!({"x": true})),
- },
- )
- .await
- .expect_err("missing message update fails");
- assert!(missing_update.contains("message") || missing_update.contains("not found"));
-
- let missing_delete = thread_ops::thread_delete(
- openhuman_core::openhuman::memory::DeleteConversationThreadRequest {
- thread_id: "missing-thread-round20".to_string(),
- deleted_at: Utc::now().to_rfc3339(),
- },
- )
- .await
- .expect("missing thread delete is idempotent")
- .value
- .data
- .expect("delete data");
- assert!(!missing_delete.deleted);
-
- std::fs::create_dir_all(harness.workspace_dir().join("session_raw")).expect("raw dir");
- std::fs::write(
- harness.workspace_dir().join("session_raw/ignore.jsonl"),
- "{\"_meta\":{\"agent\":\"orchestrator\",\"thread_id\":\"t\"}}\n",
- )
- .expect("write non-welcome transcript");
- let migration =
- migrate_welcome_agent_artifacts(&harness.workspace_dir()).expect("noop migration");
- assert_eq!(migration.threads_updated, 0);
- assert_eq!(migration.transcripts_updated, 0);
-}
-
-fn write_fake_gh_round20(path: &PathBuf) {
- let script = r#"#!/usr/bin/env bash
-set -euo pipefail
-if [[ "${1:-}" == "--version" ]]; then
- echo "gh version 2.0.0"
- exit 0
-fi
-if [[ "${1:-}" != "api" ]]; then
- echo "unsupported gh command" >&2
- exit 2
-fi
-case "${2:-}" in
- repos/tinyhumansai/openhuman/commits\?*)
- cat <<'JSON'
-[{"sha":"def456","commit":{"message":"Round20 commit fixture","author":{"name":"Ada","email":"[email protected]","date":"2026-05-29T00:00:00Z"},"committer":{"name":"Ada","email":"[email protected]","date":"2026-05-29T00:00:00Z"}}}]
-JSON
- ;;
- repos/tinyhumansai/openhuman/issues\?*)
- cat <<'JSON'
-[{"number":20,"title":"Round20 issue","body":null,"state":"closed","user":null,"labels":[],"created_at":null,"updated_at":"2026-05-29T00:30:00Z","pull_request":null}]
-JSON
- ;;
- repos/tinyhumansai/openhuman/pulls\?*)
- cat <<'JSON'
-[{"number":21,"title":"Round20 merged PR","body":null,"state":"closed","user":null,"labels":[],"created_at":null,"updated_at":"2026-05-29T01:00:00Z","merged_at":"2026-05-29T01:00:00Z","comments":0}]
-JSON
- ;;
- repos/tinyhumansai/openhuman/pulls/21)
- cat <<'JSON'
-{"number":21,"title":"Round20 merged PR","body":null,"state":"closed","user":null,"labels":[],"created_at":null,"updated_at":"2026-05-29T01:00:00Z","merged_at":"2026-05-29T01:00:00Z","comments":0}
-JSON
- ;;
- repos/tinyhumansai/openhuman/issues/21/comments\?*)
- cat <<'JSON'
-[]
-JSON
- ;;
- *)
- echo "unexpected gh api path: ${2:-}" >&2
- exit 3
- ;;
-esac
-"#;
- std::fs::write(path, script).expect("write fake gh");
- #[cfg(unix)]
- {
- use std::os::unix::fs::PermissionsExt;
- let mut perms = std::fs::metadata(path)
- .expect("fake gh metadata")
- .permissions();
- perms.set_mode(0o755);
- std::fs::set_permissions(path, perms).expect("chmod fake gh");
- }
-}
diff --git a/tests/support/memory_golden.rs b/tests/support/memory_golden.rs
deleted file mode 100644
index 9cc8c9504d..0000000000
--- a/tests/support/memory_golden.rs
+++ /dev/null
@@ -1,874 +0,0 @@
-//! Golden-workspace fixture: seeding, read-back, and schema-manifest capture.
-//!
-//! This module is the engine behind `tests/memory_golden_fixture_e2e.rs`, the
-//! schema gate that stands between a memory-store change and a corrupted user
-//! workspace.
-//!
-//! # Why it is a test-target module and not a library one (#5560)
-//!
-//! It used to be `src/openhuman/memory/store_golden.rs`, declared
-//! `pub mod store_golden;` — **not** `#[cfg(test)]` — so it compiled into the
-//! shipped library and its seven `tinymemory_core::` references were production
-//! references, keeping the engine crate in the product dependency graph for the
-//! sake of a fixture.
-//!
-//! Its own module doc justified living in-crate by saying it needed
-//! `pub(crate)` reach an integration test does not have, naming
-//! `MemoryClient::profile_conn`, `trees::store::insert_summary_tx` and
-//! `trees::store::update_tree_after_seal_tx` as "deliberately crate-private
-//! escape hatches". That was true before the memory extraction and is not true
-//! now: all three live in `tinymemory-core`, a *different* crate, where
-//! `pub(crate)` would have been unreachable from `src/` too — and all three are
-//! `pub`. Every OpenHuman item this file names (`memory::ops::*`,
-//! `memory::rpc_models::QueryNamespaceRequest`, `config::Config`) is `pub` as
-//! well, so nothing here ever needed in-crate reach.
-//!
-//! The two alternatives were considered and are worse:
-//!
-//! - **`#[cfg(test)]` on the module** does not work at all. `cfg(test)` is set
-//! only for the crate own unit-test build; an integration test links the
-//! library as an ordinary dependency, so the module would simply not exist
-//! and the golden gate would stop compiling.
-//! - **Routing it onto the memory contract** is both blocked and beside the
-//! point. Blocked because `MemoryChunks` is a read family with no write or
-//! transaction door, and this seeder writes through `store::chunks`,
-//! `namespace_store::{events, fts5, profile, segments}` and two `_tx` tree
-//! helpers inside one transaction. Beside the point because the gate exists
-//! to exercise the engine own DDL and write paths against a `.db` built by
-//! an older binary — a contract-routed seeder would be testing the module
-//! wire surface, which is a different test.
-//!
-//! So it moved here. `tinymemory-core` is a **dev-dependency**
-//! (with `features = ["test-support"]`), which integration tests link exactly
-//! as they link `tinymemory-api`; `memory_golden_fixture_e2e.rs` already calls
-//! `tinymemory_core::global::init` directly, so this file sits in the same
-//! dependency position as the code that drives it. Nothing else changed: the
-//! only edits are the four `crate::openhuman::` paths, rewritten to name the
-//! library from outside as `openhuman_core::openhuman::`.
-//!
-//! Included as a module rather than being its own `tests/*.rs` file so cargo
-//! does not build it as a second test target — the same reason
-//! `tests/raw_coverage/` is a plain directory rather than a set of targets.
-//!
-//! # The four entry points
-//!
-//! - [`seed`] materialises every structure the gate protects into a workspace,
-//! using production write paths (`memory::ops::*` and the same typed store
-//! helpers the archivist and the learning cache call).
-//! - [`read_back`] reads all of it out again through `memory::ops` — proving
-//! the *code path* still works, not merely that the schema still parses.
-//! - [`init_fresh_schema`] stands up an empty workspace's schema, which is the
-//! only way to see an *in-place* DDL redefinition (`CREATE … IF NOT EXISTS`
-//! is a no-op against a DB that already holds the name).
-//! - [`schema_manifest`] dumps `sqlite_master` (tables, indexes, triggers) plus
-//! `PRAGMA user_version` across every `*.db` in the workspace, normalised to
-//! a deterministic, diffable text form.
-//!
-//! # Why the fixture must be captured, not synthesised
-//!
-//! The committed fixture under `tests/fixtures/memory_golden/` was produced by
-//! a **specific past build**. The manifest is derived from that fixture by
-//! [`schema_manifest`], never hand-written. That combination is what makes the
-//! gate bite: editing a `CREATE TABLE` in `namespace_store/init.rs` *and*
-//! editing the manifest to match still fails, because the committed `.db` was
-//! built by the older binary and no longer matches the new DDL. Making the
-//! suite green requires deliberately regenerating the fixture — a visible,
-//! reviewable act. See `tests/fixtures/memory_golden/README.md`.
-//!
-//! Debug logging uses the `[golden]` prefix throughout. Nothing seeded here is
-//! real user data: every value is a fixed literal chosen to be obviously
-//! synthetic.
-
-use std::collections::BTreeSet;
-use std::path::{Path, PathBuf};
-
-use anyhow::{Context as _, Result};
-use chrono::{DateTime, TimeZone, Utc};
-
-use openhuman_core::openhuman::config::Config;
-use openhuman_core::openhuman::memory::ops::{
- doc_list, doc_put, graph_query, graph_upsert, kv_get, memory_query_namespace, GraphQueryParams,
- GraphUpsertParams, KvGetDeleteParams, KvSetParams, NamespaceOnlyParams, PutDocParams,
-};
-use openhuman_core::openhuman::memory::rpc_models::QueryNamespaceRequest;
-use tinymemory_api::chunks::{Chunk, Metadata, SourceKind, SourceRef};
-use tinymemory_core::store::chunks;
-use tinymemory_core::store::namespace_store::{events, fts5, profile, segments};
-use tinymemory_core::store::trees;
-use tinymemory_core::store::trees::types::{SummaryNode, Tree, TreeKind, TreeStatus};
-
-// ── Fixture identity ─────────────────────────────────────────────────────────
-//
-// Every constant below is part of the fixture's contract: the committed `.db`
-// contains rows under exactly these keys, and `read_back` looks them up by
-// name. Changing one means regenerating the fixture.
-
-/// First seeded namespace.
-pub const NAMESPACE_PRIMARY: &str = "golden-primary";
-/// Second seeded namespace — the gate needs ≥ 2 so namespace scoping is real.
-pub const NAMESPACE_SECONDARY: &str = "golden-secondary";
-/// Document key in [`NAMESPACE_PRIMARY`].
-pub const DOC_KEY_PRIMARY: &str = "golden-doc-primary";
-/// Document key in [`NAMESPACE_SECONDARY`].
-pub const DOC_KEY_SECONDARY: &str = "golden-doc-secondary";
-/// Body of the primary document; also the target of [`RECALL_QUERY`].
-pub const DOC_CONTENT_PRIMARY: &str =
- "The golden fixture pins the memory workspace schema for regression testing.";
-/// Body of the secondary document.
-pub const DOC_CONTENT_SECONDARY: &str =
- "A second namespace exists so namespace scoping is exercised, not assumed.";
-/// Key used for both the global and the namespace-scoped KV write.
-pub const KV_KEY: &str = "golden-kv-canary";
-/// Graph triple subject.
-pub const GRAPH_SUBJECT: &str = "golden-subject";
-/// Graph triple predicate.
-pub const GRAPH_PREDICATE: &str = "relates-to";
-/// Graph triple object.
-pub const GRAPH_OBJECT: &str = "golden-object";
-/// Session id shared by the episodic row, the segment, and the event.
-pub const SESSION_ID: &str = "golden-session";
-/// Seeded conversation segment id.
-pub const SEGMENT_ID: &str = "golden-segment";
-/// Seeded event id.
-pub const EVENT_ID: &str = "golden-event";
-/// Seeded profile facet key.
-pub const PROFILE_KEY: &str = "golden/verbosity";
-/// Seeded profile facet value.
-pub const PROFILE_VALUE: &str = "concise";
-/// Seeded summary-tree id.
-pub const TREE_ID: &str = "golden-tree";
-/// Seeded summary node id (the sealed root of [`TREE_ID`]).
-pub const SUMMARY_ID: &str = "golden-summary";
-/// Embedding model signature stamped on every seeded vector.
-pub const MODEL_SIGNATURE: &str = "golden-fixture/dim-4";
-/// The deterministic vector written to every embedding tier.
-pub const EMBEDDING: [f32; 4] = [0.25, 0.5, 0.75, 1.0];
-/// Fixed recall query — [`read_back`] asserts its result set exactly.
-pub const RECALL_QUERY: &str = "golden fixture schema";
-
-/// Fixed timestamp for every seeded row, so a regenerated fixture differs from
-/// the committed one only where the *schema* differs.
-fn fixed_time() -> DateTime<Utc> {
- Utc.timestamp_opt(1_700_000_000, 0)
- .single()
- .expect("fixed fixture timestamp is valid")
-}
-
-fn fixed_epoch_secs() -> f64 {
- 1_700_000_000.0
-}
-
-/// Build a [`Config`] rooted at `workspace`, for the tinycortex-backed tiers
-/// (`chunks::*` / `trees::*`) which resolve their DB path from `workspace_dir`.
-fn fixture_config(workspace: &Path) -> Config {
- let mut config = Config::default();
- config.workspace_dir = workspace.to_path_buf();
- config
-}
-
-// ── Seeding ──────────────────────────────────────────────────────────────────
-
-/// Seed a complete golden workspace at `workspace`.
-///
-/// The caller must have bound the process-global memory client to `workspace`
-/// (`memory::global::init`) and pointed `OPENHUMAN_WORKSPACE` at it first, so
-/// the `memory::ops` write paths land in the same place as the direct store
-/// writes below.
-///
-/// Idempotent: every write is an upsert or `INSERT OR REPLACE`, so re-seeding
-/// an already-seeded workspace is a no-op at the row level.
-pub async fn seed(workspace: &Path) -> Result<()> {
- tracing::debug!(workspace = %workspace.display(), "[golden] seeding golden workspace");
-
- seed_documents().await?;
- seed_kv().await?;
- seed_graph().await?;
-
- let client = tinymemory_core::global::client()
- .map_err(|e| anyhow::anyhow!("[golden] memory client not bound: {e}"))?;
- let conn = client.profile_conn();
-
- seed_episodic(&conn)?;
- seed_segment(&conn)?;
- seed_event(&conn)?;
- seed_profile(&conn)?;
- drop(conn);
-
- seed_chunk_and_tree(workspace)?;
-
- tracing::debug!("[golden] seeding complete");
- Ok(())
-}
-
-async fn seed_documents() -> Result<()> {
- for (namespace, key, content) in [
- (NAMESPACE_PRIMARY, DOC_KEY_PRIMARY, DOC_CONTENT_PRIMARY),
- (
- NAMESPACE_SECONDARY,
- DOC_KEY_SECONDARY,
- DOC_CONTENT_SECONDARY,
- ),
- ] {
- tracing::debug!(namespace, key, "[golden] seeding document");
- doc_put(PutDocParams {
- namespace: namespace.to_string(),
- key: key.to_string(),
- title: format!("Golden fixture document ({namespace})"),
- content: content.to_string(),
- source_type: "doc".to_string(),
- priority: "medium".to_string(),
- tags: vec!["golden".to_string()],
- metadata: serde_json::json!({ "fixture": true }),
- category: "core".to_string(),
- session_id: None,
- document_id: None,
- })
- .await
- .map_err(|e| anyhow::anyhow!("[golden] doc_put({namespace}/{key}) failed: {e}"))?;
- }
- Ok(())
-}
-
-async fn seed_kv() -> Result<()> {
- for namespace in [None, Some(NAMESPACE_PRIMARY.to_string())] {
- tracing::debug!(?namespace, key = KV_KEY, "[golden] seeding kv");
- openhuman_core::openhuman::memory::ops::kv_set(KvSetParams {
- namespace: namespace.clone(),
- key: KV_KEY.to_string(),
- value: serde_json::json!({ "fixture": "golden", "v": 1 }),
- })
- .await
- .map_err(|e| anyhow::anyhow!("[golden] kv_set({namespace:?}) failed: {e}"))?;
- }
- Ok(())
-}
-
-async fn seed_graph() -> Result<()> {
- tracing::debug!(subject = GRAPH_SUBJECT, "[golden] seeding graph triple");
- graph_upsert(GraphUpsertParams {
- namespace: Some(NAMESPACE_PRIMARY.to_string()),
- subject: GRAPH_SUBJECT.to_string(),
- predicate: GRAPH_PREDICATE.to_string(),
- object: GRAPH_OBJECT.to_string(),
- attrs: serde_json::json!({ "fixture": true }),
- })
- .await
- .map_err(|e| anyhow::anyhow!("[golden] graph_upsert failed: {e}"))?;
- Ok(())
-}
-
-type SharedConn = std::sync::Arc<parking_lot::Mutex<rusqlite::Connection>>;
-
-/// Episodic row — also materialises the `episodic_fts` shadow tables through
-/// the `episodic_ai` trigger.
-fn seed_episodic(conn: &SharedConn) -> Result<()> {
- tracing::debug!(session = SESSION_ID, "[golden] seeding episodic row");
- fts5::episodic_insert(
- conn,
- &fts5::EpisodicEntry {
- id: None,
- session_id: SESSION_ID.to_string(),
- timestamp: fixed_epoch_secs(),
- role: "user".to_string(),
- content: "Golden fixture episodic turn about the memory schema.".to_string(),
- lesson: Some("Fixtures beat hand-written constants.".to_string()),
- tool_calls_json: None,
- cost_microdollars: 0,
- },
- )
- .context("[golden] episodic_insert")?;
- // The insert now answers with the assigned row id; the golden fixture only
- // needs the row to exist.
- Ok(())
-}
-
-/// A sealed (summarised) conversation segment with both embedding tiers.
-fn seed_segment(conn: &SharedConn) -> Result<()> {
- tracing::debug!(
- segment = SEGMENT_ID,
- "[golden] seeding conversation segment"
- );
- let now = fixed_epoch_secs();
- segments::segment_create(
- conn,
- SEGMENT_ID,
- SESSION_ID,
- NAMESPACE_PRIMARY,
- 1,
- Some(0),
- now,
- now,
- )
- .context("[golden] segment_create")?;
- segments::segment_append_turn(conn, SEGMENT_ID, 1, Some(1), now, now)
- .context("[golden] segment_append_turn")?;
- segments::segment_close(conn, SEGMENT_ID, now).context("[golden] segment_close")?;
- segments::segment_set_summary(conn, SEGMENT_ID, "Golden fixture segment summary.", now)
- .context("[golden] segment_set_summary")?;
- segments::segment_set_embedding(conn, SEGMENT_ID, &EMBEDDING, now)
- .context("[golden] segment_set_embedding")?;
- segments::segment_embedding_upsert(conn, SEGMENT_ID, MODEL_SIGNATURE, &EMBEDDING, now)
- .context("[golden] segment_embedding_upsert")
-}
-
-/// An event row (materialising the `event_fts` shadow tables via trigger) plus
-/// its per-model embedding.
-fn seed_event(conn: &SharedConn) -> Result<()> {
- tracing::debug!(event = EVENT_ID, "[golden] seeding event row");
- let now = fixed_epoch_secs();
- events::event_insert(
- conn,
- &events::EventRecord {
- event_id: EVENT_ID.to_string(),
- segment_id: SEGMENT_ID.to_string(),
- session_id: SESSION_ID.to_string(),
- namespace: NAMESPACE_PRIMARY.to_string(),
- event_type: events::EventType::Decision,
- content: "Decided to pin the memory schema with a captured fixture.".to_string(),
- subject: Some(GRAPH_SUBJECT.to_string()),
- timestamp_ref: None,
- confidence: 0.9,
- embedding: Some(EMBEDDING.to_vec()),
- source_turn_ids: None,
- created_at: now,
- },
- )
- .context("[golden] event_insert")?;
- events::event_embedding_upsert(conn, EVENT_ID, MODEL_SIGNATURE, &EMBEDDING, now)
- .context("[golden] event_embedding_upsert")
-}
-
-/// A `user_profile` facet — the learning tier.
-fn seed_profile(conn: &SharedConn) -> Result<()> {
- tracing::debug!(key = PROFILE_KEY, "[golden] seeding profile facet");
- profile::profile_upsert(
- conn,
- "golden-facet",
- &profile::FacetType::Preference,
- PROFILE_KEY,
- PROFILE_VALUE,
- 0.8,
- Some(SEGMENT_ID),
- fixed_epoch_secs(),
- )
- .context("[golden] profile_upsert")
-}
-
-/// The tinycortex substrate: one leaf chunk with an embedding, plus a tree
-/// sealed to an L1 summary node with its own embedding.
-fn seed_chunk_and_tree(workspace: &Path) -> Result<()> {
- let config = fixture_config(workspace);
- let at = fixed_time();
-
- let metadata = Metadata {
- source_kind: SourceKind::Document,
- source_id: "golden-source".to_string(),
- owner: "golden-owner".to_string(),
- timestamp: at,
- time_range: (at, at),
- tags: vec!["golden".to_string()],
- source_ref: Some(SourceRef::new("golden://fixture/1")),
- path_scope: Some("golden".to_string()),
- };
- let chunk = Chunk {
- id: chunks::types::chunk_id(
- SourceKind::Document,
- "golden-source",
- 0,
- DOC_CONTENT_PRIMARY,
- ),
- content: DOC_CONTENT_PRIMARY.to_string(),
- metadata,
- token_count: 20,
- seq_in_source: 0,
- created_at: at,
- partial_message: false,
- };
- let chunk_id = chunk.id.clone();
- tracing::debug!(chunk = %chunk_id, "[golden] seeding tinycortex leaf chunk");
- chunks::store::upsert_chunks(&config, std::slice::from_ref(&chunk))
- .context("[golden] upsert_chunks")?;
- chunks::store::set_chunk_embedding(&config, &chunk_id, &EMBEDDING)
- .context("[golden] set_chunk_embedding")?;
-
- tracing::debug!(tree = TREE_ID, "[golden] seeding summary tree");
- trees::store::insert_tree(
- &config,
- &Tree {
- id: TREE_ID.to_string(),
- kind: TreeKind::Source,
- scope: "golden-source".to_string(),
- root_id: None,
- max_level: 0,
- status: TreeStatus::Active,
- created_at: at,
- last_sealed_at: None,
- ask: None,
- },
- )
- .context("[golden] insert_tree")?;
-
- let node = SummaryNode {
- id: SUMMARY_ID.to_string(),
- tree_id: TREE_ID.to_string(),
- tree_kind: TreeKind::Source,
- level: 1,
- parent_id: None,
- child_ids: vec![chunk_id.clone()],
- content: "Golden fixture summary node.".to_string(),
- token_count: 8,
- entities: vec![GRAPH_SUBJECT.to_string()],
- topics: vec!["golden".to_string()],
- time_range_start: at,
- time_range_end: at,
- score: 1.0,
- sealed_at: at,
- deleted: false,
- embedding: None,
- doc_id: None,
- version_ms: None,
- };
-
- // Seal in one transaction, exactly as the production seal path does.
- chunks::store::with_connection(&config, |conn| {
- let tx = conn.unchecked_transaction()?;
- trees::store::insert_summary_tx(&tx, &node, None, MODEL_SIGNATURE)?;
- trees::store::update_tree_after_seal_tx(&tx, TREE_ID, SUMMARY_ID, 1, at)?;
- tx.commit()?;
- Ok(())
- })
- .context("[golden] seal summary tree")?;
-
- trees::store::set_summary_embedding(&config, SUMMARY_ID, &EMBEDDING)
- .context("[golden] set_summary_embedding")?;
- Ok(())
-}
-
-/// Materialise a **fresh** workspace's schema at `workspace` — no rows, no
-/// process-global memory client, just the bootstrap DDL both tiers run on
-/// every open.
-///
-/// This exists to close a blind spot in the "reopen the committed fixture"
-/// check. `CREATE TABLE / INDEX / TRIGGER IF NOT EXISTS` is a **no-op** against
-/// a database that already has the name, so redefining an existing object
-/// in place is invisible when the gate only ever reopens an old DB. A fresh
-/// DB takes the new DDL, so comparing it to the same manifest catches the edit.
-pub async fn init_fresh_schema(workspace: &Path) -> Result<()> {
- tracing::debug!(workspace = %workspace.display(), "[golden] initialising a fresh schema");
- std::fs::create_dir_all(workspace).context("[golden] create fresh workspace dir")?;
-
- // Host unified tier.
- let memory = tinymemory_core::store::UnifiedMemory::new(
- workspace,
- std::sync::Arc::new(tinymemory_api::host::NoopEmbedding),
- None,
- )
- .context("[golden] UnifiedMemory::new on a fresh workspace")?;
-
- // The crate KV tier (`kv_global` / `kv_namespace` + `idx_kv_ns`) is created
- // **lazily** by `KvStore::from_shared_connection` on first use, not by
- // `UnifiedMemory::new`. Touch it, or the fresh schema is missing `idx_kv_ns`
- // and the gate reports a false drift.
- memory
- .kv_get_global("golden-schema-probe")
- .await
- .map_err(|e| anyhow::anyhow!("[golden] crate KV tier init: {e}"))?;
-
- // tinycortex chunk-DB substrate.
- let config = fixture_config(workspace);
- chunks::store::with_connection(&config, |_conn| Ok(()))
- .context("[golden] tinycortex chunk-DB init on a fresh workspace")?;
- Ok(())
-}
-
-// ── Read-back ────────────────────────────────────────────────────────────────
-
-/// Everything [`read_back`] recovered from a seeded workspace.
-///
-/// Deliberately plain data so the test can assert on it without re-deriving
-/// any of the lookup logic.
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub struct Readback {
- /// Document keys found in [`NAMESPACE_PRIMARY`], sorted.
- pub primary_doc_keys: Vec<String>,
- /// Document keys found in [`NAMESPACE_SECONDARY`], sorted.
- pub secondary_doc_keys: Vec<String>,
- /// Whether the global-scope KV value round-tripped.
- pub kv_global_present: bool,
- /// Whether the namespace-scope KV value round-tripped.
- pub kv_namespace_present: bool,
- /// Number of graph triples matching the seeded subject.
- pub graph_hits: usize,
- /// Session ids of episodic rows recovered for [`SESSION_ID`].
- pub episodic_sessions: Vec<String>,
- /// Segment ids recovered for [`NAMESPACE_PRIMARY`], sorted.
- pub segment_ids: Vec<String>,
- /// Event ids recovered for the seeded segment, sorted.
- pub event_ids: Vec<String>,
- /// Profile facet keys recovered, sorted.
- pub profile_keys: Vec<String>,
- /// Leaf chunk ids present in the tinycortex substrate, sorted.
- pub chunk_ids: Vec<String>,
- /// Summary node ids present under [`TREE_ID`], sorted.
- pub summary_ids: Vec<String>,
- /// Whether the seeded tree reports a sealed root.
- pub tree_sealed: bool,
- /// Whether every embedding tier read back the exact seeded vector.
- pub embeddings_match: bool,
- /// Chunk contents returned by the fixed [`RECALL_QUERY`], sorted.
- pub recall_chunks: Vec<String>,
-}
-
-/// Read every seeded structure back out of `workspace`.
-///
-/// Documents, KV and graph go through `memory::ops` — the same handlers the
-/// JSON-RPC surface calls — so this proves the *code path*, not just that the
-/// schema parses. The episodic / segment / event / profile / substrate tiers
-/// have no `ops` reader, so they use the same typed store helpers their
-/// production readers use.
-pub async fn read_back(workspace: &Path) -> Result<Readback> {
- tracing::debug!(workspace = %workspace.display(), "[golden] reading golden workspace back");
-
- let primary_doc_keys = doc_keys_in(NAMESPACE_PRIMARY).await?;
- let secondary_doc_keys = doc_keys_in(NAMESPACE_SECONDARY).await?;
-
- let kv_global_present = kv_get(KvGetDeleteParams {
- namespace: None,
- key: KV_KEY.to_string(),
- })
- .await
- .map_err(|e| anyhow::anyhow!("[golden] kv_get(global) failed: {e}"))?
- .value
- .is_some();
- let kv_namespace_present = kv_get(KvGetDeleteParams {
- namespace: Some(NAMESPACE_PRIMARY.to_string()),
- key: KV_KEY.to_string(),
- })
- .await
- .map_err(|e| anyhow::anyhow!("[golden] kv_get(namespace) failed: {e}"))?
- .value
- .is_some();
-
- let graph_hits = graph_query(GraphQueryParams {
- namespace: Some(NAMESPACE_PRIMARY.to_string()),
- subject: Some(GRAPH_SUBJECT.to_string()),
- predicate: None,
- })
- .await
- .map_err(|e| anyhow::anyhow!("[golden] graph_query failed: {e}"))?
- .value
- .len();
-
- let client = tinymemory_core::global::client()
- .map_err(|e| anyhow::anyhow!("[golden] memory client not bound: {e}"))?;
- let conn = client.profile_conn();
-
- let episodic_sessions: Vec<String> = fts5::episodic_session_entries(&conn, SESSION_ID)
- .context("[golden] episodic_session_entries")?
- .into_iter()
- .map(|entry| entry.session_id)
- .collect();
-
- let mut segment_ids: Vec<String> =
- segments::segments_by_namespace(&conn, NAMESPACE_PRIMARY, 16)
- .context("[golden] segments_by_namespace")?
- .into_iter()
- .map(|segment| segment.segment_id)
- .collect();
- segment_ids.sort();
-
- let mut event_ids: Vec<String> = events::events_for_segment(&conn, SEGMENT_ID)
- .context("[golden] events_for_segment")?
- .into_iter()
- .map(|event| event.event_id)
- .collect();
- event_ids.sort();
-
- let mut profile_keys: Vec<String> = profile::profile_select_all(&conn)
- .context("[golden] profile_select_all")?
- .into_iter()
- .map(|facet| facet.key)
- .collect();
- profile_keys.sort();
-
- let segment_vector = segments::segment_embedding_get(&conn, SEGMENT_ID, MODEL_SIGNATURE)
- .context("[golden] segment_embedding_get")?;
- let event_vector = events::event_embedding_get(&conn, EVENT_ID, MODEL_SIGNATURE)
- .context("[golden] event_embedding_get")?;
- drop(conn);
-
- let config = fixture_config(workspace);
- let mut chunk_ids: Vec<String> = chunks::store::list_chunks(
- &config,
- &chunks::ListChunksQuery {
- limit: Some(64),
- ..Default::default()
- },
- )
- .context("[golden] list_chunks")?
- .into_iter()
- .map(|chunk| chunk.id)
- .collect();
- chunk_ids.sort();
-
- let mut summary_ids: Vec<String> = trees::store::list_summaries_at_level(&config, TREE_ID, 1)
- .context("[golden] list_summaries_at_level")?
- .into_iter()
- .map(|node| node.id)
- .collect();
- summary_ids.sort();
-
- let tree_sealed = trees::store::get_tree(&config, TREE_ID)
- .context("[golden] get_tree")?
- .is_some_and(|tree| tree.root_id.as_deref() == Some(SUMMARY_ID));
-
- let chunk_vector = chunk_ids
- .first()
- .map(|id| chunks::store::get_chunk_embedding(&config, id))
- .transpose()
- .context("[golden] get_chunk_embedding")?
- .flatten();
- let summary_vector = trees::store::get_summary_embedding(&config, SUMMARY_ID)
- .context("[golden] get_summary_embedding")?;
-
- let embeddings_match = [segment_vector, event_vector, chunk_vector, summary_vector]
- .iter()
- .all(|vector| vector.as_deref() == Some(&EMBEDDING[..]));
-
- // Fixed-query recall through the production handler. Asserting on chunk
- // *contents* rather than scores keeps this deterministic across embedding
- // backends while still proving the retrieval path runs end to end.
- let recall_envelope = memory_query_namespace(QueryNamespaceRequest {
- namespace: NAMESPACE_PRIMARY.to_string(),
- query: RECALL_QUERY.to_string(),
- include_references: Some(true),
- document_ids: None,
- limit: Some(16),
- max_chunks: None,
- })
- .await
- .map_err(|e| anyhow::anyhow!("[golden] memory_query_namespace failed: {e}"))?
- .value;
- anyhow::ensure!(
- recall_envelope.error.is_none(),
- "[golden] recall returned an error envelope: {:?}",
- recall_envelope.error
- );
- let mut recall_chunks: Vec<String> = recall_envelope
- .data
- .and_then(|response| response.context)
- .map(|context| {
- context
- .chunks
- .into_iter()
- .map(|chunk| chunk.content)
- .collect()
- })
- .unwrap_or_default();
- recall_chunks.sort();
-
- let readback = Readback {
- primary_doc_keys,
- secondary_doc_keys,
- kv_global_present,
- kv_namespace_present,
- graph_hits,
- episodic_sessions,
- segment_ids,
- event_ids,
- profile_keys,
- chunk_ids,
- summary_ids,
- tree_sealed,
- embeddings_match,
- recall_chunks,
- };
- tracing::debug!(?readback, "[golden] read-back complete");
- Ok(readback)
-}
-
-async fn doc_keys_in(namespace: &str) -> Result<Vec<String>> {
- let listed = doc_list(Some(NamespaceOnlyParams {
- namespace: namespace.to_string(),
- }))
- .await
- .map_err(|e| anyhow::anyhow!("[golden] doc_list({namespace}) failed: {e}"))?;
- // Strict on shape. A tolerant `unwrap_or_default()` here would turn a
- // change to the `doc_list` envelope into "zero documents", which reads as
- // a data-loss failure and hides the real cause.
- let rows = listed
- .value
- .get("documents")
- .and_then(|v| v.as_array())
- .cloned()
- .ok_or_else(|| {
- anyhow::anyhow!(
- "[golden] doc_list({namespace}) envelope has no `documents` array: {}",
- listed.value
- )
- })?;
- let mut keys: Vec<String> = Vec::with_capacity(rows.len());
- for row in rows {
- let key = row
- .get("key")
- .and_then(|v| v.as_str())
- .ok_or_else(|| anyhow::anyhow!("[golden] doc_list row has no `key`: {row}"))?;
- keys.push(key.to_string());
- }
- keys.sort();
- Ok(keys)
-}
-
-// ── Schema manifest ──────────────────────────────────────────────────────────
-
-/// Recursively collect every `*.db` under `dir`, sorted by path.
-pub fn db_files(dir: &Path) -> Vec<PathBuf> {
- fn walk(dir: &Path, out: &mut Vec<PathBuf>) {
- let Ok(entries) = std::fs::read_dir(dir) else {
- return;
- };
- for entry in entries.flatten() {
- let path = entry.path();
- if path.is_dir() {
- walk(&path, out);
- } else if path.extension().and_then(|e| e.to_str()) == Some("db") {
- out.push(path);
- }
- }
- }
- let mut out = Vec::new();
- walk(dir, &mut out);
- out.sort();
- out
-}
-
-/// Collapse every whitespace run in a DDL statement to a single space.
-///
-/// SQLite stores `sqlite_master.sql` verbatim, so re-indenting a `CREATE TABLE`
-/// would otherwise read as a schema change. Formatting is not the contract;
-/// structure is.
-fn normalize_sql(sql: &str) -> String {
- sql.split_whitespace().collect::<Vec<_>>().join(" ")
-}
-
-/// Deterministic, diffable dump of every schema object in `workspace`.
-///
-/// One line per object, of the form:
-///
-/// ```text
-/// <db-relative-path>\t<type>\t<name>\t<normalized sql>
-/// ```
-///
-/// plus one `pragma\tuser_version` line per DB file. Lines are collected into a
-/// `BTreeSet`, so the result is order-independent and compares as a **set** —
-/// the test reports missing and extra objects separately rather than a
-/// whole-file diff.
-///
-/// Covers `type IN ('table','index','trigger')`, including SQLite's internal
-/// `sqlite_autoindex_*` entries (deterministic consequences of the DDL) and the
-/// FTS5 shadow tables.
-pub fn schema_manifest(workspace: &Path) -> Result<BTreeSet<String>> {
- let mut lines = BTreeSet::new();
- let files = db_files(workspace);
- anyhow::ensure!(
- !files.is_empty(),
- "[golden] no *.db files found under {}",
- workspace.display()
- );
-
- for db in files {
- let relative = db
- .strip_prefix(workspace)
- .unwrap_or(&db)
- .to_string_lossy()
- .replace('\\', "/");
- tracing::debug!(db = %relative, "[golden] dumping schema");
-
- let conn =
- rusqlite::Connection::open_with_flags(&db, rusqlite::OpenFlags::SQLITE_OPEN_READ_ONLY)
- .with_context(|| format!("[golden] open {relative} read-only"))?;
-
- let user_version: i64 = conn
- .query_row("PRAGMA user_version", [], |row| row.get(0))
- .with_context(|| format!("[golden] read user_version of {relative}"))?;
- lines.insert(format!("{relative}\tpragma\tuser_version\t{user_version}"));
-
- let mut stmt = conn
- .prepare(
- "SELECT type, name, COALESCE(sql, '') FROM sqlite_master
- WHERE type IN ('table','index','trigger')",
- )
- .with_context(|| format!("[golden] prepare sqlite_master scan of {relative}"))?;
- let rows = stmt
- .query_map([], |row| {
- Ok((
- row.get::<_, String>(0)?,
- row.get::<_, String>(1)?,
- row.get::<_, String>(2)?,
- ))
- })
- .with_context(|| format!("[golden] scan sqlite_master of {relative}"))?;
- for row in rows {
- let (kind, name, sql) = row.context("[golden] read sqlite_master row")?;
- lines.insert(format!(
- "{relative}\t{kind}\t{name}\t{}",
- normalize_sql(&sql)
- ));
- }
- }
-
- tracing::debug!(objects = lines.len(), "[golden] manifest built");
- Ok(lines)
-}
-
-/// Render a manifest as the committed file format: one line per object,
-/// newline-separated, trailing newline.
-pub fn render_manifest(manifest: &BTreeSet<String>) -> String {
- let mut out = manifest.iter().cloned().collect::<Vec<_>>().join("\n");
- out.push('\n');
- out
-}
-
-/// Parse a committed manifest file back into a set, ignoring blank lines and
-/// `#` comments.
-pub fn parse_manifest(text: &str) -> BTreeSet<String> {
- text.lines()
- .filter(|line| !line.trim().is_empty() && !line.starts_with('#'))
- .map(str::to_string)
- .collect()
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn normalize_sql_ignores_formatting_but_not_structure() {
- assert_eq!(
- normalize_sql("CREATE TABLE t (\n a TEXT,\n b INTEGER\n)"),
- normalize_sql("CREATE TABLE t ( a TEXT, b INTEGER )")
- );
- assert_ne!(
- normalize_sql("CREATE TABLE t (a TEXT)"),
- normalize_sql("CREATE TABLE t (a INTEGER)")
- );
- }
-
- #[test]
- fn manifest_round_trips_through_render_and_parse() {
- let manifest: BTreeSet<String> = [
- "a\ttable\tx\tCREATE TABLE x (i INT)",
- "a\tpragma\tuser_version\t0",
- ]
- .into_iter()
- .map(str::to_string)
- .collect();
- assert_eq!(parse_manifest(&render_manifest(&manifest)), manifest);
- }
-
- #[test]
- fn parse_manifest_skips_comments_and_blanks() {
- let parsed = parse_manifest("# header\n\na\ttable\tx\tCREATE TABLE x (i INT)\n");
- assert_eq!(parsed.len(), 1);
- }
-}