Pluggable memory backends behind one driver contract
Summary
Make memory a bound subsystem rather than a fused implementation: consolidate the TinyCortex
engine out of the host into vendor/tinycortex, expose it through a single driver contract, and add
external backends (Supermemory, mem0, agentmemory, cognee) behind that same contract.
Problem / Context
We want to plug external memory backends into OpenHuman. The blocker is not the external side — it is that the current memory system is not behind any interface at all, so "pluggable" would be a fiction even with adapters written.
The embedded path is privileged today in ways no external driver can match:
- Retrieval reads a host task-local (
memory::source_scope::current_source_scope()) from inside the engine — five files undermemory/tree/retrieval/. A second driver would silently lose the per-turn source allowlist. - 78 engine files import
crate::openhuman::config,crate::core::event_bus, orcrate::openhuman::securitydirectly (tree/33,store/16,sources/13,sync/11,queue/5). - The agent's memory handle leaks a raw
Arc<Mutex<rusqlite::Connection>>out to the ArchivistHook (agent/harness/session/builder/factory.rs:290) — an escape hatch no remote backend can satisfy.
So the sequence is consolidate → contract → backends. When the embedded driver is just another driver, the external ones become straightforward.
Measured state (current main, post domain-collapse)
Host src/openhuman/memory/ is 84,165 LOC — still larger than vendor/tinycortex/src (73,646).
Roughly two thirds is movable engine code, concentrated in store/ (17.8k), sync/ (17.1k),
tree/ (10.0k), sources/ (5.0k), people/ (3.3k), queue/ (1.4k).
The re-disposition this rests on
docs/tinycortex-cutover-evaluation-2026-07-28.md asked "is this product policy or engine logic?"
and concluded the remaining modules must stay. The kernel criterion changes the question to "would
a Supermemory-only build still need this file?" — several modules it retained are implementation
of the default driver, which is where they belong once a second driver is possible.
Its core warning still holds and is honoured throughout: RPC, policy, secrets, and runtime composition must not move into the crate. Please do not re-litigate the cutover evaluation's conclusion without addressing this reframing.
Scope
Three phases, one child issue per landable unit.
Phase 1 — Consolidation. Move the engine into vendor/tinycortex; the remaining
memory/tinycortex/ seam becomes the embedded driver.
Phase 2 — The adapter interface. tinycortex-api contract additions, the /v1 wire spec, the
conformance suite, and the adapters/ skeleton.
Phase 3 — The backends. One crate per external backend, each an independent PR needing no core edits — which is the proof the seam works.
Two metrics, not line count
Line count is explicitly not the goal. The metrics are:
grep -rln "tinycortex::" src/openhuman/ | grep -v memory/tinycortex/ | wc -l— 111 → 0. Done when onlymemory/subsystem/drivers/andmemory/tinycortex/name the crate.- Reach-back files (importing
crate::openhuman::config/crate::core::event_bus/crate::openhuman::securityfrom engine directories) — 78 → 0.
Every child PR quotes both counters in its body so the burn-down is visible.
Stays in the host, always
memory/{ops,schemas,schema,read_rpc,rpc_models} · memory/tools/*, search/tools/, the
tool_memory tool surface · SecurityPolicy gating, source_scope, util/redact.rs ·
preferences.rs, remember.rs, tree_policy.rs · global.rs → becomes the bind site ·
credentials / keychain / Composio OAuth · schedulers (sync/periodic.rs), bus subscribers · config
mapping · the new memory/subsystem/.
The shims stay host-owned. memory/schemas/*.rs keeps defining the schema and keeps handle_*
delegating — but to the guard rather than a concrete TinyCortex path. The crate never learns
JSON-RPC exists. The inverse (crate-owned RPC re-exported by the host) inverts the dependency
boundary: a reusable engine would learn OpenHuman's method names, error envelope, and policy
vocabulary, and a second driver could no longer satisfy the same RPC surface. So the ~51 controller
schemas do not move, thin as they are. Thin is what a good syscall table looks like.
Acceptance criteria
Phase 1 — Consolidation
- [ ] #5373 — Land the memory driver contract crate and subsystems config
- [ ] #5374 — Pass the source scope into retrieval instead of reading a task-local
- [ ] #5375 — Add the memory subsystem slot that binds one driver per process
- [ ] #5376 — Add MemoryGuard to enforce scope, taint, and trust on every memory call
- [ ] #5377 — Implement the tinycortex embedded memory driver
- [ ] #5378 — Route the live memory path through the bound driver
- [ ] #5379 — Move the memory job queue engine into TinyCortex
- [ ] #5380 — Move the memory store engine into TinyCortex
- [ ] #5381 — Move the memory tree engine into TinyCortex
- [ ] #5382 — Move the memory source readers and registry into TinyCortex
- [ ] #5383 — Move the memory sync engine into TinyCortex
- [ ] #5384 — Move the people contact engine into TinyCortex
- [ ] #5385 — Move the remaining memory engine internals and collapse the facade directories
- [ ] #5386 — Filter the memory RPC surface and agent tools by driver capability
- [ ] #5387 — Make auto-recall and auto-capture kernel-owned turn hooks
Phase 2 — The adapter interface
- [ ] #5388 — Add write visibility to the memory driver contract
- [ ] #5389 — Add the memory-spec adapter crate, conformance suite, and reference server
- [ ] #5390 — Add the adapters directory, dependency rule, and Cargo wiring
Phase 3 — The backends
- [ ] #5391 — Add the supermemory memory adapter
- [ ] #5392 — Add a self-hosted supermemory end-to-end test outside CI
- [ ] #5393 — Add the mem0 memory adapter
- [ ] #5394 — Add the agentmemory memory adapter
- [ ] #5395 — Add the cognee memory adapter
Epic-level done
- [ ] Metric 1 —
grep -rln "tinycortex::" src/openhuman/ | grep -v memory/tinycortex/ | wc -lreturns 0. - [ ] Metric 2 — 0 engine files import
crate::openhuman::config/crate::core::event_bus/crate::openhuman::security. - [ ] No behaviour change for the default build —
cargo test --test memory_golden_parity_e2egreen throughout; RPC surface, agent tools, and on-disk workspace byte-identical to today. - [ ] A backend binds with no core edits — at least one Phase 3 adapter lands as a PR touching only
adapters/andCargo.toml.
Related
docs/specs/plan-memory.md— Memory Subsystem: Pluggable Provider API & TinyCortex Consolidationdocs/specs/kernel.md— OpenHuman as a Kernel: Subsystem & Driver Modeldocs/tinycortex-cutover-evaluation-2026-07-28.md— re-dispositioned above, not supersededdocs/tinycortex-migration-spec.md,docs/tinycortex-parity-checklist.md- #4795 — feature-gates epic, whose parent/child shape this follows
I'd like to pick up the host half of this and want to check the seam shape with you first, because the answer changes the whole PR and I'd rather ask than guess.
What I found. The adapters this epic's children describe (#5391 supermemory, #5393 mem0, #5394 agentmemory, #5395 cognee) appear to have already landed upstream in tinymemory-remote rather than in the openhuman/adapters/ layout #5390 proposed — and at the currently pinned submodule commit, so no bump is needed:
vendor/tinymemory/crates/tinymemory-remote/src/shipssupermemory.rs,mem0.rs,cognee.rs,agentmemory.rs, plusconformance_test.rsandfailure_test.rs.lib.rsexports ready constructors —supermemory_provider,mem0_provider,cognee_provider,agentmemory_provider, and the graph-advertisingcognee_graph_provider/mem0_graph_provider.- Their return types (
MemoryTraitProvider,Mem0Provider,GraphMemoryProvider) all implement the sameMemoryProviderthe host binds, sobind_providershould take them as-is with no shim.
That seems consistent with the 2026-08-10 amendment in docs/specs/plan-memory.md (adapters upstream, not host-side crates). If I've read that wrong, please say so and I'll stop here.
What's left is host-side only, and it's one wall. src/openhuman/memory/binding.rs refuses every external driver before it can reach a transport:
// binding.rs:287
return Err(refuse(
"external driver transport is not implemented yet (the http adapter lands in M4)",
));
Everything around it already works: the fail-closed trust_state gate immediately above (:279), MemoryDriverConfig's five fields (class/transport/endpoint/credential_ref/trust_state) with the redacting Debug, capability-filtered controller + tool registration, MemoryGuard, the fallback DomainEvent, and subsystems_status. The tests even use credential_ref: "keychain:supermemory" fixtures already. (Small thing: that comment says M4, but per §8 M4 is MemoryGuard and M6 is the HTTP adapter — I think the comment is just stale.)
The question. #5391 says: "If this PR needs to touch src/openhuman/, the seam is not finished — that is the signal to fix the seam rather than special-case the adapter." Since the bind path hard-refuses, the seam isn't finished — but that leaves two very different PRs, and I don't want to pick for you:
- A driver-id → constructor registry. A table in the host mapping a driver id to a constructor, seeded with the four upstream ones, so the seam is what lands and backends are data. Smaller, uses the already-conformance-tested adapters, but the set of backends is compiled in.
- The generic
httpwire contract from §4.2 (/v1/handshake,/v1/memory/*,501→Unsupported). Lets a third party implement a backend with no Rust and no vendoring — which reads like the actual intent behind #5390's "an adapter may not depend onopenhuman" rule — but it's a second transport alongside the native per-vendor adapters that already exist upstream.
My instinct is (1) as the first increment because it's the smaller reviewable change and doesn't foreclose (2), but (2) is what the spec text describes, so I'd rather follow your call.
How I'd phase it, if you want it at all:
credential_refresolution alone (keychain:<name>→ the existing keychain, throughkeyring_consent::policy::check_secret_accessandkeyring::is_availablethe wayweb3::walletdoes it). No behaviour change — the refusal above stays — so it's independently reviewable and useful under either option.- The external bind seam:
admitacceptingExternalon a valid transport/endpoint,buildgaining the non-null arm,GuardPolicytaking the configured trust state instead of the hardcoded"trusted", and the endpoint routed throughsecurity::egress. - The remaining backends as data.
Also happy to leave this entirely to you if it's already in flight — I checked and couldn't find an open PR or branch, but you'd know better. Either way I'll follow whatever you decide here rather than opening something unsolicited.
A small follow-up question that came out of review on #5976, kept separate from the seam-shape question above because it is independent of how that one is answered.
Does the keyring need a lookup mode for keys that are themselves sensitive?
Every current keyring::get caller passes a fixed key — wallet_mnemonic, the OAuth entries, and so on — and ops::get logs key={key} at debug on every hit and miss, plus the KeyringError (whose Display interpolates the key) at warn on failure. That is deliberate: KeyringError::diagnostic()'s doc states it outright, and with fixed keys it is plainly harmless.
credential_ref is the first operator-configured key to reach that path. A reviewer's example on #5976 makes the difference concrete: keychain:supermemory-prod-key-9f3a writes an operator-chosen name — which may carry tenancy or environment information — into logs on a successful lookup, while the surrounding code goes to some trouble to keep that same name out of subsystems_status.
Two reasons I did not simply fix it in #5976:
store::backend()ispub(super), socredentials/cannot bypassops::get. The only available fix is new shared keyring API (something like agetvariant that omits the key from its diagnostics), which is kernel surface.- By kernel.md §5 this is not a memory question. Inference, channels and sandbox all bind through the same §3.6
credential_reffield, so whatever the answer is, it should be one answer rather than four.
So: worth a narrow addition to security/keyring/, or is the entry name considered a handle and therefore fine in local debug logs? Happy to implement either — I would just rather not narrow a shared contract unilaterally. #5976 stands on its own under both answers; it changes only its own logging.
Triage: valid — Current review confirms this is a concrete, in-scope engineering issue or request: “Pluggable memory backends behind one driver contract”. No complete resolution is evident in current main.
Thanks for the detailed plan, and @mysma-9403, sorry your seam question went unanswered. Here's where this stands on current main.
Memory v2 (#6949, merged 2026-10-04) replaced most of what this epic plans against:
- TinyCortex is no longer vendored. The engine contract is now TinyMemory's
MemoryEngine(contract 2.0), bound throughEngineBinderincrates/openhuman-core/src/memory/engine.rs, and outside crates can register an engine (register_memory_engine). binding.rsand its "external driver transport is not implemented" refusal are gone. An unknown engine id now turns memory off with a clear message.- The supermemory / mem0 / cognee / agentmemory adapters in
tinymemory-remotewere removed upstream, so the engines available in this build are CortexDB and TinyHumans.
So the consolidation half (#5378, #5381–#5385) is done or no longer applies, and we're closing those children. The open question is product-level: are external memory backends still wanted? If yes, the adapters would go upstream in TinyMemory behind register_memory_engine, and #5389–#5395 should be restated on that seam. If not, we'll close those too. A maintainer will confirm the direction here.
Also, a few docs still describe the old nested TinyCortex (AGENTS.md, crates/openhuman-core/README.md, memory/README.md), and OPENHUMAN_MEMORY_DRIVER in .env.example is no longer read by anything. These are worth a small cleanup PR.
Closing as not planned, together with the adapter sub-issues (#5389, #5391, #5392, #5393, #5394, #5395).
This plan was written against the memory architecture that Memory v2 (#6949) replaced. What exists on main today:
- The contract is
tinymemory-api'sMemoryEngine(contract version 2.0), bound throughEngineBinder. The olderbinding.rs/bind_providerpath is gone. - The external adapters this plan lists (supermemory, mem0, cognee, agentmemory) and
tinymemory-remotewere removed upstream in tinymemory#192. The built-in engines arecortexdbandtinyhumans. - An outside crate can still register its own engine through the engine registry, so a third-party backend is possible without it living in this repository. An unknown engine id turns memory off with "the configured memory engine is not available in this build".
As noted in the earlier comment here, the seam for a third-party backend is the in-process engine registry, not an HTTP wire contract; there is no /v1 contract for backends written outside Rust.
Still open on its own, because it is not about external backends: #5387 (capture has no size budget, and [subsystems.memory] is parsed but ignored).
Two leftovers from the old design are worth a small clean-up and are noted for a follow-up: docs that still describe a nested tinycortex, and OPENHUMAN_MEMORY_DRIVER in .env.example, which nothing reads.
If external memory backends come back as a goal, a new issue written against the MemoryEngine contract would be the place to start; please reopen or link from here.