Skip to content

feat(id): libsql HTTP adapter v1 — read-only foreign store (#7577) - #8115

Merged
dezren39 merged 1 commit into
mainfrom
queue/14504-7577-libsql-adapter
Nov 10, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/14504-7577-libsql-adapter

Conversation

@dezren39

@dezren39 dezren39 commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Closes #7577. Implements the #5806 decision record (B3 under #5672 Part B) exactly as recorded; no parent decision is re-decided.

What lands

pkgs/id/src/foreign_libsql.rs — a read-only Turso/libsql HTTP adapter v1:

  • Protocol: raw libsql HTTP v2 pipeline (JSON) over a hand-rolled HTTP/1.1 transport (TCP, rustls for https) — not the libsql crate, not Hrana-over-WebSocket. One pipeline request carries one execute + close under a null baton.
  • Addressing/credentials: stores are id://foreign/libsql/<alias>; the alias resolves only in local operator config to {url, credential reference}. The token is resolved per call (env: references built in; other stores plug in via CredentialResolver), never stored, logged, or placed in errors — auth errors name the reference only.
  • Read-only by construction: queries are a structured GrantedQuery (table + granted columns + mandatory grant predicate + optional filter + limit) compiled to a single SELECT. Write shapes cannot be expressed; fragments with write keywords or statement separators are refused.
  • Existence privacy: the grant predicate is pushed into the remote query; ungranted rows are never fetched. Not-found and not-granted return the identical empty result; server bodies are never copied into errors; the only exposed schema is the granted view.
  • Type mapping (record item 5), validated in both directions: u64 > i64::MAX as 8-byte big-endian BLOB (never REAL), bool as INTEGER 0/1, NULL distinct from empty TEXT/BLOB, non-UTF-8 TEXT rejected, server affinity mismatches are TypeMismatch errors — never silent coercions. Oversize BLOBs are refused with a named size error, never truncated.
  • Errors/resilience (record item 7): connect 5s, per-statement deadline 30s default per alias; auth fatal and unretried; transient network/5xx/timeout retried up to 3 attempts with bounded backoff; per-alias circuit breaker opens after 5 consecutive transient failures and half-opens after 30s. Adapter failures cannot block native (redb) operations.

Dependencies (per pkgs/id AGENTS.md disclosure)

Three direct deps added to the root id package, all already present in Cargo.lock via iroh/quinn — the lock diff is +3 lines (edges on the id package only, no new packages): rustls 0.23 (ring/std/tls12), tokio-rustls 0.26 (ring/tls12), webpki-roots 1. No SQLite-family dependency is added.

Tests (oracles named per the testing doctrine)

17 new tests in foreign_libsql::tests, each citing its oracle (record item or wire format): the five lossy corners (u64 > i64::MAX, f64 precision, non-UTF-8 bytes, NULL vs empty, bool encoding), grant push-down SQL shape, write/missing-grant refusal, auth fatality + reference-only errors, bounded 5xx retry, malformed-response determinism, circuit breaker open/half-open/close, pipeline wire round-trip under contract, and a live pass-through round trip over real HTTP against a local listener playing the sqld endpoint (verifies POST /v2/pipeline, bearer header, grant-pushed SQL). A real Turso-cloud endpoint was not used: no credential is available to the fleet lane; the live test's oracle is the protocol wire format itself.

  • cargo test -p id --lib foreign_libsql — 17 passed
  • cargo test -p id --lib test_the_lock_has_no_sqlite_with_logsync_wired — passes unmodified; FUEL_BUDGETS untouched
  • cargo check -p id --lib — clean, no new warnings in the module

Queue: task 14504, lane code-p. Worktree note: an accidental package-wide cargo fmt during development reformatted 7 unrelated files in the task worktree; those changes were discarded before push and are not in this PR.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Implements the #5806 decision record (B3 under #5672): raw libsql HTTP v2 pipeline client in pkgs/id/src/foreign_libsql.rs — no libsql crate, no SQLite-family dependency (guard test passes unmodified, FUEL_BUDGETS untouched). Structured GrantedQuery pushes the grant predicate into the remote SELECT; writes are unrepresentable and write fragments are refused. Type mapping validates both directions per record item 5 (u64>i64::MAX as 8-byte BE blob, bool as 0/1, NULL distinct from empty, non-UTF8 TEXT rejected, type mismatch is an error). Per-alias circuit breaker, bounded read retries, fatal auth naming the credential reference only. 17 oracle-named tests pass, including a live local-HTTP round trip.
@dezren39
dezren39 requested a review from a team as a code owner November 10, 2026 04:01
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-10T04:01:11.559270Z
We couldn’t complete this review. Comment @codex review to try again.
64c03be PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Nov 10, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 44 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1926a068-6952-49bb-a307-bc19f8af0997
Commits

Reviewing files that changed from the base of the PR and between a849685 and 64c03be.

Files ignored due to path filters: 1

  • pkgs/id/Cargo.lock is excluded by !**/*.lock
Files selected for processing: 3

  • pkgs/id/Cargo.toml
  • pkgs/id/src/foreign_libsql.rs
  • pkgs/id/src/lib.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@dezren39

Copy link
Copy Markdown
Member Author

🤖 Agent note · review disposition (task 14504, lane code-p)

  • Codex (chatgpt-codex-connector[bot]): review-limit blocked — its only comments state the Codex usage limit for code reviews is reached. Zero findings were produced in any round; there is nothing undispositioned.
  • CodeRabbit: rate-limit blocked (free OSS review limit; summary comment only). Zero findings.
  • Self-review by this lane: diff is the 4 files described in the PR body; targeted tests verified on the laptop (17/17 adapter tests, shipped-build guard test green, cargo check clean). Merging under the standing merge criteria on that verification.

@dezren39
dezren39 merged commit c1f200e into main Nov 10, 2026
6 of 9 checks passed
@dezren39
dezren39 deleted the queue/14504-7577-libsql-adapter branch November 10, 2026 04:04
@dezren39

Copy link
Copy Markdown
Member Author

Follow-up issue #8798 tracks the newly identified half-open circuit-breaker concurrency gap: allow() admits every caller while a recovery probe is in flight. The issue body includes evidence and acceptance criteria.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

id: implement Turso/libsql HTTP adapter v1 (read-only, live) per #5806 decision record

1 participant