Skip to content

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

docs(storage): document the legacy small-store import

Steven Enamakel6fbd2409eda4
diff --git a/crates/openhuman-core/src/storage/README.md b/crates/openhuman-core/src/storage/README.md
index 80ff8dd501..45f589cd18 100644
--- a/crates/openhuman-core/src/storage/README.md
+++ b/crates/openhuman-core/src/storage/README.md
@@ -33,6 +33,15 @@ A URL for a driver the build lacks fails at `open`, naming the feature.
always compiled in; `storage-mongodb` is in neither, a cloud build turns it
on.
+## Legacy import
+
+`import/` copies the four small stores' legacy SQLite files into an installed
+backend once, read-only (see the module doc and the architecture page). The
+core calls `import::run` from `bootstrap_core_runtime` before any domain store
+opens; `run_with` takes an explicit backend for tests. Sessions, cron jobs and
+the flow catalog are not imported here: their formats belong to TinyAgents and
+TinyFlows.
+
## Entry points
- `configured_url(&Config)` / `url_from(env, &Config)`: the URL in effect.
diff --git a/gitbooks/developing/architecture/storage.md b/gitbooks/developing/architecture/storage.md
index fea63bbc4d..2f1ab1dcfb 100644
--- a/gitbooks/developing/architecture/storage.md
+++ b/gitbooks/developing/architecture/storage.md
@@ -103,7 +103,15 @@ On a shared backend (MongoDB) other processes may write the same records, so boo
| `file:<dir>` | `<dir>/scopes/<scope>/docs/<collection>/<id>.json` for documents, with collection metadata in `<dir>/_meta/collections/<collection>.json`. Streams are JSONL and blobs are raw files under the same scope directory. |
| `mongodb://…/<db>` | One database. Each named database is a collection prefix, and every record carries its scope. |
-Without a URL, the classic layout is unchanged: per-domain SQLite databases (`approval/approval.db`, `devices/devices.db`, `notifications/notifications.db`, `task_sources/sources.db`, `cron/jobs.db`, `flows/flows.db`, `graph_checkpoints.db`), JSON and JSONL files, and the OS keyring or `secrets.enc`. Records written to a configured backend are not copied back to those files. The domain stores do not import their files either, with one exception: credentials. On first read with a backend installed, the auth-profile and HTTP-credential stores copy the records in their files into the backend, and the keyring adopts a secret it finds in the process backend. The source files are left untouched.
+Without a URL, the classic layout is unchanged: per-domain SQLite databases (`approval/approval.db`, `devices/devices.db`, `notifications/notifications.db`, `task_sources/sources.db`, `cron/jobs.db`, `flows/flows.db`, `graph_checkpoints.db`), JSON and JSONL files, and the OS keyring or `secrets.enc`. Records written to a configured backend are not copied back to those files. On first read with a backend installed, the auth-profile and HTTP-credential stores copy the records in their files into the backend, and the keyring adopts a secret it finds in the process backend. The source files are left untouched.
+
+### Importing the legacy small stores
+
+When a backend is installed, the core runs a one-time import at boot (`storage::import`, before any domain store opens). It covers the four small stores that keep one SQLite file each: approvals (`approval/approval.db`), devices (`devices/devices.db`), notifications (`notifications/notifications.db`) and task sources (`task_sources/sources.db`). The import is read-only. It copies the file, with its `-wal` and `-shm` companions, into a scratch directory and reads the copy, so the legacy reader's schema migration and the SQLite driver's table declaration never touch the real file. Both on-disk shapes are read: the original tables, and the driver document tables an earlier default wrote into the same file (those records win an id clash, being newer). Notifications for the core are re-filed under the real workspace's key.
+
+Every record is written with an absent-only precondition, so an existing record is never overwritten. When a domain's records are written, a marker document (`storage_import/<domain>@<workspace digest>`, local scope) is stored, and a later boot does nothing. A deleted record is therefore not brought back from the untouched file. A failed import leaves no marker and is retried at the next boot; boot continues either way. SaaS processes have no workspace files and import nothing.
+
+Not yet imported: sessions and transcripts, cron jobs, the flow catalog and graph checkpoints. Their formats belong to TinyAgents and TinyFlows, so their importers are upstream work. Until they exist, a desktop with no URL keeps its classic layout and the default stays unchanged.
Secrets with a backend installed are encrypted documents in the current storage scope: the acting agent's scope on a desktop or CLI host, and the profile's scope under SaaS, where every agent in one profile shares the profile's credentials and data key. Each scope's data key is derived with HKDF-SHA256 from the keyring master key (`OPENHUMAN_KEYRING_MASTER_KEY` or `_FILE`, else the OS keychain), and with no master key they fail closed. The config encryption key stays on the process keyring because `config.toml` is loaded before any agent acts.