openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

Free memory migration from local TinyCortex storage to hosted CortexDB for current subscribers

Open Al629176 opened this issue 1 month ago • 3 comments

Description

Migrate current subscribers' existing TinyCortex memory into hosted TinyHumans CortexDB, at no cost to them.

This is the data-migration half of #6718 (retire the embedded tinycortex engine). That issue covers validating hosted recall and swapping the engine; it does not move anyone's existing data. Retiring tinycortex without this strands every subscriber's memory.

The constraint that shapes everything: the data is on their device

TinyCortex is local-first — its own README leads with "Local-first & inspectable ◦ Markdown as source of truth", and it ships as an embedded Rust library, not a service. Subscriber memory sits on subscriber machines.

So this cannot be a server-side batch job. The migration has to run in the OpenHuman client, read the local store, and upload. That means:

  • it only runs when the user opens the app, so it is a rollout over weeks, not a maintenance window
  • it must survive the app being quit mid-migration
  • it needs progress the user can see, because it is their data moving
  • a user on several machines has several local stores, and the second one to migrate must merge rather than duplicate

Migrate the Markdown, re-derive the rest

TinyCortex's architecture makes this much simpler than it looks. From its README:

"Markdown files are the source of truth. SQLite chunk rows, summary trees, vectors, and a git-backed change ledger … are derived indexes that accelerate reads and can be rebuilt from canonical content."

So do not attempt to port vectors, chunk rows or summary trees. Send the canonical Markdown and let CortexDB derive its own. This is not just easier — it is the only correct option, since CortexDB pins its vector space at 1536 dims against its own embedding model, and foreign vectors in that index would degrade recall silently (same hazard as #7001's embedding section).

Two attributes must survive the move, both named in the same paragraph: "Every item carries source provenance and a security taint (internal vs. external-sync)." Taint is a security attribute — if migration drops it, externally-synced content lands indistinguishable from the user's own trusted memory. Whether CortexDB's event model can carry taint and provenance is a go/no-go question to answer first, not during implementation.

The write path exists, and so does its blocker

POST /v1/experience/bulk takes { "items": [ …experience bodies… ], "ordering": "strict_temporal" }, and each experience body accepts observed_at. That is exactly right for a migration: original timestamps preserved, strict ordering, batched.

Preserving observed_at is mandatory, not optional. CortexDB's recall body accepts a temporal clause. If migrated items land stamped "now", every item in a subscriber's history collapses to migration day and temporal recall becomes wrong — while appearing to work.

The blocker: tinysweeper#147 — "CortexDB answers 408 on /v1/experience/bulk for very large conversations." That is the endpoint this migration depends on, and large histories are precisely what subscribers have. This is the critical path.

"Free" has a specific technical meaning here

cortexdb-saas gates experience on the user's credit balance:

"experience, recall, answer and blob uploads … ask the ledger for the tenant's balance first … At or below CORTEX_SAAS_MIN_BALANCE_USD the request is refused with 402 INSUFFICIENT_CREDITS and never reaches the engine."

So a subscriber with a low balance would get 402 part-way through their own migration. Making it free therefore needs two distinct things:

  1. The gate must not refuse migration traffic — an exempt path, or pre-funding, decided deliberately rather than discovered in production.
  2. The charge must not land on the user — metering still records units (that service "owns units" while the backend "owns money"), so the backend must attribute migration units to us.

The real cost is re-derivation: embeddings plus enrichment for every migrated item, and CORTEX_ENTITY_GRAPH=1 in production multiplies write cost ~3×. This is a direct reason to land #7001 first — routing that work through Surplus Intelligence reduces the bill we are choosing to absorb.

Prerequisite: per-user scoping

#7002 — the CortexDB tenant boundary is single-layer, the CortexEngine::direct wire bypasses it, and no cross-user isolation test exists. Uploading subscribers' complete personal memory into a shared engine makes #7002 a hard prerequisite. A cross-user leak is far more damaging on a user's own imported history than on product-generated data.

Keep the local store

TinyCortex is local-first and inspectable, which makes rollback nearly free: do not delete anything locally until the migration is verified. The local store is the backup. Deletion should be a separate, later, explicitly-consented step — or simply never, leaving it as an export the user already owns.

Open questions

  • Who counts as a "current subscriber"? Active paid subscription at migration time, or anyone who ever paid? This decides the cost ceiling.
  • Is it opt-in or automatic? Automatic moves everyone and is simpler to reason about; opt-in respects users who deliberately keep memory on-device. TinyCortex's local-first positioning argues for asking.
  • Can CortexDB's event model carry taint and provenance? If not, what is the fallback — refuse to migrate external-sync items, or migrate them marked untrusted?
  • What does verification look like? Item counts match is weak. A recall-equivalence check — the same queries against both engines returning comparable results — is the real test, and needs a defined bar.
  • What happens to the admission gate? TinyCortex "drops low-value content at ingest" via a multi-signal gate. Items already stored passed that gate; CortexDB has its own enrichment and filtering. Migrated memory may be treated differently from how it was treated at home.

Related

  • #6718 — validate hosted CortexDB recall and retire tinycortex; this is its data half
  • #7002 — per-user scoping; hard prerequisite
  • #7001 — Surplus routing; reduces the re-derivation cost we absorb
  • #7003 — credits for migrating memory in from other products; this issue is the internal counterpart and should reuse the same importer plumbing
  • tinysweeper#147 — bulk ingest 408; critical path
  • #6717 — usage and balance reporting; migration units must not appear as user spend

Acceptance Criteria

  • [ ] Go/no-go recorded first: whether CortexDB can carry TinyCortex's taint and source provenance, with the fallback named if it cannot
  • [ ] tinysweeper#147 is fixed and bulk ingest is verified against a real large subscriber history
  • [ ] #7002's cross-user isolation check passes before any subscriber data is uploaded
  • [ ] Subscriber eligibility is defined in writing in this issue, with the resulting cost ceiling estimated
  • [ ] Opt-in vs automatic is decided and recorded
  • [ ] Migration runs client-side, is chunked, resumable and idempotent — quitting the app mid-run and reopening resumes without duplicating or losing items
  • [ ] Multiple devices for one account merge rather than duplicate
  • [ ] observed_at is preserved per item, verified by a temporal recall query returning the original dates
  • [ ] Canonical Markdown is migrated and indexes are re-derived; no vectors, chunk rows or summary trees are ported
  • [ ] The billing gate does not refuse migration traffic, and migration units are attributed to us, not the subscriber — verified on an account at minimum balance
  • [ ] A recall-equivalence check against an agreed bar: the same queries on both engines return comparable results for a sample of migrated accounts
  • [ ] The local TinyCortex store is left intact; any later deletion is a separate consented step
  • [ ] Progress and completion are visible to the user, and a failed migration is visible to us
  • [ ] A documented rollback: a subscriber can be returned to the local engine with no data loss
  • [ ] A dry run on internal accounts precedes any subscriber rollout

Al629176 avatar Oct 05 '26 08:10 Al629176

Free client-side migration of subscribers' local TinyCortex memory into hosted CortexDB, the data half of #6718. Distinct from #7003 (external product import) and the other related issues; no true duplicate among candidates.

Labelled priority: p2.

tinysweeper avatar Oct 05 '26 08:10 tinysweeper

Status update (2026-10-05)

The code for this issue is merged, and its infrastructure is live in production. Two things remain before subscribers can migrate: starting the free month (a team decision, see below) and the next OpenHuman release.

Decisions recorded (2026-10-06)

  • Eligibility: memory is free for every user for one month, capped at the first $1000 of usage. No per-subscriber check, since it could be gamed.
  • Opt-in vs automatic: opt-in. The user confirms in the app before anything is uploaded.
  • Models: Flash only. DeepSeek v4.1 Flash, then GLM 5.3 Flash, both via Surplus, with OpenRouter GLM 5.3 Flash as the outage fallback.
  • #7002: to be rewritten (it was written for the cloud server), so it isn't a blocker here.

What shipped

PR What it does State
#7011 The import stops on exhausted credits or an unreachable engine instead of skipping every item and reporting "Done". It resumes on its own after the app quits, never while background work is paused, and a resume that can't start is persisted as stopped. A Resume button sits behind consent (Playwright-covered). merged, ships with the next release
tinyhumansai/tinymemory#201 The v1 importer keeps TinyCortex's taint: externally synced rows arrive tagged taint:external_sync. merged
#7012 Bumps the tinymemory pin to include #201. merged, ships with the next release
tinyhumansai/backend#1402 A memory free period. Until MEMORY_FREE_UNTIL, and while giveaway usage stays under MEMORY_FREE_BUDGET_USD (default $1000), every user is served at a $0 balance and charges are recorded at $0. The budget is reserved atomically, and the period ends on its own. merged, in production (off)
tinyhumansai/k8s#100 llm-router in front of CortexDB: entity extraction and enrichment run on Surplus Flash models with failover (#7001). merged, live
tinyhumansai/k8s#101 Sets MEMORY_FREE_UNTIL=2026-11-06T00:00:00Z in the backend config. merged, not applied yet
tinyhumansai/k8s#102, tinyhumansai/k8s#103 Model-call timeouts: CortexDB waits 400s per call, and the router gives each attempt 120s. merged, live

Production, verified 2026-10-05

  • Backend production-main-172.1-637d5c4 deployed with a rolling update and no downtime. The free period is off until MEMORY_FREE_UNTIL is set.
  • CortexDB → llm-router → Surplus went live at 21:57Z.
    • The router was tested on its own first, and embeddings are unchanged (openai/text-embedding-3-small, no mock).
    • The live seller price is about $0.0018 per 1M output tokens, against $0.25 for the previous gpt-6-luna flex.
  • Timeouts found and fixed after go-live:
    • CortexDB gave up before slow sellers answered: 70 extraction timeouts, fixed by #102.
    • #102's 55s per router attempt then cut off large prompts on every provider: 18 calls had all three models fail.
    • #103 set 120s per attempt and 400s in CortexDB. Since then: 0 extraction timeouts and 0 router failures.
  • Found while watching: CortexDB's background compaction repeatedly tries to persist "procedure" abstractions spanning two tenant roots. Its own validator blocks every one, so nothing cross-tenant is stored, and they aren't model calls. This is tracked in tinyhumansai/cortexdb-saas#13 (p1). Whether to start the free month before #13 is answered is the open decision.

Acceptance criteria

  • [x] Go/no-go on taint and provenance: go. Taint survives as a tag in MemoryMeta, which CortexDB stores whole (tinyhumansai/tinymemory#201). Not yet: the chat memory pack doesn't act on the tag (true for all synced content, not just imports); this needs a follow-up.
  • [ ] tinyhumansai/tinysweeper#147 (bulk 408): not re-verified. The importer sends 25-item batches through the backend's /memory/experience.
  • [ ] #7002 cross-user isolation: to be rewritten per the decision above. See tinyhumansai/cortexdb-saas#13 for a related engine finding.
  • [x] Eligibility defined, with a cost ceiling: everyone, one month, $1000 cap, enforced in code.
  • [x] Opt-in vs automatic: opt-in.
  • [x] Client-side, chunked, resumable, idempotent (#7011).
  • [ ] Multiple devices merge rather than duplicate: not verified.
  • [ ] observed_at preserved, verified by a temporal recall query: the importer carries it; the recall query isn't run yet.
  • [x] Canonical content migrated, with indexes re-derived and no vectors ported.
  • [ ] Billing gate doesn't refuse migration traffic, and units are attributed to us: built and deployed (backend#1402); takes effect when the free month starts.
  • [ ] Recall-equivalence check on migrated accounts: not done.
  • [x] The local TinyCortex store is left intact.
  • [ ] Progress visible to the user: yes (banner, Resume). A failed migration visible to us: not yet.
  • [x] Documented rollback. Local data is never deleted; the router rollback is documented in k8s/base/memory/README.md.
  • [ ] Dry run on internal accounts: not done.

Next

  1. Decide on the free month (now, or after tinyhumansai/cortexdb-saas#13), then apply k8s#101 (MEMORY_FREE_UNTIL) and restart the backend.
  2. Cut the next OpenHuman release so users get #7011 and #7012.
  3. Before a wide rollout: a dry run on internal accounts, a recall-equivalence spot check, and a temporal recall check.

CodeGhost21 avatar Oct 05 '26 22:10 CodeGhost21

Closing criteria. Keeping this open until:

  1. The next OpenHuman release ships #7011 and #7012. The last release is v0.64.10, which predates them.
  2. One internal dry run passes end to end: an account with a v1 TinyCortex store imports through the app banner while the free month is on, and we confirm:
    • the import completes and survives an app restart mid-way (auto-resume);
    • the account is charged $0 (MemoryCharge.free: true) and the memoryfreebudgets counter moves;
    • original dates come back on a temporal recall query;
    • externally synced items carry taint:external_sync;
    • facts and entities derive through llm-router, with no extraction timeouts.

The remaining unchecked items in the status update above (recall equivalence on a sample of migrated accounts, failure visibility for us, multi-device merge, the tinyhumansai/tinysweeper#147 re-check) move to follow-up issues once that passes.

CodeGhost21 avatar Oct 06 '26 11:10 CodeGhost21