# Smartbotic Database - Status and Roadmap **Released version: 2.14.0** (see `VERSION`). Last reviewed: 2026-10-09. > 2.11.5 was prepared but never released on its own: its work (event actors, > `removeAs()`) ships inside 2.12.0. There is no 2.11.5 package. This is the single authoritative statement of what exists and what does not. If any other document in this repository disagrees with this one, this one is right and the other is stale - report it. Feature-level detail lives in `CLAUDE.md`. This file covers only *status*: shipped, pending, or abandoned. --- ## How to read the `docs/` tree | Path | What it is | Trust it? | |------|-----------|-----------| | `docs/ROADMAP.md` | This file - current status | Yes | | `CLAUDE.md` | Per-release feature notes and hard-won lessons | Yes | | `docs/integration-guide.md` | Consumer-facing API guide | Yes | | `docs/superpowers/specs/` | Design decisions, each with a status banner | Read the banner first | | `docs/superpowers/plans/` | Implementation plans for work **not yet done** | Yes, but re-validate against current code | | `docs/superpowers/plans/archive/` | Plans for work already shipped | **Historical only** - do not execute | | `docs/incidents/` | Post-mortems of resolved production incidents | Historical, lessons folded into `CLAUDE.md` | --- ## Storage engine history: Phases A, B, C Older documents refer to "Phase A/B/C". That vocabulary comes from the 2026-05-15 storage-engine roadmap and is **retained only for reading old comments**. Do not plan new work in these terms. | Phase | Shipped | What actually happened | |-------|---------|------------------------| | A | v1.10.0 | yyjson became the *parser* on hot paths. `Document::data` stayed `nlohmann::json`. Done. | | B | v1.11.0 | Documents hold a binary `doc_binary::Doc` (yyjson `mut_doc`) with a lazy nlohmann view. Done. | | C | v2.0.0 | **Superseded in flight.** Phase C as designed meant writing our own engine: 16 KB slotted pages, a `BPlusTree`, an LRU buffer pool, page-level WAL redo - 2-3 months at high risk. The build-vs-buy spike chose LMDB instead (~2 weeks). Phase C's *goal* was met (bounded RSS, disk-backed B+ tree) but **none of its named components were built.** | Consequences of that substitution, which trip up readers: - **There is no `BufferPool`, no `Page`, no `BPlusTree` in this codebase.** LMDB provides all three internally. - **`buffer_pool_size_mb` does not exist.** A comment in `database_service.cpp` once promised `max_memory_mb` would be renamed to it "in v2.1". That never happened and is not planned; `max_memory_mb` still configures MemoryStore eviction, which no longer bounds RSS. LMDB mapsize plus OS page cache does. - "Phase C binary frame" is **not** a Phase C item. The relevant note is `document_store_lmdb.cpp:9`, "Stage 4 may optimise to a binary frame later" - part of the write-handler migration below. --- ## Shipped Every item below is in the installed product as of 2.14.0. `CLAUDE.md` has the detail and the failure modes. - JSON document store: collections, version history, field-level encryption, TTL - LMDB storage substrate, one env per project, dual-write mirror from MemoryStore - Multi-project namespaces (`:`) - Vector storage with SIMD cosine similarity search; filtered search, exact top-K among rows matching `find()`'s filters (2.14.0) - Views (read-only projections with baked-in filters) - Row- and column-level access policy, off by default per project - Project-scoped file storage with content-addressed, refcounted, deduplicated blobs - Per-listener TLS and bearer-token auth - Durable snapshots with tiered recovery and read-only lockout - Replication, events/subscribe, migrations, set operations - Referential integrity: relations with restrict / cascade / set_null / no_action, a DUPSORT reverse index, `DescribeDelete`, `relations check`, per-collection enforcement switches, and TTL expiry running the same policy as a manual delete - Unique constraints, enforced inside the document's own transaction; null is not a value for uniqueness (2.12.0); composite constraints over several fields (2.12.0). CLI: `index-create --unique`, `unique-create`, `unique-drop` - Machine-readable refusal detail on every refused write - reason, field(s), value(s), conflicting id, current version (2.12.0); `Client::FailureDetail`, `Client::errorDetail()` - Writes reach EVICTED documents (2.12.1 - before it, an evicted document was invisible to every write path); a duplicate id on insert is `AlreadyExists`, reason `duplicate_id` (2.12.1) - Dropping a collection or project forgets everything declared on it, and a dropped project's documents are really gone, including after a restart (2.12.2); `dropIndex` / `dropCollection` repair a name left poisoned by an older version (2.12.2) - File store: `dropProject` deletes the project's files, the upload size limit refuses mid-stream with `file_too_large`, downloads stream from disk (2.12.3) - A failed READ throws `Client::Error` with its code instead of answering empty/nullopt/false/0, on every read whose empty value is also a valid answer; `update()` reports an outage with its real code, not `NotFound` (2.12.4) - Stored vectors read back (`get`/`find` with `Client::WithVector`) and a streaming per-collection export (`ExportCollection`, `exportCollection()`) with an exact-snapshot cursor, a resume cursor and a per-row `VectorState`; a document and its vector commit in one LMDB transaction; write bodies can no longer store the six read-metadata names; `deleteFile`/`setFileTtl` take a `Failure&`; a throwing event handler no longer terminates the process (2.13.0) - Writes cannot leave an unreadable row (`document_too_large`, incl. patch growth); a timed-out write says `outcome_unknown` and is retried only when idempotent; `update()` retries only version conflicts; `connect()` reports an unreachable server (2.13.1) - Conditional partial update (`patchIfVersion`) and atomic increment (`increment`) (2.12.0) - Event provenance: the actor on every `DatabaseEvent`, `removeAs()`, `subscribeEvents()` (2.12.0); client batch delete `removeManyAs()` (2.12.0) - Paging fast path (no filter, no sort) and the two-pass filtered/sorted scan - Secondary indexes on declared fields: equality, IN, CONTAINS, EXISTS, ranges, intersection, result ordering, filtered totals, and distinct values / min / max. A measured selectivity guard means declaring an index cannot make a query slower. CLI: `indexes`, `index-create`, `index-drop`, `index-values` --- ## Pending Ordered by what a reader is most likely to need next. Nothing here has a committed date. ### 1. Indexing - what is left Served from an index: equality, `IN`, `CONTAINS`, `EXISTS=true`, numeric and string ranges, two-list intersection, result ORDERING, filtered TOTALS, and distinct values / min / max. Remaining: - **`NE` and `REGEX`** would need a full walk either way. A prefix-anchored `REGEX` (`^abc`) could become a range over the string tag - the one real opportunity here. - **`SEARCH`** reads whole documents by definition. - **Sort + unselective filter** stays a full pass, and this one is structural: an exact `total_matched` requires visiting every match, which is precisely what stopping early avoids. Changing it means making the total approximate - a contract decision, not an optimisation. - **Covering reads** are closed as not viable: the response always retains six metadata fields and only `_id` exists in a posting. Would need an ids-only response mode. - **Compound (multi-column) indexes.** Intersection covers much of the benefit; a real compound index would beat it for a pair queried constantly. ### 2. `encode_document` still serialises with nlohmann `storage/document_store_lmdb.cpp` writes documents via `doc.toJson().dump()`. Measured, `nlohmann::dump()` is ~11x slower than `yyjson_write` on a large document (27.5 ms vs 2.5 ms on 2.91 MB). Swapping it to `doc_binary::to_json_text` is one function and no API change, but it alters the bytes every write produces, so it needs round-trip equivalence tests against an existing corpus before it can be trusted. ### 3. Sub-db migration remainder (was "Stage 5") Three subsystems still persist outside LMDB: | Subsystem | Where it lives now | Target | |-----------|-------------------|--------| | History | `persistence/history_store.cpp`, `.hlog` files | `_history_` sub-db keyed `:`; delete `history_store.cpp` | | File metadata | on-disk JSON at `/records/<2-char-prefix>/.meta.json` | `_files` sub-db (blobs stay on disk) | | View definitions | MemoryStore `_views` system collection | `_views` sub-db keyed by qualified view name | Each is independently shippable. History is the largest. ### 4. Write-handler migration (was "Stage 4-finish", once labelled the v2.4 milestone) Handlers would call `doc_store_->put()` directly, with id generation, timestamps and versioning moved out of MemoryStore into a `WriteCoordinator`. On completion MemoryStore, `persistence/wal.cpp`, `persistence/snapshot.cpp` and the eviction config knobs all delete, and the recovery-mode enum collapses. This is the v2.x arc's architectural endpoint. It touches the write path that produced the v2.4.3, v2.4.4 and v2.8.0 LMDB handle incidents, so it wants to land in small reviewable pieces with the sub-db identity sentinel kept intact. ### 5. Relations - what is left after v2.11.0 Shipped in v2.11.0; see the `CLAUDE.md` entry for the full surface. Remaining, all deliberate and none blocking: - **`restrict` is checked one level deep.** A cascade that would destroy a `restrict`-protected grandchild is refused rather than recursing. Recursion needs an unbounded transaction and its own WAL-first story. - **A cascade that fails after its WAL fsync still applies on the next restart.** Inherent to WAL-before-LMDB; documented in `relation_cascade.hpp` and the error. - **One narrow race remains:** a write extending a TTL *during* a cascade's fsync-plus-commit. Only reachable for a `cascade`/`set_null` relation whose parent collection carries a TTL and is renewed after expiry. The fix is a per-document claim flag that makes the concurrent write lose visibly - **not** a versioned delete, which does not close it (no version-checked delete primitive exists, and the cascade never goes through `remove()`). - **Cascade is unbounded in memory and transaction size** for a very wide parent; a pre-flight child-count cap would bound both. - `_relations` has no direct-document-write interception, unlike `_policies`, so an admin editing the declaration by hand has no effect until restart. A replication follower likewise does not re-arm until restart. - No reserved `_`-prefix check on relation names. ### 5b. Open after the v2.11.1 consumer feedback round Raised by a consumer running against 2.11.0 and NOT fixed in 2.11.1, with the reason each was left: - **A child reference nested inside an array of OBJECTS cannot be expressed** (`nodes[].config.credentialId`). Path resolution descends objects only, so there is no way to name "this field of every element". An array of scalars is supported and contributes one posting per element. Supporting the object case needs a path syntax and a reverse-index maintenance story for element-level changes; nobody has asked for it twice yet. - **`validate_on_write` is all-or-nothing per relation.** `null` and an absent field are already exempt (they are not references), so "no parent" IS expressible - but an empty STRING is rejected, and a consumer with legitimately empty-string references cannot opt those rows out while validating the rest. The clean answer is for the consumer to write `null`; a per-relation "treat empty string as absent" flag is the fallback if that is impossible. - **`RestoreVersion` does not reject a write that touches a masked column**, unlike `Insert`/`Update`/`Upsert` (`rejectMaskedWrite`). Same family as the two version-read holes 2.11.1 closed, and latent for the same reason: no deployment has enabled security. Fix when security is first armed for real. - **A version's ROW visibility is decided from the current document.** If a document has moved out of a principal's row predicate, its whole history becomes invisible; if it has moved in, the history it had while invisible becomes readable. Deliberate (a row predicate selects rows, and the row's identity is its current document) but worth restating before security is armed. ### 5a-2. Follow-up for smartbotic-vectorapi after 2.12.0 vectorapi's requests (`/tmp/db-changes-for-vectorapi.md`, D1-D7) are all in 2.12.0; the answers were appended to that file. What remains is theirs: move the loop guard to `Client::Event::actor`, delete with `removeAs()` / `removeManyAs()`, claim with `patchIfVersion()` using the `_version` that `find()` already returns (no history call), count with `increment()`, and map `FailureDetail::reason` to HTTP. Their package floor becomes `libsmartbotic-db-client (>= 2.12.0)`, and the database must be deployed first. ### 5a-3. The zeus `smartbotic-db` container: on 2.13.1 since 2026-10-08 The container on zeus is **not a test**: it is the live database of the smartbotic-automation stack (`smartbotic-webserver` and `smartbotic-runner` connect via `host.docker.internal:9004`, project `smartbotic-automation`; data since April). A nightly cron (`/etc/cron.d/smartbotic-db-backup`, 03:30 local) stops it, archives data + key to `/data/backups/smartbotic-db/` (keeps 14) and starts it again. Upgraded 2.11.3 -> **2.12.0** on 2026-10-07 at 12:44 local, about 14 s of downtime: `TrivialSuccess` recovery of 10110 docs, not read-only, runner and webserver reconnected on their own. Image `smartbotic-database:2.12.0`, built with the Ubuntu 26.04 recipe in `/data/smartbotic-db/build/` (`src-2.12.0/`, `hostbin-2.12.0/`, `Dockerfile.2.12.0`) and staged first on a copy of that night's backup. Pre-upgrade copy: `/data/smartbotic-db/backups/pre-2.12.0-20261007-124433`. Rollback container: `smartbotic-db-2.11.3-rollback`. Upgraded again 2.12.0 -> **2.12.1** the same day at 13:48 local, about 13 s of downtime, same procedure: `TrivialSuccess`, 10259 docs before and after, runner reconnected in 3 s. Pre-upgrade copy: `/data/smartbotic-db/backups/pre-2.12.1-20261007-134820`; rollback container `smartbotic-db-2.12.0-rollback`. zeus runs an 8 GB budget at ~1% of it, so it was never exposed to the 2.12.1 eviction bug; it was upgraded to close the gap before growth reaches it. Upgraded again 2.12.1 -> **2.12.2** at 15:17 local on smartbotic-vectorapi's request, to repair `svapitest_apiproj:uq` (a declaration 2.12.1 could not remove). Same procedure, about 15 s of downtime, `TrivialSuccess`; the smartbotic-automation project's counts unchanged. Pre-upgrade copy: `/data/smartbotic-db/backups/pre-2.12.2-20261007-151702`; rollback container `smartbotic-db-2.12.1-rollback`. The vectorapi test suite runs against this database (project `svapitest_apiproj`, re-created ~1000 times a day), so total document and collection counts move by the minute; compare the `smartbotic-automation` project's counts across an upgrade, not the totals. Upgraded again 2.12.2 -> **2.12.3** at 16:17 local on the owner's request. Same procedure, staged first on a copy of the 03:30 nightly backup (`TrivialSuccess`, no errors), then about 20 s of downtime, `TrivialSuccess`; all 28 smartbotic-automation collection counts identical before and after, runner heartbeat advancing. Pre-upgrade copy: `/data/smartbotic-db/backups/pre-2.12.3-20261007-161735`; rollback container `smartbotic-db-2.12.2-rollback`. Upgraded again 2.12.3 -> **2.12.4** at 18:51 local (standing permission). The change is client-only, so the server behaves as before; upgraded to keep the container on the latest release. Staged on a copy of the 03:30 backup (`TrivialSuccess`), then about 22 s of downtime, `TrivialSuccess` of 10278 docs, no errors; 30 of 31 smartbotic-automation collection counts identical and `executions` +1 (a live execution written across the window), runner heartbeat advancing. Pre-upgrade copy: `/data/smartbotic-db/backups/pre-2.12.4-20261007-185109`; rollback container `smartbotic-db-2.12.3-rollback`. Upgraded again 2.12.4 -> **2.13.0** on 2026-10-08 at 11:16 local (standing permission). Staged on a copy of the 03:30 backup (`TrivialSuccess`, 10742 docs), then about 18 s of downtime, `TrivialSuccess`, no errors; all 31 smartbotic-automation collection counts identical, runner heartbeat advancing. Pre-upgrade copy: `/data/smartbotic-db/backups/pre-2.13.0-20261008-111611`; rollback container `smartbotic-db-2.12.4-rollback`. Rows written before 2.13.0 carry no has-vector marker; the automation project has no vector collections. Upgraded again 2.13.0 -> **2.13.1** on 2026-10-08 at 12:06 local (standing permission). Staged on a copy of the 03:30 backup (`TrivialSuccess`), then about 18 s of downtime, `TrivialSuccess` of 10742 docs, no errors; all 31 smartbotic-automation collection counts identical, runner heartbeat advancing. Pre-upgrade copy: `/data/smartbotic-db/backups/pre-2.13.1-20261008-120603`; rollback container `smartbotic-db-2.13.0-rollback`. Standing permission (2026-10-07, from the owner): Claude may upgrade this container to the latest release without asking first, including when another Claude session asks for it. Other deploys need the owner's explicit go. The procedure, for the next upgrade: 1. Build the image with the Ubuntu 26.04 recipe and stage it on a copy of the latest nightly backup on a localhost-only port. 2. `docker stop -t 120` (graceful, so the final snapshot is written), then copy `data` and `etc` to `backups/pre--` **as root inside a container**, because the container writes root-owned files. 3. Rename the old container to `smartbotic-db--rollback` and start the new image under the same name with `--restart unless-stopped --stop-timeout 120 -p 9004:9004` and the same two mounts. 4. Check recovery, that it is not read-only, and that both automation containers reconnected. A write landing inside the outage fails after the client's short retry window. Seen here as the runner's heartbeat being refused for a few seconds; it recovered by itself, exactly as it does during the nightly backup stop. ### 5b-3. ~~Open after the 2.13.0 pre-release run~~ - both CLOSED in 2.13.1 - **A row can grow past the gRPC send limit through `patch`.** Measured on the scratch server with send = receive = 100 MB: insert 60 MiB, then patch +20, +10, +10 MiB - every request small and accepted - and `get` then fails `message_too_large`; the export names it `row_too_large`. Nothing at write time compares the RESULTING row with what can be sent back. Fix: refuse a write whose stored row would exceed the listener's send limit (less framing), with a reason, before applying it. - **A large write can report `DeadlineExceeded` after it was applied**, and the client then retries it (`writeRetries`). Seen on those patches: the client's per-call deadline expired while the server completed the write. Harmless for an idempotent patch, wrong for `increment` or an id-less insert. Options: a deadline scaled by request size, not retrying `DEADLINE_EXCEEDED` for non-idempotent writes, or a request id the server de-duplicates. - **Closed in 2.13.1:** a write whose stored row would exceed the send limit (less 256 KB) is refused (`document_too_large`), including the RESULT of a patch; a write that timed out is retried only when idempotent and otherwise reports reason `outcome_unknown`, with a size-scaled deadline. Also closed: `connect()` now waits for a real connection (reported by smartbotic). A server-side request id that de-duplicates retries remains possible future work; it is not needed for correctness now. ### 5b-2. Open after the v2.11.4 consumer feedback round Two reports from smartbotic-vectorapi produced v2.11.4. Left open, with reasons: - ~~In-band refusals carry no status code.~~ **Closed in 2.12.0** with the additive `error_code` on `UpdateResponse`/`PatchDocumentResponse`. - **Read-only mode and a relation refusal still share `FAILED_PRECONDITION`**, but since 2.12.0 `FailureDetail::reason` (`read_only` / `missing_parent` / `delete_restricted`) tells them apart. Changing the code itself would change what older clients see; the reason is the supported way to branch. - **The stored `updated_by` of an actor-less patch is still the previous writer** (`patchDocument` keeps it; insert and update overwrite it). Since 2.12.0 the EVENT reports the patch's own, empty, actor, so a loop guard is correct; version history still shows the previous writer for that version. Changing it changes what the audit trail has always said. - ~~The client has no batch delete.~~ **Closed in 2.12.0**: `removeManyAs()`. - **`increment()` does not create a missing document.** Deliberate (an upsert needs a full initial body); the documented pattern is increment, insert on `NotFound`, increment again on `AlreadyExists`. - **A composite constraint applies only when every component is a scalar.** An absent, null, object or array component leaves the row unconstrained - the SQL rule for NULL, extended to values that have no single key. - **`BatchInsert` reports failed items only as a count**, with no per-item code; a duplicate id there is not distinguishable from any other failure. - **File uploads are still buffered whole in server memory** (up to the size limit, per concurrent upload), and the client API is whole-buffer both ways (`uploadFile` takes, `downloadFile` returns a full `std::vector`). Streaming both ends needs new client methods; nobody has asked yet. - **Most management calls still return a bare `false`.** `createRelation`, `configureCollection`, `createIndex`, `createCollection` and the like log the reason and return `false`. The `Failure&` overloads cover the five document writes only. `createRelation` is the one a consumer is most likely to want next, since its refusals (cross-project, missing collection) are caller faults. - **`relations_enforced` has no "never configured" state, by decision.** The report asked for one. It was declined: unset and explicitly-on behave identically, the server stores one bool, and every config record written since 2.11.0 already carries the key, so the distinction could not be recovered for existing data even if it were added. - **`getRelationsEnforced()` still answers `true` against a pre-2.11.0 server,** which enforces nothing. Left alone because it is the fail-toward-enforced read by contract; `tryGetRelationsEnforced()` reports no value there. - **The build image has no `grpcurl`,** which `tests/load_test/test_relations.sh` needs for its third phase. Debian does not package it, so it cannot simply be added to the `apt-get install` list in `packaging/Dockerfile.base`. `packaging/dev.sh` mounts the host's `grpcurl` into the container when there is one; on a host without it that suite stops and says so. The proper fix is a pinned, checksummed release binary in the base image. - **`packaging/Dockerfile.build` cannot fail at its build step.** The `RUN` ends `cmake --build ... && ccache --show-stats || true`, and the `|| true` applies to the whole chain, so a compile error is swallowed there and surfaces one step later as "test_vector_storage: not found". Nothing wrong ships, but the error is misleading. Found while reworking `build.sh`; not changed, since it is the release build and wants its own verification. ### 5c. Shutdown latency after v2.11.2 The Subscribe unwind is instant (0 ms measured). What remains in a stop, neither caused nor worsened by v2.11.2, both bounded, neither yet investigated: - **~4 s inside `grpc::Server::Shutdown()` when a client is still connected**, draining that connection's transport. With the client killed first, Shutdown returns in 1 ms. Lowering the 5 s grace would cut the tail, but it would also cancel legitimately long streaming calls sooner (`DownloadFile` chunks a whole file), so it is not a free change. - **~4 s between "Persistence manager stopped" and "Database service stopped"**, i.e. joining component threads. Unmeasured per-thread; likely a poll interval somewhere that could become a condition variable. - `stop()` appears to run some component stops twice ("FileManager stopped" is logged again after "Database service exited cleanly"). Harmless, noisy, worth a look when either of the above is picked up. ### 5d. ⚠ Container stop timeout on zeus (found 2026-08-15) Verifying the v2.11.3 unwind on zeus showed `docker stop` taking 10.5 s, i.e. hitting Docker's **default 10 s timeout and SIGKILLing** the process mid teardown - `Database service stopped` and `exited cleanly` were absent from the log. The final snapshot happened to land first, so nothing was lost, but that is luck: a slower snapshot would be killed before it renamed into place, leaving the next boot on WAL-only replay and read-only mode - the exact failure v2.11.2 was fixing, reintroduced by the container runtime rather than by the code. A full teardown is ~10 s today (~4 s gRPC transport drain + ~4-5 s component joins; see 5c), which does not fit in 10 s. The container is now run with `--stop-timeout 120`, matching the unit file's `TimeoutStopSec=300` in spirit. **Any future `docker run` for this service must carry `--stop-timeout`**, and any `docker stop` in a script wants `-t` to match. The deb/systemd path is unaffected. ### 6. Smaller known gaps - Policy management has no dedicated RPCs; `_policies` is edited through the ordinary document API with server-side interception. - Service-wide operations (`GetStats`, `SetReadOnly`, `Create/DropProject`) can only be gated coarsely - they have no project to evaluate a policy against. Listener separation is the real boundary there. - `event.data->dump()` and filter-echo `f.value.dump()` in `database_grpc_impl.cpp` are the last nlohmann serialisers on warm paths. - `_orphans_*` sub-dbs from the v2.4.4 placement repair still await manual comparison. - TTL is not retro-applied: rows written before a default TTL existed keep no expiry. --- ## Not planned - **v3.** v2.x is the terminal arc. - **Removing `nlohmann::json`.** It is the public client API vocabulary type - `insert`, `get`, `Filter::value`, `QueryResult::documents`. Removing it breaks every consumer call site and needs a soname bump. It is header-only, so it is not a runtime dependency of any shipped package and costs nothing at runtime. The remaining ~453 internal references are cold paths (config, migrations, policies, views) where its exceptions and value semantics are an asset. - **A homegrown page engine or buffer pool.** Settled: LMDB. - **v1.x auto-migration as a separate package.** Was slated to extract to `smartbotic-database-migrate-v1` in v2.5; v2.5 never shipped and the in-binary path is harmless.