RFC/draft: opt-in libSQL/Turso storage backend for concurrent multi-writer memory#262
Draft
Donach wants to merge 2 commits into
Draft
RFC/draft: opt-in libSQL/Turso storage backend for concurrent multi-writer memory#262Donach wants to merge 2 commits into
Donach wants to merge 2 commits into
Conversation
…ite) Re-architect the Turso backend as a thin overlay to minimise the diff against upstream (store.rs is upstream's most-churned file → fewer rebase conflicts). dbcompat is now a faithful rusqlite-0.34-shaped drop-in (exact Params model: empty [], [T;1..32], &[&dyn ToSql]; params! -> &[&dyn ToSql]; phantom-lifetime Row<'_>; types::ToSql). store.rs/schema.rs are byte-identical to upstream except 'use crate::dbcompat as rusqlite;' plus the connection-open path (open_backend + remote PRAGMA guard) — store.rs touched lines: 206 -> ~15 + one isolated fn; schema.rs: 34 -> 3. Tests: 161 pass / 1 perf-test fail (same as before). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Turn the Turso support into a mutually-exclusive Cargo feature so it's purely additive for existing users: - default (`backend-rusqlite`) = upstream rusqlite, untouched — store.rs/schema.rs are byte-identical apart from cfg-gated imports and the connection-open path. - `--no-default-features --features turso` routes the same SQL through the libSQL-backed dbcompat shim (aliased as `rusqlite`). rusqlite is then absent, so there's no extern/alias clash. Backends are mutually exclusive (compile_error guards if both/neither). - Feature plumbed through icm-mcp + icm-cli; flake builds the turso binary. Tests: default 162/162; turso 161/162 (only perf_fts_search_100, documented). Docs: docs/turso-backend.md. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary — opt-in libSQL/Turso storage backend (draft / RFC)
ICM keeps memory in a single local SQLite file, so it can't be shared or written
concurrently from more than one machine/process. This adds an opt-in backend
that runs the existing
icm-storeSQL over the asynclibsqlclient, so thestore can live in a libSQL/Turso database — local file, a remote
sqld/Tursoserver, or an embedded replica. A remote server is the multi-writer path (it
serialises writes from every ICM process).
The default build is completely unchanged —
rusqlite, exactly as today. Thetwo backends are mutually-exclusive Cargo features. Still a draft: I'd like
your read on whether you want this at all and how you'd shape it before polishing.
What changed
icm-storegains a small sync-over-async facade (crates/icm-store/src/dbcompat.rs)mirroring the slice of the rusqlite API the store uses. Under
--features tursoit's aliased as
rusqlite, sostore.rs/schema.rsare byte-identical to thedefault build apart from cfg-gated imports and the connection-open path.
backend-rusqlite→ upstream rusqlite, untouched.cargo build -p icm-cli --no-default-features --features turso,embeddings,tui→ libSQL. With rusqlite absent there's no extern/alias clash;
compile_error!guards reject enabling both/neither.
icm-mcp+icm-cli. Runtime backend chosen by env(
TURSO_DATABASE_URL/LIBSQL_URL+TURSO_AUTH_TOKEN;ICM_TURSO_REPLICA=1).Verified
icm-storetests pass (unchanged behaviour).perf_fts_search_100regresses (see gaps).sqld(sqlite-vec loaded via--extensions-path):store/recall, and 16 concurrent
icmprocesses wrote with zero lost rows.Honest remaining gaps
block_onper call, soperf_fts_search_100regresses on the turso build (worse over the network).Wants connection reuse or an async store path — I'd value your steer here.
backends, but CI for the turso feature would need a spun-up
sqld(or thein-memory path).
use crate::dbcompat as rusqlite;alias keeps the diff tiny but isunusual — happy to refactor toward a
Storagetrait if you'd prefer.sqlite-vecmust be loaded server-side for the vector schema; embeddedreplicas can't forward the
vec0DDL (so remote is the vector path).Questions
icm cloudisalready Turso-backed — or is hosted-only intentional?
develop?connection pooling?
Branched off
main@804dac2for a clean diff; glad to rebase ontodevelop.Setup + verified results in
docs/turso-backend.md.Disclosure: implemented with AI assistance and human-reviewed; commits carry a
Co-Authored-Bytrailer. Flagging it up front.