Repository navigation
Closed
Description
Goal
Validate and implement the migration of the local embedded database from SurrealDB (RocksDB backend) to SQLite via the libsql Rust driver. The cloud DB stays SurrealDB — this is a local-only change.
Motivation
- Inspectable — DB Browser, sqlite3 CLI, and standard tooling work with SQLite files. SurrealDB embedded (RocksDB) is opaque — no dev tooling.
- Leaner — SurrealDB embedded carries graph engine, RLS, LIVE SELECT, and query parser machinery that is irrelevant locally. Local DB has no access control — if data is in the local DB, the user has access by definition.
- Simpler — Local operations are just CRUD + graph traversal. No SurrealQL needed. Standard SQL +
WITH RECURSIVEcovers everything. - Async-native —
libsqlis async-native Rust. Nospawn_blockingwrappers needed (unlikerusqlite). - access_tags cloud-only — Local schema is clean with no ACL fields. CloudSyncService enforces what flows in and purges revoked data.
Architecture Context
Local: libsql (SQLite file, local mode) — lean, inspectable, no ACL
Cloud: SurrealDB (Cloud or self-hosted) — RLS, LIVE SELECT, Stamped ACL, namespace-per-tenant
Bridge: CloudSyncService — enforces what flows between them, purges revoked data locally
CloudSyncService talks to NodeService via domain events broadcast channel — it never touches the storage layer directly. The abstraction means CloudSyncService (nodespace-sync) requires no changes for this migration.
Validation Points
Phase 1 — File format compatibility
- Create a SQLite file via
libsqllocal mode (no Turso sync features) - Confirm DB Browser for SQLite can open and read it correctly
- Confirm
sqlite3CLI can open it - Confirm no WAL/SHM artifacts when app is not running
Phase 2 — Schema design
-
nodetable — id, type, content, properties (JSON), title, lifecycle_status, version, sync_seq, created_at, modified_at -
relationshiptable — in (FK → node), out (FK → node), type, created_at (no access_tags — cloud only) -
embeddingtable — node_id (FK → node), vector (BLOB), model, created_at -
WITH RECURSIVECTE for graph traversal (children tree, ancestor path) -
sqlite-vecextension for HNSW vector search - Cascade delete: node deletion removes relationships atomically (FK + trigger or explicit transaction)
Phase 3 — NodeService implementation
- Replace
surreal_store.rswithsqlite_store.rsbacked bylibsql - Implement all
NodeServicestorage operations: create/get/update/delete node, create/delete relationship, get_children, vector search - Domain event broadcast unchanged — NodeService already owns this
- All existing NodeService tests pass against SQLite backend
Phase 4 — Performance validation
- Basic CRUD latency vs SurrealDB embedded (hypothesis: faster, less overhead)
-
WITH RECURSIVEgraph traversal for a 1000-node tree -
sqlite-vecHNSW search across 10k embeddings
Key Decisions Already Made
libsqloverrusqlite— async-native, nospawn_blocking, standard SQLite file format in local mode, no Turso cloud coupling neededsqlite-vecover separate embedding store — keeps everything in one file, simpler ops- No access_tags locally — cloud-only concern. Close Stamp access_tags on relationships (local schema + NodeService) #1217.
- Cloud DB stays SurrealDB — this migration is local-only, CloudSyncService unchanged
Success Criteria
- DB Browser reads libsql-created SQLite file correctly (Phase 1)
- All NodeService operations implemented and tested against SQLite
- Graph traversal (
get_children, ancestor path) correct viaWITH RECURSIVE - Vector search works via
sqlite-vec - All existing NodeService tests pass
- nodespace-sync smoke test passes (CloudSyncService unaffected)
Related
- Closes nodespace-sync Precision Cursor Positioning for Click-to-Edit Text #81 (LanceDB/Neon experiment — superseded by this decision)
- Closes Stamp access_tags on relationships (local schema + NodeService) #1217 (access_tags on local relationships — not needed, cloud-only)
- ADR-025 (Stamped ACL — cloud-only, unchanged)
- ADR-027 (local-first sync — unchanged)
- ADR-031 (daemon-client architecture — unchanged)
- nodespace-sync CloudSyncService — no changes required
Metadata
Metadata
Assignees
Labels
No labels
Activity
malibio commentedon May 28, 2026
Frontend baseline: 93 failed | 3843 passed (pre-existing persistence/layout test failures unrelated to SQLite migration)
WIP: Phases 4-5 complete — all compile errors fixed, all tests passing
Migrate local DB from SurrealDB to SQLite (libsql) (closes #1219)
Migrate local DB from SurrealDB embedded to SQLite (libsql) (#1222)