Skip to content

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

docs(session_store): document storage-backed session store installation

Steven Enamakel97220527b7a0
diff --git a/AGENTS.md b/AGENTS.md
index 7496a64a1c..26add9095e 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -19,7 +19,7 @@ Architecture: [overview](gitbooks/developing/architecture.md),
| `crates/openhuman-core/src/core/` | CLI, controller contract (`Outcome`, schemas) and in-process dispatch, controller registry, event bus, runtime composition; no business logic and no JSON-RPC server |
| `crates/openhuman-cli/` | The `openhuman-core` binary (`src/main.rs`), the developer/benchmark bins (`src/bin/`), and every root `tests/*.rs` / `examples/*.rs` target; depends on `openhuman-tinyhumans` for the backend transport the core does not carry |
| `crates/openhuman-embed/` | Typed library facade for embedding the core in another product |
-| `crates/openhuman-rpc/` | JSON-RPC 2.0 over the core: envelopes, HTTP client, and the server (router, Socket.IO, listener, `run_server*`) used by app, CLI and TUI; plus `session_store` (`session-store` feature), the on-disk session store (`session_raw/`, `session_db/`, `tinyagents_store/`, turn states) behind TinyAgents' session store port, which the app, CLI and TUI install. Core and embed reach session state through the port (`agent::session_store`); a few legacy paths still fall back to workspace files when no store is installed |
+| `crates/openhuman-rpc/` | JSON-RPC 2.0 over the core: envelopes, HTTP client, and the server (router, Socket.IO, listener, `run_server*`) used by app, CLI and TUI; plus `session_store` (`session-store` feature), the on-disk session store (`session_raw/`, `session_db/`, `tinyagents_store/`, turn states) behind TinyAgents' session store port, which the app, CLI and TUI install. Core and embed reach session state through the port (`agent::session_store`); a few legacy paths still fall back to workspace files when no store is installed. With a storage URL (`OPENHUMAN_STORAGE_URL` / `[storage] url`), `install_for_host` installs TinyAgents' `DriverSessionStores` over that backend instead (core `storage` domain) |
| `crates/openhuman-tinyhumans/` | The TinyHumans layer above embed: SDK-backed backend transport, a `RuntimeBuilder` that boots connected, and the host-side login/session owner (login-token exchange, `/auth/me`, current-user cache, credential handoff) used by app and TUI |
| `crates/openhuman-tui/` | Standalone terminal frontend |
| `tests/` | Rust integration and JSON-RPC tests |
diff --git a/crates/openhuman-core/src/storage/README.md b/crates/openhuman-core/src/storage/README.md
new file mode 100644
index 0000000000..d79e6f0308
--- /dev/null
+++ b/crates/openhuman-core/src/storage/README.md
@@ -0,0 +1,45 @@
+# storage
+
+The process's storage backend on the
+[tinystoragedrivers](https://github.com/tinyhumansai/tinystoragedrivers)
+ports, vendored through `vendor/tinyagents/vendor/tinystoragedrivers`.
+
+One URL picks it: `OPENHUMAN_STORAGE_URL`, else `[storage] url` in
+`config.toml` (`config::StorageConfig`). With neither set, the desktop
+default, nothing is opened and every domain keeps the classic on-disk layout
+under the workspace.
+
+| URL | Driver | Cargo feature |
+| --- | --- | --- |
+| `memory` | in-process, keeps nothing | always |
+| `sqlite:<path>` (a `.db` file, or a directory with one file per database) | SQLite | `storage-sqlite` |
+| `mongodb://…/<db>`, `mongodb+srv://…/<db>` | MongoDB, one database shared by every scope | `storage-mongodb` |
+| `file:<dir>` | JSON and JSONL files | `storage-file` |
+
+A URL for a driver the build lacks fails at `open`, naming the feature. None
+of the features are in the shipped desktop product yet; a cloud build turns
+on `storage-mongodb`.
+
+## Entry points
+
+- `configured_url(&Config)` / `url_from(env, &Config)`: the URL in effect.
+- `open(url)`: parse and open a backend (credentials are redacted in logs).
+- `install(backend)` / `installed()` / `clear()`: the process slot domains
+ read the backend from.
+- `scope_for_agent(agent_id)`: the storage scope an agent's records live
+ under, the same mapping TinyAgents' `DriverSessionStores` uses, so every
+ domain agrees.
+
+## Consumers
+
+- The session store: `openhuman_rpc::session_store::install_for_host` opens
+ the configured backend before boot and installs `DriverSessionStores`
+ over it. See that module's README.
+
+## Boundaries
+
+The ports, drivers, scopes and conformance suites are tinystoragedrivers';
+the session store over them is `tinyagents-session`. This domain only
+resolves the URL, opens the backend, and holds it for the process. The
+`[storage]` section is bootstrap configuration and is never read from
+storage itself.
diff --git a/crates/openhuman-rpc/src/session_store/README.md b/crates/openhuman-rpc/src/session_store/README.md
index 639918a7f6..554b5b635f 100644
--- a/crates/openhuman-rpc/src/session_store/README.md
+++ b/crates/openhuman-rpc/src/session_store/README.md
@@ -62,11 +62,37 @@ tinyagents_store/{kv,journal}/ run status, goals, todos,
turn journal
```
+## A storage-backed store instead
+
+`install_for_host()` is what the server shims and the TUI call. With no
+storage URL configured (`OPENHUMAN_STORAGE_URL`, else `[storage] url` in
+`config.toml`) it is `install()` above, unchanged. With one, it opens that
+backend (`openhuman_core::storage::open`), makes it the process's storage
+backend, and installs TinyAgents' `DriverSessionStores` over it instead:
+
+```text
+ install_for_host()
+ storage URL? no -> install() (the layout above)
+ yes -> storage::open(url) -> storage::install(backend)
+ DriverSessionStores::new(backend)
+ .recover_on_open(driver != "mongodb")
+ -> agent::session_store::install(provider)
+```
+
+Every agent then gets its own storage scope (its id, or `sha256:` of an id
+that is not a valid scope), so agents sharing one MongoDB database never see
+each other's transcripts, turn states, records or journals. A single-process
+backend (SQLite, memory, files) interrupts an agent's in-flight turns the
+first time it is opened; MongoDB does not, because another process may own
+them. A URL that cannot be parsed or opened fails the boot rather than
+falling back to local files. `install_for_url` is the same with the URL
+already resolved, for tests and hosts that read it themselves.
+
## Layout
| File | What it does |
| --- | --- |
-| `mod.rs` | `SqliteSessionStores` (`at`, `resolving`), its `SessionStoreProvider` impl (`for_agent`, `recover`, `destination_key`, `workspace_dir`), and `install()`. |
+| `mod.rs` | `SqliteSessionStores` (`at`, `resolving`), its `SessionStoreProvider` impl (`for_agent`, `recover`, `destination_key`, `workspace_dir`), `install()`, and `install_for_host()` / `install_for_url()`, which install `DriverSessionStores` when a storage URL is configured. |
## Key types and entry points