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 default sqlite backend and legacy imports

Steven Enamakel164ed17ae736
diff --git a/gitbooks/developing/architecture/storage.md b/gitbooks/developing/architecture/storage.md
index c61ffa402b..7058527fd8 100644
--- a/gitbooks/developing/architecture/storage.md
+++ b/gitbooks/developing/architecture/storage.md
@@ -9,7 +9,7 @@ icon: database
OpenHuman keeps durable state on the ports of [`tinystoragedrivers`](https://github.com/tinyhumansai/tinystoragedrivers), vendored through `vendor/tinyagents/vendor/tinystoragedrivers`. One URL picks the backend for the whole process. The host adapter is `crates/openhuman-core/src/storage/`. It resolves the URL, opens the backend, holds it in a process slot and decides which scope a call runs in. The ports, the drivers and their conformance suites belong to `tinystoragedrivers`, and the typed records stay with the domain that owns them.
-With no URL configured, which is the desktop default, nothing here is opened and every domain keeps its classic on-disk layout under the workspace. Setting a URL switches the domains that have moved onto the ports. The rest still use their files.
+With no URL configured, which is the desktop default, the host opens `sqlite:<workspace>/storage` and installs it. The URL decides where the whole process keeps its state, and there is no second layout: older installs' per-domain databases, transcripts and turn-state files are imported once, read-only, when the backend is installed. The files that remain outside the ports are listed under "What is not on the ports yet" below.
## The ports
@@ -31,7 +31,9 @@ The storage URL is the first of these that is set. Blank values count as unset.
1. `OPENHUMAN_STORAGE_URL`
2. `[storage] url` in `config.toml`
-3. Nothing: the classic layout
+3. The default, `sqlite:<workspace>/storage` (one database per workspace)
+
+The retired `classic` opt-out value is read as unset, with a warning.
`[storage]` is bootstrap configuration. It is always read from the environment or the file and never from storage itself.
@@ -103,19 +105,27 @@ 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 holds for the other domains: per-domain SQLite databases (`approval/approval.db`, `devices/devices.db`, `notifications/notifications.db`, `task_sources/sources.db`, `graph_checkpoints.db`), JSON and JSONL files, and the OS keyring or `secrets.enc`. Cron jobs and the flow catalog are the exception: they live in the document databases `cron/schedule.db` and `flows/catalog.db`, beside the retained legacy `cron/jobs.db`, `flows/flows.db` and `flows/checkpoints.db`, which are no longer read after the one-time import. 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.
+### The default follows the workspace
+
+The default URL is rooted at the workspace, so a different workspace is a different database. The desktop rebinds its workspace when a different user signs in. `storage::rebind` then re-resolves the URL for the new workspace, opens its backend, points the session store (`ReboundSessionStores`) and the process slot at it together, and runs the legacy importers over it. This happens before any other store is rebound, and a failed reopen is an error that leaves the previous backend installed rather than continuing on it. An explicit URL names one backend for every user and is never replaced.
+
+A SaaS core with no URL keeps one default database per profile workspace, and its profiles never share a scope.
+
+### What is not on the ports yet
+
+The keyring or `secrets.enc`, the path-bound artifacts and media, and a few stores that keep a file next to a document fallback (cost tracking, the Composio file store, sub-agent sessions, agent artifacts) still use files when no backend is installed. The vault watcher's mtime table stays a per-machine SQLite file on purpose, because its rows are absolute paths on one host. 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.
+When the 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.
The tinyflows stores are imported the same way with TinyFlows' own reader (`tinyflows-import`): cron jobs with their runs and policies (`cron/jobs.db`, and each agent's `agents/<id>/cron/jobs.db`, filed under that agent's scope), and the flow catalog with its drafts and checkpoints (`flows/flows.db`, `flows/drafts/*.json`, `flows/checkpoints.db`). Records keep their ids, markers are `cron`, `cron/<agent>` and `flows`, and a build without the `flows` gate imports no cron jobs.
-TinyFlows has no storage backend of its own any more, so these stores are on the ports whatever the URL says. With no URL, and under the `classic` opt-out, they live in SQLite document databases of their own (`cron/schedule.db`, `agents/<id>/cron/schedule.db`, `flows/catalog.db`), and the first use of each imports the legacy files into it. The legacy files are never modified, and the old `jobs.db` and `flows.db` are no longer written.
+TinyFlows has no storage backend of its own any more, so these stores are on the ports whatever the URL says, and the legacy files are never modified or written again.
-Not yet imported: sessions and transcripts, whose format belongs to TinyAgents.
+Sessions are imported through TinyAgents' `legacy` reader, which owns those formats (`storage::import::sessions`): `session_db/sessions.db` (copied with `VACUUM INTO` first, because the reader refuses a database with a WAL sidecar) fills the run ledger of the default agent, each `session_raw` transcript lands in the scope of the agent its stem names (matched against the known agent definitions, else the default agent), and the turn-state JSON goes to the default agent. The marker is `sessions`; a run that skipped records leaves no marker and is retried.
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.